Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from random import randint
- def registration():
- username=input("Create a username.")
- password=input("Create a password.")
- myFile=open("authentication.txt", "a+")
- myFile.write(username + "," + password + "\n")
- myFile.close()
- print("Registration successful.")
- def login():
- file=open("authentication.txt", "r")
- logins=file.read()
- username=input("Enter your username.")
- password=input("Enter your password.")
- authorised=False
- while True:
- if (username+ "," +password) not in logins:
- print("Login unsuccessful. Type exit to exit")
- username=input("Enter your username.")
- password=input("Enter your password.")
- else:
- authorised=True
- break
- if username=="exit" or password=="exit":
- return False
- if authorised:
- print("Login successful.")
- return True
- def playerturns():
- totalscore=0
- num1=randint(1, 6)
- num2=randint(1, 6)
- totalscore=num1+num2
- if totalscore<0:
- totalscore=0
- if num1==num2:
- totalscore+=randint(1, 6)
- if(num1+num2)%2==0:
- totalscore=totalscore+10
- else:
- totalscore=totalscore-5
- print("Rolled",num1,",",num2)
- print(totalscore, "points added to your score")
- return totalscore
- p1total=0
- p2total=0
- registration()
- login()
- for i in range(0,5):
- print("Player 1's turn!")
- p1total=p1total+playerturns()
- print("Player 1's score is", p1total)
- input("Press enter to roll the die")
- print("\n"*10)
- print("Player 2's turn!")
- p2total=p2total+playerturns()
- print("Player 2's score is", p2total)
- input("Press enter to roll the die")
- print("\n"*10)
- while p1total==p2total:
- p1num=randint(0, 6)
- p2num=randint(0, 6)
- p1total=p1total+p1num
- p2total=p2total+p2num
- if p1total>p2total:
- print("Player1 wins." + "\n" + "Player1TotalPoints: " + str(p1total) + "\n" + "Player2TotalPoints: " + str(p2total))
- elif p1total<p2total:
- print("Player2 wins." + "\n" + "Player1TotalPoints: " + str(p1total) + "\n" + "Player2TotalPoints: " + str(p2total))
- if p1total>p2total:
- p1name=input("Player1, enter your name.")
- myFile=open("scores.txt", "a")
- myFile.write(str(p1name)+ "," +str(p1total)+ "\n")
- myFile.close()
- elif p1total<p2total:
- p2name=input("Player2, enter your name.")
- myFile=open("scores.txt", "a")
- myFile.write(str(p2name)+ "," +str(p2total)+ "\n")
- myFile.close()
- myFile=open("scores.txt","r")
- pscores=[line.rstrip() for line in myFile]
- def bubblesort(pscores):
- swapsmade=True
- while swapsmade==True:
- swapsmade=False
- for i in range(0, len(pscores)-1):
- if int(pscores[i][1])<int(pscores[i+1][1]):
- temp=pscores[i]
- pscores[i]=pscores[i+1]
- pscores[i+1]=temp
- swapsmade=True
- for i in range (0,5):
- print(pscores[i])
- return pscores
- bubblesort(pscores)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement