
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
PLZZZ PYTHON
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](https://content.bartleby.com/qna-images/question/7cef3050-b0aa-40af-9112-57cab04a18ba/feaa816d-68eb-4718-a497-31fd5ffe29e8/qo5i0ew_thumbnail.jpeg)
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

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

arrow_forward
Step 1
The answer is given below.
Step by stepSolved in 5 steps with 3 images

Knowledge Booster
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
- QUESTION 26 Write code that uses a while loop to display the powers of 2 exactly as shown below: 1248163264128arrow_forwardin python i need help writing a program that inclues all of the following program has to include at least one of each of the following: if statements loops arrays (lists) files functionsarrow_forward*The following needs to be in python For this application, you will need to create a Python application that reads the sales for 12 months from a file and calculates the total yearly sales as well as the average monthly sales. In addition, this program should let the user edit the sales for any month. Jan 14317 Feb 3903 Mar 1073 Apr 3463 May 2429 Jun 4324 Jul 9762 Aug 15578 Sep 2437 Oct 6735 Nov 88 Dec 2497 Step 1 Define a display_title() function and have it use the print() to show the text: [FirstName] [LastName]'s Monthly Sales Replace the placeholders with your own first and last name add a space using the print() Define a display_menu() function and have it Use the print() function several times to show the following text with a space after: COMMAND MENUmonthly - View monthly salesyearly - View yearly summaryedit - Edit sales for a monthexit - Exit program Step 2 Define a main() function Call the display_title() function and the…arrow_forward
- -all-occurrences-of-a-substring-in-a-string/.arrow_forwardUse C++ Comment Lines:- Name of the cpp file- Your name- Why you are doing this program Input- Enter in the number of sales items- Enter in the name of the sales item- Enter in the price of the sales item Output- Title for the output- The sales items names- The price of each sales items- The sales price total- The sales tax- The grand total- Money amount have 2 decimal point places- Money amount to be aligned- Boarder around the outputThe user will have the ability to run this program againarrow_forwardC programming: 11. Which type(s) of loop (for/do-while/while) would you use in each of the following situations? a)Asking the user if the program has guessed their number or not. b)Printing the name of each of the 36 students in the class. c)Asking the user for an unknown number of class grades. d)Counting how many times it takes the user toguess the program’s number. 12. How are the loops controlled (event or counter) in the following situations? a)Asking the user if the song is over. b)Counting how many times it takes the user to guess the program’s number. c)Asking the user to enter all 6 of their classwork grades to date. d)Printing the 16 steps of the Cupid Shuffle.arrow_forward
- Python programming help I need help of question 1 to read a file from persons.txt Write a program that takes a person’s details (name, age and a city), and writes to a file (persons.txt) using a loop repeatedly. You should write three person’s to the file. The program terminates on entering any key by the user, except on (Y or y) key. Sample output of the first run of the program is shown below: Enter name: JohnEnter age: 20Enter city: SydneyData saved: John 20 SydneyPress (Y or y) to add another person, or any key to exit Question 1) Write a program that read a file (persons.txt) from previous question given on the top of this question, and shows all the records/lines from the file as a nicely formatted report with a header as shown: Name Age City +---------------------+--------------------+--------------arrow_forwardWhat does the following python code do? f = open("sample.txt", "w") Choose all that apply. Select 2 correct answer(s) Question 14 options: If the file called sample.txt exists, it writes at the bottom of the file writes "w" to the file called sample.txt closes a file called sample.txt opens a file called sample.txt for appending opens a file called sample.txt for reading reads the file called sample.txt starting from the top if the file sample.txt exists, deletes everything in it if the file sample.txt does not exist, it creates the file and opens it for writingarrow_forward// Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input // file and prints the information to the user's screen. // Input: flowers.dat. // Output: Names of flowers and the words sun or shade. #include <fstream> #include <iostream> #include <string> using namespace std; int main() { // Declare variables here // Open input file // Write while loop that reads records from file. fin >> flowerName; // Print flower name using the following format //cout << var << " grows in the " << var2 << endl; fin.close(); return 0; } // End of main functionarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education