python猜数字,只有3次机会

来源:互联网 发布:单机游戏编程语言 编辑:程序博客网 时间:2024/05/16 02:04
  1 number = 59  2 num_chances = 3  3 print("You have only 3 chances to guess")  4   5 for i in range(1, num_chances + 1):     # i in range(1,4)  6         print("chance " + str(i))  7         print("=" * 8)  8         guess = int(input('Enter an integer: '))  9  10         if guess == number: 11                 print("Bingo! you guessed it right.") 12                 print("(but you do not win any prizes!)") 13                 break 14  15         elif guess < number: 16                 print("Sorry, the number is higher than that, keep guessing, you have " + str(num_chances - i) + "chances left") 17         else: 18                 print("Sorry, the number is lower than that, keep guessing, you have " + str(num_chances - i) + "chances left") 19  20 print("*** End ***")

阅读全文
0 0
原创粉丝点击