笨办法学python第11课

2018-09-06  本文已影响21人  3ab9db71c244
print("how old are you?", end = '  ')  #用end = ' '的意义在于,把age = input()放到同一行
age = input()
print('how tall are you?', end = ' ')  
height = input()
print("how much do you weigh?", end = ' ')
weight = input()
print(f"so, you're {age} old, {height} tall and {weight} heavy.") #input的age也可以成为打印字符串的变量

运行结果:
/Users/tongshiba/PycharmProjects/ex3/test11.py
how old are you?29
how tall are you?180
how much do you weigh?18
so ,you're 29 old, 180 tall and 18 heavy.
Process finished with exit code 0



Study Drills练习题
1. Go online and find out what Python’s input does.

找到input的用法

2. Can you find other ways to use it? Try some of the samples you find.

not yet

3. Write another “form” like this to ask some other questions

not yet

Common Student Questions常见问题:
1.How do I get a number from someone so I can do math? 

That’s a little advanced, but try x = int(input()), which gets the number as a string from input(), then converts it to an integer using int(). 

2.I put my height into raw input like this input("6'2") but it doesn’t work. 

Don’t put your height in there; type it directly into your Terminal. First, go back and make the code exactly like mine. Next, run the script, and when it pauses, type your height in at your keyboard. That’s all there
is to it.
上一篇下一篇

猜你喜欢

热点阅读