Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import csv
  2.  
  3. def importfile():
  4. """reads in the file"""
  5. with open ("USER.csv","r") as myfile:
  6. reader = csv.reader(myfile)
  7. studentlist = list(reader)
  8. return studentlist
  9.  
  10. def ded():
  11. print("player 1")
  12. User=input("usename: ")
  13. Pass=input("paswword: ")
  14. return(User,Pass)
  15.  
  16. def checkuser(username,password,uList):
  17. valid = False
  18. for i in range(0,len(uList)):
  19. if username == uList[i][0] and password == uList[i][1]:
  20. valid = True
  21. break
  22. else:
  23. valid = False
  24. return (valid)
  25.  
  26. def main(studentlist):
  27. uname,pword=ded()
  28. validUser=checkuser(uname,pword,studentlist)
  29.  
  30. if validUser==True:
  31. print("Welcome to the game player 1")
  32. else:
  33. print("Incorrect details entered!")
  34. main(studentlist)
  35.  
  36. studentlist = importfile()
  37. main(studentlist)
  38.  
  39.  
  40. def ded():
  41. print("player2")
  42. User=input("usename: ")
  43. Pass=input("paswword: ")
  44. return(User,Pass)
  45.  
  46. def checkuser(username,password,uList):
  47. valid = False
  48. for i in range(0,len(uList)):
  49. if username == uList[i][0] and password == uList[i][1]:
  50. valid = True
  51. break
  52. else:
  53. valid = False
  54. return (valid)
  55.  
  56. def main(studentlist):
  57. uname,pword=ded()
  58. validUser=checkuser(uname,pword,studentlist)
  59.  
  60. if validUser==True:
  61. print("Welcome to the game player2")
  62. else:
  63. print("Incorrect details entered!")
  64. main(studentlist)
  65.  
  66. studentlist = importfile()
  67. main(studentlist)
  68.  
  69.  
  70. from random import randint
  71. from time import sleep
  72.  
  73. playerOneWins = 0
  74. playerTwoWins = 0
  75.  
  76. for i in range(0,5):
  77. print("Player 1 it's your turn. Type 'roll' to roll the dice or tap enter to see your result. ")
  78. userOneInput = input(">>>")
  79. if userOneInput == "roll":
  80. valueOne = randint(1,12)
  81. print("Player 1 rolled ", valueOne)
  82. print(" Player 2 it's your turn. Type 'roll' to roll the dice or tap enter to end the game and see your result. ")
  83. userTwoInput = input(">>>")
  84. if userTwoInput == "roll":
  85. valueTwo = randint(1,12)
  86. print("Player 2 rolled ", valueTwo)
  87. if valueOne > valueTwo:
  88. print("Player 1 wins this round! ")
  89. playerOneWins += 1
  90. elif valueOne == valueTwo:
  91. print("It's a tie! ")
  92. else:
  93. print("Player 2 wins this round;")
  94. playerTwoWins += 1
  95. elif userTwoInput == "forfeit":
  96. print("Player 1 wins this round! ")
  97. playerOneWins += 1
  98. else:
  99. print("the game ended, your results are shown bellow.")
  100. break
  101. elif userOneInput == "forfeit":
  102. print ("Player 2 wins this round! ")
  103. playerTwoWins += 1
  104. else:
  105. print("the game ended, your results are shown bellow.")
  106. break
  107.  
  108. sleep(2)
  109.  
  110.  
  111. print("Final results: ", playerOneWins, "-", playerTwoWins)
  112. if playerOneWins > playerTwoWins:
  113. print("Player 1 is the winner! ")
  114. elif playerOneWins == playerTwoWins:
  115. print("It's a tie! ")
  116. else:
  117. print("Player 2 is the winner! ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement