Guest User

Untitled

a guest
Oct 6th, 2022
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. import random
  2.  
  3. while True:
  4. while True:
  5. pencils = input("How many pencils would you like to use: ")
  6. try:
  7. int(pencils)
  8. break
  9. except ValueError:
  10. print("The number of pencils should be numeric")
  11. continue
  12. pencils = int(pencils)
  13. if pencils < 0:
  14. print("The number of pencils should be numeric")
  15. elif pencils == 0:
  16. print("The number of pencils should be positive")
  17. else:
  18. break
  19.  
  20.  
  21. # Deciding who will go first
  22.  
  23. name_list = ["John", "Jack"]
  24. while True:
  25. name = input("Who will go first (" + str(name_list[0]) + "," + str(name_list[1]) + ")")
  26. if name not in name_list:
  27. print("Choose between " + name_list[0] + " and " + name_list[1])
  28. else:
  29. break
  30.  
  31. away = 0
  32. bot = 0
  33.  
  34. if name == name_list[0]:
  35. bot = 0
  36. else:
  37. bot = 1
  38.  
  39. print("|" * pencils)
  40.  
  41. if bot == 1:
  42. print(name + "'s turn:")
  43. else:
  44. print(name + "'s turn!")
  45.  
  46. while pencils > 0:
  47. while bot == 1 and pencils > 0:
  48. if pencils == 5:
  49. away = random.randint(1, 3)
  50. print(away)
  51. elif pencils % 5 == 0:
  52. away = 1
  53. print(away)
  54. elif pencils % 4 == 0:
  55. away = 3
  56. print(away)
  57. elif pencils % 3 == 0:
  58. away = 2
  59. print(away)
  60. elif pencils % 5 > 3:
  61. away = 1
  62. print(away)
  63. elif pencils % 5 == 3:
  64. away = 3
  65. print(away)
  66. elif pencils % 5 == 2:
  67. away = 2
  68. print(away)
  69. else:
  70. away = 1
  71. print(away)
  72.  
  73. pencils -= away
  74. if pencils > 0:
  75. print(pencils * "|")
  76. bot = 0
  77. print(name_list[bot] + "'s turn!")
  78. else:
  79. bot = 0
  80. print(name_list[bot] + " won!")
  81.  
  82. while bot == 0 and pencils > 0:
  83. while True:
  84. take_away = input()
  85. try:
  86. int(take_away)
  87. break
  88. except ValueError:
  89. print("Possible values:'1','2', or '3'")
  90. continue
  91. take_away = int(take_away)
  92. if take_away not in [1, 2, 3]:
  93. print("Possible values:'1','2', or '3'")
  94. elif take_away > pencils:
  95. print("Too many pencils were taken")
  96. else:
  97. pencils -= take_away
  98. if pencils > 0:
  99. print(pencils * "|")
  100. bot = 1
  101. print(name_list[bot] + "'s turn:")
  102. else:
  103. bot = 1
  104. print(name_list[bot] + " won!")
  105. ____________________________________________________________________________________________
  106. TEST #17
  107. ___________________________________________________________________________________________-
  108. Wrong answer in test #17
  109.  
  110. After inputting number of pencils, that John has taken, there should be printed exactly 5 non-empty lines in such order:
  111. 2 for Jack
  112. 1 for Jack's move
  113. 2 for John
  114.  
  115. Please find below the output of your program during this failed test.
  116. Note that the '>' character indicates the beginning of the input line.
  117.  
  118. ---
  119.  
  120. How many pencils would you like to use: > 3
  121. Who will go first (John,Jack)> JohnJack
  122. Choose between John and Jack
  123. Who will go first (John,Jack)> JohnJack
  124. Choose between John and Jack
  125. Who will go first (John,Jack)> JohnJack
  126. Choose between John and Jack
  127. Who will go first (John,Jack)> JohnJack
  128. Choose between John and Jack
  129. Who will go first (John,Jack)> JohnJack
  130. Choose between John and Jack
  131. Who will go first (John,Jack)> John
  132. |||
  133. John's turn!
  134. > 4
  135. Possible values:'1','2', or '3'
  136. > a
  137. Possible values:'1','2', or '3'
  138. > 0
  139. Possible values:'1','2', or '3'
  140. > -1
  141. Possible values:'1','2', or '3'
  142. > _
  143. Possible values:'1','2', or '3'
  144. > |
  145. Possible values:'1','2', or '3'
  146. > |||||
  147. Possible values:'1','2', or '3'
  148. > 1
  149. ||
  150. Jack's turn:
  151. 2
  152. John won!
  153. __________________________________________________________________________________________________
  154. TEST #18
  155. ________________________________________________________________________________________________
  156.  
  157. Wrong answer in test #18
  158.  
  159. After inputting number of pencils, that John has taken, there should be printed exactly 5 non-empty lines in such order:
  160. 2 for Jack
  161. 1 for Jack's move
  162. 2 for John
  163.  
  164. Please find below the output of your program during this failed test.
  165. Note that the '>' character indicates the beginning of the input line.
  166.  
  167. ---
  168.  
  169. How many pencils would you like to use: > 4
  170. Who will go first (John,Jack)> JohnJack
  171. Choose between John and Jack
  172. Who will go first (John,Jack)> JohnJack
  173. Choose between John and Jack
  174. Who will go first (John,Jack)> JohnJack
  175. Choose between John and Jack
  176. Who will go first (John,Jack)> JohnJack
  177. Choose between John and Jack
  178. Who will go first (John,Jack)> JohnJack
  179. Choose between John and Jack
  180. Who will go first (John,Jack)> John
  181. ||||
  182. John's turn!
  183. > 4
  184. Possible values:'1','2', or '3'
  185. > a
  186. Possible values:'1','2', or '3'
  187. > 0
  188. Possible values:'1','2', or '3'
  189. > -1
  190. Possible values:'1','2', or '3'
  191. > _
  192. Possible values:'1','2', or '3'
  193. > |
  194. Possible values:'1','2', or '3'
  195. > |||||
  196. Possible values:'1','2', or '3'
  197. > 2
  198. ||
  199. Jack's turn:
  200. 2
  201. John won!
  202. __________________________________________________________________________________________________
  203. TEST #19
  204. ________________________________________________________________________________________________
  205.  
  206. Wrong answer in test #19
  207.  
  208. After inputting number of pencils, that John has taken, there should be printed exactly 5 non-empty lines in such order:
  209. 2 for Jack
  210. 1 for Jack's move
  211. 2 for John
  212.  
  213. Please find below the output of your program during this failed test.
  214. Note that the '>' character indicates the beginning of the input line.
  215.  
  216. ---
  217.  
  218. How many pencils would you like to use: > 5
  219. Who will go first (John,Jack)> JohnJack
  220. Choose between John and Jack
  221. Who will go first (John,Jack)> JohnJack
  222. Choose between John and Jack
  223. Who will go first (John,Jack)> JohnJack
  224. Choose between John and Jack
  225. Who will go first (John,Jack)> JohnJack
  226. Choose between John and Jack
  227. Who will go first (John,Jack)> JohnJack
  228. Choose between John and Jack
  229. Who will go first (John,Jack)> John
  230. |||||
  231. John's turn!
  232. > 4
  233. Possible values:'1','2', or '3'
  234. > a
  235. Possible values:'1','2', or '3'
  236. > 0
  237. Possible values:'1','2', or '3'
  238. > -1
  239. Possible values:'1','2', or '3'
  240. > _
  241. Possible values:'1','2', or '3'
  242. > |
  243. Possible values:'1','2', or '3'
  244. > |||||
  245. Possible values:'1','2', or '3'
  246. > 3
  247. ||
  248. Jack's turn:
  249. 2
  250. John won!
  251. __________________________________________________________________________________________________
  252. TEST #20
  253. ________________________________________________________________________________________________
  254.  
  255. Wrong answer in test #20
  256.  
  257. Jack's move doesn't follow a winning strategy. Example:
  258. If there are 6 pencils left and it's Jack's turn, he takes 2 pencils instead of 1
  259.  
  260. Please find below the output of your program during this failed test.
  261. Note that the '>' character indicates the beginning of the input line.
  262.  
  263. ---
  264.  
  265. How many pencils would you like to use: > 9
  266. Who will go first (John,Jack)> JohnJack
  267. Choose between John and Jack
  268. Who will go first (John,Jack)> JohnJack
  269. Choose between John and Jack
  270. Who will go first (John,Jack)> JohnJack
  271. Choose between John and Jack
  272. Who will go first (John,Jack)> JohnJack
  273. Choose between John and Jack
  274. Who will go first (John,Jack)> JohnJack
  275. Choose between John and Jack
  276. Who will go first (John,Jack)> John
  277. |||||||||
  278. John's turn!
  279. > 4
  280. Possible values:'1','2', or '3'
  281. > a
  282. Possible values:'1','2', or '3'
  283. > 0
  284. Possible values:'1','2', or '3'
  285. > -1
  286. Possible values:'1','2', or '3'
  287. > _
  288. Possible values:'1','2', or '3'
  289. > |
  290. Possible values:'1','2', or '3'
  291. > |||||
  292. Possible values:'1','2', or '3'
  293. > 3
  294. ||||||
  295. Jack's turn:
  296. 2
  297. ||||
  298. John's turn!
Advertisement
Add Comment
Please, Sign In to add comment