How to get else option that prints out ("This is not a number"). Strings and Ints HELP! (ValueError: invalid literal for int() with base 10:)
How to get else option that prints out ("This is not a number"). Strings and Ints HELP! (ValueError: invalid literal for int() with base 10:)
错误信息:
ValueError:以 10 为底的 int() 无效文字:“
Thanks
# Name
name = input("Enter Name: ")
# Age
age = int(input("Enter Age: "))
if age == str():
print("Not a Number!")
else:
pass
# Age - 100 equals
subage = 100 - age
# Take the result of previous expression and add to year.
age100 = subage + 2020
# Print out results
print(name,"! " "You will be 100 years of age in the year of: ", age100)
只是写了更多,这样我就可以把这个东西送到 post。
sdfsdff
sfsdf
将 age = int(input("Enter Age: ")) 放在 try 块中,如果发生错误,则在其后跟一个 except 块:
try:
age = int(input("Enter Age: "))
# Age - 100 equals
subage = 100 - age
# Take the result of previous expression and add to year.
age100 = subage + 2020
# Print out results
print(name,"! " "You will be 100 years of age in the year of: ", age100)
except ValueError:
print(“This is not a number”)
错误信息: ValueError:以 10 为底的 int() 无效文字:“
Thanks
# Name
name = input("Enter Name: ")
# Age
age = int(input("Enter Age: "))
if age == str():
print("Not a Number!")
else:
pass
# Age - 100 equals
subage = 100 - age
# Take the result of previous expression and add to year.
age100 = subage + 2020
# Print out results
print(name,"! " "You will be 100 years of age in the year of: ", age100)
只是写了更多,这样我就可以把这个东西送到 post。 sdfsdff sfsdf
将 age = int(input("Enter Age: ")) 放在 try 块中,如果发生错误,则在其后跟一个 except 块:
try:
age = int(input("Enter Age: "))
# Age - 100 equals
subage = 100 - age
# Take the result of previous expression and add to year.
age100 = subage + 2020
# Print out results
print(name,"! " "You will be 100 years of age in the year of: ", age100)
except ValueError:
print(“This is not a number”)