# [Tutor] Hi there!

Hamnah Baig hamnahxbaig at gmail.com
Wed Dec 18 05:40:33 EST 2019

```Can you help me with this code?
along with an exit option that exits and goes back to the start.

code :
# import varibles

import time #Used to lock
import random #Used for dice
import sys #Used to exit
from random import randint

#Varibles
p1totaltotal = 0
p2totaltotal = 0
#opt = " "
#scoreboards = 0
tries = 1
enter = 0
rounds = 0
#]p1 = 0
#p2 = 0
#p1roll3 = 0
#p2roll3 = 0
even = [2, 4, 6, 8, 10, 12, 14, 16, 18]
odd = [3, 5, 7, 9, 11, 13, 15, 17]
#no = 0
#rolls = 1
#Droll = 1
p1go = 0
p2go = 0
rolling = 0
#rollin = 0
#dice = 0

while enter == 0:
print ('\n')
print('Authorization password is correct, Welcome to the Dice
Game.')
rolls = 0
enter = 1 + enter
elif tries == 3:
print('Ops, you have entered the authorization password wrong too
many times.')
print('You have been locked out for 10 minutes')
time.sleep(600)
tries = 0
else:
help desk')
tries = 1 + tries

# This is how to enter the players Usernames

print ('\n')
if true == "!":

print('This is a 2 player game, so can the players please enter their
pname1 = input ('\nWhat would player one liked to be called?')
pname2 = input ('\nWhat would player two liked to be called?')
print('welcome', pname1, ',and welcome', pname2, ',to the two player dice
game')

# This it how to can select an option
print ('\n')
opt = input("please type 'open' to look at the options?")
if opt == "open":
print("1: Enter the game")
print("2: Rules")
print("3: Exit")
opt=input('What would you like to do, please select a number:')
else:

while int(opt) < 1 or int(opt) > 4:
print('That is not a valid option.')
print('Please enter a number between 1 and 4:')
opt=input()

#This is the game rules

if opt == 2:
print('\nRules')
print('\nThe dice game is a very simple game to understand:')
print('\nTwo players take turns to roll two dices.')
print("\nThey both roll the dice twice over 5 rounds")
print("\nthe way to win is who ever has the highest even number
will win")
print("\nIf both players have the same score at the end of the 5
rounds, they will each roll one more dice and whoever has the highest score
will be the winner")

#this is how you exit the game

print ('\n')
if opt == 3:
print('now exiting the game')
sys.exit()

#This is the game code

if opt == 1:

time.sleep(0.3)
print("Hello player!")

while rounds < 5:
print("Round ",rounds + 1)

p1 = input("\nPlayer 1 press r to roll")
if p1 == "r":
p1roll1 = random.randint(1, 6)
p1roll2 = random.randint(1, 6)
p1roll3 = p1roll1 + p1roll2
print("Dice 1 rolled a", p1roll1, ".")
print("Dice 2 rolled a", p1roll2, ".")
print("Player 1 your roll was a", p1roll3, ".")

else:
print("\nTo play the game could you please press 'r'")

if p1roll1 == p1roll2:
print("You got a double. You get one more roll.")
double = random.randint(1, 6)
p1roll3 = p1roll3 + double
print("The double dice rolled a", double, ".")
print("You got", p1roll3, ".")

#Rolls an odd

if p1roll3 % 2 ==0:
p1roll3 = p1roll3 + 10

else:
p1roll3 = p1roll3 - 5
if p1roll3 <0:
p1roll3 = 0
print("You rolled a odd number 5 points have been removed from your
score.  You now have",p1roll3, "points.")

p1totaltotal = p1totaltotal + p1roll3

p2 = input("\nPlayer 2 press r to roll")
if p2 == "r":
p2roll1 = random.randint(1, 6)
p2roll2 = random.randint(1, 6)
p2roll3 = p2roll1 + p2roll2
print("Dice 1 rolled a", p2roll1, ".")
print("Dice 2 rolled a", p2roll2, ".")
print("Player 2 your roll was a", p2roll3, ".")

else:
print("\nTo play the game could you please press 'r'")

if p2roll1 == p2roll2:
print("You got a double. You get one more roll.")
double = random.randint(1, 6)
p2roll3 = p1roll3 + double
print("The double dice rolled a", double, ".")
print("You got", p2roll3, ".")

#Rolls an odd

if p2roll3 % 2 ==0:
p2roll3 = p2roll3 + 10

else:
p2roll3 = p2roll3 - 5
if p2roll3 <0:
p2roll3 = 0
print("You rolled a odd number 5 points have been removed from your
score.  You now have",p2roll3, "points.")

p2totaltotal = p2totaltotal + p2roll3

rounds = rounds + 1

#Final Scores

print("\nThe scores have been added up and")
time.sleep(2)
print('\n')
print(pname1 , "got", p1go, ".")
print(pname2 , "got", p2go, ".")
```