Advertisement
timber101

Dice Game 5 - Tidy Up

Dec 4th, 2022
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. # Tidy up
  2.  
  3. import random, time
  4.  
  5. def roll():
  6.     d1 = random.randint(1,6)
  7.     d2 = random.randint(1,6)
  8.     #d1 = int(input("Enter d1 >>"))
  9.     #d2 = int(input("Enter d2 >>"))
  10.     d3 = 0
  11.     tot = d1 + d2
  12.     if tot % 2 ==0:  # testing there for an even number
  13.         tot +=10
  14.     else:
  15.         tot -= 5 # tot = tot -5
  16.         if tot < 0:
  17.             tot = 0
  18.     if d1 == d2: # checking for both the same
  19.         d3 = random.randint(1,6)
  20.         tot += d3
  21.     #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot) # for testing
  22.     return tot
  23.  
  24.  
  25. user_list= ["Bob","Fred","Pragya","Colin"]
  26. password = "Its raining"
  27.  
  28. user1 = input("Who are you user1? >>")
  29. user2 = input("Who are you user2? >>")
  30. #if user in user_list and pword == password:
  31. if user1 in user_list and user2 in user_list and user1 != user2:
  32.     print("you're in the auth user list")
  33.     pword= input("What's the password? >>")
  34.     if pword == password:
  35.         print("Password OK")
  36.         print("Users and password ok")
  37.     else:
  38.         print("Password not ok...  exiting")
  39.         exit()
  40. else:
  41.     print("User(s) Not in the list")
  42.     exit()
  43. ###
  44.  
  45. p1score = 0 # initalising total variables
  46. p2score = 0
  47. for i in range(5):
  48.     print("round", i+1)
  49.     p1roll = roll()
  50.     p2roll = roll()
  51.     time.sleep(1)
  52.     print(user1, p1roll)
  53.     time.sleep(1)
  54.     print(user2, p2roll)
  55.     p1score +=p1roll
  56.     p2score +=p2roll # p2score = p2score +p2roll
  57.     time.sleep(1)
  58.     print("Total scores",user1,"-", p1score,user2,"-", p2score)
  59.  
  60.  
  61. while p1score == p2score:
  62.     print("Draw round")
  63.     p1roll = roll()
  64.     p2roll = roll()
  65.     time.sleep(1)
  66.     print(user1,"Draw roll scored", p1roll)
  67.     time.sleep(1)
  68.     print(user2,"Draw roll scored", p2roll)
  69.     p1score +=p1roll
  70.     p2score +=p2roll # p2score = p2score +p2roll
  71.     time.sleep(1)
  72.     print("Total scores",user1,"-", p1score,user2,"-", p2score)
  73.  
  74. #who won!    
  75. if p1score > p2score:
  76.     print(user1,"wins score", p1score)
  77.     new_item = [p1score,user1]
  78. else:
  79.     print(user2,"wins score", p2score)  
  80.     new_item = [p2score,user2]
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement