Background Information
This assignment tests your understanding of and ability to apply the programming concepts we have covered in the unit so far, including the usage of variables, input/output, data types, selection, iteration, functions and data structures.
Pseudocode
As emphasised in the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design as well as the code for the program. Furthermore, while your tutors are happy to provide help and feedback on your assignment work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code.
Write a separate section of pseudocode for each function in your program.
Assignment Requirements
You are required to design and implement a “Golf Club” program that records information about golfers and tournaments. The program should have a menu system as shown below.
Welcome to Springfield Golf Club.
Select Option:
1) Enter Scores
2) Find Golfer
3) Display Scoreboard
4) Exit Program
>
Implement all of the following requirements, and ask your tutor if you do not understand any of the requirements.
1. The program should welcome the user and display the menu.
2. Re-prompt the user until a valid response (1, 2, 3 or 4) is entered.
3. The Enter Scores option should ask the user how many golfers in the group and then ask to enter the following information about each golfer and put the information into some data structure(s) as appropriate:
a. Name
b. Result (this is the number of stokes taken – it ranges between 18 to 108)
4. If a name matches a name already in the data structure, the user should be warned that the result will be altered and given the option to keep existing data.
5. The Find Golfer option should allow the user to enter a name and if the name is in the data structure should display their score, if the name is not found it should display an appropriate message.
6. The Display Scoreboard option should display ALL golfers entered and their score, in order of best (lowest score) to highest.
7. The Exit Program option should display an appropriate message and the program should exit.
Solutions:
pseoudocode
set a golfertRecords dictionary data strucutres to store record as empty
def menu():
show message to user "Please select an option: "
show option " 1 Enter Score "
show option " 2 Find Golfer ")
show option " 3 Display Scoreboard ")
show option " 4 Exit ")
def findGolfer(name,golferRecords):
if name in golferRecords:
display player details
return True
else:
return False
def displayScoreboard(golferRecords):
show message to user prompt "Players Scoreboard'
records = [(v, k) for k, v in golferRecords.items()]
records.sort()
for record in records:
show each players details
def enterScores(golferRecords):
name=input("Enter Your Name: ")
result=int(input("Enter the score: "))
if result is in range 18 to 108:
if call findGolfer(name,golferRecords) to check user existence:
print('User already Exists!')
else:
golferRecords[name]=result
else:
display message "Please enter score between 18 and 108"
call enterScores(golferRecords)
display welcome message "Welcome to Springfield Golf Club"
while True:
read input choice from user input prompt
if choice is 1:
menu()
else if choice is 2:
name=input("Enter golfer name to search: ")
if name is in findGolfer(name,golferRecords) to check:
print(name,"doesn't exist!")
else if choice is 3:
displayScoreboard(golferRecords)
else if choice is 4:
exit the while loop using break
Python code:
# Golf club.py
# golferRecords dictionary data structures for storing records.
golferRecords={}
# function for display options
def menu():
print("\nPlease select an option: ")
print(" 1 Enter Score ")
print(" 2 Find Golfer ")
print(" 3 Display Scoreboard ")
print(" 4 Exit ")
# function for find Golfer
def findGolfer(name,golferRecords):
if name in golferRecords.keys():
print(name,golferRecords[name])
return True
else:
return False
# funtion for display scoreboard
def displayScoreboard(golferRecords):
print("="*60)
print('Players Scoreboard')
print("="*60)
records = [(v, k) for k, v in golferRecords.items()]
records.sort()
for record in records:
print(record[1],record[0])
#function for enter golfer Scores
def enterScores(golferRecords):
try:
name=input("Enter Your Name: ")
result=int(input("Enter the score: "))
if result>=18 and result<=108:
if findGolfer(name,golferRecords):
print('User already Exists!')
else:
golferRecords[name]=result
else:
print("\nPlease enter score between 18 and 108")
enterScores(golferRecords)
except ValueError:
print("\nOops! That is no valid score. input valid score...")
#===============main=======================
# print '=' 60 times on console
print("="*60)
#Welcome Message to display at output prompt
print("Welcome to Springfield Golf Club")
print("="*60)
while True:
try:
menu()
option=int(input("> "))
if option == 1: # Enter score
try:
num=int(input("Please enter the number of players: "))
for i in range(num):
enterScores(golferRecords)
except ValueError:
print("Oops! That was no valid imput. please input an integer...")
elif option == 2: # Search golfer
name=input("Enter golfer name to search: ")
if not findGolfer(name,golferRecords):
print(name,"doesn't exist!")
elif option == 3: # display Scoreboard
displayScoreboard(golferRecords)
elif option == 4: # Terminate the program
print("Program terminated..")
break
else:
print("Opp!,Invalid input")
except ValueError:
print("\nOops! That is no valid option. input valid number...")