0

Error

I created my code about calculator. I used "a, b and c". When i give for a input and b, then i write c=a+b, and in console i take, that "c" is not such variable. What can i fix it? FE: a = int(input("Write variable a = ") b = int(input("Write b = ") what = input("What we doing? (+, -) Write = ") if what == "+": c = a + b print("Your result is: " + c) elif what == "-": c = a - b print("Your result is: " + c) I havent opportunity now, but i think, problem is when i write result, i not write "Your result is: " + "c". I missed on " "?

24th Sep 2019, 11:53 AM
MrAladawee
MrAladawee - avatar
4 Antworten
+ 3
1. You're missing two closing parentheses. a = int(input("Write variable a = ")) b = int(input("Write b = ")) 2. Use commas to print multiple expressions. String concatenation (e.g. "Hello "+"world") can only be done between two strings. print("Your result is", c)
24th Sep 2019, 12:08 PM
Diego
Diego - avatar
+ 3
You have 2 ways to print strings with variables. Convert to string or separate them. Convert to str: print("Your result is: " + str(c)) Separate them: print("Your result is:", c) #If you seperate them, print() will add a space for each variables.
24th Sep 2019, 12:10 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
If i do not forgot, i cannot constructively str and int/float? Only str+str, and other?
24th Sep 2019, 12:01 PM
MrAladawee
MrAladawee - avatar
0
OH, thanks guys.
24th Sep 2019, 1:04 PM
MrAladawee
MrAladawee - avatar