+ 2

How can you get two inputs for variables in a code?

Dear community, I just began programming and wanted to code a simple mathematical task. I want to use two inputs for the calculation, but my code can't do that. I also have some other mistakes in my code, feel free to tell me about them, and how you would change it. Thank you very much. My code: print("Choose two numbers for a multiplication, sothat the prudact equals 20") x=int(input("number one: ") y=int(input("numver two: ") if x*y == 20: print ("Correct") else: print("this is the first number you chose: ") print(x) y = int(input("Please choose a second number, sothat the product equals 20: ")) if x*y == 20: print ("Correct") else: print ("Unfortunately your answer was incorrect, this is the right choice for number two") print (20/x)

10th Aug 2018, 9:16 AM
Joseph.Atzinger
4 Respuestas
+ 2
Thank you Kaimi for your response. I fixed the mistakes you mentioned. However, there still seems to be a problem with the code. File "..\Playground\", line 13 if x*y == 20: ^ SyntaxError: invalid syntax print("Choose two numbers for a multiplication, sothat the prudact equals 20") x=int(input("number one: ")) y=int(input("numver two: ")) if (x*y)==20: print ("Correct") else: i=1 while x*y != 20 and i<4: i+=1 print("this is the first number you chose: ") print(x) y = int(input("Please choose a second number, sothat the product equals 20: ") if x*y == 20: print ("Correct") break print ("Unfortunately your answer was incorrect, this is the right number for number two") print (20/x)
14th Aug 2018, 11:26 AM
Joseph.Atzinger
0
Thank you for helping me out again. If i type in a correct multiplication, the output is "correct". That works. But if i put in an incorrect multiplication, the code struggles with giving me the chance to choose an input for a second time. This is the error the code produces: Please choose your second number again, sothat the product equals 20: Traceback (most recent call last): File "..\Playground\", line 10, in <module> y = int(input("Please choose your second number again, sothat the product equals 20: ")) EOFError: EOF when reading a line After the initial input, is it possible to create a second opportunity for an input? And how can you make it happen?
29th Aug 2018, 6:01 AM
Joseph.Atzinger