- 1
Is it correct?
7 Antworten
+ 3
You probably want to add num1 and num2, so you should change result = int(input() + input()) to result = num1 + num2. Otherwise the program will ask for input five times and num1 and num2 won't be used anywhere
+ 3
Instead of:
print(int(input() + input())
Just say:
print(num1 + num2)
With the former statement it would have done this:
* example input = 2, 3
Output: 23
The reason for this is that you added two strings, then converted the result into an integer
You also would have had to give 4 inputs (2 of which were unneccecary)
Also the indentation is wrong. It should be:
if {condition}:
{code}
Here is the fixed code according to the fixes I mentioned:
https://code.sololearn.com/cZE3G7g7bwA8/?ref=app
+ 2
Piyush Kumar
If all the following are true:
- no error is raised
- the result is what you expected to be given the input. 2 + 5 should NOT be 25🐍
+ 1
How can I check if the output is right or wrong?
0
Piyush Kumar you must add a tab before each line in if block
0
#so it will be:
user_input = input(": ")
if user_input == "add":
num1 = float(input("Enter"))
num2 = float(input("Enter"))
result = str(num1 + num2)
print(result)