1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Wittaler [7]
3 years ago
4

IN python The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you to write two program

s: 1. A program that will read each player’s name and golf score as keyboard input, and then save these as records in a file named golf.txt. (Each record will have a field for the player’s name and afield for the player’s score.) 2. A program that reads the records from the golf.txt file and displays them.
Computers and Technology
1 answer:
Aliun [14]3 years ago
8 0

Answer:

Check the explanation

Explanation:

<em>We can use a while loop to keep getting names end scores from the user. We just need to start with a single name as a priming read. Assuming it, not a 'q' (for quit), the while loop is entered where the score is obtained from the user and both the name and score are written to the file. Then we read another name and check if the user has decided to quit yet. </em>

<em>Note: because this exercise doesn't ask us to modify records of already existing players, we can assume that we should open the file in write mode instead of append mode (or else we'd potentially end up with multiple records for the same golfer). But in a real scenario you'd need to be very explicit with the customer that this program will delete any data that’s already in the file when it is run</em>

#creat and open the file in write mode

File_obj = open(‘golf.text’, ‘w’)

#obtain the first player’s name

Name = input(’enter the name of a golfer or q if you/’re done: ‘)

while name != 'q' and name !=’Q’:

#Obtain the player' e score

score + int (input ('Enter the golf score if player ' + name + ':’ ))

#Write a record if the player's name and score to the file

File_obj.write (name +’/n’)

File_obj.write (str(score) +’/n’)

Obtain the next player’s name or quit  

Name=inPut (' /nEnter the name of a golfer or q if you/’re done:’)

#close the file

File_obj.close()

<em>In this part, we’ll want to do a priming read consisting of the name of the first record in the file. Then we’ll get the associated score and print both separate columns. A while loop will continue getting names and scores until we run out of records and file_obj.readline() returns the empty string. </em>

<em>note that we’ll need to strip the extra new line escape sequence character from the names in the records. We don't need to for the scores because the int () function drops that character. </em>

<em>As in my previous solutions, I like to underline the header of my tables. That line should run on your system regardless of your OS, but if not, then just remove the strings ' /033[4m' and '/033[0m' and the header will print without being underlined.</em>

<em />

#Open the file in read mode

file_obj = open(’golf.txt', 'r')

#Read name of first record and remove trailing new line escape sequence

name file_obj.readline().rstrip(’/n’)

#Print header far table

print(' \ n'+’ \003[4m’+’name   Scare' ’\033[0m’)

#keep retrieving and printing names and scores from the file until the EOF while name !=":

Score=int(file_obj.readline())

print(format(name, '12s’), format(score, '>10d’))  #align +alumna

name = file_obj.readline().rstrip(’\n’)

# Close the file

file_obj.close()

You might be interested in
Match the cell reference to its definition
Alisiya [41]

Answer:

which cell reference:-|

6 0
3 years ago
Read 2 more answers
Type the correct answer in the box. Spell all words correctly.
KonstantinChe [14]

Answer:

Aspiring illustrators can hone their talent and skills using Adobe Illustrator software.

Explanation:

  • By using this software we enroll graphics for out Television.Computer etc ..
5 0
3 years ago
Who is familiar with Pixlr E.com on here????!!!!!
dsp73

meAnswer:

Explanation:

5 0
3 years ago
Problem 1a. Write a function named hasFinalLetter that takes two parameters 1. strList, a list of non-empty strings 2. letters,
mash [69]

Answer:

The answer is the programming in Python language has strings and characters that has to be declared in the method.

Explanation:

#method

def hasFinalLetter(strList,letters):

output = #output list

#for every string in the strList

for string in strList:

#findout the length of each string in strList

length = len(string)

#endLetter is last letter in each string

endLetter = string[length-1]

#for each letter in the letters list

for letter in letters:

#compare with endLetter

#if we found any such string

#add it to output list

if(letter == endLetter):

output.append(string)

#return the output list

return output

#TestCase 1 that will lead to return empty list

strList1 = ["user","expert","login","compile","Execute","stock"]

letters1 = ["a","b","y"]

print hasFinalLetter(strList1,letters1)

#TestCse2

strList2 = ["user","expert","login","compile","Execute","stock"]

letters2 = ["g","t","y"]

print hasFinalLetter(strList2,letters2)

#TestCase3

strList3 = ["user","expert","login","compile","Execute","stock"]

letters3 = ["k","e","n","t"]

print hasFinalLetter(strList3,letters3)

8 0
4 years ago
The Double.parseDouble() method requires a String argument, but it fails if the String cannot be converted to a floating-point n
Andrei [34K]

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        String numStr = input.nextLine();
  6.        double num;
  7.        try{
  8.            num = Double.parseDouble(numStr);
  9.        }
  10.        catch(NumberFormatException e){
  11.            num = 0;
  12.            System.out.println("Value entered cannot be converted to a floating point number.");
  13.        }
  14.    }
  15. }

Explanation:

The solution code is written in Java.

Firstly, we create a Scanner object and prompt user to input a number (Line 5-6). Next, we create a try -catch block and place the parseDouble inside the try block. If the input is invalid (e.g. "abc"), a NumberFormatException error will be thrown and captured and set the num to 0 and display the error message (Line 11 - 13).  

3 0
3 years ago
Other questions:
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    11·1 answer
  • 1. Which of the following options will allow you to insert a quick table? (1 point) Insert ribbon &gt; Shapes drop-down menu
    6·2 answers
  • When a project is saved, the new file name appears on the ____ tab?
    10·1 answer
  • Hello, please help write code in C++. Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go nort
    12·1 answer
  • Write a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement pa
    13·1 answer
  • The__________is an HTML tag that provides information on the keywords that represent the contents of a Web page.
    14·1 answer
  • What are the network topologies? Advantages and disadvantages.
    9·1 answer
  • Retail products are identified by their Universal Product Codes (UPCs). The most commonform of a UPC has 12 decimal digits: The
    8·1 answer
  • Your task is to build a palindrome from an input string.A palindrome is a word that readsthe same backward or forward. Your code
    12·1 answer
  • (Java) Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!