0

What will happen when there are 2 inputs in a program

a= input ("Enter a value:") b= input ("Enter another value:") x = a+b print(x) y=a-b print(y) when we need to provide input values for a AND b when we run the program a screen appears on the window says "Seems like your program requires input" , do we need to provide 2 numbers at a time.. I tried in different ways ... my program doesn't give me expected output

10th Jan 2018, 1:48 PM
Jyoshna
Jyoshna - avatar
1 Odpowiedź
+ 4
You didn't get the expected output because you're confusing the type of variable you tried to addition: input() function return a string (in Python3, prior to 3 you need to use raw_input() to get the same behaviour), so 'a' and 'b' variables store string, even if user type number... if you want to addition number instead of concatenate string, you must convert the input, either when storing the input or when using it: a = int(input("Enter a value:") b = input("Enter another value:") x = a+int(b) print(x)
10th Jan 2018, 3:04 PM
visph
visph - avatar