代码
print("How old are you?", end = " ")
age = input("input somethin:\n")
print("How tall are you?", end = " ")
height = int(input())
print("How much do you weight?", end = " ")
weight = str(input())
#可以输入各种类型的字符,如果input()改为int/floet/complex/str(input()),就只能输入相对应的内容。
print(type(age))
print(type(height))
print(type(weight))
print("So, you're {} old, {} tall and {} heavy.".format(age, height, weight))
print("So, your total number is {}.".format(int(age)+ int(height)+int(weight)))
遇到问题
?
学到的
a = input()的代码,可以输入任何的字符,出来后是string格式。而如果input()改为int/floet/complex/str/…(input()),就只能输入相对应的内容。否则大概率报错:如代码运行到height这块,输入字母或文字,怎出现错误提示:
Traceback (most recent call last):
File “ex11.py”, line 4, in
height = int(input())
ValueError: invalid literal for int() with base 10: ‘dd’