age = 22
#优化前
'''
for i in range(10):
guess_num = int(input('input your guess num:'))
if guess_num == age :
print('Congratulations ! you got it.')
elif guess_num > age:
print('Think smaller!')
else:
print('Think Big...')
'''
#优化后:要求输入用户名输入正确以后不执行语句
'''
for i in range(10):
if i < 3:
guess_num = int(input('input your guess num:'))
if guess_num == age :
print('Congratulations ! you got it.')
break #跳出整个循环
elif guess_num > age:
print('Think smaller!')
else:
print('Think Big...')
else:
print('too many attumt.bye')
break
'''
#再优化:要求循环3次后询问一次
counter = 0
for i in range(10):
print('counter',counter)
if counter < 3:
guess_num = int(input('input your guess num:'))
if guess_num == age :
print('Congratulations ! you got it.')
break #跳出整个循环
elif guess_num > age:
print('Think smaller!')
else:
print('Think Big...')
else:
continue_confirm = input('Do you want to continue because you are stupid:')
if continue_confirm == 'y':
counter = 0
continue #跳出本次循环
else:
print('bye')
break
counter += 1 #counter = counter + 1