-2

I am making a Celsius to Fahrenheit computer, but when I take the user's input, the program crashes.

I tried using raw_input, but i've got python 3.6.

print("Enter Celsius degrees to convert them into Fahrenheit degrees: ")
x = input()
y = x * 9 / 5 + 32
print(y)
input()

It should take the input, then automatically convert it into Fahrenheit, then print the Fahrenheit degrees.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • And what actually happens? I mean, I know, but a good question details what is the actual outcome versus the expected one. your problem is that `input` returns a string. you want to do: `x = float(input())` to solve the problem – Tomerikoo Jul 18 '19 at 10:04
  • `input()` function returns `string`. You can cast it – Orestis Zekai Jul 18 '19 at 10:04
  • Thank you.I didn't know the input always returns strings.You solved my problem. – bencxikyoungg Jul 18 '19 at 10:10

1 Answers1

0

Function input() returns only string. Even if you type a number, the value in variable x will be string. For example, you type 20 as input. x == "20" will be true, but x == 20 will be false. For this reason you must convert your x into int or float to be able to use arithmetical operation using x . You can do it in two place.

  1. When you are read data from input x = float(input())

  2. Or when you use x to convert from Celsius to Fahrenheit y = float(x) * 9 / 5 + 32

Michalsz99
  • 16
  • 3