# -*- coding:utf-8 -*- # -Author: Paulliam - # if else 判断; age_of_yu = 56 guess_count = 0 while guess_count<3: guess_age = int(input("guess age:")) if guess_age == age_of_yu : print("yes, you got it.") #行首的同级TAB分隔符相当于C语言的花括号 break #行首的同级TAB分隔符相当于C语言的花括号 elif guess_age < age_of_yu: print("think smaller...") elif guess_age > age_of_yu: print("think bigger...") guess_count +=1 if guess_count == 3: continue_flag = input("do you want to keep guessing...?") if continue_flag != 'n': #输入字符不是n,则继续循环 guess_count = 0 # for的循环变量i的值是调整不了的 print("guess_count was cleared!") #if 3 == guess_count: #特别用法,该行使用效果等同于下行 else: #相当于while guess_count<3:不成立时执行下面 print("you have trried too many times! fuck off")
##########运行结果:
"D:\Program Files\python-3.6.4\python.exe" C:/Users/Administrator/Desktop/python-prj/guess1.py
guess age:12
think smaller...
guess age:87
think bigger...
guess age:34
think smaller...
do you want to keep guessing...?n
you have trried too many times! fuck off
Process finished with exit code 0