Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.79 KB | None | 0 0
  1. import random
  2. ryuk=[]
  3. #from tutor system program practice coursework
  4. def login():
  5.     cpassword="399"
  6.     cpassword2="chair"
  7.     username=input("username: ")
  8.     password=input("password: ")
  9.     while password!=cpassword:
  10.        
  11.         if password!=cpassword:
  12.             print("invalid password P1")
  13.         username=input("username: ")
  14.         password=input("password: ")
  15.     print("logged in P1")
  16.     username2=input("username P2")
  17.     password2=input("password P2")
  18.    
  19.     while password2!=cpassword2:
  20.         if password2!=cpassword2:
  21.                 print("invalid password P2")
  22.         username2 = input("username P2")
  23.         password2 = input("password P2")
  24.     print("logged in P2")
  25.     return username,username2
  26.  
  27. # from my snakes and ladders practice coursework
  28. player1 = 0
  29. player2 = 0
  30. roundno=0
  31. #the dice and all the rules associated with score
  32. def dice(score):
  33.        
  34.  
  35.         random_number = random.randint(1,6)
  36.         print("You rolled a",random_number)
  37.        
  38.  
  39.         random_number1 = random.randint(1,6)
  40.         print("You rolled a",random_number1)
  41.    
  42.         roll = random_number + random_number1
  43.  
  44.         print(roll)
  45.        
  46.         if random_number != random_number1:
  47.             score=score+roll
  48.         #if a double is rolled rule
  49.         if random_number == random_number1:
  50.             random_number2 = random.randint(1,6)
  51.             print(score)
  52.             print("You rolled an exra",random_number2)
  53.             roll = random_number + random_number1 + random_number2
  54.             score=score+roll
  55.  
  56.        
  57.         #even rule
  58.         if score%2==0:
  59.                 print("an even score thats 10 extra points")
  60.                 score=score+10
  61.         #odd rule
  62.         if score%2!=0:
  63.                 print ("an odd score sorry thats -5 points")
  64.                 score = score-5
  65.         #doesnt let score go below 0
  66.         if score < 0:
  67.                 score = 0
  68.         return score
  69.  
  70. def load():
  71.     file=open("thingy.txt","r")
  72.     for line in file:
  73.         temp=line.split(",")
  74.         ryuk.append ([temp[0],int(temp[1])])
  75.        
  76.  
  77.     file.close()    
  78. name1,name2=login()
  79. load()
  80. #outputs the score and lets players roll
  81. while roundno<5:
  82.    
  83.    
  84.     roundno = roundno + 1
  85.     print("it is round",roundno)
  86.     print(name1,"it's your turn")
  87.     loll=input("press enter to roll")
  88.     player1=dice(player1)
  89.     print(name1,"your score is",player1)
  90.     print (name2,"it's your turn")
  91.     lolll=input("press enter to roll")
  92.     player2=dice(player2)
  93.     print(name2, "your score is",player2)
  94.  
  95. #decides who wins and adds them to the list
  96. if player1 > player2:
  97.     print (name1," wins")
  98.     ryuk.append([name1,player1])
  99. elif player2 > player1:
  100.     print(name2," wins")
  101.     ryuk.append([name2,player2])
  102. #in event of a draw
  103. else:
  104.         while player1 == player2:
  105.             print("now you only get one dice")
  106.             random_number = random.randint(1,2)
  107.             print("You rolled a",random_number)
  108.             player1 = player1 + random_number
  109.             print(name1,"your score is",player1)
  110.             random_number1 = random.randint(1,2)
  111.             print("You rolled a",random_number1)
  112.             player2 = player2 + random_number1
  113.             print(name2,"your score is",player2)
  114.             if player1 > player2:
  115.                 print (name1," wins")
  116.                 ryuk.append([name1,player1])
  117.             elif player2 > player1:
  118.                 print(name2," wins")
  119.                 ryuk.append([name2,player2])
  120.  
  121. file=open("thingy.txt","w")
  122. #saves winner to file
  123. for score in ryuk:
  124.     file.write(score[0]+","+str(score[1])+"\n")
  125. file.close()
  126. #sorts list
  127. List = ryuk
  128. sortedlist =sorted(List,key=lambda x:x[1], reverse=True)
  129. #prints top 5 winners  
  130. for k in range(5):
  131.     print(sortedlist[k])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement