+ 2
multiple Inputs
In python, how to make it so that the user can only enter one of the multiple inputs.
11 Respuestas
+ 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.....
+ 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)
+ 1
Can you give an example please
+ 1
See this code
+ 1
Thank you Rik
+ 1
I understand what you have done
+ 1
+ 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()]
+ 1
Ok