2 player dice game, where even total gains points and odd total loses points NEA task computer science...












1














This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points if it is odd, they lose 5.



If there it is a draw after five rounds then the both users will have to roll one dice to determine the winner.



One of the updates that I have done to this code is that I added functions to it so that it reduces the size of the code and I also removed repeated code and I also tried my very best act upon the suggestions that were given to me on my old code and I have tried my very best to improve DRY (don't repeat yourself) skills



I just want suggestions on how I could improve this updated code



import time
import sys
import random
import operator
total_score2 = 0
total_score1 = 0
rounds = 0
playerOnePoints = 0
playerTwoPoints = 0
counter = 0

print("*****************Welcome To The DICE Game*******************")
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
ens=input("")
while ens not in ('e', 'n', 's'): # if anything else but these characters are entered it will loop until it is correct
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
ens = input()

if ens == "s":
s = open("scores.txt","r")
file_content = s.read().splitlines()
users_points = {i.split()[0]: int(i.split()[2]) for i in file_content}
best_player = max(users_points.items(), key=operator.itemgetter(1))[0]
print("LeaderBoard: ")
print("n")
print('player with maximum points is {}, this player has {} points'.format(best_player, users_points[best_player]))
best_players = sorted(users_points, key=users_points.get, reverse=True)
for bp in best_players:
print('{} has {} points'.format(bp, users_points[bp])) # This prints all players scores
print("n")
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
ens=input("")

if ens == "n":
file = open("accountfile.txt","r+")
text = file.read().strip().split()
check = True
while check:
username=input("Please enter appropiate username: ") #Takes input of a username from user
if username == "": #if no value is entered for the username
continue
if username in text: #username in present in the text file
print("Username is taken please try another one")
else: #username is absent in the text file
print("Username has been accepted")
check = False
check = True
while check:
password1=input("Please enter password: ")
password2=input("Please re-enter password: ")
if password1 == password2:
if password2 in text:
print("Password has been taken please try another one")
else:
print("Username and Password have sucessfully been made Thankyou")
file.write("username: " + username + " " + "password: " + password2 + "n")
file.close()
check = False
else:
print("passwords do not match please try again")
file.close()

def write1():
print("Player 1 ",username1," Wins!")
file = open("scores.txt","a")
file.write(username1 + " has " + str(total_score1) + " points" + "n")
file.close()
sys.exit()
def write2():
print("Player 2 ",username2," Wins!")
file = open("scores.txt","a")
file.write(username2 + " has " + str(total_score2) + " points" + "n")
file.close()
sys.exit()
def validation():
global counter
print("Sorry, this username or password does not exist please try again")
counter = counter + 1
if counter == 3:
print("----------------------------------------------------")
print("You have been locked out please restart to try again")
sys.exit()
def game():
global total_score1
global total_score2
global rounds
global number
global number2
global playerOnePoints
global playerTwoPoints
total_score2 = total_score2 + playerTwoPoints
total_score1 = total_score1 + playerOnePoints
rounds = rounds + 1
number = random.randint(1,6)
number2 = random.randint(1,6)
playerOnePoints = number + number2
print("-------------------------------------------")
print("Round",rounds)
print("-------------------------------------------")
print("Player 1's turn Type 'roll' to roll the dice")
userOneInput = input(">>> ")
if userOneInput == "roll":
time.sleep(1)
print("Player 1's first roll is", number)
print("Player 1's second roll Type 'roll' to roll the dice")
userOneInput = input(">>> ")
if userOneInput == "roll":
time.sleep(1)
print("player 1's second roll is", number2)
if playerOnePoints % 2 == 0:
playerOnePoints = playerOnePoints + 10
print("Player 1's total is even so + 10 points")
print("-------------------------------------------")
print("Player 1 has",playerOnePoints, "points")
else:
playerOnePoints = playerOnePoints - 5
print("player 1's total is odd so -5 points")
print("-------------------------------------------")
print("Player 1 has",playerOnePoints, "points")
number = random.randint(1,6)
number2 = random.randint(1,6)
playerTwoPoints = number + number2
print("-------------------------------------------")
print("Player 2's turn Type 'roll' to roll the dice")
userTwoInput = input(">>> ")
if userTwoInput == "roll":
time.sleep(1)
print("Player 2's first roll is", number)
print("Player 2's second roll Type 'roll' to roll the dice")
userTwoInput = input(">>> ")
if userTwoInput == "roll":
time.sleep(1)
print("player 2's second roll is", number2)
if playerTwoPoints % 2 == 0:
playerTwoPoints = playerTwoPoints + 10
print("Player 2's total is even so + 10 points")
print("-------------------------------------------")
print("Player 2 has",playerTwoPoints, "points")
else:
playerTwoPoints = playerTwoPoints - 5
print("player 2's total is odd so -5 points")
print("-------------------------------------------")
print("Player 2 has",playerTwoPoints, "points")

if ens == "e":
counter = 0
check_failed = True
while check_failed:
print("Could player 1 enter their username and password")
username1=input("Please enter your username ")
password=input("Please enter your password ")
with open("accountfile.txt","r") as username_finder:
for line in username_finder:
if ("username: " + username1 + " password: " + password) == line.strip():
print("you are logged in")
check_failed = False
check_failed = True
while check_failed:
print("Could player 2 enter their username and password")
username2=input("Please enter your username ")
password=input("Please enter your password ")
with open("accountfile.txt","r") as username_finder:
for line in username_finder:
if ("username: " + username2 + " password: " + password) == line.strip():
print("you are logged in")
check_failed = False
time.sleep(1)
print("Welcome to the dice game")
time.sleep(1)
while rounds < 5:
game()
print("-------------------------------------------")
print("Total score for player 1 is", total_score1)
print("-------------------------------------------")
print("Total score for player 2 is", total_score2)
print("-------------------------------------------")
if total_score1 > total_score2:
write1()
if total_score2 > total_score1:
write2()
if total_score1 == total_score2:
print("Its a draw!")
game()
if total_score1 > total_score2:
write1()
if total_score1 < total_score2:
write2()
else:
validation()

else:
validation()


This is the link to my old code










share|improve this question



























    1














    This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points if it is odd, they lose 5.



    If there it is a draw after five rounds then the both users will have to roll one dice to determine the winner.



    One of the updates that I have done to this code is that I added functions to it so that it reduces the size of the code and I also removed repeated code and I also tried my very best act upon the suggestions that were given to me on my old code and I have tried my very best to improve DRY (don't repeat yourself) skills



    I just want suggestions on how I could improve this updated code



    import time
    import sys
    import random
    import operator
    total_score2 = 0
    total_score1 = 0
    rounds = 0
    playerOnePoints = 0
    playerTwoPoints = 0
    counter = 0

    print("*****************Welcome To The DICE Game*******************")
    print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
    ens=input("")
    while ens not in ('e', 'n', 's'): # if anything else but these characters are entered it will loop until it is correct
    print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
    ens = input()

    if ens == "s":
    s = open("scores.txt","r")
    file_content = s.read().splitlines()
    users_points = {i.split()[0]: int(i.split()[2]) for i in file_content}
    best_player = max(users_points.items(), key=operator.itemgetter(1))[0]
    print("LeaderBoard: ")
    print("n")
    print('player with maximum points is {}, this player has {} points'.format(best_player, users_points[best_player]))
    best_players = sorted(users_points, key=users_points.get, reverse=True)
    for bp in best_players:
    print('{} has {} points'.format(bp, users_points[bp])) # This prints all players scores
    print("n")
    print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
    ens=input("")

    if ens == "n":
    file = open("accountfile.txt","r+")
    text = file.read().strip().split()
    check = True
    while check:
    username=input("Please enter appropiate username: ") #Takes input of a username from user
    if username == "": #if no value is entered for the username
    continue
    if username in text: #username in present in the text file
    print("Username is taken please try another one")
    else: #username is absent in the text file
    print("Username has been accepted")
    check = False
    check = True
    while check:
    password1=input("Please enter password: ")
    password2=input("Please re-enter password: ")
    if password1 == password2:
    if password2 in text:
    print("Password has been taken please try another one")
    else:
    print("Username and Password have sucessfully been made Thankyou")
    file.write("username: " + username + " " + "password: " + password2 + "n")
    file.close()
    check = False
    else:
    print("passwords do not match please try again")
    file.close()

    def write1():
    print("Player 1 ",username1," Wins!")
    file = open("scores.txt","a")
    file.write(username1 + " has " + str(total_score1) + " points" + "n")
    file.close()
    sys.exit()
    def write2():
    print("Player 2 ",username2," Wins!")
    file = open("scores.txt","a")
    file.write(username2 + " has " + str(total_score2) + " points" + "n")
    file.close()
    sys.exit()
    def validation():
    global counter
    print("Sorry, this username or password does not exist please try again")
    counter = counter + 1
    if counter == 3:
    print("----------------------------------------------------")
    print("You have been locked out please restart to try again")
    sys.exit()
    def game():
    global total_score1
    global total_score2
    global rounds
    global number
    global number2
    global playerOnePoints
    global playerTwoPoints
    total_score2 = total_score2 + playerTwoPoints
    total_score1 = total_score1 + playerOnePoints
    rounds = rounds + 1
    number = random.randint(1,6)
    number2 = random.randint(1,6)
    playerOnePoints = number + number2
    print("-------------------------------------------")
    print("Round",rounds)
    print("-------------------------------------------")
    print("Player 1's turn Type 'roll' to roll the dice")
    userOneInput = input(">>> ")
    if userOneInput == "roll":
    time.sleep(1)
    print("Player 1's first roll is", number)
    print("Player 1's second roll Type 'roll' to roll the dice")
    userOneInput = input(">>> ")
    if userOneInput == "roll":
    time.sleep(1)
    print("player 1's second roll is", number2)
    if playerOnePoints % 2 == 0:
    playerOnePoints = playerOnePoints + 10
    print("Player 1's total is even so + 10 points")
    print("-------------------------------------------")
    print("Player 1 has",playerOnePoints, "points")
    else:
    playerOnePoints = playerOnePoints - 5
    print("player 1's total is odd so -5 points")
    print("-------------------------------------------")
    print("Player 1 has",playerOnePoints, "points")
    number = random.randint(1,6)
    number2 = random.randint(1,6)
    playerTwoPoints = number + number2
    print("-------------------------------------------")
    print("Player 2's turn Type 'roll' to roll the dice")
    userTwoInput = input(">>> ")
    if userTwoInput == "roll":
    time.sleep(1)
    print("Player 2's first roll is", number)
    print("Player 2's second roll Type 'roll' to roll the dice")
    userTwoInput = input(">>> ")
    if userTwoInput == "roll":
    time.sleep(1)
    print("player 2's second roll is", number2)
    if playerTwoPoints % 2 == 0:
    playerTwoPoints = playerTwoPoints + 10
    print("Player 2's total is even so + 10 points")
    print("-------------------------------------------")
    print("Player 2 has",playerTwoPoints, "points")
    else:
    playerTwoPoints = playerTwoPoints - 5
    print("player 2's total is odd so -5 points")
    print("-------------------------------------------")
    print("Player 2 has",playerTwoPoints, "points")

    if ens == "e":
    counter = 0
    check_failed = True
    while check_failed:
    print("Could player 1 enter their username and password")
    username1=input("Please enter your username ")
    password=input("Please enter your password ")
    with open("accountfile.txt","r") as username_finder:
    for line in username_finder:
    if ("username: " + username1 + " password: " + password) == line.strip():
    print("you are logged in")
    check_failed = False
    check_failed = True
    while check_failed:
    print("Could player 2 enter their username and password")
    username2=input("Please enter your username ")
    password=input("Please enter your password ")
    with open("accountfile.txt","r") as username_finder:
    for line in username_finder:
    if ("username: " + username2 + " password: " + password) == line.strip():
    print("you are logged in")
    check_failed = False
    time.sleep(1)
    print("Welcome to the dice game")
    time.sleep(1)
    while rounds < 5:
    game()
    print("-------------------------------------------")
    print("Total score for player 1 is", total_score1)
    print("-------------------------------------------")
    print("Total score for player 2 is", total_score2)
    print("-------------------------------------------")
    if total_score1 > total_score2:
    write1()
    if total_score2 > total_score1:
    write2()
    if total_score1 == total_score2:
    print("Its a draw!")
    game()
    if total_score1 > total_score2:
    write1()
    if total_score1 < total_score2:
    write2()
    else:
    validation()

    else:
    validation()


    This is the link to my old code










    share|improve this question

























      1












      1








      1


      1





      This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points if it is odd, they lose 5.



      If there it is a draw after five rounds then the both users will have to roll one dice to determine the winner.



      One of the updates that I have done to this code is that I added functions to it so that it reduces the size of the code and I also removed repeated code and I also tried my very best act upon the suggestions that were given to me on my old code and I have tried my very best to improve DRY (don't repeat yourself) skills



      I just want suggestions on how I could improve this updated code



      import time
      import sys
      import random
      import operator
      total_score2 = 0
      total_score1 = 0
      rounds = 0
      playerOnePoints = 0
      playerTwoPoints = 0
      counter = 0

      print("*****************Welcome To The DICE Game*******************")
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens=input("")
      while ens not in ('e', 'n', 's'): # if anything else but these characters are entered it will loop until it is correct
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens = input()

      if ens == "s":
      s = open("scores.txt","r")
      file_content = s.read().splitlines()
      users_points = {i.split()[0]: int(i.split()[2]) for i in file_content}
      best_player = max(users_points.items(), key=operator.itemgetter(1))[0]
      print("LeaderBoard: ")
      print("n")
      print('player with maximum points is {}, this player has {} points'.format(best_player, users_points[best_player]))
      best_players = sorted(users_points, key=users_points.get, reverse=True)
      for bp in best_players:
      print('{} has {} points'.format(bp, users_points[bp])) # This prints all players scores
      print("n")
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens=input("")

      if ens == "n":
      file = open("accountfile.txt","r+")
      text = file.read().strip().split()
      check = True
      while check:
      username=input("Please enter appropiate username: ") #Takes input of a username from user
      if username == "": #if no value is entered for the username
      continue
      if username in text: #username in present in the text file
      print("Username is taken please try another one")
      else: #username is absent in the text file
      print("Username has been accepted")
      check = False
      check = True
      while check:
      password1=input("Please enter password: ")
      password2=input("Please re-enter password: ")
      if password1 == password2:
      if password2 in text:
      print("Password has been taken please try another one")
      else:
      print("Username and Password have sucessfully been made Thankyou")
      file.write("username: " + username + " " + "password: " + password2 + "n")
      file.close()
      check = False
      else:
      print("passwords do not match please try again")
      file.close()

      def write1():
      print("Player 1 ",username1," Wins!")
      file = open("scores.txt","a")
      file.write(username1 + " has " + str(total_score1) + " points" + "n")
      file.close()
      sys.exit()
      def write2():
      print("Player 2 ",username2," Wins!")
      file = open("scores.txt","a")
      file.write(username2 + " has " + str(total_score2) + " points" + "n")
      file.close()
      sys.exit()
      def validation():
      global counter
      print("Sorry, this username or password does not exist please try again")
      counter = counter + 1
      if counter == 3:
      print("----------------------------------------------------")
      print("You have been locked out please restart to try again")
      sys.exit()
      def game():
      global total_score1
      global total_score2
      global rounds
      global number
      global number2
      global playerOnePoints
      global playerTwoPoints
      total_score2 = total_score2 + playerTwoPoints
      total_score1 = total_score1 + playerOnePoints
      rounds = rounds + 1
      number = random.randint(1,6)
      number2 = random.randint(1,6)
      playerOnePoints = number + number2
      print("-------------------------------------------")
      print("Round",rounds)
      print("-------------------------------------------")
      print("Player 1's turn Type 'roll' to roll the dice")
      userOneInput = input(">>> ")
      if userOneInput == "roll":
      time.sleep(1)
      print("Player 1's first roll is", number)
      print("Player 1's second roll Type 'roll' to roll the dice")
      userOneInput = input(">>> ")
      if userOneInput == "roll":
      time.sleep(1)
      print("player 1's second roll is", number2)
      if playerOnePoints % 2 == 0:
      playerOnePoints = playerOnePoints + 10
      print("Player 1's total is even so + 10 points")
      print("-------------------------------------------")
      print("Player 1 has",playerOnePoints, "points")
      else:
      playerOnePoints = playerOnePoints - 5
      print("player 1's total is odd so -5 points")
      print("-------------------------------------------")
      print("Player 1 has",playerOnePoints, "points")
      number = random.randint(1,6)
      number2 = random.randint(1,6)
      playerTwoPoints = number + number2
      print("-------------------------------------------")
      print("Player 2's turn Type 'roll' to roll the dice")
      userTwoInput = input(">>> ")
      if userTwoInput == "roll":
      time.sleep(1)
      print("Player 2's first roll is", number)
      print("Player 2's second roll Type 'roll' to roll the dice")
      userTwoInput = input(">>> ")
      if userTwoInput == "roll":
      time.sleep(1)
      print("player 2's second roll is", number2)
      if playerTwoPoints % 2 == 0:
      playerTwoPoints = playerTwoPoints + 10
      print("Player 2's total is even so + 10 points")
      print("-------------------------------------------")
      print("Player 2 has",playerTwoPoints, "points")
      else:
      playerTwoPoints = playerTwoPoints - 5
      print("player 2's total is odd so -5 points")
      print("-------------------------------------------")
      print("Player 2 has",playerTwoPoints, "points")

      if ens == "e":
      counter = 0
      check_failed = True
      while check_failed:
      print("Could player 1 enter their username and password")
      username1=input("Please enter your username ")
      password=input("Please enter your password ")
      with open("accountfile.txt","r") as username_finder:
      for line in username_finder:
      if ("username: " + username1 + " password: " + password) == line.strip():
      print("you are logged in")
      check_failed = False
      check_failed = True
      while check_failed:
      print("Could player 2 enter their username and password")
      username2=input("Please enter your username ")
      password=input("Please enter your password ")
      with open("accountfile.txt","r") as username_finder:
      for line in username_finder:
      if ("username: " + username2 + " password: " + password) == line.strip():
      print("you are logged in")
      check_failed = False
      time.sleep(1)
      print("Welcome to the dice game")
      time.sleep(1)
      while rounds < 5:
      game()
      print("-------------------------------------------")
      print("Total score for player 1 is", total_score1)
      print("-------------------------------------------")
      print("Total score for player 2 is", total_score2)
      print("-------------------------------------------")
      if total_score1 > total_score2:
      write1()
      if total_score2 > total_score1:
      write2()
      if total_score1 == total_score2:
      print("Its a draw!")
      game()
      if total_score1 > total_score2:
      write1()
      if total_score1 < total_score2:
      write2()
      else:
      validation()

      else:
      validation()


      This is the link to my old code










      share|improve this question













      This is a game for two users who roll 2 dice 5 times. If the total of dice is even the player gains 10 points if it is odd, they lose 5.



      If there it is a draw after five rounds then the both users will have to roll one dice to determine the winner.



      One of the updates that I have done to this code is that I added functions to it so that it reduces the size of the code and I also removed repeated code and I also tried my very best act upon the suggestions that were given to me on my old code and I have tried my very best to improve DRY (don't repeat yourself) skills



      I just want suggestions on how I could improve this updated code



      import time
      import sys
      import random
      import operator
      total_score2 = 0
      total_score1 = 0
      rounds = 0
      playerOnePoints = 0
      playerTwoPoints = 0
      counter = 0

      print("*****************Welcome To The DICE Game*******************")
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens=input("")
      while ens not in ('e', 'n', 's'): # if anything else but these characters are entered it will loop until it is correct
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens = input()

      if ens == "s":
      s = open("scores.txt","r")
      file_content = s.read().splitlines()
      users_points = {i.split()[0]: int(i.split()[2]) for i in file_content}
      best_player = max(users_points.items(), key=operator.itemgetter(1))[0]
      print("LeaderBoard: ")
      print("n")
      print('player with maximum points is {}, this player has {} points'.format(best_player, users_points[best_player]))
      best_players = sorted(users_points, key=users_points.get, reverse=True)
      for bp in best_players:
      print('{} has {} points'.format(bp, users_points[bp])) # This prints all players scores
      print("n")
      print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user and enter 's' to display scores")
      ens=input("")

      if ens == "n":
      file = open("accountfile.txt","r+")
      text = file.read().strip().split()
      check = True
      while check:
      username=input("Please enter appropiate username: ") #Takes input of a username from user
      if username == "": #if no value is entered for the username
      continue
      if username in text: #username in present in the text file
      print("Username is taken please try another one")
      else: #username is absent in the text file
      print("Username has been accepted")
      check = False
      check = True
      while check:
      password1=input("Please enter password: ")
      password2=input("Please re-enter password: ")
      if password1 == password2:
      if password2 in text:
      print("Password has been taken please try another one")
      else:
      print("Username and Password have sucessfully been made Thankyou")
      file.write("username: " + username + " " + "password: " + password2 + "n")
      file.close()
      check = False
      else:
      print("passwords do not match please try again")
      file.close()

      def write1():
      print("Player 1 ",username1," Wins!")
      file = open("scores.txt","a")
      file.write(username1 + " has " + str(total_score1) + " points" + "n")
      file.close()
      sys.exit()
      def write2():
      print("Player 2 ",username2," Wins!")
      file = open("scores.txt","a")
      file.write(username2 + " has " + str(total_score2) + " points" + "n")
      file.close()
      sys.exit()
      def validation():
      global counter
      print("Sorry, this username or password does not exist please try again")
      counter = counter + 1
      if counter == 3:
      print("----------------------------------------------------")
      print("You have been locked out please restart to try again")
      sys.exit()
      def game():
      global total_score1
      global total_score2
      global rounds
      global number
      global number2
      global playerOnePoints
      global playerTwoPoints
      total_score2 = total_score2 + playerTwoPoints
      total_score1 = total_score1 + playerOnePoints
      rounds = rounds + 1
      number = random.randint(1,6)
      number2 = random.randint(1,6)
      playerOnePoints = number + number2
      print("-------------------------------------------")
      print("Round",rounds)
      print("-------------------------------------------")
      print("Player 1's turn Type 'roll' to roll the dice")
      userOneInput = input(">>> ")
      if userOneInput == "roll":
      time.sleep(1)
      print("Player 1's first roll is", number)
      print("Player 1's second roll Type 'roll' to roll the dice")
      userOneInput = input(">>> ")
      if userOneInput == "roll":
      time.sleep(1)
      print("player 1's second roll is", number2)
      if playerOnePoints % 2 == 0:
      playerOnePoints = playerOnePoints + 10
      print("Player 1's total is even so + 10 points")
      print("-------------------------------------------")
      print("Player 1 has",playerOnePoints, "points")
      else:
      playerOnePoints = playerOnePoints - 5
      print("player 1's total is odd so -5 points")
      print("-------------------------------------------")
      print("Player 1 has",playerOnePoints, "points")
      number = random.randint(1,6)
      number2 = random.randint(1,6)
      playerTwoPoints = number + number2
      print("-------------------------------------------")
      print("Player 2's turn Type 'roll' to roll the dice")
      userTwoInput = input(">>> ")
      if userTwoInput == "roll":
      time.sleep(1)
      print("Player 2's first roll is", number)
      print("Player 2's second roll Type 'roll' to roll the dice")
      userTwoInput = input(">>> ")
      if userTwoInput == "roll":
      time.sleep(1)
      print("player 2's second roll is", number2)
      if playerTwoPoints % 2 == 0:
      playerTwoPoints = playerTwoPoints + 10
      print("Player 2's total is even so + 10 points")
      print("-------------------------------------------")
      print("Player 2 has",playerTwoPoints, "points")
      else:
      playerTwoPoints = playerTwoPoints - 5
      print("player 2's total is odd so -5 points")
      print("-------------------------------------------")
      print("Player 2 has",playerTwoPoints, "points")

      if ens == "e":
      counter = 0
      check_failed = True
      while check_failed:
      print("Could player 1 enter their username and password")
      username1=input("Please enter your username ")
      password=input("Please enter your password ")
      with open("accountfile.txt","r") as username_finder:
      for line in username_finder:
      if ("username: " + username1 + " password: " + password) == line.strip():
      print("you are logged in")
      check_failed = False
      check_failed = True
      while check_failed:
      print("Could player 2 enter their username and password")
      username2=input("Please enter your username ")
      password=input("Please enter your password ")
      with open("accountfile.txt","r") as username_finder:
      for line in username_finder:
      if ("username: " + username2 + " password: " + password) == line.strip():
      print("you are logged in")
      check_failed = False
      time.sleep(1)
      print("Welcome to the dice game")
      time.sleep(1)
      while rounds < 5:
      game()
      print("-------------------------------------------")
      print("Total score for player 1 is", total_score1)
      print("-------------------------------------------")
      print("Total score for player 2 is", total_score2)
      print("-------------------------------------------")
      if total_score1 > total_score2:
      write1()
      if total_score2 > total_score1:
      write2()
      if total_score1 == total_score2:
      print("Its a draw!")
      game()
      if total_score1 > total_score2:
      write1()
      if total_score1 < total_score2:
      write2()
      else:
      validation()

      else:
      validation()


      This is the link to my old code







      python python-3.x game homework dice






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      colkat406

      797




      797



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210517%2f2-player-dice-game-where-even-total-gains-points-and-odd-total-loses-points-nea%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210517%2f2-player-dice-game-where-even-total-gains-points-and-odd-total-loses-points-nea%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre