-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.py
38 lines (31 loc) · 873 Bytes
/
functions.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
import random
def load_quotes(filename):
quotes = []
with open(filename, 'r') as file:
lines = file.readlines()
for line in lines:
line = line.strip()
if line:
quotes.append(line)
return quotes
def random_quote(quotes):
random_quote = random.choice(quotes)
return random_quote
def print_quote(quote):
print(quote)
def view_quotes(quotes):
for quote in quotes:
print_quote(quote)
def display_quotes(quotes, count):
if count >= len(quotes):
print("All Quotes:")
view_quotes(quotes)
else:
print(f"First {count} Quotes:")
for i in range(count):
print_quote(quotes[i])
def add_quote(quotes, filename):
new_quote = input("Enter a new quote: ")
quotes.append(new_quote)
with open(filename, 'a') as file:
file.write(new_quote)