My function does not calculate a simple math operation

I am doing Celsius and Fahrenheit Temperature Calculator

In Python, I completely conceive

I have Python 3.3

So, I made this function to calculate the Farenheit value for 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 value itself, it does not perform math operations

Hope you help me guys.

+4
source share
4 answers

Your real problem is here:

 int(5/9) 

5/9 gives you 0.555 , which when you click on int() gives you 0

Try the following:

 print((int(Fvalue) - 32) * 5/9) 
+2
source

The problem is that you have chosen the 5/9 value for int , which will give you a value of 0. Just delete the cast and everything will be fine. And also you need to add brackets around the subtraction.

Change your print statement to:

 print((int(Fvalue) - 32) * 5/9) 
+2
source

int((5/9)) gives 0, so int(32) * int((5/9)) is 0, so you just print Fvalue

This should fix your problem:

 print((int(Fvalue) - 32) * 5.0 / 9)) 

Using simple math, this expression will be cleaner:

 print (Fvalue - 32) / 1.8 
0
source

Your code should be as below, u does not require casting for integers 32 and (5/9),

 def C(): print('Enter a temperature:') Fvalue = input() print(int(Fvalue) - 32 * 5/9) 
0
source

Source: https://habr.com/ru/post/1489567/


All Articles