Computer Science
Write a program to accept string/sentences from the user till the user enters “END” to. Save the data in a text file and then display only those sentences which begin with an uppercase alphabet.
Python File Handling
1 Like
Answer
f = open("new.txt", "w")
while True:
st = input("Enter next line:")
if st == "END":
break
f.write(st + '\n')
f.close()
f = open("new.txt", "r")
while True:
st = f.readline()
if not st:
break
if st[0].isupper():
print(st)
f.close()
Output
Enter next line:Hello world
Enter next line:welcome to
Enter next line:Python programming
Enter next line:END
Hello world
Python programming
Answered By
2 Likes
Related Questions
Write a command(s) to write the following lines to the text file named hello.txt. Assume that the file is opened in append mode.
“ Welcome my class” “It is a fun place” “You will learn and play”
Write a Python program to open the file hello.txt used in question no 6 in read mode to display its contents. What will be the difference if the file was opened in write mode instead of append mode?
Define pickling in Python. Explain serialization and deserialization of Python object.
Write a program to enter the following records in a binary file :
Item No — integer
Item_Name — string
Qty — integer
Price — floatNumber of records to be entered should be accepted from the user. Read the file to display the records in the following format:
Item No :
Item Name :
Quantity :
Price per item :
Amount : ( to be calculated as Price * Qty)