2 player dice game, where even total gains points and odd total loses points NEA task computer science
up vote
2
down vote
favorite
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 die to determine the winner.
from random import randint
from time import sleep
import time
import sys
import random
import operator
total_score2 = 0
total_score1 = 0
rounds = 0
playerOnePoints = 0
playerTwoPoints = 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 != ("e") and ens != ("n") and ens != ("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
if ens == "n":
username=input("Please enter appropiate username: ")
password1=input("Please enter password: ")
password2=input("Please re-enter password: ")
if password1 == password2: # checking if both passwords entered are the same
print("your account has been successfully been made Thankyou")
file = open("accountfile.txt","a")
file.write("username: ")
file.write(username)
file.write(" ")
file.write("password: ")
file.write(password2)
file.write("n")
file.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
ens=input(" ")
if password1 != password2: # if passwords entered are not the same will loop until they are correctly entered
correctPassword=(password1)
while True:
password=input('Enter password again ')
if password == correctPassword:
print('Correct password has been entered')
f = open ("accountfile.txt","a+")
f.write("username: ")
f.write(username)
f.write(" ")
f.write("password: ")
f.write(correctPassword)
f.write("n")
f.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
en=input(" ")
print('Incorrect password ')
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
counter = 0
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:
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("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 <= 0:
playerOnePoints = 0
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")
if playerOnePoints <= 0:
playerOnePoints = 0
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 <= 0:
playerTwoPoints = 0
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")
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:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score1 == total_score2:
print("Its a draw!")
print("So both players will have to roll one more dice")
time.sleep(2)
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")
print("-------------------------------------------")
if total_score1 > total_score2:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
else:
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()
else:
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()
This was a project that i have been doing in computer science which I have now finished if anyone has any suggestions on how I could make it better they will appreciated alot so please suggest how I can improve it. Also It would be very helpful to me if you could rewrite the parts of my code that need improving or are wrong step by step so I can understand it better
Thanks
python python-3.x game homework dice
add a comment |
up vote
2
down vote
favorite
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 die to determine the winner.
from random import randint
from time import sleep
import time
import sys
import random
import operator
total_score2 = 0
total_score1 = 0
rounds = 0
playerOnePoints = 0
playerTwoPoints = 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 != ("e") and ens != ("n") and ens != ("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
if ens == "n":
username=input("Please enter appropiate username: ")
password1=input("Please enter password: ")
password2=input("Please re-enter password: ")
if password1 == password2: # checking if both passwords entered are the same
print("your account has been successfully been made Thankyou")
file = open("accountfile.txt","a")
file.write("username: ")
file.write(username)
file.write(" ")
file.write("password: ")
file.write(password2)
file.write("n")
file.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
ens=input(" ")
if password1 != password2: # if passwords entered are not the same will loop until they are correctly entered
correctPassword=(password1)
while True:
password=input('Enter password again ')
if password == correctPassword:
print('Correct password has been entered')
f = open ("accountfile.txt","a+")
f.write("username: ")
f.write(username)
f.write(" ")
f.write("password: ")
f.write(correctPassword)
f.write("n")
f.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
en=input(" ")
print('Incorrect password ')
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
counter = 0
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:
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("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 <= 0:
playerOnePoints = 0
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")
if playerOnePoints <= 0:
playerOnePoints = 0
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 <= 0:
playerTwoPoints = 0
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")
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:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score1 == total_score2:
print("Its a draw!")
print("So both players will have to roll one more dice")
time.sleep(2)
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")
print("-------------------------------------------")
if total_score1 > total_score2:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
else:
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()
else:
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()
This was a project that i have been doing in computer science which I have now finished if anyone has any suggestions on how I could make it better they will appreciated alot so please suggest how I can improve it. Also It would be very helpful to me if you could rewrite the parts of my code that need improving or are wrong step by step so I can understand it better
Thanks
python python-3.x game homework dice
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 die to determine the winner.
from random import randint
from time import sleep
import time
import sys
import random
import operator
total_score2 = 0
total_score1 = 0
rounds = 0
playerOnePoints = 0
playerTwoPoints = 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 != ("e") and ens != ("n") and ens != ("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
if ens == "n":
username=input("Please enter appropiate username: ")
password1=input("Please enter password: ")
password2=input("Please re-enter password: ")
if password1 == password2: # checking if both passwords entered are the same
print("your account has been successfully been made Thankyou")
file = open("accountfile.txt","a")
file.write("username: ")
file.write(username)
file.write(" ")
file.write("password: ")
file.write(password2)
file.write("n")
file.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
ens=input(" ")
if password1 != password2: # if passwords entered are not the same will loop until they are correctly entered
correctPassword=(password1)
while True:
password=input('Enter password again ')
if password == correctPassword:
print('Correct password has been entered')
f = open ("accountfile.txt","a+")
f.write("username: ")
f.write(username)
f.write(" ")
f.write("password: ")
f.write(correctPassword)
f.write("n")
f.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
en=input(" ")
print('Incorrect password ')
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
counter = 0
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:
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("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 <= 0:
playerOnePoints = 0
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")
if playerOnePoints <= 0:
playerOnePoints = 0
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 <= 0:
playerTwoPoints = 0
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")
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:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score1 == total_score2:
print("Its a draw!")
print("So both players will have to roll one more dice")
time.sleep(2)
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")
print("-------------------------------------------")
if total_score1 > total_score2:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
else:
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()
else:
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()
This was a project that i have been doing in computer science which I have now finished if anyone has any suggestions on how I could make it better they will appreciated alot so please suggest how I can improve it. Also It would be very helpful to me if you could rewrite the parts of my code that need improving or are wrong step by step so I can understand it better
Thanks
python python-3.x game homework dice
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 die to determine the winner.
from random import randint
from time import sleep
import time
import sys
import random
import operator
total_score2 = 0
total_score1 = 0
rounds = 0
playerOnePoints = 0
playerTwoPoints = 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 != ("e") and ens != ("n") and ens != ("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
if ens == "n":
username=input("Please enter appropiate username: ")
password1=input("Please enter password: ")
password2=input("Please re-enter password: ")
if password1 == password2: # checking if both passwords entered are the same
print("your account has been successfully been made Thankyou")
file = open("accountfile.txt","a")
file.write("username: ")
file.write(username)
file.write(" ")
file.write("password: ")
file.write(password2)
file.write("n")
file.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
ens=input(" ")
if password1 != password2: # if passwords entered are not the same will loop until they are correctly entered
correctPassword=(password1)
while True:
password=input('Enter password again ')
if password == correctPassword:
print('Correct password has been entered')
f = open ("accountfile.txt","a+")
f.write("username: ")
f.write(username)
f.write(" ")
f.write("password: ")
f.write(correctPassword)
f.write("n")
f.close()
print("Please enter 'n' if you are a new user and 'e' if you are a exsiting user")
en=input(" ")
print('Incorrect password ')
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
counter = 0
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:
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("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 <= 0:
playerOnePoints = 0
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")
if playerOnePoints <= 0:
playerOnePoints = 0
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 <= 0:
playerTwoPoints = 0
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")
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:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
if total_score1 == total_score2:
print("Its a draw!")
print("So both players will have to roll one more dice")
time.sleep(2)
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")
print("-------------------------------------------")
if total_score1 > total_score2:
print("Player 1 Wins!")
file = open("scores.txt","a")
file.write(username1)
file.write(" has ")
file.write(str(total_score1))
file.write(" points")
file.write("n")
file.close()
if total_score2 > total_score1:
print("Player 2 Wins!")
file = open("scores.txt","a")
file.write(username2)
file.write(" has ")
file.write(str(total_score2))
file.write(" points")
file.write("n")
file.close()
sys.exit()
else:
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()
else:
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()
This was a project that i have been doing in computer science which I have now finished if anyone has any suggestions on how I could make it better they will appreciated alot so please suggest how I can improve it. Also It would be very helpful to me if you could rewrite the parts of my code that need improving or are wrong step by step so I can understand it better
Thanks
python python-3.x game homework dice
python python-3.x game homework dice
edited Nov 26 at 17:00
asked Nov 24 at 18:19
colkat406
597
597
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14
add a comment |
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
- You need to run your UI text through a spell checker. Example -
exsiting
- Since each player has more than one attribute (
total_score
,points
,password
, etc.) each player should be represented by a class, or at least anamedtuple
. - You have a
print
followed by a blankinput("")
. Don't do this; just put the content of the print into the prompt argument of the input call.
while ens != ("e") and ens != ("n") and ens != ("s")
should be something likewhile ens not in ('e', 'n', 's'):
- Rather than bare
open
/close
calls, you should use a properwith
statement. - Rather than using a half a dozen
write
calls, consider just issuing onewrite
call with a multi-line (triple-quoted) string. - Something like
"username: " + username1 + " password: " + password
is better done with aformat
call.
Other than that, you really need to strengthen your DRY (don't repeat yourself) skills. Writing a handful of functions for repeated code would be a good start.
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
|
show 1 more comment
up vote
5
down vote
- The requirements for this game are unclear. Code is always produced to implement a set of well defined and understood requirements, even if you are defining these yourself.
- The code is monolithic, break it down into functions, this is functional decomposition and one of the first skills a programmer needs to learn.
- Use
unittests
to automatically test the functionality of those functions, learning to useunittest
to engage in Test Driven development will increase your speed of learning at first and make you a far better developer in the long run. - The code has a very linear flow, programms should provide flexible flows, break it down into three parts, the setup, the game and the results, wrap these with a menu, to setup, play, see score or exit. Once each part is complete return to the menu loop.
- What is the point of requiring usernames then referring to Players 1 & 2.
- It include lots of pointless functionality such usernames and password from plain text files, capture the names, but do away with the password, security by obscurity offers no security at all.
- It fails if you enter S when first starting, if the file does not exist use Exception Handing to catch this failure, create the blank file and continue. Always attempt to recover from error conditions, make it second nature.
Always validate user input before proceeding.- Learn to use the built in language features and libraries, this example plays a similar game with much better usage of Python's built in capabilities. How to make this random number game better?
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
- You need to run your UI text through a spell checker. Example -
exsiting
- Since each player has more than one attribute (
total_score
,points
,password
, etc.) each player should be represented by a class, or at least anamedtuple
. - You have a
print
followed by a blankinput("")
. Don't do this; just put the content of the print into the prompt argument of the input call.
while ens != ("e") and ens != ("n") and ens != ("s")
should be something likewhile ens not in ('e', 'n', 's'):
- Rather than bare
open
/close
calls, you should use a properwith
statement. - Rather than using a half a dozen
write
calls, consider just issuing onewrite
call with a multi-line (triple-quoted) string. - Something like
"username: " + username1 + " password: " + password
is better done with aformat
call.
Other than that, you really need to strengthen your DRY (don't repeat yourself) skills. Writing a handful of functions for repeated code would be a good start.
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
|
show 1 more comment
up vote
3
down vote
accepted
- You need to run your UI text through a spell checker. Example -
exsiting
- Since each player has more than one attribute (
total_score
,points
,password
, etc.) each player should be represented by a class, or at least anamedtuple
. - You have a
print
followed by a blankinput("")
. Don't do this; just put the content of the print into the prompt argument of the input call.
while ens != ("e") and ens != ("n") and ens != ("s")
should be something likewhile ens not in ('e', 'n', 's'):
- Rather than bare
open
/close
calls, you should use a properwith
statement. - Rather than using a half a dozen
write
calls, consider just issuing onewrite
call with a multi-line (triple-quoted) string. - Something like
"username: " + username1 + " password: " + password
is better done with aformat
call.
Other than that, you really need to strengthen your DRY (don't repeat yourself) skills. Writing a handful of functions for repeated code would be a good start.
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
|
show 1 more comment
up vote
3
down vote
accepted
up vote
3
down vote
accepted
- You need to run your UI text through a spell checker. Example -
exsiting
- Since each player has more than one attribute (
total_score
,points
,password
, etc.) each player should be represented by a class, or at least anamedtuple
. - You have a
print
followed by a blankinput("")
. Don't do this; just put the content of the print into the prompt argument of the input call.
while ens != ("e") and ens != ("n") and ens != ("s")
should be something likewhile ens not in ('e', 'n', 's'):
- Rather than bare
open
/close
calls, you should use a properwith
statement. - Rather than using a half a dozen
write
calls, consider just issuing onewrite
call with a multi-line (triple-quoted) string. - Something like
"username: " + username1 + " password: " + password
is better done with aformat
call.
Other than that, you really need to strengthen your DRY (don't repeat yourself) skills. Writing a handful of functions for repeated code would be a good start.
- You need to run your UI text through a spell checker. Example -
exsiting
- Since each player has more than one attribute (
total_score
,points
,password
, etc.) each player should be represented by a class, or at least anamedtuple
. - You have a
print
followed by a blankinput("")
. Don't do this; just put the content of the print into the prompt argument of the input call.
while ens != ("e") and ens != ("n") and ens != ("s")
should be something likewhile ens not in ('e', 'n', 's'):
- Rather than bare
open
/close
calls, you should use a properwith
statement. - Rather than using a half a dozen
write
calls, consider just issuing onewrite
call with a multi-line (triple-quoted) string. - Something like
"username: " + username1 + " password: " + password
is better done with aformat
call.
Other than that, you really need to strengthen your DRY (don't repeat yourself) skills. Writing a handful of functions for repeated code would be a good start.
answered Nov 25 at 4:47
Reinderien
1,664616
1,664616
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
|
show 1 more comment
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:22
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
@colkat406 absolutely not. Then you wouldn't learn. Try it yourself and submit a new review.
– Reinderien
Nov 25 at 20:17
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you show me an example of a namedtuple
– colkat406
Nov 27 at 17:00
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:10
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
If it isn't working, that's a question for StackOverflow :)
– Reinderien
Nov 27 at 17:46
|
show 1 more comment
up vote
5
down vote
- The requirements for this game are unclear. Code is always produced to implement a set of well defined and understood requirements, even if you are defining these yourself.
- The code is monolithic, break it down into functions, this is functional decomposition and one of the first skills a programmer needs to learn.
- Use
unittests
to automatically test the functionality of those functions, learning to useunittest
to engage in Test Driven development will increase your speed of learning at first and make you a far better developer in the long run. - The code has a very linear flow, programms should provide flexible flows, break it down into three parts, the setup, the game and the results, wrap these with a menu, to setup, play, see score or exit. Once each part is complete return to the menu loop.
- What is the point of requiring usernames then referring to Players 1 & 2.
- It include lots of pointless functionality such usernames and password from plain text files, capture the names, but do away with the password, security by obscurity offers no security at all.
- It fails if you enter S when first starting, if the file does not exist use Exception Handing to catch this failure, create the blank file and continue. Always attempt to recover from error conditions, make it second nature.
Always validate user input before proceeding.- Learn to use the built in language features and libraries, this example plays a similar game with much better usage of Python's built in capabilities. How to make this random number game better?
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
add a comment |
up vote
5
down vote
- The requirements for this game are unclear. Code is always produced to implement a set of well defined and understood requirements, even if you are defining these yourself.
- The code is monolithic, break it down into functions, this is functional decomposition and one of the first skills a programmer needs to learn.
- Use
unittests
to automatically test the functionality of those functions, learning to useunittest
to engage in Test Driven development will increase your speed of learning at first and make you a far better developer in the long run. - The code has a very linear flow, programms should provide flexible flows, break it down into three parts, the setup, the game and the results, wrap these with a menu, to setup, play, see score or exit. Once each part is complete return to the menu loop.
- What is the point of requiring usernames then referring to Players 1 & 2.
- It include lots of pointless functionality such usernames and password from plain text files, capture the names, but do away with the password, security by obscurity offers no security at all.
- It fails if you enter S when first starting, if the file does not exist use Exception Handing to catch this failure, create the blank file and continue. Always attempt to recover from error conditions, make it second nature.
Always validate user input before proceeding.- Learn to use the built in language features and libraries, this example plays a similar game with much better usage of Python's built in capabilities. How to make this random number game better?
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
add a comment |
up vote
5
down vote
up vote
5
down vote
- The requirements for this game are unclear. Code is always produced to implement a set of well defined and understood requirements, even if you are defining these yourself.
- The code is monolithic, break it down into functions, this is functional decomposition and one of the first skills a programmer needs to learn.
- Use
unittests
to automatically test the functionality of those functions, learning to useunittest
to engage in Test Driven development will increase your speed of learning at first and make you a far better developer in the long run. - The code has a very linear flow, programms should provide flexible flows, break it down into three parts, the setup, the game and the results, wrap these with a menu, to setup, play, see score or exit. Once each part is complete return to the menu loop.
- What is the point of requiring usernames then referring to Players 1 & 2.
- It include lots of pointless functionality such usernames and password from plain text files, capture the names, but do away with the password, security by obscurity offers no security at all.
- It fails if you enter S when first starting, if the file does not exist use Exception Handing to catch this failure, create the blank file and continue. Always attempt to recover from error conditions, make it second nature.
Always validate user input before proceeding.- Learn to use the built in language features and libraries, this example plays a similar game with much better usage of Python's built in capabilities. How to make this random number game better?
- The requirements for this game are unclear. Code is always produced to implement a set of well defined and understood requirements, even if you are defining these yourself.
- The code is monolithic, break it down into functions, this is functional decomposition and one of the first skills a programmer needs to learn.
- Use
unittests
to automatically test the functionality of those functions, learning to useunittest
to engage in Test Driven development will increase your speed of learning at first and make you a far better developer in the long run. - The code has a very linear flow, programms should provide flexible flows, break it down into three parts, the setup, the game and the results, wrap these with a menu, to setup, play, see score or exit. Once each part is complete return to the menu loop.
- What is the point of requiring usernames then referring to Players 1 & 2.
- It include lots of pointless functionality such usernames and password from plain text files, capture the names, but do away with the password, security by obscurity offers no security at all.
- It fails if you enter S when first starting, if the file does not exist use Exception Handing to catch this failure, create the blank file and continue. Always attempt to recover from error conditions, make it second nature.
Always validate user input before proceeding.- Learn to use the built in language features and libraries, this example plays a similar game with much better usage of Python's built in capabilities. How to make this random number game better?
edited Nov 25 at 16:23
Graipher
23k53384
23k53384
answered Nov 24 at 20:52
Martin Spamer
340212
340212
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
add a comment |
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
Is it possible for you to re write my code so it isn't so long. it would be very helpful if you did it. :)
– colkat406
Nov 25 at 19:30
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
@Graipher could you also show me how to use a function for username and password becasue it is not working for me
– colkat406
Nov 27 at 17:13
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208342%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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
please could other people contribute for this. I really need to know how to improve this properly since it is my NEA computer science programming task.
– colkat406
Nov 26 at 17:14