while 条件:
执行代码
a = -1
while a < 100:
a += 1
print(a)
a = 0
while a <= 100:
print("loop ", a)
a += 1
print("-----loop is ended----")
a=0
while a <= 100:
print("double ", a)
a += 2
print("-----loop is ended----")
a = 1
while a <=100:
if a == 50:
pass
elif a >= 60 and a <= 80:
b = a**2
print("the square of loop is ", b)
else:
print("loop ", a)
a += 1
print("------loop is ended-----")
猜年龄游戏:
# age = 48
# trial_number = 1
# while trial_number <=3:
# userguess = int(input("your guess:"))
# if userguess == 48:
# print("恭喜你猜对了!")
# break
# elif userguess >= 0 and userguess < 48:
# print("try bigger")
# elif userguess < 0:
# print("please enter a valid age number")
# else:
# print("try smaller")
# trial_number_left = 3 - trial_number
# if trial_number_left == 0:
# print("对不起,系统检测到您的猜测次数已经用完,请充值后再试")
# else:
# print("你还剩下", trial_number_left, "次机会")
# trial_number += 1
# print("游戏结束")
age = 48
trial_number = 1
while trial_number <=3:
userguess = int(input("your guess:"))
if userguess == 48:
print("恭喜你猜对了!")
break
elif userguess >= 0 and userguess < 48:
print("try bigger")
elif userguess < 0:
print("please enter a valid age number")
else:
print("try smaller")
trial_number_left = 3 - trial_number
if trial_number_left == 0:
willing_to_go_on = input("对不起,系统检测到您的猜测次数已经用完,您还要重新玩一次吗?")
if willing_to_go_on == "y":
trial_number = 1
continue #此句不需要
else:
print("你还剩下", trial_number_left, "次机会")
trial_number += 1
print("游戏结束")
除此之外,回顾了1小时的pycharm使用秘籍
还有1个半小时的Mastering Pycharm课程