Why isnt my code working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why isnt my code working

from random import randint user_input = input(":") if user_input == ("add"): num1 = (randint(0,100)) num2 = (randint(0,100)) result = str(num1 + num2) print ("answer : ") print (result) print ("numbers added :") print (num1) print (num1) if user_input == ("multiply"): num3 = (randint(0,100)) num4 = (randint(0,100)) resul = str(num3 + num4) print ("answer : ") print (resul) print ("numbers added :") print (num3) print (num4)

3rd Mar 2017, 11:50 PM
ProgramBoi
3 Answers
+ 8
there's no need for putting () on if statements >> if user_input == "add" another tip: you can dry your code by using concatenation. and pay attention to indentation
4th Mar 2017, 3:22 AM
LayB
LayB - avatar
0
from random import randint user_input = input(":") if user_input == ("add"): num1 = (randint(0,100)) num2 = (randint(0,100)) result = str(num1 + num2) print ("answer : ") print (result) print ("numbers added :") print (num1) print (num1) if user_input == ("multiply"): num3 = (randint(0,100)) num4 = (randint(0,100)) resul = str(num3 + num4) print ("answer : ") print (resul) print ("numbers added :") print (num3) print (num4) you forgot some indentations
4th Mar 2017, 12:08 AM
ramzi
ramzi - avatar
0
actually layB is right but I suggest u do use the () it helps with the organization of big math lines and is used in a lot of other languages
4th Mar 2017, 3:54 AM
Riley Laher
Riley Laher - avatar