变量和循环
变量是用来存储一个数据,以便于后续调用
变量定义规则
• 变量名只能是字母,数字或下划线的任意组合
• 变量名第一个字符不能是数字
• 以下关键字不能为变量名
• [‘and’,‘as’,‘assert’,‘break’,‘class’,‘def’,‘elif’,‘else’,‘except’,‘exec’,‘finally’,‘for’,‘from’,‘global’,‘if’,‘impot’,‘in’,‘is’,‘lambda’,‘not’, ‘or’,‘pass’,‘print’,‘raise’,‘return’,‘try’,‘while’,‘with’,‘yield’]
Python中变量名全大写表示是该变量是常量
字符集声明:# -- coding:utf-8 --
注释:
• 单行注释:#
• 多行注释:’’’
if判断
age_js = 26
guess_age = int(input(“Guess_age:”))
if guess_age == age_js:
print(“bingo”)
elif guess_age > age_js:
print(“guess smaller”)
else :
print(“guess bigger”)
while循环
age_js = 26
count = 0
while count < 3:
guess_age = int(input(“Guess_age:”))
if guess_age == age_js:
print(“bingo”)
break
elif guess_age > age_js:
print(“guess smaller”)
else:
print(“guess bigger”)
count +=1
if count == 3:
countine_confirm = input(“仍要继续尝试吗”)
if countine_confirm != ‘n’:
count = 0
for循环
for i in range(0,10,2):
print(“loop”,i)
age_js = 26
for i in range(3):
guess_age = int(input(“Guess_age:”))
if guess_age == age_js:
print(“bingo”)
break
elif guess_age > age_js:
print(“guess smaller”)
else:
print(“guess bigger”)
else:
print(“没有次数了!”)