7. 输入和while循环
函数input()的工作原理
- input()让程序暂停运行,等待用户输入一些文本
height = input('How tall are you')
height = int(height)
if height >= 180:
print('You are tall enough to ride')
else:
print('\nYou will be able to ride when you are a little older')
使用while循环
while循环不断运行,直到指定的条件不满足为止break退出循环continue退出当前循环,继续下一次循环
current_number = 1
while current_number <= 5:
print(current_number)
current_number += 1