-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepad.py
56 lines (44 loc) · 1.45 KB
/
notepad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
def create_file():
"""Create a new file and write text to it."""
filename = input("Enter the name of the file: ")
text = input("Enter the text you want to write to the file: ")
with open(filename, 'w') as file:
file.write(text)
print("File created and text written successfully.")
def read_file():
"""Read the contents of an existing file."""
filename = input("Enter the name of the file: ")
if os.path.exists(filename):
with open(filename, 'r') as file:
contents = file.read()
print(contents)
else:
print("File not found.")
def update_file():
"""Append text to an existing file."""
filename = input("Enter the name of the file: ")
if os.path.exists(filename):
text = input("Enter the text you want to add to the file: ")
with open(filename, 'a') as file:
file.write(text)
print("Text added to file successfully.")
else:
print("File not found.")
while True:
print("\nNotebook Menu:")
print("1. Create a new file")
print("2. Read an existing file")
print("3. Update an existing file")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == '1':
create_file()
elif choice == '2':
read_file()
elif choice == '3':
update_file()
elif choice == '4':
break
else:
print("Invalid choice. Please enter a number between 1 and 4.")