PLZZZ PYTHON PROGRAMMING ONLY (PLEASE HELP IF YOU KNOW ABOUT PYTHON AND FILES)    Modify your code to print to a file instead of the console. make sure your program performs the following actions:   Ask the user how many numbers they would like to enter Then prompt the user to enter a number as many times as they requested. Print the following to a file:   How many numbers they entered The sum of the numbers The highest number The average of the numbers Make sure to use a try-except block and include the finally block.   Describe the numbers you print. Do not just print numbers to the screen explain what each number represents. (first picture is my code second picture is of a try-except- finally example that ive done as reference )

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

PLZZZ PYTHON PROGRAMMING ONLY (PLEASE HELP IF YOU KNOW ABOUT PYTHON AND FILES) 

 

Modify your code to print to a file instead of the console. make sure your program performs the following actions:

 

  • Ask the user how many numbers they would like to enter

Then prompt the user to enter a number as many times as they requested.

Print the following to a file:

 

  • How many numbers they entered
  • The sum of the numbers
  • The highest number
  • The average of the numbers

Make sure to use a try-except block and include the finally block.

 

Describe the numbers you print. Do not just print numbers to the screen explain what each number represents.

(first picture is my code second picture is of a try-except- finally example that ive done as reference )

File Edit View Navigate Code Refactor Run Tools VCS Window Help
CSCI-145 CSCI-145
포포 O
✓ CSCI-145
Bookmarks
. Structure
>
1
|CSCI-145 2
FileSer 3
FilesLe 4
Home
5
myDat
Person
6
7
8
Review
Review
studen 9
Studen 10
venv libra 11
checkEma 12
checkPhor 13
scratch_4. 14
StudentFil
Week4Ass
Week5Ass
week6assi
15
16
17
> IIIII External Libra 18
Scratches and 19
| Scratches 20
checkP 21
library. 22
myDat 23
Object 24
scratch
scratch
4
10
20
scratch
scratch
scratch
Homework4.py
scratch_4.py X scratch_3.py X
def createList():
numList = []
while (True):
scratch
scratch
scratch
scratch
Week4
Week4 else
A
break
AnumList.append(int (variable))
if len (numList) > 0:
return numList
else:
scratch_2.py X
variable = input ("Enter a number or Enter done to quit: ")
if(variable=='done') :
print("List is empty!")
return 0
# display the information
list = createList()
CSCI-145 - Homework4.py
e se:
ObjectsLecture1.py X FilesLecture.py X Person.py X
if list != 0:
print("The total amount of numbers entered: "len(list))
print("The total of numbers: "sum(list))
print("The average of all numbers: "sum (list)/len(list))
print("The largest number is: "max (list))
print("Cannot find largest number in an empty array."2
student.txt x
FileServices.py X
Homework4.py
Version Control
Python Packages E TODO
Python Console
Problems
Terminal ▸ Services
Download pre-built shared indexes: Reduce the indexing time and CPU load with pre-built Python packages shared indexes // Always download // Download once // Don't show again // Configure... (10 minutes ago)
Person ▾
StudentFile.py X
A 28
A V
24:21 LF UTF-8 1 space* Python 3.9 (CSCI-145)
2
Transcribed Image Text:File Edit View Navigate Code Refactor Run Tools VCS Window Help CSCI-145 CSCI-145 포포 O ✓ CSCI-145 Bookmarks . Structure > 1 |CSCI-145 2 FileSer 3 FilesLe 4 Home 5 myDat Person 6 7 8 Review Review studen 9 Studen 10 venv libra 11 checkEma 12 checkPhor 13 scratch_4. 14 StudentFil Week4Ass Week5Ass week6assi 15 16 17 > IIIII External Libra 18 Scratches and 19 | Scratches 20 checkP 21 library. 22 myDat 23 Object 24 scratch scratch 4 10 20 scratch scratch scratch Homework4.py scratch_4.py X scratch_3.py X def createList(): numList = [] while (True): scratch scratch scratch scratch Week4 Week4 else A break AnumList.append(int (variable)) if len (numList) > 0: return numList else: scratch_2.py X variable = input ("Enter a number or Enter done to quit: ") if(variable=='done') : print("List is empty!") return 0 # display the information list = createList() CSCI-145 - Homework4.py e se: ObjectsLecture1.py X FilesLecture.py X Person.py X if list != 0: print("The total amount of numbers entered: "len(list)) print("The total of numbers: "sum(list)) print("The average of all numbers: "sum (list)/len(list)) print("The largest number is: "max (list)) print("Cannot find largest number in an empty array."2 student.txt x FileServices.py X Homework4.py Version Control Python Packages E TODO Python Console Problems Terminal ▸ Services Download pre-built shared indexes: Reduce the indexing time and CPU load with pre-built Python packages shared indexes // Always download // Download once // Don't show again // Configure... (10 minutes ago) Person ▾ StudentFile.py X A 28 A V 24:21 LF UTF-8 1 space* Python 3.9 (CSCI-145) 2
def writeToFile(self):
#local scope to method
myTextFile = None
try:
#local scope to try
myTextFile = open(self._filePath, self._mode)
#write data to the text file after open is completed
myTextFile.write(f' {self._data}\n')
# close
# close will end the programs connection to the file.
# will save the data in the text file.
# will cause the file to be unusable and may corrupt the file.
# completes the file
except TypeError:
print (f'Check your mode for the correct data ype for mode: {mode}, must be
except ValueError:
print (f'Check your mode you entered and invalid mode: {mode}.')
except FileNotFoundError:
print('Your file does not exist')
except:
print('Error: check your mode and data entered. Mode is string, Data is string')
finally:
string ')
myTextFile.close()
Transcribed Image Text:def writeToFile(self): #local scope to method myTextFile = None try: #local scope to try myTextFile = open(self._filePath, self._mode) #write data to the text file after open is completed myTextFile.write(f' {self._data}\n') # close # close will end the programs connection to the file. # will save the data in the text file. # will cause the file to be unusable and may corrupt the file. # completes the file except TypeError: print (f'Check your mode for the correct data ype for mode: {mode}, must be except ValueError: print (f'Check your mode you entered and invalid mode: {mode}.') except FileNotFoundError: print('Your file does not exist') except: print('Error: check your mode and data entered. Mode is string, Data is string') finally: string ') myTextFile.close()
Expert Solution
Step 1

The answer is given below.

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Files and Directory
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