Last active
March 8, 2020 02:02
-
-
Save TheFlyingDeutchMan/7ec2082713b4cb087bac87504fbb7213 to your computer and use it in GitHub Desktop.
Jim's Computer store assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # This program is designed to interpret total cost of the computers bought with the | |
# TODO: DOCUMENTATION FOR SCRIPT | |
from pprint import pprint | |
product_names = ["Home Basic", "Office", "Gamer", "Studio"] | |
product_prices = [ | |
900, | |
1200, | |
1500, | |
2200 | |
] | |
product_specs = [ | |
'4GB - Built in Graphics - 20" monitor', | |
'8GB - Built in Graphics - 23" monitor', | |
'16GB - 4GB Nvidia Graphics - 27" monitor', | |
'16GB - 4GB Quadro Grapihics - Dual 23" monitor' | |
] | |
# list of selected purchases | |
# right now we assume only 1 computer is bought | |
shopping_cart = [] | |
# ## def topbanner(text_1, message, text_2): | |
# # print("") | |
# # print("*" * 10) | |
# # print("") | |
# ## topbanner("*" * 8, "Welcome to Jims Store", "*" * 8) | |
def ask_user_name(): | |
while True: | |
name = input("May I have your name, please? ") | |
if not name: | |
print("Please enter a valid name :)") | |
elif name.isalpha(): | |
return name | |
else: | |
print("Please use only letters, try again") | |
def ask_for_integer(msg): | |
while True: | |
result = input(msg) | |
if not result: | |
print("Please input a number\n") | |
else: | |
try: | |
result_int = int(result) | |
return result_int | |
except ValueError: | |
print("Please enter only numbers\n") | |
return result_int | |
def go_shopping(): | |
menu = """ | |
Welcome to Jim's Computer Shop | |
1 - Home Basic - $900 | |
4GB RAM, Built in Graphics, 20" Monitor | |
2 - Office - $1200 | |
8GB RAM, Built in Graphics, 23" Monitor | |
3 - Gamer - $1500 | |
16GB RAM, 4GB Nvidia Graphics, 27" Monitor | |
4 - Studio - $2200 | |
16GB RAM, 4GB Quadro Graphics, Dual 23" Monitor | |
To buy one of these computers, please enter 1, 2, 3 or 4. | |
""" | |
while True: | |
choice = ask_for_integer(menu) | |
if choice in [1, 2, 3, 4]: | |
shopping_cart.append(choice) | |
break | |
else: | |
print("Please select either 1, 2, 3 or 4") | |
def shopping_cart_summary(): | |
# print summary for every item in the shopping cart | |
for product_index in shopping_cart: | |
line_output = str(product_prices[product_index]) \ | |
+ " - " + product_names[product_index] + " - " + product_specs[product_index] | |
print(line_output) | |
# gather all input variables | |
user_name = ask_user_name() | |
user_age = ask_for_integer("Please tell me your age ") | |
budget = ask_for_integer("Please tell me your shopping budget ") | |
go_shopping() | |
# determine which computer was selected to get the purchase cost of it | |
purchase_item_index = shopping_cart[0] - 1 | |
purchase_cost = product_prices[purchase_item_index] | |
# compare purchase_cost against budget | |
if budget >= purchase_cost: | |
# you can pick up your order | |
print("Please come into the store to pick up your purchased goods") | |
shopping_cart_summary() | |
elif user_age >= 18: | |
# finance availabe message | |
print("""We offer finance, though ID will be required to see if you're actually at age. | |
If we doubt you sorry but you may need to come here""") | |
shopping_cart_summary() | |
else: | |
# keep saving, come back | |
print("Keep saving") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment