Reputation: 75
I'm making a Temperature Calculator Celsius and Farenheit
I'm a completely begginer in Python
I have Python 3.3
So, I made this function to calculate a Farenheit value to a Celsius value
def C():
print('Enter a temperature:')
Fvalue = input()
print(int(Fvalue) - int(32) * int((5/9)))
I run it and it just prints the Fvalue itself, it doesn't make the math operations
I hope you can help me guys
Upvotes: 4
Views: 181
Reputation:
Your code be should be as given below, u don't require casting for integers 32 and (5/9),
def C():
print('Enter a temperature:')
Fvalue = input()
print(int(Fvalue) - 32 * 5/9)
Upvotes: 0
Reputation: 213223
The problem is, you are casting the value of 5 / 9
to an int
, which will give you 0 as a value. Just remove the cast, and it will be fine. And also you need to add parenthesis around the subtraction.
Change your print statement to:
print((int(Fvalue) - 32) * 5/9)
Upvotes: 2
Reputation: 27792
int((5/9))
gives you 0, so int(32) * int((5/9))
is 0, so you simply print Fvalue
This should fix your issue:
print((int(Fvalue) - 32) * 5.0 / 9))
With some easy math, this expression would be cleaner:
print (Fvalue - 32) / 1.8
Upvotes: 0
Reputation: 99620
Your real problem lies here:
int(5/9)
5/9
gives you 0.555
which when cast to int()
gives you 0
Try this:
print((int(Fvalue) - 32) * 5/9)
Upvotes: 2