用户输入和while循环
7.1 函数input()的工作原理
函数input()让程序暂停运行,等待用户输入一些文本。
message = input(“Tell me something,and I will repeat it back to you:”)
print(message)
7.1.1 编写清晰的程序
每当你使用函数input()时,都应指定清晰而明白的提示。
7.1.2 用int()来获取数值输入
用input()获取的输入为字符串,
age = input(“How old are you?”)
age = int(age)
7.1.3 求模运算
求模运算符(%)将两个数相除并返回余数
7.2 while循环简介
while a:
print(“Hello !”)
while循环中使用break语句立即退出while循环
任何Python循环中都可以使用break退出循环
在循环中使用continue语句,退出本次循环,直接进行下一次循环。