This is my project(beta) after studying for 3 weeks. It took me more or less 30 hours of writing and researching. I would appreciate a review based on my beginner level. I'm very proud of it, it was hard work for me.
Learned...
Files management, control if
for
while
loops, integers and strings, lists dictionaries and tuples.
Code:
#C:\restaurant software
with open('names.txt', 'r') as r :
f_n = r.read().splitlines()
print("Welcome to NAME.app")
##############
# USER LOGIN #
##############
while True:
name = input("""
\n - Insert name to logg in
\n - ADD to save new user
\n - LIST to see saved users
\n - REMOVE to delete a user
\n - EXIT to finish
\n - ...""")
lname = name.lower()
if lname == "add":
n_input = input("Name:")
with open('names.txt', 'a') as f:
f.write(n_input + '\n')
elif lname == "list":
with open('names.txt') as f:
print(f.read().splitlines())
f.close()
elif name in f_n:
print("Logged as", name.upper())
user = name
input('Welcome, press enter to continue \n')
break
elif lname == 'remove':
rem = input("Insert user name to remove \n ...")
with open('names.txt', 'r+') as f:
l = f.readlines()
l = [z for z in l if rem not in z]
with open('names.txt', 'w') as f:
f.writelines(l)
elif lname == "exit":
exit()
####################
# TABLE MANAGEMENT #
####################
#C:\restaurant software
while True:
action = input ('''
- NEW table
\n - ADD table
\n - BILL
\n - CLOSING
\n - EXIT
\n - ... ''')
d = {'(1) chburger': 19,'(2) bncburger': 23,'(3) plpasta': 6}
if action == 'new' :
tn = input('Insert table number \n - ...')
name = 'T' + tn
t = open(name + '.txt', 'w+')
print('Done')
elif action.lower() == 'add':
# Select table
table = input ('Select desired table number: \n - ...')
fulltab = 'T' + table
with open(fulltab + '.txt', 'w+') as f :
# Order list and add Order
while True:
for k, v in d.items() :
print(k, v)
addprod = input('Insert order. \n - ...')
for k, v in d.items() :
if addprod == k[1] :
f.write(str(v) + '\n')
#Option to continue.
q = input('Add more? y/n \n -...')
if q.lower() == 'y' : continue
if q.lower() == 'n' : break
#File as F
elif action.lower() == 'bill' :
p_b = input('Please insert number of table. \n -... ')
with open (('T' + p_b)+ '.txt', 'r+') as p :
tobill = 0
for line in p : tobill = int(tobill) + int(line)
xtra = input('Group table (+10 ppl)? y/n: \n')
if xtra == 'y' :
tobill = tobill + (tobill/100)*10
print('SERVICE CHARGE ADDED.')
elif xtra == 'n' : print ('Processing bill...')
print('Total to pay:', tobill)
print('Serviced by', user)
#### Closing added part to bill.
with open('closing.txt', 'a+') as f :
f.write(str(tobill) + '\n')
# Closing days balance.
elif action.lower() == 'closing' :
date = input('Please enter DATE. ')
with open('closing.txt', 'r+') as f :
result = 0
for line in f : result = int(result) + int(line)
print('Closing is...')
print(result)
print('Today tips', (result / 100 * 10))
current_closing = 'C:restaurant software\\closing.txt'
old_closing = 'C:restaurant software\\' + date + '.txt'
import os
os.rename(current_closing, old_closing)
print('Day closed, find the closing balance in the specific dated document.')
# Exit command.
elif action.lower() == 'exit' :
exit()
I know I have to improve the log in system with the possible names that someone could enter and a lot more of things.
Before starting this project the largest that I write was 30 lines.