Hey all, I'm trying to wok on a game tracker for my friends. What I have here partly works but there are areas that I want to change and some areas that are just not working for me.
The areas that I am having difficulty with are the def pointsNeeded and oppPointsNeeded. What is strange to me is that I had pointsNeeded almost exactly as oppPointsNeeded and only pointsNeeded worked. I'd like to change this to one function since it does the same thing. I've tried using a dictionary but that does not seem to be working well either. Any advice would be great. Thanks in advance. CODE #=============================================================================== # Get users name -- DONE # Get Users opponent name DONE # Get user opponents APA number --DONE # get users APA number -- DONE # Determine if this is 8-ball or 9-ball -- DONE # create number of points needed to win for 9-ball # create number of games needed to win for 8-ball # Get Users skill level -- DONE # get users current opponent skill level -- DONE # get number of innings played # number of defenses played # record who won and lost #=============================================================================== import __builtin__ import string pointDictionary = {1:14, 2:19, 3:25, 4:31, 5:38, 6:46, 7:55, 8:65, 9:75} def getUserName(): return raw_input("Enter your name: ") def getUserOppName(): return raw_input ("Enter your opponents name: ") def getUserNumber(): UserID = raw_input("Enter your APA ID number: ") while (str.isdigit(UserID)==False): UserID = raw_input("That is not a proper ID. Please re-enter your APA number: ") return UserID def getUserOppNumber(): OppUserID = raw_input("Enter your opponents APA ID number: ") while (str.isdigit(OppUserID)==False): UserID = raw_input("That is not a proper ID. Please re-enter your opponents APA number: ") return OppUserID def getGameType(): temp = 0 while temp == 0: GameType = raw_input("Are you playing 8-ball or 9-ball? ") if GameType == "8": print "Good luck and don't get an early 8" GameType = 8 temp = 1 elif GameType == "9": print "Good luck! Let's hope you sink the stripe on the break!" GameType = 9 temp = 1 else: print "That's not a valid entry, Please try again.: " return int(GameType) def CheckRange8Ball(GameType, min=1, max=8): if not min <= GameType <= max: raise ValueError('Value out of range') def getUserSkillLvl(GameType): if GameType == 8: UserSkillLvl = prompt = "Enter your current 8-ball skill level: " elif GameType == 9: UserSkillLvl = prompt = "Enter your current 9-ball level:" UserSkillLvl = raw_input(prompt) UserSkillLvl = int(UserSkillLvl) if GameType == 9: temp = 0 while temp == 0: if ((UserSkillLvl <= 9) and (UserSkillLvl >=1)): print "Thank You" temp = 1 break elif ((UserSkillLvl >9) or (UserSkillLvl < 1)): while temp == 0: UserSkillLvl = raw_input("Please re-enter your 9-ball skill level") return UserSkillLvl if GameType == 8: temp = 0 while temp == 0: if ((UserSkillLvl <= 8) and (UserSkillLvl >=1)): print "thank you" temp = 1 break elif (UserSkillLvl >8) or (UserSkillLvl < 1): while temp == 0: UserSkillLvl = raw_input("Please re-enter your skill level: ") return UserSkillLvl def getUserOppSkillLvl(): UserOppSkillLvl = raw_input("Enter your opponents current skill level: ") while (str.isdigit(UserOppSkillLvl)==False): UserOppSkillLvl = raw_input("That is not a proper Skill Level. \ Please enter a number between 1 and 9 for 9-ball or 1 and 8 for 8-ball: ") UserOppSkillLvl = int(UserOppSkillLvl) return UserOppSkillLvl def getPointsNeeded(): if (GameType == 9): for UserSkillLvl in range (0, len(pointDictionary)): pointsNeeded = pointDictionary(UserSkillLvl) return pointsNeeded def getOppPointsNeeded(): if (GameType == 9): if (UserOppSkillLvl == 9): oppPointsNeeded = 75 elif (UserOppSkillLvl == 8): oppPointsNeeded = 65 elif (UserOppSkillLvl == 7): oppPointsNeeded = 55 elif(UserOppSkillLvl == 6): oppPointsNeeded = 46 elif (UserOppSkillLvl == 5): oppPointsNeeded = 38 elif (UserOppSkillLvl == 4): oppPointsNeeded = 31 elif (UserOppSkillLvl == 3): oppPointsNeeded = 25 elif (UserOppSkillLvl == 2): oppPointsNeeded = 19 elif (UserOppSkillLvl == 1): oppPointsNeeded = 14 return oppPointsNeeded UserName = getUserName() UserOppName = getUserOppName() UserID = getUserNumber() OppUserID = getUserOppNumber() GameType = getGameType() UserSkillLvl = getUserSkillLvl(GameType) UserOppSkillLvl = getUserOppSkillLvl() print "\nPlayer Name:",UserName, "\nOpponent Name:", UserOppName, "\nUser ID: ",UserID, "\nOpponent APA ID", OppUserID, \ "\nGameType: ",GameType,"\nUser Skill Level: ",UserSkillLvl, "\nUser Opponents Level: ",UserOppSkillLvl pointsNeeded = getPointsNeeded() oppPointsNeeded = getOppPointsNeeded() print "\nYou need", pointsNeeded, "to win while your opponent needs", oppPointsNeeded,"." -- ~MEN _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor