Phyton: Program 6: Write a program that allows the user to add data from files or by hand.  The user may add more data whenever they want.  The print also allows the user to display the data and to print the statistics.  The data is store in a list.  It’s easier if you make the list global so that other functions can access it. You should have the following functions: ·        add_from_file() – prompts the user for a file and add the data from it. ·        add_by_hand() – prompts the user to enter data until user type a negative number. ·        print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions. Handling errors such as whether the input file exist is extra credit. To print a 10-column table, you can use the code below:    for i in range(len(data)):       print(f"{data[i]:3}", end="")       if (i+1)%10==0:          print()    print()   Sample run: Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 2 Type a positive number (-1 to end):1 Type a positive number (-1 to end):2 Type a positive number (-1 to end):3 Type a positive number (-1 to end):-1 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 4   1  2  3 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 1 Enter file to read: a.txt Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 4   1  2  3  3  1  4  5 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 1 Enter file to read: b.txt Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 4   1  2  3  3  1  4  5  9  8  5   Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 2 Type a positive number (-1 to end):10 20 Type a positive number (-1 to end):20 Type a positive number (-1 to end):30 Type a positive number (-1 to end):-1 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 4   1  2  3  3  1  4  5  9  8  5  10 20 30 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 4   1  2  3  3  1  4  5  9  8  5  10 20 30 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 3 min = 1 max = 30 mean= 7.769230769230769 sum = 101 Choose an action   1) add data from a file   2) add data by hand   3) print stats   4) view data   5) exit Choice: 5 Goodbye

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Phyton:

Program 6:

Write a program that allows the user to add data from files or by hand.  The user may add more data whenever they want.  The print also allows the user to display the data and to print the statistics.  The data is store in a list.  It’s easier if you make the list global so that other functions can access it.

You should have the following functions:

  • ·        add_from_file() – prompts the user for a file and add the data from it.
  • ·        add_by_hand() – prompts the user to enter data until user type a negative number.
  • ·        print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions.

Handling errors such as whether the input file exist is extra credit.

To print a 10-column table, you can use the code below:

   for i in range(len(data)):

      print(f"{data[i]:3}", end="")

      if (i+1)%10==0:

         print()

   print()

 

Sample run:

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 2

Type a positive number (-1 to end):1

Type a positive number (-1 to end):2

Type a positive number (-1 to end):3

Type a positive number (-1 to end):-1

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 4

  1  2  3

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 1

Enter file to read: a.txt

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 4

  1  2  3  3  1  4  5

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 1

Enter file to read: b.txt

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 4

  1  2  3  3  1  4  5  9  8  5

 

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 2

Type a positive number (-1 to end):10 20

Type a positive number (-1 to end):20

Type a positive number (-1 to end):30

Type a positive number (-1 to end):-1

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 4

  1  2  3  3  1  4  5  9  8  5

 10 20 30

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 4

  1  2  3  3  1  4  5  9  8  5

 10 20 30

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 3

min = 1

max = 30

mean= 7.769230769230769

sum = 101

Choose an action

  1) add data from a file

  2) add data by hand

  3) print stats

  4) view data

  5) exit

Choice: 5

Goodbye

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education