函数input()
比较大小要同类型:
- age=iput()
- 21
- age=int(age)
- age>=10
- true
1 prompt = "If you tell us who you are, we can personalize the messages you see." 2 prompt += " What is your first name? " 3 #运算符+=在存储prompt中的字符串末尾附加一个字符串。其实可以这样理解:prompt + = ' zifuchuang'+ 4 name = input(prompt) 5 print(" Hello, " + name + "!")
求模运算符:两个数相除并返回余数。
1 number = input("Enter a number, and I'll tell you if it's even or odd: ") 2 print(type(number)) #输入为str 3 number = int(number) 4 print(type(number)) #转换为int 5 if number % 2 == 0: 6 print(" The number " + str(number) + " is even.") 7 else: 8 print(" The number " + str(number) + " is odd.")
while循环
while 判断条件:
执行条件
在循环中使用continue:执行余下的代码并推出整个循环,执行continue语句,让python忽略余下的代码,并返回到循环的开头。