Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Golf Tournament Record Input Program Pseudocode:

Start
Display Message How many players participated in the tournament?
Read num_players
Open golf.txt file
for num_players
Display Message Enter the data for Player #
Display Message Player:
Read name
Display Message Score:
Read score
Write the name to golf.txt file
Write the score to golf.txt file
End for
Close golf.txt
End

START

Display Message How


many players participated
in the tournament?

Read num_players

Open golf.txt file

Set Count = 0

Yes

Count = num_players

No
END

Display Message Enter


the data for Player #

Close golf.txt

Display Message
Player:

Read name

Python Code (Used as a reference)


def main():
num_players = int(input("How many players participated in the tournament? "))

Display Message
Score:

golf = open('golf.txt', 'w')


for count in range(0, num_players):
print("Enter the data for Player #", count, sep='')
name = input("Player: ")
score = input("Score ")

Read score

Write name to golf.txt


file

golf.write(name + '\n')
golf.write(score + '\n')

print()

Write score to golf.txt


file

golf.close()
print("Player names and scores written to golf.txt.")

Add 1 to count

main()

Golf Tournament Record Retrieval Program:


Start
Open file named golf.txt
Read name field from golf.txt
while name field is not blank (name != ;)
read score field from golf.txt
strip name newlines
strip score newlines
Display name record
Display score record
Display blank line
read name field from golf.txt
endwhile
Close the golf.txt file
End

START

Open golf.txt file

Python Code (Used as a reference)


def main():
golf = open('golf.txt', 'r')

Read name field from


golf.txt

name = golf.readline()
while name != ' ':
score = golf.readline()
name = name.rstrip('\n')
score = score.rstrip('\n')
print('Name:', name)
print('Score:', score)
print()
name = golf.readline()
golf.close()

main()

True
While name field is not blank
(name != ;)

False
END

Read
score
from
golf.txt

Strip name
newlines

Strip score
newlines

Display
name
record

Display
score
record

Display
blank line

You might also like