0
Why does line produce an error? Warning\Error File "file.py", line 13 num1 = float(input("Enter a number:"))
10 Réponses
+ 2
Fill in the blanks to handle all possible exceptions.
try:
num1 = input(":")
num2 = input(":")
print(float(num1)/float(num2))
except:
print("Invalid input")
+ 1
ok sorry heres full code
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input == "add":
num1 = float(input("Enter a number: "))
num2 = float(input("Enter another number: "))
print("Your answer is (num1 + num2)")
elif user_input == "subtract"
num3 = float(input("Enter a number"))
num4 = float(input("Enter another number"))
print("Your answer is (num3 - num4)")
elif user_input == "multiply":
num5 = float(input("Enter a number"))
num6 = float(input("Enter another number"))
print("Your anser is (num5 * num6)")
elif user_input == "divide":
num7 = float(input("Enter a number"))
num8 = float(input("Enter another number"))
print("Your answer is (num7/num8)")
0
do you see an EOF error in this code as well?
0
try:
num1 = input(":")
num2 = input(":")
print(float(num1)/float(num2))
except:
print("Invalid input")
0
try:
num1 = input(":")
num2 = input(":")
print(float(num1)/float(num2))
except:
print("Invalid input")
- 1
that line/statement -> num1 = float(input("Enter a number:"))
doesn't give any error unless u input invalid input(string)
this information is not enough to figure out the issue.show full code or code block.
- 1
There are many syntax errors and indentation issues..
Try this. In Python indentation is important to mark the code scope/block.
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input == "add":
num1 = float(input("Enter a number: "))
num2 = float(input("Enter another number: "))
print("Your answer is (num1 + num2)")
elif user_input == "subtract":
num3 = float(input("Enter a number"))
num4 = float(input("Enter another number"))
print("Your answer is (num3 - num4)")
elif user_input == "multiply":
num5 = float(input("Enter a number"))
num6 = float(input("Enter another number"))
print("Your anser is (num5 * num6)")
elif user_input == "divide":
num7 = float(input("Enter a number"))
num8 = float(input("Enter another number"))
print("Your answer is (num7/num8)")
- 1
Fill in the blanks to handle all possible exceptions.
try:
num1 = input(":")
num2 = input(":")
print(float(num1)/float(num2))
except:
print("Invalid input")
- 2
yaaaaa the question is awsome
- 2
try:
except: