This Python program receives multiple sentences from the user and saves them into a .TXT file located on drive D:.
It’s useful for creating quick notes, logs, or storing user input in a structured text format.
# Ask user how many sentences to enter
n = int(input("How many sentences do you want to enter? "))
# Collect sentences in a list
sentences = []
for i in range(n):
sentence = input(f"Sentence {i+1}: ")
sentences.append(sentence)
# File path on drive D
file_path = "D:/sentences.txt"
# Write sentences to the file
with open(file_path, "w", encoding="utf-8") as f:
for line in sentences:
f.write(line + "\n")
print("Sentences saved successfully.")
How many sentences do you want to enter? 2
Sentence 1: Hello world
Sentence 2: This is a test
Sentences saved successfully.
- The user specifies how many sentences to enter
- Each sentence is collected using input() and stored in a list
- The file is created at D:/sentences.txt
- A loop writes each sentence to the file, one per line
- A success message confirms the operation