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 " "?
4 RĂ©ponses
+ 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)
+ 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.
0
If i do not forgot, i cannot constructively str and int/float?
Only str+str, and other?
0
OH, thanks guys.