Question

Compose a program that reads in lines from standard input with each line containing a name...

Compose a program that reads in lines from standard input with each line containing a name and two integers and then uses writef() to write a table with a column of the names, the integers, and the result of dividing the first by the second, accurate to three decimal places. You could use a program like this to tabulate batting averages for baseball players or grades for students. PLEASE BE IN PYTHON :) ….

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: -

1) file.write() is used for writing input to file. input().split() is used to take multiple inputs in single line.

2) Don't forget to upvote. For any doubts ask in comments section.

CODE(IMAGE): -

CODE(TEXT):-

def main():
   print("y) For writing")
   print("else) For quit")

   inp = input("Enter your option : ") #if inp == "y" takes input and write to file
   file = open("test.txt", "w") #opening file


   while inp == "y" : #loop while inp == "y"
       name, value1, value2 = input("Enter your name, value 1, value 2 : ").split() #used for single line input reading
       #split is used to split depending on spaces
       value1 = int(value1) #typecast value1 to int
       value2 = int(value2) #typecast value 1 to int
       file.write('%10s %5d %5d %8.3f\n'%(name, value1, value2, value1/value2)) #values are written to file
       print("") #newline printing
       inp = input("Do you want to continue : ") #checks if user want to continue

main() #main function calling

SAMPLE TERMINAL INPUT :-

SAMPLE OUTPUT TEXT FILE :-

Add a comment
Know the answer?
Add Answer to:
Compose a program that reads in lines from standard input with each line containing a name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *Please use StdIn. not Scanner. Thanks Write a program that reads in lines from standard input...

    *Please use StdIn. not Scanner. Thanks Write a program that reads in lines from standard input with each line containing a name and two integers and then prints a table with a column of the names, the integers, and the result of dividing the first by the second, accurate to three decimal places. You could use a program like this to tabulate batting averages for baseball players or grades for students. Should see: Name 1 Name 2 Name 3 20...

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on...

    write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on a team. Team name, player name, and player position will also be input.(two dimensional array) The program should then calculate and print the individual batting average and, after all 9 players have been entered, calculate and print the team batting average. Example of inputs and Outputs... Enter the Team name: (one time entry)...

  • python Write a program that reads the name of fruits and the colors from an input...

    python Write a program that reads the name of fruits and the colors from an input file fruit. txt. Each fruit name and the color is given on a line as shown below separated by space Apple Red Orange Orange Grape Green Now write output to an output file (fruit2.txt) as shown below Color of Apple is Red Color of Orange is Orange Color of Grape is Green The program has to be general to read in as many lines...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • PLEASE DO THIS IN C#.Design and implement a program (name it ProcessGrades) that reads from the...

    PLEASE DO THIS IN C#.Design and implement a program (name it ProcessGrades) that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered: 95, 80, 100, 70 Highest grade: 100 Lowest grade: 70 Average grade: 86.25

  • Within this C program change the input to a file instead of individual input from the...

    Within this C program change the input to a file instead of individual input from the user. You must take the input file name on the command line. Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of grades Third Line: Student Names, space delimited Fourth+ Line(s): Grades for all students for one assignment, space delimited....

  • Python -  Compose a program script that accepts input for album data for 3 albums including Artist,...

    Python -  Compose a program script that accepts input for album data for 3 albums including Artist, Title, and exactly five track titles. Collect these into a dictionary of dictionaries structure, stores the result in a JSON file and then reads the records and displays them in tabular form with column headings. Input Output Artist – The Beatles Title – Abbey Road Number of Tracks - 0 Artist: The Beatles    Title: Abbey Road Artist – The Beatles Title – Revolver Number...

  • Create a java program that reads an input file named Friends.txt containing a list 4 names...

    Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do:   1. Add a new name   2. Change a name 3. Delete a name 4. Print the list   or 5. Quit    When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT