这是学习python的第9课,主要学习了使用python中的 input() 函数,把数据读到自己的程序里去。
print("How old are you?",end=' ')
age = input()
print("How tall are you?",end=' ')
height = input()
print("How much do you weight?",end=' ')
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
运行结果:
总结:
<1>. input() 函数直接接受且不改变输入数据的类型,但是需要注意的是使用 input() 在输入字符串时需要添加引号,否则会报错 。
<2>. end=' ' 标明在 end 后面传递一个空字符串,这样print函数不会在字符串末尾添加一个换行符,而是添加一个空字符串,也就是说,它的意思是 末尾不换行,加空格。
上面代码的另一种写法:
age = input("How old are you? ")
height = input("How tall are you? ")
weight = input("How much do you weigh? ")
print(f"So,you're {age} old,{height} tall and {weight} heavy.")