标签:原因 error got 数据 wrong 分析 scores 大小 强制
death_age = 80
name = input(“your name:”)
age = input("your age:")
#print(name,age)
print("your name:",name)
print("you can still live for ",(death_age - age))
或者print("you can still live for "+(death_age - age))
直接运行报错
syntax error :unsupported operand type
语法错误:不支持的操作运算类型
原因分析:input默认接收数据类型为str(string),str跟int类型不能进行数学运算,需进行强制数据类型转换
猜年龄游戏
age_of_ principal = 56
guess_age = int (input(">>:"))
if guess_age == age_of_principal:
print("yes,you got it")
else;
print("no,you are wrong")
缩进介绍
为什么要有缩进?程序需要知道代码什么时候开始、什么时候结束。python通过统一的缩进规范同级代码。
age_of_ principal = 56
guess_age = int (input(">>:"))
if guess_age == age_of_principal:
print("yes,you got it")
else;
print("no,you are wrong")
IndentationError:expected an indented block
猜年龄增加大小判断
age_of_principal = 56
guess_age = int(input(">>:"))
if guess_age == age_of_principal:
print("yes,you got it")
elif guess_age > age_of_principal:
print("should try smaller...")
else:
print("should try bigger...")
score = int(input("scores:"))
if score > 90:
print("A")
elif score > 80:
print("B")
elif score > 70:
print("C")
else:
print("D")
标签:原因 error got 数据 wrong 分析 scores 大小 强制
原文地址:https://www.cnblogs.com/python-beginner/p/11974293.html