Guest User

Untitled

a guest
Nov 27th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. if ens == "n":
  2. username=input("Please enter appropiate username: ")
  3. password1=input("Please enter password: ")
  4. password2=input("Please re-enter password: ")
  5. if password1 == password2: # checking if both passwords entered are the same
  6. print("your account has been successfully been made Thankyou")
  7. file = open("accountfile.txt","a")
  8. file.write("username: ")
  9. file.write(username)
  10. file.write(" ")
  11. file.write("password: ")
  12. file.write(password2)
  13. file.write("n")
  14. file.close()
  15. print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
  16. ens=input(" ")
  17. if password1 != password2: # if passwords entered are not the same will loop until they are correctly entered
  18. correctPassword=(password1)
  19. while True:
  20. password=input('Enter password again ')
  21. if password == correctPassword:
  22. print('Correct password has been entered')
  23. f = open ("accountfile.txt","a+")
  24. f.write("username: ")
  25. f.write(username)
  26. f.write(" ")
  27. f.write("password: ")
  28. f.write(correctPassword)
  29. f.write("n")
  30. f.close()
  31. print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
  32. en=input(" ")
  33. print('Incorrect password ')
  34.  
  35. if ens == "e":
  36. counter = 0
  37. check_failed = True
  38. while check_failed:
  39. print("Could player 1 enter their username and password")
  40. username1=input("Please enter your username ")
  41. password=input("Please enter your password ")
  42. with open("accountfile.txt","r") as username_finder:
  43. for line in username_finder:
  44. if ("username: " + username1 + " password: " + password) == line.strip():
  45. print("you are logged in")
  46. check_failed = False
  47. counter = 0
  48. check_failed = True
  49. while check_failed:
  50. print("Could player 2 enter their username and password")
  51. username2=input("Please enter your username ")
  52. password=input("Please enter your password ")
  53. with open("accountfile.txt","r") as username_finder:
  54. for line in username_finder:
  55. if ("username: " + username2 + " password: " + password) == line.strip():
  56. print("you are logged in")
  57. check_failed = False
  58. time.sleep(1)
  59. print("Welcome to the dice game")
  60. time.sleep(1)
  61. while rounds < 5:
  62. total_score2 = total_score2 + playerTwoPoints
  63. total_score1 = total_score1 + playerOnePoints
  64. rounds = rounds + 1
  65. number = random.randint(1,6)
  66. number2 = random.randint(1,6)
  67. playerOnePoints = number + number2
  68. print("Round",rounds)
  69. print("-------------------------------------------")
  70. print("Player 1's turn Type 'roll' to roll the dice")
  71. userOneInput = input(">>> ")
  72. if userOneInput == "roll":
  73. time.sleep(1)
  74. print("Player 1's first roll is", number)
  75. print("Player 1's second roll Type 'roll' to roll the dice")
  76. userOneInput = input(">>> ")
  77. if userOneInput == "roll":
  78. time.sleep(1)
  79. print("player 1's second roll is", number2)
  80. if playerOnePoints % 2 == 0:
  81. playerOnePoints = playerOnePoints + 10
  82. print("Player 1's total is even so + 10 points")
  83. print("-------------------------------------------")
  84. print("Player 1 has",playerOnePoints, "points")
  85. else:
  86. playerOnePoints = playerOnePoints - 5
  87. print("player 1's total is odd so -5 points")
  88. print("-------------------------------------------")
  89. print("Player 1 has",playerOnePoints, "points")
  90. number = random.randint(1,6)
  91. number2 = random.randint(1,6)
  92. playerTwoPoints = number + number2
  93. print("-------------------------------------------")
  94. print("Player 2's turn Type 'roll' to roll the dice")
  95. userTwoInput = input(">>> ")
  96. if userTwoInput == "roll":
  97. time.sleep(1)
  98. print("Player 2's first roll is", number)
  99. print("Player 2's second roll Type 'roll' to roll the dice")
  100. userTwoInput = input(">>> ")
  101. if userTwoInput == "roll":
  102. time.sleep(1)
  103. print("player 2's second roll is", number2)
  104. if playerTwoPoints % 2 == 0:
  105. playerTwoPoints = playerTwoPoints + 10
  106. print("Player 2's total is even so + 10 points")
  107. print("-------------------------------------------")
  108. print("Player 2 has",playerTwoPoints, "points")
  109. else:
  110. playerTwoPoints = playerTwoPoints - 5
  111. print("player 2's total is odd so -5 points")
  112. print("-------------------------------------------")
  113. print("Player 2 has",playerTwoPoints, "points")
  114. print("-------------------------------------------")
  115. print("Total score for player 1 is", total_score1)
  116. print("-------------------------------------------")
  117. print("Total score for player 2 is", total_score2)
  118. print("-------------------------------------------")
  119. if total_score1 > total_score2:
  120. print("Player 1 Wins!")
  121. file = open("scores.txt","a")
  122. file.write(username1)
  123. file.write(" has ")
  124. file.write(str(total_score1))
  125. file.write(" points")
  126. file.write("n")
  127. file.close()
  128. if total_score2 > total_score1:
  129. print("Player 2 Wins!")
  130. file = open("scores.txt","a")
  131. file.write(username2)
  132. file.write(" has ")
  133. file.write(str(total_score2))
  134. file.write(" points")
  135. file.write("n")
  136. file.close()
  137. if total_score1 == total_score2:
  138. print("Its a draw!")
  139. print("So both players will have to roll one more dice")
  140. time.sleep(2)
  141. print("-------------------------------------------")
  142. print("Player 1's turn Type 'roll' to roll the dice")
  143. userOneInput = input(">>> ")
  144. if userOneInput == "roll":
  145. time.sleep(1)
  146. print("Player 1's first roll is", number)
  147. print("Player 1's second roll Type 'roll' to roll the dice")
  148. userOneInput = input(">>> ")
  149. if userOneInput == "roll":
  150. time.sleep(1)
  151. print("player 1's second roll is", number2)
  152. if playerOnePoints % 2 == 0:
  153. playerOnePoints = playerOnePoints + 10
  154. print("Player 1's total is even so + 10 points")
  155. print("-------------------------------------------")
  156. print("Player 1 has",playerOnePoints, "points")
  157. else:
  158. playerOnePoints = playerOnePoints - 5
  159. print("player 1's total is odd so -5 points")
  160. print("-------------------------------------------")
  161. print("Player 1 has",playerOnePoints, "points")
  162. number = random.randint(1,6)
  163. number2 = random.randint(1,6)
  164. playerTwoPoints = number + number2
  165. print("-------------------------------------------")
  166. print("Player 2's turn Type 'roll' to roll the dice")
  167. userTwoInput = input(">>> ")
  168. if userTwoInput == "roll":
  169. time.sleep(1)
  170. print("Player 2's first roll is", number)
  171. print("Player 2's second roll Type 'roll' to roll the dice")
  172. userTwoInput = input(">>> ")
  173. if userTwoInput == "roll":
  174. time.sleep(1)
  175. print("player 2's second roll is", number2)
  176. if playerTwoPoints % 2 == 0:
  177. playerTwoPoints = playerTwoPoints + 10
  178. print("Player 2's total is even so + 10 points")
  179. print("-------------------------------------------")
  180. print("Player 2 has",playerTwoPoints, "points")
  181. else:
  182. playerTwoPoints = playerTwoPoints - 5
  183. print("player 2's total is odd so -5 points")
  184. print("-------------------------------------------")
  185. print("Player 2 has",playerTwoPoints, "points")
  186. print("-------------------------------------------")
  187. if total_score1 > total_score2:
  188. print("Player 1 Wins!")
  189. file = open("scores.txt","a")
  190. file.write(username1)
  191. file.write(" has ")
  192. file.write(str(total_score1))
  193. file.write(" points")
  194. file.write("n")
  195. file.close()
  196. if total_score2 > total_score1:
  197. print("Player 2 Wins!")
  198. file = open("scores.txt","a")
  199. file.write(username2)
  200. file.write(" has ")
  201. file.write(str(total_score2))
  202. file.write(" points")
  203. file.write("n")
  204. file.close()
  205. else:
  206. print("Sorry, this username or password does not exist please try again")
  207. counter = counter + 1
  208. if counter == 3:
  209. print("----------------------------------------------------")
  210. print("You have been locked out please restart to try again")
  211. sys.exit()
  212.  
  213. else:
  214. print("Sorry, this username or password does not exist please try again")
  215. counter = counter + 1
  216. if counter == 3:
  217. print("----------------------------------------------------")
  218. print("You have been locked out please restart to try again")
  219. sys.exit()
Add Comment
Please, Sign In to add comment