Python Error Question ValueError: invalid literal for int() with base 10: ''

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

num1 = int("number1 ==> 100")
num2 = int (input ("number2 == > 3"))

result1 = num1 * num2
result2 = num1 % num2
result3 = num1 // num2
result4 = num1 ** num2

print("The value multiplied by the numbers 1 and 2 is result1")
print("The remainder divided by the number 1 by 2 is result2)
print("The quotient of the number 1 divided by 2 is result3")
print("The value n-square of the number 1 by the number 2 is result4")
number 1 ==> 100
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    num1 = int (input ("number 1 == > 100"))
ValueError: invalid literal for int() with base 10: ''

Could you tell me how to solve this error?

python

2022-09-20 14:38

2 Answers

ValueError: invalid literal for int() with base 10: ''

Message that the object cannot be converted to a number.

Looking at the message, it seems that you entered the input command but didn't enter anything?

It's not an error, it's a mistake that you could tell if you think a little bit about what you did wrong.

You can't have written the input command without knowing what it is.


2022-09-20 14:38

Write the f-string statement in the print statement

num1 = int("number 1 is ==> 100: "))
num2 = int (input ("number 2 is ==> 3: ")))

result1 = num1 * num2
result2 = num1 % num2
result3 = num1 // num2
result4 = num1 ** num2

print (f"number 1 multiplied by 2 is {result1}")
print (f"the remainder divided by the number 1 by 2 is {result2}")
print (f"number 1 divided by 2 is {result3}"
print("f"n-square number 1 by number 2 is {result4}")


2022-09-20 14:38

If you have any answers or tips


© 2022 pinfo. All rights reserved.