Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- ryuk=[]
- #from tutor system program practice coursework
- def login():
- cpassword="399"
- cpassword2="chair"
- username=input("username: ")
- password=input("password: ")
- while password!=cpassword:
- if password!=cpassword:
- print("invalid password P1")
- username=input("username: ")
- password=input("password: ")
- print("logged in P1")
- username2=input("username P2")
- password2=input("password P2")
- while password2!=cpassword2:
- if password2!=cpassword2:
- print("invalid password P2")
- username2 = input("username P2")
- password2 = input("password P2")
- print("logged in P2")
- return username,username2
- # from my snakes and ladders practice coursework
- player1 = 0
- player2 = 0
- roundno=0
- #the dice and all the rules associated with score
- def dice(score):
- random_number = random.randint(1,6)
- print("You rolled a",random_number)
- random_number1 = random.randint(1,6)
- print("You rolled a",random_number1)
- roll = random_number + random_number1
- print(roll)
- if random_number != random_number1:
- score=score+roll
- #if a double is rolled rule
- if random_number == random_number1:
- random_number2 = random.randint(1,6)
- print(score)
- print("You rolled an exra",random_number2)
- roll = random_number + random_number1 + random_number2
- score=score+roll
- #even rule
- if score%2==0:
- print("an even score thats 10 extra points")
- score=score+10
- #odd rule
- if score%2!=0:
- print ("an odd score sorry thats -5 points")
- score = score-5
- #doesnt let score go below 0
- if score < 0:
- score = 0
- return score
- def load():
- file=open("thingy.txt","r")
- for line in file:
- temp=line.split(",")
- ryuk.append ([temp[0],int(temp[1])])
- file.close()
- name1,name2=login()
- load()
- #outputs the score and lets players roll
- while roundno<5:
- roundno = roundno + 1
- print("it is round",roundno)
- print(name1,"it's your turn")
- loll=input("press enter to roll")
- player1=dice(player1)
- print(name1,"your score is",player1)
- print (name2,"it's your turn")
- lolll=input("press enter to roll")
- player2=dice(player2)
- print(name2, "your score is",player2)
- #decides who wins and adds them to the list
- if player1 > player2:
- print (name1," wins")
- ryuk.append([name1,player1])
- elif player2 > player1:
- print(name2," wins")
- ryuk.append([name2,player2])
- #in event of a draw
- else:
- while player1 == player2:
- print("now you only get one dice")
- random_number = random.randint(1,2)
- print("You rolled a",random_number)
- player1 = player1 + random_number
- print(name1,"your score is",player1)
- random_number1 = random.randint(1,2)
- print("You rolled a",random_number1)
- player2 = player2 + random_number1
- print(name2,"your score is",player2)
- if player1 > player2:
- print (name1," wins")
- ryuk.append([name1,player1])
- elif player2 > player1:
- print(name2," wins")
- ryuk.append([name2,player2])
- file=open("thingy.txt","w")
- #saves winner to file
- for score in ryuk:
- file.write(score[0]+","+str(score[1])+"\n")
- file.close()
- #sorts list
- List = ryuk
- sortedlist =sorted(List,key=lambda x:x[1], reverse=True)
- #prints top 5 winners
- for k in range(5):
- print(sortedlist[k])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement