您好,登錄后才能下訂單哦!
age = 22 #優(yōu)化前 ''' 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...') ''' #優(yōu)化后:要求輸入用戶名輸入正確以后不執(zhí)行語句 ''' 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 #跳出整個循環(huán) elif guess_num > age: print('Think smaller!') else: print('Think Big...') else: print('too many attumt.bye') break ''' #再優(yōu)化:要求循環(huán)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 #跳出整個循環(huán) 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 #跳出本次循環(huán) else: print('bye') break counter += 1 #counter = counter + 1
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。