0% found this document useful (0 votes)
28 views

Python Practical 14

Python Practical

Uploaded by

rutujapawar.1408
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Python Practical 14

Python Practical

Uploaded by

rutujapawar.1408
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 14

(Files and Exceptions Part-1)

Q1 Open a blank file in your text editor and write a few lines summarizing what you’ve
learned about Python so far. Start each line with the phrase In Python you can.... Save the
file as learning_python.txt in the same directory as your exercises from this chapter. Write a
program that reads the file and prints what you wrote three times. Print the contents once by
reading in the entire file, once by looping over the file object, and once by storing the lines in
a list and then working with them outside the with block.

Step I] Create a text file learning_python.txt

Step II] Create a python file learning_python.py


Output:

Q2 Write a while loop that prompts users for their name. When they enter their name, print a
greeting to the screen and add a line recording their visit in a file called guest_book.txt. Make
sure each entry appears on a new line in the file.

Step I] Create a blank text file guest_book.txt

Step II] Create a python file guest_book.py


Output:

guest_book.txt

Q3 Write a while loop that asks people why they like programming. Each time someone
enters a reason, add their reason to a file that stores all the responses.

Step I] Create a blank text file programming_poll.txt


Step I] Create a python file programming_poll.txt
Output:

programming_poll.txt

You might also like