Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tidy up
- import random, time
- def roll():
- d1 = random.randint(1,6)
- d2 = random.randint(1,6)
- #d1 = int(input("Enter d1 >>"))
- #d2 = int(input("Enter d2 >>"))
- d3 = 0
- tot = d1 + d2
- if tot % 2 ==0: # testing there for an even number
- tot +=10
- else:
- tot -= 5 # tot = tot -5
- if tot < 0:
- tot = 0
- if d1 == d2: # checking for both the same
- d3 = random.randint(1,6)
- tot += d3
- #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot) # for testing
- return tot
- user_list= ["Bob","Fred","Pragya","Colin"]
- password = "Its raining"
- user1 = input("Who are you user1? >>")
- user2 = input("Who are you user2? >>")
- #if user in user_list and pword == password:
- if user1 in user_list and user2 in user_list and user1 != user2:
- print("you're in the auth user list")
- pword= input("What's the password? >>")
- if pword == password:
- print("Password OK")
- print("Users and password ok")
- else:
- print("Password not ok... exiting")
- exit()
- else:
- print("User(s) Not in the list")
- exit()
- ###
- p1score = 0 # initalising total variables
- p2score = 0
- for i in range(5):
- print("round", i+1)
- p1roll = roll()
- p2roll = roll()
- time.sleep(1)
- print(user1, p1roll)
- time.sleep(1)
- print(user2, p2roll)
- p1score +=p1roll
- p2score +=p2roll # p2score = p2score +p2roll
- time.sleep(1)
- print("Total scores",user1,"-", p1score,user2,"-", p2score)
- while p1score == p2score:
- print("Draw round")
- p1roll = roll()
- p2roll = roll()
- time.sleep(1)
- print(user1,"Draw roll scored", p1roll)
- time.sleep(1)
- print(user2,"Draw roll scored", p2roll)
- p1score +=p1roll
- p2score +=p2roll # p2score = p2score +p2roll
- time.sleep(1)
- print("Total scores",user1,"-", p1score,user2,"-", p2score)
- #who won!
- if p1score > p2score:
- print(user1,"wins score", p1score)
- new_item = [p1score,user1]
- else:
- print(user2,"wins score", p2score)
- new_item = [p2score,user2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement