multiple Inputs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

multiple Inputs

In python, how to make it so that the user can only enter one of the multiple inputs.

14th Jun 2021, 7:24 AM
Yogeshwara Sai Kurapaty
11 Answers
+ 5
You could set up an if / elif / else statement to discriminate which which input to use. example: unit = input() if unit == "K": use the kelvin code section elif unit == etc.....
14th Jun 2021, 7:55 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
Yogeshwara Sai Kurapaty Something like this unit = input() temperature = float(input()) K = 0 F = 0 C = 0 if unit == 'K': K = temperature elif unit == 'F': F = temperature else: C = temperature A = K-273.15 B = A*1.8+32 M = round (A, 4) N = round (B, 4) I = "{} Kelvin = {} Celcius and {} Farenheight".format (K, M, N) print (I) D = (F-32)*(5/9) E = D+273.15 O = round (D, 4) P = round (E, 4) J = "{} Fahrenheit = {} Celcius and {} Kelvin".format (F, O, P) print (J) G = C + 273.15 H = C * 1.8 + 32 Q = round (G, 4) S = round (H, 4) L = "{} Celcius = {} Kelvin and {} Fahrenheit".format (C, Q, S) print (L)
14th Jun 2021, 8:02 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Can you give an example please
14th Jun 2021, 7:47 AM
Rik Wittkopp
Rik Wittkopp - avatar
14th Jun 2021, 7:49 AM
Yogeshwara Sai Kurapaty
+ 1
See this code
14th Jun 2021, 7:49 AM
Yogeshwara Sai Kurapaty
+ 1
Thank you Rik
14th Jun 2021, 8:25 AM
Yogeshwara Sai Kurapaty
+ 1
I understand what you have done
14th Jun 2021, 8:25 AM
Yogeshwara Sai Kurapaty
14th Jun 2021, 8:30 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
A = [i for i in input().split()] This is list comprehension. Multiple inputs are stored as strings in a list If you want integer values, then use this code : A = [int(i) for i in input().split()]
15th Jun 2021, 2:27 AM
Pardha Saradhi
+ 1
Ok
15th Jun 2021, 4:13 AM
Yogeshwara Sai Kurapaty