-
Notifications
You must be signed in to change notification settings - Fork 0
/
working_with_files.py
170 lines (135 loc) · 5.17 KB
/
working_with_files.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
# importing datetime module for now()
from datetime import datetime, date
import self as self
now = datetime.now()
today = date.today()
current_time = now.strftime("%H:%M:%S")
# Month abbreviation, day and year
current_date = today.strftime("%b-%d-%Y")
full_datetime = print("Time and Date =", current_time, current_date)
# creating a dictionary of items to sell in the shop
# The 1 will skip 0 when listing the item number
wands = {'Oak': 23, 'Pine': 99, 'Maple': 837}
# FUNCTIONS
def program_title_bar():
# Clears the terminal screen, and displays a title bar.
os.system('clear')
print("****************************************************************")
print("*** You are about to enter another dimension. ***")
print("*** A dimension not only of sight and sound, but of mind. ***")
print("*** A journey into a wondrous land of imagination. ***")
print("****************************************************************")
def store_title_bar():
# Clears the terminal screen, and displays a Store title bar.
os.system('clear')
print("****************************************************************")
print("*** Oleanders Wand Shop ***")
print("****************************************************************")
def riddle_game():
answer = "teeth"
riddle = "Thirty white horses on a red hill, First they champ, Then they stamp, Then they stand still."
riddle_guess = int(input(riddle))
while riddle_guess != answer:
bad_guess = "Guess Again "
riddle_guess = int(input(bad_guess))
print("Impressive! You guessed right.")
def shopping_spree():
purchase = []
print('I hope you love to shop...because you have no other options!')
q1 = input("Do you have any money? ")
if q1 == 'y':
q1_2 = int(input("How much? "))
elif q1 == 'n':
q1_2 = int(input('How much would you like to borrow? '))
print(f"Lets see what you can buy with $ {q1_2}")
store_title_bar()
for i, (k, v) in enumerate(wands.items()):
print(f"[{i}] {k} ${v}")
owner_q1 = input('Would you like to buy something? ')
if owner_q1 == 'y':
purchase_number = int(input('Please Enter the Number of the item you would like to buy at this time? '))
purchase.append(purchase_number)
print()
elif owner_q1 == 'n':
print('no')
def nerd_quiz():
# questions dict.items()
nerd_questions = {"What part of the plant conducts photosynthesis? ": "leaf",
"Frog is a reptile or amphibian? ": "amphibian",
"Which scientist proposed the three laws of motion? ": "isaac newton",
"The standard unit of measurement for energy is ____. ": "joule"}
# guesses
nerd_guesses = []
score = 0
for x in nerd_questions.keys():
nerd_guess = input(x)
nerd_guesses.append(nerd_guess.lower())
for x, y in nerd_questions.items():
for i in nerd_guesses:
if i == y:
score += 1
nerd_guesses.pop(0)
break;
print(f'You answered {score} answers correct')
# Open the coffee.txt file in append mode.
quiz_file = open('quiz.txt', 'a')
save_results = input('Would you like to save your results? ')
if save_results == 'y':
# Append the data to the file.
quiz_file.write(
user + ': scored ' + str(score) + ' points : ' + str(current_time) + ' ' + str(current_date) + '\n')
# Close the file.
quiz_file.close()
print('Data appended to coffee.txt.')
def quiz_results():
# Open a file named philosophers.txt.
infile = open('quiz.txt', 'r')
# Read the file's contents.
file_contents = infile.read()
# Close the file.
infile.close()
# Print the data that was read into
# memory.
full_quiz_content = print(file_contents)
def get_user_choice():
# Let users know what they can do.
print("\n[1] Answer My Riddle")
print("[2] Go Shopping")
print("[3] Take a quiz")
print("[4] List All Quiz Participants")
# print("[5] User Quest Tracker")
print("[e] Exit\n")
return input("What would you like to do? ")
# MAIN PROGRAM
# Set up a loop where users can choose what they'd like to do.
class User:
def __init__(self, name, password):
self.name = name
self.password = password
f = open("demofile3.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()
#open and read the file after the appending:
f = open("demofile3.txt", "r")
print(f.read())
choice = ''
program_title_bar()
# print(f"\nWelcome, '{user}!")
while choice != 'e':
choice = get_user_choice()
# Respond to the user's choice.
if choice == '1':
print("\nCreate new file\n")
elif choice == '2':
print("\nDisplay current users\n")
elif choice == '3':
print("\nUpdate Users\n")
elif choice == '4':
print("\nYOur Profile\n")
elif choice == '5':
print("\nPLEASE TRY AGAIN LATER\n")
elif choice == 'e':
print("\nSorry.\nBut up can never leave.\nYou live here now.\nGoodBye.")
else:
print("\nI didn't understand that choice.\n")