+ 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".

2nd Aug 2021, 5:12 PM
Gerard
Gerard - avatar
6 Respostas
+ 2
c = int(input("What is " + str(a) + "+ " + str(b) + "?"))
2nd Aug 2021, 5:19 PM
Simon Sauter
Simon Sauter - avatar
+ 8
c=int(input(f"what is {a} + {b}"))
2nd Aug 2021, 5:17 PM
Abhay
Abhay - avatar
+ 2
Simon Sauter calm down... das kommt😊
2nd Aug 2021, 5:28 PM
Oma Falk
Oma Falk - avatar
+ 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) ")
2nd Aug 2021, 6:00 PM
ጠ Ø λ 千 ₳ ℝ
ጠ Ø λ 千 ₳ ℝ - avatar
+ 1
Simon Sauter i’m learning defining functions
2nd Aug 2021, 9:39 PM
Gerard
Gerard - avatar
- 2
Btw. why on earth do you create two functions that simply print a word?
2nd Aug 2021, 5:22 PM
Simon Sauter
Simon Sauter - avatar