目录
Python——input
代码
结果
Python——str/int强制转换/字符串拼接
代码
结果
int和str不能拼接
Python——if/else
代码
结果
Python——input
代码
结果
Python——input
代码
结果
Python——input
代码
结果
-
Python——input
-
代码
input("please?")
print("result",input("please?"))
-
结果
-
Python——str/int强制转换/字符串拼接
-
代码
death_age = 90
name = input("your name:")
age = input("your age:")
print("----------------")
print("强制转换前 death_age type:", type(death_age))
print("强制转换前 age type:", type(age))
""""age从str强制转换成int"""
print("强制转换后 age type:", type(int(age)))
print("----------------")
print("your can still live for:", death_age - int(age), "years......")
-
结果
print("your can still live for:" + str(death_age - int(age)), "years......")
-
int和str不能拼接
- 1 错误代码
print("your can still live for:"+ death_age - int(age), "years......")
-
2 修改为
print("your can still live for:" + str(death_age - int(age)), "years......")
-
Python——if/else
-
代码
orgNum = 7
inputNum = input("请输入1-10范围的数字:")
if orgNum == int(inputNum):
print("right")
else:
print("error")
-
结果
-
Python——input
-
代码
-
结果
-
Python——input
-
代码
-
结果
-
Python——input
-
代码
-
结果