Trying to make a unit converter in python but the input value is not being acted upon -


i new python , have written,

print(" please type : \nmeters = m \ncentimeters = cm \nkilometers = km ")  print("please enter unit of input value") unit1 = input() print("please enter unit of output value") unit2 = input() print("please enter value") value = int(input())  def calculator():     if unit1 == "m" , unit2 == "cm":         value == value * 100     elif unit1 == "m" , unit2 == "km":         value == value / 1000     elif unit1 == "m" , unit2 == "m":          value == value     elif unit1 == "cm" , unit2 == "m":         value == value / 1000     elif unit1 == "cm" , unit2 == "km":         value == value / 100000     elif unit1 == "cm" , unit2 == "cm":         value == value     elif unit1 == "km" , unit2 == "cm":         value == value * 100000     elif unit1 == "km" , unit2 == "m":         value == value * 1000     elif unit1 == "km" , unit2 == "km":         value == value     else:         print("the unit entered not valid")  calculator() print("your value is...") print(value, unit2) 

when use code no effect taken on value. value outputs inputted as.

thanks

value , unit2 global variables user has given input. made function calculator not passing values , print(value, unit2) gets evaluated results in printing user defined value of value , unit2.

you need pass value, unit1 & unit2 in calculator method , need take these variables arguments while calculating final value. lastly need return value came from.

basically code should this:

def calculator(value, unit1, unit2):     # if-elif loop     else:         return("the unit entered not valid")     return value  print("your value is...") print(calculator(value, unit1, unit2)) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -