two inputs in one function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

two inputs in one function ?

I’m trying to create a code for conversion of Celsius (C) to Fahrenheit (F) and vice verse, also to ask the user if they want the conversion from C to F or from F to C. This is the code i wrote: __________________________________________ def C_to_F(x): return x, "celsius →", x * (9/5) + 32, "fahrenheit" def F_to_C(x): return x, "fahrenheit →", (x - 32) / (9/5), "celsius" def conversion(n): y = int(input("To convert C to F press 1. To Convert F to C press 2 ")) if y == 1: return C_to_F(n) elif y == 2: return F_to_C(n) else: return None print(conversion(43)) _____________________________________ So far, it works, but i have to put in the temperature value in the print function, in this case print(conversion(43)). What i want is the user to put in the value, but i cant find a way of putting one more input command in the code without getting an error. Can you give me some advice please. How can i put two inputs in a funcion?

28th Jan 2021, 3:02 PM
Goran
2 Answers
+ 3
you mean print (conversion(int(input()),right ? If yes enter inputs as follow: 43 1 or 2
28th Jan 2021, 3:09 PM
Abhay
Abhay - avatar
+ 2
Taking 2 inputs in the same program is totally possible. x = int(input("Enter x: ")) y = int(input("Enter y: ")) print("x =", x, "y =", y) You can take an input just before the print statement and pass it to conversion() n = int(input("Enter value: ")) print(conversion(n))
28th Jan 2021, 3:08 PM
XXX
XXX - avatar