Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Python) What is the syntax for this textbook solution? The first and second photos contain the programs code. Step 3 shows what is in 'numbers.txt'

(Python) What is the syntax for this textbook solution? The first and second photos contain the programs code. Step 3 shows what is in 'numbers.txt' and step 4 is the sample output.
image text in transcribed
image text in transcribed
image text in transcribed
Starting out with Python Program: #main function def main(): flag = False #try statement to handle text file exceptions try: #open text file in read mode filel = open('numbers.txt', 'r') #Declare and initialize variables total = 0 count=0 #Use for loop to read all numbers from #text file for line in filel: #try statement to handle value error try: #Make increment in value of count count += 1 #Type cast value into integer type #to perform addition. num = int(line) #Add current read value into total total += num #except statement to handle value error except ValueError: print('Not Integer: String could'+ 'not be converted into integer') flag=True #close text file filel.close() if flag=False: #Calculate and display average on screen Chapter 6 Problem 9PE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions