+ 2
I need help
I'm trying to create a program that chooses two random numbers and asks the user to add them, if correct it will tell the user it is correct import random def wrong(): print("Wrong") def correct(): print("Correct") a = random.randint(0,100) print (a) b = random.randint(0,100) print (b) c = int(input("what is the answer: ")) if c == a + b: correct() else: wrong() the code works fine but what I want is that instead of printing both a and b separately then asking for the answer, I want to ask in the input, like "what is a + b".
6 Respostas
+ 2
c = int(input("What is " + str(a) + "+ " + str(b) + "?"))
+ 8
c=int(input(f"what is {a} + {b}"))
+ 2
Simon Sauter calm down... das kommt😊
+ 1
import random
again = 'y'
while again=='y':
x = random.randint(1,500)
y = random.randint(1,500)
print(str(x)+" + "+str(y)+" ? ")
answer = int(input())
if(answer==x+y):
print("Yes correct, you are great!")
else:
print("Incorrect, Learn how to do additions")
again = input("You want to tray again? (y/n) ")
+ 1
Simon Sauter i’m learning defining functions
- 2
Btw. why on earth do you create two functions that simply print a word?