Set word as a value if user input is x (python3. 7) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Set word as a value if user input is x (python3. 7)

I want to set a value like x = 0.25 if user input for exmple is '2' what can i do?

24th Jul 2019, 6:14 PM
hamed
5 Answers
+ 6
if you write "if" in lowercase your code does work as expected. Also put print() in indentation as shown: a1 = float(input("what is first mark?")) if a1 == 2: p1 = '0.25' print(p1)
24th Jul 2019, 7:17 PM
Lothar
Lothar - avatar
+ 3
you can try this: inp = input('Input:') if inp == '2': x = 0.25
24th Jul 2019, 6:21 PM
Lothar
Lothar - avatar
+ 1
For exmple it would like to be something like this : a1 = float(input("what is first mark?")) If a1 == 2: p1 = '0.25' print(p1)
24th Jul 2019, 6:24 PM
hamed
+ 1
I tried but it dosent work, just like my own code it says the 'x' is not defined 🤷‍♂️
24th Jul 2019, 6:30 PM
hamed
+ 1
Thank you very much, it was very helpful🤩
26th Jul 2019, 6:53 PM
hamed