Advertisement
timber101

Dice Game 3 - Looping and Function

Nov 23rd, 2022
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # dice game - scores
  2. # roll even number +10, roll odd -5 ( cant go below zero ) roll a double get an extra roll
  3. # Again, DONT JUST COPY THIS CODE, type it in yourself, please
  4.  
  5. import random
  6.  
  7. def roll():
  8.     d1 = random.randint(1,6)
  9.     d2 = random.randint(1,6)
  10.  
  11.     #d1 = int(input("Enter d1 >>"))
  12.     #d2 = int(input("Enter d2 >>"))
  13.     d3 = 0
  14.  
  15.     tot = d1 + d2
  16.  
  17.     if tot % 2 ==0:  # testing there for an even number
  18.         #tot = tot +10
  19.         tot +=10
  20.     else:
  21.         tot -= 5 # tot = tot -5
  22.         if tot < 0:
  23.             tot = 0
  24.  
  25.     if d1 == d2: # checking for both the same
  26.         d3 = random.randint(1,6)
  27.         tot += d3
  28.     #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot) # for testing
  29.     return tot
  30.  
  31. #while True:
  32. for i in range(5):
  33.     thisroll = roll()
  34.     print(thisroll)
  35.     #input()
  36.  
  37. #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot)
  38. #print("die1= " + str(d1) +" die2= " +str(d2) + " tot= " +str(tot)) # concatenation + casting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement