当前位置:   article > 正文

Python版猜数字_python幼儿教育猜数字ppt

python幼儿教育猜数字ppt

废话不多说,上代码:

  1. import random
  2. life=5
  3. ans=0
  4. print("欢迎来到猜数字游戏!")
  5. print('1.1~15')
  6. print('2.1~30')
  7. print('3.1~100')
  8. NUMBER=int(input('请选择您的等级:'))
  9. if NUMBER==1:
  10. guess=random.randint(1,15)
  11. a=True
  12. while a:
  13. number=int(input('Type a number:'))
  14. if number>guess:
  15. print("Too Big!")
  16. life-=1
  17. print('Life is ',life)
  18. ans+=1
  19. elif number<guess:
  20. print("Too Small!")
  21. life-=1
  22. print('Life is ', life)
  23. ans += 1
  24. else:
  25. print("That's Right!")
  26. ans+=1
  27. print('你用了', ans, '次')
  28. a=False
  29. if life==0:
  30. print("The number is",guess)
  31. a=False
  32. if NUMBER==2:
  33. guess = random.randint(1,30)
  34. a = True
  35. while a:
  36. number = int(input('Type a number:'))
  37. if number > guess:
  38. print("Too Big!")
  39. life -= 1
  40. print('Life is ', life)
  41. ans += 1
  42. elif number < guess:
  43. print("Too Small!")
  44. life -= 1
  45. print('Life is ', life)
  46. ans += 1
  47. else:
  48. print("That's Right!")
  49. ans += 1
  50. print('你用了', ans, '次')
  51. a = False
  52. if life == 0:
  53. print("The number is", guess)
  54. a = False
  55. if NUMBER==3:
  56. guess = random.randint(1,100)
  57. a = True
  58. while a:
  59. number = int(input('Type a number:'))
  60. if number > guess:
  61. print("Too Big!")
  62. life -= 1
  63. print('Life is ', life)
  64. ans += 1
  65. elif number < guess:
  66. print("Too Small!")
  67. life -= 1
  68. print('Life is ', life)
  69. ans += 1
  70. else:
  71. print("That's Right!")
  72. ans += 1
  73. print('你用了', ans, '次')
  74. a = False
  75. if life == 0:
  76. print("The number is", guess)
  77. a = False
  78. if NUMBER!=1 and NUMBER!=2 and NUMBER!=3:
  79. print('输入错误!程序崩溃!')
  80. print('Windows崩溃!')
  81. a=False

emmm没有注释哟~~~~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/769111
推荐阅读
相关标签
  

闽ICP备14008679号