Why is it not displaying the input and nither is it performing the operation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it not displaying the input and nither is it performing the operation?

https://code.sololearn.com/cH4n5PLLzh7Q/?ref=app

15th Aug 2020, 10:10 AM
Sameel Khan
Sameel Khan - avatar
9 Answers
+ 7
There is still some room for improvement. (1) try to get numbers as int direct when input is called. (2) there is no need to have input values captured separate for each operation. Just place it once as shown in the code below: x =["add","subtract",] user_input=input() num_1 = int(input("enter first number:")) num_2 = int(input("enter second number")) if user_input == x[0]: print(num_1 + num_2) elif user_input == x[1]: print (num_1 - num_2 )
15th Aug 2020, 11:31 AM
Lothar
Lothar - avatar
+ 6
Sameel Khan , you are very welcome. happy coding!
15th Aug 2020, 2:40 PM
Lothar
Lothar - avatar
+ 3
Sameel Khan It will be shown in output when you are asked to enter a number. If you don't want anything except the output either you can creat a function to clear screen(in cmd/terminal) or just remove "enter a number"
15th Aug 2020, 11:30 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 1
you dont need = in print statement
15th Aug 2020, 10:13 AM
Taste
Taste - avatar
+ 1
uhh... You have used print = (num_1 + num_2) but it is used as print( num_1 + num_2 ) Also, SL doesn't support multiple inputs so you jave to run it in any other IDE
15th Aug 2020, 10:16 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 1
Use print() as function not as a variable.. Modify the stmts to.. print(int(num_1 )+int(num_2 )) print(int(num_1 )-int(num_2 )) Now you'll get the required o/p
15th Aug 2020, 10:18 AM
sarada lakshmi
sarada lakshmi - avatar
+ 1
Lothar thanks for the suggestion it's definitely more efficient that way ,I have much to learn :)
15th Aug 2020, 11:34 AM
Sameel Khan
Sameel Khan - avatar
0
Thank you all for the help
15th Aug 2020, 11:21 AM
Sameel Khan
Sameel Khan - avatar
0
I had one more problem , Why does the input("enter a number") show in the output ,it is just supposed to be for the user right?
15th Aug 2020, 11:27 AM
Sameel Khan
Sameel Khan - avatar