#==========================================
# IS340 PROJECT 1 KEN TRAN =
#==========================================
import datetime #importing the date/time module
#Assigning differrent prices and rates
AdventurePrice = 450
DeluxePrice = 675
ElephantPrice = 150
taxRate = 0.095
loopAgain = True
while loopAgain:
print()
#Gathering input from the user
number_of_people = int(input("Enter Number of People: ")) #Asking the number of people on
the tour
safariChoice = input("Which type of Safari A - Adventure or D - Deluxe: ").lower() #Asking for
type of Safari
if safariChoice not in ['a', 'd']:
print("Oops! Please enter A or D ")
continue
while True:
elephantChoice = input("Ride Elephants Y/N: ").lower() #Asking if they want to ride
elephants or not
if elephantChoice in ['y','n']:
break #Exit loop if choice in selection
else:
print ("Oops! Please enter Y or N.")
continue #Go back to the start of the loop to ask for input
again
while True:
memberChoice = input("Are you a member? Y/N: ").lower()#Asking if they are members or
not
if memberChoice in ['y' , 'n']:
break #Exit loop if choice in selection
else:
print ("Oops! Please enter Y or N.")
continue #Go back to the start of the loop to ask for input
again
#Calculations
if safariChoice == ("a"): #Calculating price based on type of safari
safariTotal = number_of_people * AdventurePrice
else:
safariTotal = number_of_people * DeluxePrice
if elephantChoice == "y": #Calculating price based on if they choose
elephant or not
elephantTotal = number_of_people * ElephantPrice
else:
elephantTotal = 0
Subtotal = safariTotal + elephantTotal
if memberChoice == "y": #Calculating discount price based on if they're
members or not
Total_discount = Subtotal * 0.1
else:
Total_discount = 0
taxesDue =(Subtotal - Total_discount) * (1 - taxRate) #Calculating the taxes due
Total =(Subtotal - Total_discount ) + taxesDue #Total amount due at the end of the
message
print() #Printing all the values from the calculations.
print(f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} ")
print(f"Safari cost is: {safariTotal:.2f}")
print(f"Elephants cost is: {elephantTotal:.2f}")
print(f"Subtotal is: {Subtotal:.2f}")
print(f"Discount is: {Total_discount:.2f}")
print(f"Total due after discount is: {Subtotal - Total_discount:.2f}")
print(f"Taxes due is: {(taxesDue):.2f}")
print(f"Total amount due after taxes is {Total:.2f}")
print("\n\n")
again = input("Make another reservation? Y/N: ").lower() #Asking if they want to continue
another transaction
if again != "y": #If y the loop is ran again, if not the loop ends
loopAgain = False
print(f"Thank you,and goodbye\n\n\n")
#PROJECT 2
loopAgain = True
import math
#Dictionaries to rental and sale properties
forrent = { "1542 Bartlett #199D" :2183,
"1026 17th St #124A" :1900,
"728 16th St #18M" :2633,
"1010 11th #2D" :3406}
forsale = {"4220 Edison Ave" :325000,
"2209 Gila Way" :650000,
"4640 Sagar Ave" :875000,
"3780 Las Pasas Way" :1740000}
#Function to display main menu
def displayMenu():
print("\n1.Show Available Properties")
print("2.Add Properties")
print("3.Calculate Monthly Loan Payments")
print("Q.Quit")
choice = input("\nEnter your choice: ").upper()
#Code to validate the user's choice.
if choice not in ('1', '2', '3', 'Q'):
print("Oops! Please Select A Valid Input!")
return choice
#Function to show available properties
def showProperties():
while True: #Display options for property type
print("\nWhich type of property are you looking for?")
print("S Home for Sale")
print("R Rentals")
print("B Both")
#Get the user's choice of property type
property_choice = input("Select (S,R,B):").upper()
#Display property based on user's selection
if property_choice == 'S':
showForSale()
break
elif property_choice == 'R':
showForRent()
break
elif property_choice == 'B':
showForSale()
showForRent()
break
else:
print("\nInvalid Input! Please Select Again!")
continue
#Function to display rental properties
def showForRent():
print(f'\n{"RENTALS":<16}{"PRICE":>14}')
for theKey in forrent.keys():
print(f"{theKey:<21} {forrent[theKey]:>12,} monthly")
#Function to display properties for sale
def showForSale():
print(f'\n{"FOR SALE":<16}{"PRICE":>14}')
for theKey in forsale.keys():
print(f'{theKey:<21} {forsale[theKey]:>12,}')
#Function to add rental or sale properties
def addProperties():
while True:#Display options for property type
print(f'\nWhat type of property do you want to add?')
print("R Rentals")
print("S Homes for Sale")
#Get the user's choice of property type
addChoice = input("Enter your choice (R,S):").upper()
if addChoice == "R":
addForRent()
break
elif addChoice== "S":
addForSale()
break
else:
print("\nInvalid Input! Please Select Again!")
continue
#Function to add a rental property
def addForRent():
while True:
#Get property address and value from user
address = input("\nEnter the address of the property:")
value_input = input("Enter the value of the property:")
#Validate the value inputed is a number
if value_input.isdigit():
value = int(value_input)
break
else:
print("\nPlease enter an numeric value for property.")
continue
#Add the property to the global dictionary
forrent[address]= value
showForRent()
#Function to add a property for sale
def addForSale():
while True:
#Get property address and value from user
address = input("\nEnter the address of the property:")
value_input = input("Enter the value of the property:")
#Validate the value inputed is a number
if value_input.isdigit():
value = int(value_input)
break
else:
print("\nPlease enter an numeric value for property.")
continue
#Add the property to the global dictionary
forsale[address]= value
showForSale()
#Funcion to calculate monthly loan payment base on user's input
def calcMonthlyLoanPayment(LoanAmount,InterestRate,YearsTilMaturity):
#Calculate the monthly interest rate
monthlyRate = InterestRate / 100 / 12
#Calculate the monthly payment
monthly_payment =(LoanAmount * monthlyRate)/(1 -
math.pow((1+monthlyRate),(-12*YearsTilMaturity)))
#Calculate total payments and interest paid
total_payments = monthly_payment * 12 * YearsTilMaturity
total_interest = total_payments - LoanAmount
return monthly_payment,total_payments,total_interest
#Function to get loan information from the user
def getMonthlyLoanPayment():
while True:
#Get years until loan maturity and validate the input (30 if left blank)
years_input = input("\nYears until loan maturity (leave blank for 30):")
if years_input == "":
N = 30
break
elif years_input.isdigit():
N = int(years_input)
if N > 0:
break
else:
print("\nYears until loan maturity must be greater than zero.")
else:
print("\nInvalid Input! Please Enter an Integer!")
#Get the loan amount and validate the input
while True:
loan_amount = input("Enter the loan amount(Pricipal): ")
if loan_amount.replace(".", "").isnumeric():
P = float(loan_amount)
if P > 0:
break
else:
print("\nPrincipal must be greater than zero.")
else:
print("\nInvalid Input! Please Enter a Integer or Float!")
#Get the interest rate and validate the input
while True:
interest_input = input("Enter the Annual Interest Rate: ")
if interest_input.replace(".", "").isnumeric():
R = float(interest_input)
if R <= 0:
print("\nAnnual interest rate must be greater than zero.")
elif R > 18.5:
print("\n18.5% is the maximum interest rate by state law.")
else:
break
else:
print("\nInvalid Input! Please Enter an Integer or Float!")
#Call the loan payment calculation with the user's inputs
monthly_payment,total_payments,total_interest = calcMonthlyLoanPayment(P, R, N)
return monthly_payment,total_payments,total_interest
#Main function to run the program
def main():
while True:
#Display the main menu and get the user's choice
choice = displayMenu()
#Call on appropriate funtions depending on the user's choice
if choice == '1':
showProperties() #Show properties
elif choice == '2':
addProperties() #Add property
elif choice == '3':
#Calculate and display loan payments
monthly_payment,total_payments,total_interest = getMonthlyLoanPayment()
print(f"\nThe monthly payment is: ${monthly_payment:,.2f}")
print(f"The total interest paid is: ${total_interest:,.2f}")
print(f"The total amount paid is: ${total_payments:,.2f}")
elif choice == 'Q':
#Exit the program when user wants to quit
print("\nGoodbye, Thank you")
break
#Calling function to run the program
main()
#PROJECT 3
from tkinter import *
from tkinter import messagebox, ttk
window = Tk()
window.geometry("500x600")
window.title("Pizza Order Form")
pizzariaImage = PhotoImage (file='Pizzaria2.png')
imgLabel = Label ( window, image = pizzariaImage )
imgLabel.grid( row=0, column=0, columnspan=3)
nameLabel = Label(window,
text='Customer Name:',
font=('Arial', 15))
nameLabel.grid(row=1, column=0, sticky=E, pady=(20,20))
userName = Entry(window)
userName.grid(row=1, column=1, columnspan = 2, sticky=W)
size = StringVar() # Used by Radio buttons
smallRadio = Radiobutton(window,
text="Small",
variable=size,
value="Small",
font=('Arial', 15))
mediumRadio = Radiobutton(window,
text="Medium",
variable=size,
value="Medium",
font=('Arial', 15))
largeRadio = Radiobutton(window,
text="Large",
variable=size,
value="Large",
font=('Arial', 15))
smallRadio.select()#SETS DEFAULT
smallRadio.grid(row=2, column=0, sticky=W)
mediumRadio.grid(row=2, column=1, sticky=W)
largeRadio.grid(row=2, column=2, sticky=W)
toppingsLabel = Label(window, text ="TOPPINGS", font=('Arial', 15))
toppingsLabel.grid(row=4, column=0, columnspan = 2, sticky=W,pady=10)
pp = IntVar()
ol = IntVar()
pin = IntVar()
ss = IntVar()
on = IntVar()
bp = IntVar()
pepperoni = Checkbutton(window,
text="Pepperoni",
variable=pp,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
olives = Checkbutton(window,
text="Olives",
variable=ol,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
pineapple = Checkbutton(window,
text="Pineapple ",
variable=pin,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
sausage = Checkbutton(window,
text="Sausage",
variable=ss,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
onions = Checkbutton(window,
text="Onions",
variable=on,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
bellpepper = Checkbutton(window,
text="Bell Pepper",
variable=bp,
onvalue =1,
offvalue=0,
padx=30,
font=('Arial', 14))
pepperoni.grid(row=5, column=0, sticky=W)
olives.grid(row=6, column=0, sticky=W)
pineapple.grid(row=7, column=0, sticky=W)
sausage.grid(row=5, column=1, sticky=W)
onions.grid(row=6, column=1, sticky=W)
bellpepper.grid(row=7, column=1, sticky=W)
paymentLabel = Label(window, text ="PAYMENT", font=('Arial', 15))
paymentLabel.grid(row=9, column=0,sticky=E,pady=20)
def selection_changed(event):
selection = payment.get() # gets the selected item from combo
payment = ttk.Combobox( values=["Visa", "Cash", "Venmo", "Zelle"] ) # Declare a Combobox
payment.bind("<<ComboboxSelected>>", selection_changed)
payment.grid(row=9, column=1,sticky=W,padx=20) # Position the Combobox in the Window
def resetFields():
userName.delete(0,END)
pepperoni.deselect()
olives.deselect()
pineapple.deselect()
sausage.deselect()
onions.deselect()
bellpepper.deselect()
largeRadio.select() #SETS DEFAULT Radiobutton
payment.set("Visa")
def writeToFile():
if not userName.get().strip():
messagebox.showerror("Error", "Customer name cannot be empty.")
return
log = open("order.txt", 'a')
log.write('Name: %s\n' % userName.get())
log.write(f'Size: {size.get()}\n')
if pp.get(): log.write(" Pepperoni\n")
if ol.get(): log.write(" Olives\n")
if pin.get():log.write(" Pineapple\n")
if ss.get(): log.write(" Sausage\n")
if on.get(): log.write(" Onions\n")
if bp.get(): log.write(" Bell Pepper\n")
log.write(f'Card: {payment.get()}\n')
from datetime import datetime
timestamp = datetime.now().strftime('%m/%d/%Y %I:%M %p')
log.write(f'Time: {timestamp}\n')
log.write("===================================================\n")
log.close()
messagebox.showinfo( title="Order Summary",
message=f"Order Has Been Processed" )
resetFields()
clear = Button(window,
text='Clear',
command=resetFields,
font=('Arial', 16))
resetFields()
submit = Button(window,
text='Submit',
command=writeToFile,
font=('Arial', 16))
clear.grid(row=10, column=0, sticky=E)
submit.grid(row=10, column=2, sticky=W)
window.mainloop()