← Back to all posts
##### What to do so that there isn't [mccabe] Cyclomatic complexity too high: 23 (threshold 15) message
``````#task2

import random  #It allows the user to roll the dice as it's gonna come up with a random number each time
import time  #It allows to pause the game in certain places for certain amount of time

tries = 0  #this is the number of times a user fails to enter correct verification
enter = 0  #The number of times a user enters Username and Password
rolling = 0 #number of rounds to be played
rounds = 0
rounds = rounds + 1 #how many times a player has got chance to roll

while enter == 0:  #if enter becomes other than 0, the game will start
code = input("Input the authorization code to play this game:")
if code == ("proplay"):  #Checking whether the input code is in "gamingsquad" or not
print("You have entered authorization code corectly, enjoy the game!")
Player1 = input("What would Player 1 like to be called? ") #asking each user to input the name they want to be called
Player2 = input("What would Player 2 like to be called? ")
print(Player1,"and",Player2,",now the game will start...")
time.sleep(2)
enter = 1
else:
print("\nIncorrect authorization code please try again!")
tries = 1 + tries  #required for next if statement

if tries == 4:  #If user enters wrong password or username 4 times than the user have to wait 5 minutes and try again until the user gets username and password correct
print("You have entered incorect authorization code too many times, please try again after 5 minutes!")
time.sleep(300)  #For 5 minutes the user won't be able to try again
tries = 0
else:
print()

if enter == 1:
while rounds < 5:  #until there are 5 rounds, the game continues looping
while rolling == 0: #rolling = 0 for player 1 turn and rolling = 1 for player 2
p1 = input("\nPlayer 1, press y to roll the dices: ")
if p1 != "y":
print()
else:
p1dice1 = random.randint(1,6)  #allows any number to be chosen from 1 to 6
p1dice2 = random.randint(1,6)
p1dice3 = random.randint(1,6)
print("Rolling dice 1...")
time.sleep(1)
print("Dice 1 rolled a", p1dice1)
print("Rolling dice 2...")
time.sleep(1)
print("Dice 2 rolled a", p1dice2)
p1total = p1dice1 + p1dice2
rolling = 1

if p1dice1 == p1dice2:  #if statements according to the game rule
print("You rolled a double.Good job!You get to roll one more dice.")
time.sleep(1)
print("Rolling dice 3...")
time.sleep(1)
print("Dice 3 rolled a", p1dice3)
p1total = p1total + p1dice3
else:
p1total = p1total

if p1total%2 == 0:  #To check whether the number is odd or even
p1total = p1total+10
print("You have total score as an even number. So,according to the game rule;your new total score now will be added by 10. Now,you have",p1total,"as a total score")
elif p1total%2 == 1:
p1total = p1total-5  #after it is subtracted from 5 elif statement is used as only after subtracting the number can be less than, equal or greater than 0
if p1total == 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted 5. Now,you have",p1total,"as a total score")
elif p1total < 0:
p1total = 0
print("Your total score was subtracted by 5 and went below 0 but according to the game rule, the total score can't go below 0. So, your total score remains 0")
elif p1total > 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted by 5. Now,you have",p1total,"as a total score")
else:
print()
else:
print()

while rolling == 1:
p2 = input("\nPlayer 2, press y to roll the dices: ")
if p2!= "y":
print()
else:
if p2 == "y":
p2dice1 = random.randint(1,6)
p2dice2 = random.randint(1,6)
p2dice3 = random.randint(1,6)
print("Rolling dice 1...")
time.sleep(1)
print("Dice 1 rolled a", p2dice1)
print("Rolling dice 2...")
time.sleep(1)
print("Dice 2 rolled a", p2dice2)
p2total = p2dice1 + p2dice2
rolling = 0

if p2dice1 == p2dice2:
print("You rolled a double.Good job!You get to roll one more dice.")
time.sleep(1)
print("Rolling dice 3...")
time.sleep(1)
print("Dice 3 rolled a", p2dice3)
p2total = p2total + p2dice3
else:
p2total = p2total

if p2total%2 == 0:
p2total = p2total+10
print("You have total score as an even number. So,according to the game rule;your new total score now will be added by 10. Now,you have",p2total,"as a total score")
elif p2total%2 == 1:
p2total = p2total-5
if p2total == 0:
print("You have total score as an odd number. So,according to the rule;your new total score now will be subtracted 5. Now,you have",p2total,"as a total score")
elif p2total < 0:
p2total = 0
print("Your total score was subtracted by 5 and went below 0 but according to the game rule, the total score can't go below 0. So, your total score remains 0")
elif p2total > 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted by 5. Now,you have",p2total,"as a total score")
else:
print()
else:
print()
else:
print()``````
hotnewtop
ProGamingGaming (2)

import random #It allows the user to roll the dice as it's gonna come up with a random number each time
import time #It allows to pause the game in certain places for certain amount of time

tries = 0 #this is the number of times a user fails to enter correct verification
enter = 0 #The number of times a user enters Username and Password
rolling = 0 #number of rounds to be played
rounds = 0 #how many times a player has got chance to roll

while enter == 0: #if enter becomes other than 0, the game will start
code = input("Input the authorization code to play this game:")
if code == ("proplay"): #Checking whether the input code is in "gamingsquad" or not
print("You have entered authorization code corectly, enjoy the game!")
Player1 = input("What would Player 1 like to be called? ") #asking each user to input the name they want to be called
Player2 = input("What would Player 2 like to be called? ")
print(Player1,"and",Player2,",now the game will start...")
time.sleep(2)
enter = 1
else:
print("\nIncorrect authorization code please try again!")
tries = 1 + tries #required for next if statement

``````if tries == 4:  #If user enters wrong password or username 4 times than the user have to wait 5 minutes and try again until the user gets username and password correct
print("You have entered incorect authorization code too many times, please try again after 5 minutes!")
time.sleep(300)  #For 5 minutes the user won't be able to try again
tries = 0
else:
print()

if enter == 1:
while rolling == 0:
p1 = input("\nPlayer 1, press y to roll the dices: ")
if p1!= "y":
print()
else:
p1dice1 = random.randint(1,6)  #allows any number to be chosen from 1 to 6
p1dice2 = random.randint(1,6)
p1dice3 = random.randint(1,6)
print("Rolling dice 1...")
time.sleep(1)
print("Dice 1 rolled a", p1dice1)
print("Rolling dice 2...")
time.sleep(1)
print("Dice 2 rolled a", p1dice2)
p1total = p1dice1 + p1dice2
rolling = 1

if p1dice1 == p1dice2:  #if statements according to the game rule
print("You rolled a double.Good job!You get to roll one more dice.")
time.sleep(1)
print("Rolling dice 3...")
time.sleep(1)
print("Dice 3 rolled a", p1dice3)
p1total = p1total + p1dice3
else:
p1total = p1total

if p1total%2 == 0:  #To check whether the number is odd or even
p1total = p1total+10
print("You have total score as an even number. So,according to the game rule;your new total score now will be added by 10. Now,you have",p1total,"as a total score")
elif p1total%2 == 1:
p1total = p1total-5  #after it is subtracted from 5 elif statement is used as only after subtracting the number can be less than, equal or greater than 0
if p1total == 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted 5. Now,you have",p1total,"as a total score")
elif p1total < 0:
p1total = 0
print("Your total score was subtracted by 5 and went below 0 but according to the game rule, the total score can't go below 0. So, your total score remains 0")
elif p1total > 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted by 5. Now,you have",p1total,"as a total score")
else:
print()

while rolling == 1:
p2 = input("\nPlayer 2, press y to roll the dices: ")
if p2!= "y":
print()
else:
p2dice1 = random.randint(1,6)
p2dice2 = random.randint(1,6)
p2dice3 = random.randint(1,6)
print("Rolling dice 1...")
time.sleep(1)
print("Dice 1 rolled a", p2dice1)
print("Rolling dice 2...")
time.sleep(1)
print("Dice 2 rolled a", p2dice2)
p2total = p2dice1 + p2dice2

if p2dice1 == p2dice2:
print("You rolled a double.Good job!You get to roll one more dice.")
time.sleep(1)
print("Rolling dice 3...")
time.sleep(1)
print("Dice 3 rolled a", p2dice3)
p2total = p2total + p2dice3
else:
p2total = p2total

if p2total%2 == 0:
p2total = p2total+10
print("You have total score as an even number. So,according to the game rule;your new total score now will be added by 10. Now,you have",p2total,"as a total score")
rounds = rounds + 1
rolling = 0
elif p2total%2 == 1:
p2total = p2total-5
else:
print()

if p2total == 0:
print("You have total score as an odd number. So,according to the rule;your new total score now will be subtracted 5. Now,you have",p2total,"as a total score")
rounds = rounds + 1
rolling = 0
elif p2total < 0:
p2total = 0
print("Your total score was subtracted by 5 and went below 0 but according to the game rule, the total score can't go below 0. So, your total score remains 0")
rounds = rounds + 1
rolling = 0
elif p2total > 0:
print("You have total score as an odd number. So,according to the game rule;your new total score now will be subtracted by 5. Now,you have",p2total,"as a total score")
rounds = rounds + 1
rolling = 0
else:
print()

while rounds == 5:
while p1total == p2total:
p1 = input("\nPlayer 1, press y to roll the dices: ")
if p1 != "y":
print()
else:
pdice1 = random.randint(1,6)
print("Rolling dice...")
time.sleep(2)
print("Player 1 your dice rolled a", pdice1)
p1total = p1total + pdice1
p2 = input("\nPlayer 2, press y to roll the dices: ")

if p2 !="y":
print()
else:
p2dice1 = random.randint(1,6)
print("Rolling dice...")
time.sleep(2)
print("Player 2 your dice rolled a", p2dice1)
p2total = p2total + p2dice1

if p1total > p2total:
print("\nThe scores have been added up and....")
time.sleep(2)
print("Player 1 is the winner with",p1total,"points.")
print("Player 2, better luck next time. Your total score is",p2total)
rounds = 2
else:
print("\nThe scores have been added up and....")
time.sleep(2)
print("Player 2 is the winner with",p2total,"points.")
print("Player 1, better luck next time. Your total score is",p1total)
rounds = 2

``````
LOLMcman (68)

When are you getting this error?

ProGamingGaming (2)

@LOLMcman
This is the question and I have commented my new code. Please can you check it. It will be very kind of you and tell me what to improve...
Katarina is developing a two-player dice game.
The players roll two 6-sided dice each and get points depending on what they
roll. There are 5 rounds in a game. In each round, each player rolls the two dice.
The rules are:
• The points rolled on each player’s dice are added to their score.
• If the total is an even number, an additional 10 points are added to their score.
• If the total is an odd number, 5 points are subtracted from their score.
• If they roll a double, they get to roll one extra die and get the number of points rolled added to
their score.
• The score of a player cannot go below 0 at any point.
• The person with the highest score at the end of the 5 rounds wins.
• If both players have the same score at the end of the 5 rounds, they each roll 1 die and
whoever gets the highest score wins (this repeats until someone wins).
Only authorised players are allowed to play the game.
Where appropriate, input from the user should be validated.
Design, develop, test and evaluate a program that:
1. Allows two players to enter their details, which are then authenticated to ensure that they are
authorised players.
2. Allows each player to roll two 6-sided dice.
3. Calculates and outputs the points for each round and each player’s total score.
4. Allows the players to play 5 rounds.
5. If both players have the same score after 5 rounds, allows each player to roll 1 die each until
someone wins.
6. Outputs who has won at the end of the 5 rounds.
7. Stores the winner’s score, and their name, in an external file.
8. Displays the score and player name of the top 5 winning scores from the external file.

LOLMcman (68)

@ProGamingGaming You apparently have to store the winner's score and name in an external file. I'm probably reading/understanding the question wrong since you don't really need to do this. But if you are supposed to, then you can use

``````f = open("winners.txt", "w")
f.write([winner data])
f = open("winners.txt", "r")