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)
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
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
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