Question

Need Flowchart on Python, Incorporate a user-defined function into your solution. Assume that a file containing...

Need Flowchart on Python, Incorporate a user-defined function into your solution.

Assume that a file containing a series of integers is named numbers.dat and exists on the computer's disk. Design a program that displays all of the numbers in the file.

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

'''
Python version : 3.6
Python program to create a function for displaying the integers
read from file
Each line of the file contains an integer
'''

def printNumberFromFile():
  
   file = open("numbers.dat") # open the file in read mode
   contents = file.readlines() # read the contents of the file into the list with each line being an element of the list
  
   # loop over the contents list
   for line in contents:
       print(int(line)) # print each number by converting it to integer
   #close the file
   file.close()
# call the function
printNumberFromFile()  
#end of program  

Code Screenshot:

Output:

Input file:

Input file consists of integers such that one integer is present in one line

Output:

Flowchart:

Add a comment
Know the answer?
Add Answer to:
Need Flowchart on Python, Incorporate a user-defined function into your solution. Assume that a file containing...
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
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