Question

Must be done in python and using linux mint

Write a program to create a text file which contains a sequence of test scores. Each score will be between 0 and 100 inclusive. There will be one value per line, with no additional text in the file. Stop adding information to the file when the user enters -1 The program will first ask for a file name and then the scores. Use a sentinel of -1 to indicate the user has finished supplying data A sample session of this part might be Enter data file name: scoresl.txt Enter the scores, enter -1 to quit: Score: 100 Score: 79 Score: 67 Score: 32 Score: -1 After the above session the contents of scores1.txt would be 100 79 32 Create two or more files with test results Part 2: Write a program that will ask the user for a data file. You may use raw_input or a cs160gui method to allow the user to enter a file. Use one of the data files created from part 1. Each line of the file must contain a single value. Fill a list with the values from the file Once the list has been filled with values the program should display, with appropriate labels, the largest values from the list, the smallest value from the list, the average of the list (with 2 places after the decimal point). Then ask the user for a lower limit and an upper limit. Display all the values from the list that fall within that range. The numeric values must be right justified

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

----------------------------Part1------------------------

filename = input('Enter file name : ')

# open file in write mode

fptr = open(filename, 'w')

print('Enter the scores, enter -1 to quit:')

# infinite loop

while True:

    score = int(input(''))

   

    if score == -1:

   

        break

       

    # write into the file

    fptr.write(str(score) + '\n')

-----------------------------Part2------------------------------

filename = input('Enter file name : ')

# open file in read mode

fptr = open(filename, 'r')

# read the content of file

x = fptr.read()

arr = []

# read file line by line

for y in x.split('\n'):

    arr.append( int( y ) )

   

largest = arr[0]

smallest = arr[0]

sum = arr[0]

for i in range( 1 , len(arr) ):

    if arr[i] > largest:

   

        largest = arr[i]

       

    if arr[i] < smallest:

   

        smallest = arr[i]

       

    sum += arr[i]

   

average = sum / len(arr)

   

print('Largest Score :', largest)

print('Smallest Score :', smallest)

print('Average Score :', average)

l = int(input('\nEnter the lower limit: '))

u = int(input('Enter the upper limit: '))

for i in arr:

    if i >= l and i <= u:

   

        print(i)

--------------------------scores1.txt----------------------

100
79
67
32
79
85
97
41

Sample Output

Enter file name scores1.txt Largest Score 100 Smallest Score 32 Average Score : 72.5 Enter the lower limit: 60 Enter the uppe

Add a comment
Know the answer?
Add Answer to:
Must be done in python and using linux mint Write a program to create a text...
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
  • NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work...

    NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file...

  • This will be done using Python in Linux Mint. The program should include a comment block...

    This will be done using Python in Linux Mint. The program should include a comment block at the top with your name, the program number, and the name of the course. (Make sure to have the file that does have the extension .py) How to run the file in Linux Mint?  Open a command prompt (e.g. terminal)  Make sure you are in the directory where your file is saved (e.g. type "cd ~/Desktop" if your file is on...

  • Python Programming Topics: list, file input/output You will write a program that allows the user to...

    Python Programming Topics: list, file input/output You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Must be done in C# please! Thanks! In this assignment you will create a program named...

    Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from...

    ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from files and the clipboard and performs other string, file, and directory manipulation tasks.” 2. Output the current working directory of the program. 3. Ask the user to enter the directory where they would like files to be stored, make that directory, and store files in the program in that directory. 4. Write the following three lines to file_one.txt (without bullet points): • Line 1...

  • Following should be done in C++: Create a program that reads a text file and prints...

    Following should be done in C++: Create a program that reads a text file and prints out the contents of the file but with all letters converted to uppercase. The name of the file to be read by the program will be provided by the user. Here are some example session: Contents of "data.txt": Hello, World! User input: data.txt Program output: HELLO, WORLD! Contents of "data.txt": tHiS FiLe HaS mIxEd CaSeS User input: data.txt Program output: THIS FILE HAS MIXED...

  • ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from...

    ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from files and the clipboard and performs other string, file, and directory manipulation tasks.” 2. Output the current working directory of the program. 3. Ask the user to enter the directory where they would like files to be stored, make that directory, and store files in the program in that directory. 4. Write the following three lines to file_one.txt (without bullet points): • Line 1...

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