1

For a challenge I am tasked with creating a unit converter that can change the units. I chose degrees Celsius to Fahrenheit. I am quite new to Python. My problem is that I ask a question on the code e.g.

print("Enter Value: ")

How do I make it so that the value that a user enters becomes the variable f for Fahrenheit which can then be changed to Celsius so I can do this..

print((f - 32) / 1.8)

Can anyone help and explain it in a way a beginner can understand?

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Sam
  • 43
  • 1

3 Answers3

1

Assuming you're using Python3, what you need is:

temp=input("Temperature please?")
print((int(temp)-32)/1.8)

Also, please look up the docs Jacek linked to so that you understand what's really going on here.

Anomitra
  • 1,111
  • 15
  • 31
0

Use input() function: Input and Output Docs

Jacek Zygiel
  • 153
  • 1
  • 9
0
temp = 0

# while loop
# wait until user set a input
while not temp:
  # default type in input is "str"
  user_input = input("Enter Value: ")
  if user_input.isdigit():
    temp = user_input

# we know every char is digit 
print (((int(temp)-32)/1.8))
Ari Gold
  • 1,528
  • 11
  • 18