Skip to content

Instantly share code, notes, and snippets.

@Alee14
Created March 12, 2024 13:20
Show Gist options
  • Save Alee14/2dc70f9284a9d0de0e41fa7354130c08 to your computer and use it in GitHub Desktop.
Save Alee14/2dc70f9284a9d0de0e41fa7354130c08 to your computer and use it in GitHub Desktop.
Module 6 - Build a PC
# This program will give advice for building a PC
is_laptop = False
sel_input = "> "
invalid_option = "This option is not available. Try again."
spent = float(0)
def format_currency(money):
return "${:,.2f}".format(money)
def list_items(item):
for x, y in item.items():
print(f'{str(x)}: {str(format_currency(y))}')
def spent_item(available_item, item):
return spent + available_item.get(item)
available_os = {
'Windows 11 Home': float(189.00),
'Windows 10 Home': float(139.00),
'Linux': float(0)
}
available_processor_desktop = {
'Intel Core i9 14900K': float(589.00),
'AMD Ryzen 9 7900X': float(549.00),
'Intel Core i5 14400': float(221.00),
'AMD Ryzen 5 7600': float(229.00)
}
available_processor_laptop = {
'AMD Ryzen 9 8945HS': float(529.00),
'Intel Core i9 13980HX': float(549.00),
'AMD Ryzen 5 8540U': float(249.00),
'Intel Core i5 13600HX': float(259.00)
}
available_memory = {
8: float(44.99),
16: float(64.98),
32: float(84.97),
64: float(149.99)
}
available_storage = {
'250 SSD': float(80.02),
'500 SSD': float(74.99),
'1000 HDD': float(69.99),
'2000 HDD': float(89.99),
'4000 HDD': float(189.99)
}
available_graphics = {
'Nvidia GeForce RTX 4090': float(1599.00),
'AMD Radeon RX 7900 XTX': float(920.00),
'Nvidia GeForce GTX 1660': float(219.00),
'AMD Radeon RX 6500 XT': float(199.00)
}
available_office_suite = {
'Microsoft Office': float(79.00),
'Document Foundation LibreOffice': float(0),
'Kingsoft WPS Office': float(0)
}
available_screen_size = {
'13': float(132.24),
'14': float(146.21),
'16': float(146.99),
'17': float(177.17)
}
available_battery_life = {
'8': float(29.99),
'10': float(39.99),
'11': float(49.99),
'12': float(59.99)
}
# Budget
while True:
try:
print("What is your budget?")
budget = float(input(sel_input))
if budget <= 0:
print('Enter a proper value.')
continue
elif budget <= 500:
print('That is too low... Computers are not that cheap, unless you want to get a Raspberry Pi?')
continue
elif budget >= 5000:
print('That is very expensive! Don\'t think you want to buy a computer at this price...')
print('Maybe enter a budget that is less than $5,000')
continue
break
except ValueError:
print('Please enter a proper number.')
continue
# OS
while True:
print("Which operating system would you like to use?")
list_items(available_os)
os = input(sel_input)
if os in available_os.keys():
if os == "Linux":
print('Good choice')
print('You have selected', os)
spent = spent_item(available_os, os)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
# Laptop?
print()
print("Is it going to be a laptop? (y/N)")
laptop = input(sel_input)
if laptop == "Y" or laptop == "y":
print('You have selected to buy a laptop')
is_laptop = True
else:
print('You have selected to buy a desktop')
# Processor
print("Which processor would you like to use?")
if not is_laptop:
list_items(available_processor_desktop)
print()
else:
list_items(available_processor_laptop)
print()
while True:
processor = input(sel_input)
if not is_laptop:
if processor in available_processor_desktop.keys():
print('You have selected', processor)
spent = spent_item(available_processor_desktop, processor)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
else:
if processor in available_processor_laptop.keys():
print('You have selected', processor)
spent = spent_item(available_processor_laptop, processor)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
# Memory
print()
print('How much memory do you want? (GB)')
list_items(available_memory)
while True:
try:
memory = int(input(sel_input))
if memory in available_memory.keys():
print('You have selected', memory, 'GB')
spent = spent_item(available_memory, memory)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
except ValueError:
print('Invalid value')
continue
# Storage
print()
print('How much disk storage do you want? (GB)')
list_items(available_storage)
while True:
storage = input(sel_input)
if storage in available_storage.keys():
print('You have selected', storage)
spent = spent_item(available_storage, storage)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
# Graphics Card
print()
print('What graphics card do you want?')
list_items(available_graphics)
while True:
graphics_card = input(sel_input)
if graphics_card in available_graphics.keys():
print('You have selected', graphics_card)
spent = spent_item(available_graphics, graphics_card)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
if is_laptop:
# Screen size
print()
print('Which screen size you want?')
list_items(available_screen_size)
while True:
screen_size = input(sel_input)
if screen_size in available_screen_size.keys():
print('You have selected', screen_size, 'inches')
spent = spent_item(available_screen_size, screen_size)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
print()
print('How many hours would you want your laptop to have?')
list_items(available_battery_life)
while True:
battery_life = input(sel_input)
if battery_life in available_battery_life.keys():
print('You have selected', battery_life, 'hours')
spent = spent_item(available_battery_life, battery_life)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
print()
print('What office suite would you want?')
list_items(available_office_suite)
while True:
office_suite = input(sel_input)
if office_suite in available_office_suite.keys():
print('You have selected', office_suite)
spent = spent_item(available_office_suite, office_suite)
print(f'Spent {format_currency(spent)} so far on a budget of {format_currency(budget)}.')
break
else:
print(invalid_option)
continue
if not is_laptop:
processor_price = available_processor_desktop.get(processor)
else:
processor_price = available_processor_laptop.get(processor)
print()
print('These are the components you selected:')
print('Processor:', processor, '| Price:', str(format_currency(processor_price)))
print('OS:', os, '| Price:', str(format_currency(available_os.get(os))))
print('Memory:', memory, 'GB', '| Price:', str(format_currency(available_memory.get(memory))))
print('Storage:', storage, '| Price:', str(format_currency(available_storage.get(storage))))
print('Graphics Card:', graphics_card, '| Price:', str(format_currency(available_graphics.get(graphics_card))))
if is_laptop:
print('Screen Size:', screen_size, 'inches', '| Price:', str(format_currency(available_screen_size.get(screen_size))))
print('Battery Life:', battery_life, 'hours', '| Price:', str(format_currency(available_battery_life.get(battery_life))))
print('Office Suite:', office_suite, '| Price:', str(format_currency(available_office_suite.get(office_suite))))
print()
print('Budget:', format_currency(budget))
print('Total Price:', format_currency(spent))
print()
enough_money = False
if budget > spent:
enough_money = True
print('You will be spending ', format_currency(spent), ' on a budget of ', format_currency(budget), '.', sep="")
else:
enough_money = False
price_needed = spent-budget
print('You have not have enough money to buy this computer. You will need ' + str(format_currency(price_needed)) + '.')
print('Do you want to save this configuration to a file? (y/N)')
save_file = input(sel_input)
if save_file == "Y" or save_file == "y":
print('Enter your name:')
while True:
name = input(sel_input)
if name == "":
print('Please enter a name.')
continue
else:
fileName = f'{name} PC.txt'
break
file = open(fileName, 'w')
file.writelines([f'{name}\'s PC Configuration\n',
'OS: ' + os + ' | Price: ' + str(format_currency(available_os.get(os))) + '\n',
'Processor: ' + processor + ' | Price: ' + str(format_currency(processor_price)) + '\n',
'Memory: ' + str(memory) + ' GB' + ' | Price: ' + str(format_currency(available_os.get(os))) + '\n',
'Storage: ' + storage + ' | Price: ' + str(format_currency(available_storage.get(storage))) + '\n',
'Graphics Card: ' + graphics_card + ' | Price: ' + str(format_currency(available_graphics.get(graphics_card))) + '\n',
'Office Suite: ' + office_suite + ' | Price: ' + str(format_currency(available_office_suite.get(office_suite))) + '\n\n',
])
if is_laptop:
file.writelines([
'Screen Size: ' + screen_size + ' inches' + ' | Price: ' + str(format_currency(available_screen_size.get(screen_size))) + '\n',
'Battery Life: ' + battery_life + ' hours' + ' | Price: ' + str(format_currency(available_battery_life.get(battery_life))) + '\n\n',
])
file.writelines([
'Budget: ' + str(format_currency(budget)) + '\n',
'Total Price: ' + str(format_currency(spent)) + '\n\n'
])
if not enough_money:
file.write('Money Needed: ' + str(format_currency(price_needed)))
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment