Question
Python code need it in the simplest way please use lists , files and functions only ( No classes or advanced stuff) this is half
Python code need it in the simplest way
please use lists, files and functions only (No classes or advanced stuff)
this is half of the code made by me, you can build on it or use it as a sample (feel to change some of the variables >>
def read_data(): f1 = open("Laptops.txt","r")
list = []
for i in f1: x = i.split(",") x[8] = x[8].rstrip(" ") list.append(x)
f1.close return list
def search(the_list): phrase = input("Enter the search phrase: ")
s_list = [] for i in the_list: if i[0] == phrase: s_list.append(i) return s_list
def filter_opt(the_list): print("Choose one of the following") print("1-Brands") print("2-Price") print("3-Ram") print("4-Condition") option = int(input("---> ")) while option 4: option = int(input("---> ")) if option == 1: brands(the_list) elif option == 2: price_range(the_list) elif option == 3: ram_size(the_list) elif option == 4: condition(the_list) else: print("Invalid option1")
def brands(the_list): print("1-Asus") print("2-Acer") print("3-Dell") print("4-Hp") print("5-Lenovo")
option = int(input("---> "))
b_list = [] for i in the_list: if option == 1: if i[1] == "Asus": b_list.append(i) elif option == 2: if i[1] == "Acer": b_list.append(i) elif option == 3: if i[1] == "Dell": b_list.append(i) elif option == 4: if i[1] == "Hp": b_list.append(i) elif option == 5: if i[1] == "Lenovo": b_list.append(i) else: print("invalid option2") return[] return b_list
def price_range(the_list): print("1-Less than 300") print("2-between 300 and 600") print("3-Above 600")
option = int(input("---> "))
p_list = [] for i in the_list: if option == 1: if i[2] = 300 and i[2] 600: p_list.append(i) else: print("invalid option3") return[] return p_list
def ram_size(the_list): print("1-4 GB") print("2-8 GB") print("3-16 GB")
option = int(input("---> "))
r_list = [] for i in the_list: if option == 1: if i[4] == "4": r_list.append(i) elif option == 2: if i[4] == "8": r_list.append(i) elif option == 3: if i[4] == "16": r_list.append(i) else: print("Unvelid option") return[] return r_list
def condition(the_list): print("1-New") print("2-Used")
option = int(input("---> "))
c_list = [] for i in the_list: if option == 1: if i[7] == "New": c_list.append(i) elif option == 2: if i[7] == "Used": c_list.append(i) else: print("Invalid option") return[] return c_list
def print_function(the_list): print(" ") print(format("Brand","10"),format("Price","10"),format("Condition","20"),format("Available Units","20")) print("-------------------------------------------------------------")
for i in range(len(the_list)): print(format(the_list[i][1],"10"),format(the_list[i][2],"10"),format(the_list[i][7],"20"),format(the_list[i][8],"20")) print(" ")
def main(): list = read_data() bb_list = filter_opt(list) if bb_list != []: print_function(bb_list)
main()
laptop.txt
Great laptop,Hp,299,12.3,4,250 GB,i5,New,In Stock Great laptop,Lenovo,459,14.5,8,500 GB,i7,New,In Stock Great laptop,Acer,439,15,8,512 GB,i7,Used,Out of Stock Great laptop,Lenovo,659,15.6,16,1 TB,i9,New,In Stock Great laptop,Asus,339,13.5,8,250 GB,i5,New,In Stock Great laptop,Dell,900,15.6,16,3 TB,i9,New,In Stock Great laptop,Dell,699,15.6,16,3 TB,i9,Used,In Stock Great laptop,Dell,900,15.6,16,3 TB,i7,New,Out of Stock Great laptop,Asus,319,15.6,16,500 GB,i5,New,In Stock Great laptop,Acer,549,14.5,16,500 GB,i9,New,In Stock Great laptop,Hp,589,15.3,8,1 TB,i7,New,In Stock Great laptop,Lenovo,499,15.3,8,500 GB,i7,New,Out of Stock Great laptop,Lenovo,319,15.3,8,500 GB,i7,Used,In Stock Great laptop,Lenovo,199,12.8,4,250 GB,i5,Used,In Stock Great laptop,Asus,379,12.8,4,250 GB,i5,New,In Stock Great laptop,Asus,379,12.8,4,250 GB,i9,Used,Out of Stock Great laptop,Hp,699,15.6,16,1 TB,i9,New,In Stock Great laptop,Hp,379,15.6,8,1 TB,i9,Used,In Stock Great laptop,Acer,699,15.6,16,2 TB,i7,New,In Stock Great laptop,Acer,299,15.6,4,500 GB,i5,Used,In Stock Great laptop,Hp,799,15.6,16,1 TB,i5,New,Out of Stock Great laptop,Dell,285,12.3,4,250 GB,i9,New,In Stock Greet laptop,Hp,250,12.6,8,500GB,i5,New,In Stock Greet laptop,Asus,399.9,15,16,1TB,i7,New,In Stock Greet laptop,Dell,329,14.3,4,250GB,i5,New,In Stock Greet laptop,Acer,350,14.3,8,500GB,i5,Used,In Stock Greet laptop,Hp,400,13.5,8,500GB,i7,New,In Stock Greet laptop,Asus,699.9,14.3,16,1TB,i9,New,In Stock Greet laptop,Hp,399,13,8,500GB,i7,New,In Stock Greet laptop,Lenovo,229.9,15,4,250GB,i5,Used,In Stock Greet laptop,Lenovo,390,14.2,8,500GB,i7,New,In Stock Greet laptop,Acer,500,13.5,16,1TB,i7,New,In Stock Greet laptop,Acer,499,15.6,8,500GB,i7,Used,Out of Stock Greet laptop,Asus,859,14.3,16,1TB,Ryzen 9,New,In Stock Greet laptop,Dell,530,13.3,8,1TB,Ryzen 7,New,In Stock Greet laptop,Lenovo,229,9.15,4,250GB,i5,Used,In Stock Greet laptop,Hp,515,14,8,500GB,i7,New,Out of Stock Greet laptop,Hp,760,14.3,8,1TB,i7,New,In Stock Greet laptop,Asus,999,13.5,16,1TB,Ryzen 9,New,In Stock Greet laptop,Acer,450,12,8,500GB,i7,Used,Out of Stock Greet laptop,Hp,399,13.5,8,500GB,i5,New,In Stock
main.py def read_data(): f1 = open("Laptops.txt","r") list s [] 5 6 7 for i in f1: x = i.split(",") X[8] = X[8].rstrip(" ") list.append(x) = fi.close return list 9 10 11 12 13 14 15 16 17 18 19 20 21 22 def search(the_list): phrase = input("Enter the search phrase: ") s_list = [] for i in the_list: if i[@] == phrase: s_list.append(i) return s_list SEXSS #UNGENENNE OGGEROWN 24 25 26 27 28 29 3a 31 32 def filter_opt(the_list): print("Choose one of the following") print("1-Brands") print("2-Price") print("3-Ram") print("4-Condition") 34 35 36 37 38 39 40 41 42 43 option = int(input("---> ")) while option ")) if option == 1: brands (the_list) elif option == 2: price_range(the_list) elif option == 3: ram_size(the_list) elif option == 4: condition(the_list) se: print("Invalid option1") 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 def brands (the_list): print("1-Asus") print("2-Acer") print("3-Dell") print("4-Hp") print("5-Lenovo") option = int(input("---> ")) b_list = [] for i in the_list: if option == 1: if i[1] == "Asus": main.py N889898988 59 60 61 62 63 64 65 66 67 68 69 78 71 72 73 74 75 76 77 78 79 sa 81 82 83 84 85 86 87 88 if option == 1: if i[1] == "Asus": b_list.append(i) elif option == 2: if i[1] "Acer": b_list.append(i) elif option == 3: if i[1] == "Dell": b_list.append(i) elif option SE 4: if i[1] "Hp": b_list.append(i) elif option == 5: if i[1] == "Lenovo": b_list.append(i) else: print("invalid option2") return[] return b_list == def price_range(the_list): print("1-Less than 300") print("2-between 3ee and 600") print("3-Above 600") option = int(input(" --> ")) p_list = [] for i in the_list: if option = 1: if i[2] = 300 and i[2] 680 p_list.append(i) else: print("invalid option3") return[] return p_list %88%%88%88%m%wwwmwww 91 92 93 94 95 96 97 98 99 100 101 182 103 104 105 106 107 108 109 118 111 112 113 114 def ram_size(the_list) print("1-4 GB") print("2-8 GB") print("3-16 GB") option = int(input("---> ")) = = "4": r_list = [] for i in the_list: if option = 1: if i[4] r_list.append(i) elif option == 2: if i[4] == "8": r_list.append(i) 115 116 117 118 print(2-8 GES") print("3-16 GB") option = int(input("---> ")) = "4": == "g": r_list = [] for i in the_list: if option == 1: if i[4] r_list.append(i) elif option == 2: if i[4] r_list.append(1) elif option == 3: if i[4] == "16": r_list.append(i) else: print("Unvelid option") return[] return r_list def condition(the_list): print("1-New") print("2-Used") option = int(input("---> ")) main.py 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 149 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 c_list = [] for i in the_list: if option == 1: if i[7] == "New": _list.append(i) elif option == 2: if i[7] == "Used": c_list.append(i) else: print("Invalid option") return[] return c_list def print_function(the_list): print(" ") print(format("Brand", "10"), format("Price","10"), format("condition", "20"), format("Available units","20")) print("- ") for i in range(len(the_list)): print(format(the_list[i][1],"18"), format(the_list[i][2],"10"), format(the_list[i][7],"20"), format(the_list[i][8],"28")) print(" ") def main() list = read_data() bb_list = filter_opt(list) if bb_list != []: print_function(bb_list) = main() ISOM 230 Project Fall 2021 Develop a program for an electronics store that only sells laptop computers. The program would read information about the laptops from a "laptops.txt" text file, presents statistical information about the store's laptops, provides different filters for choosing among the laptops, and writes the final results to a "results.txt" text file. Option 5: Delete a laptop ask the user to search for a particular laptop description (first occurrence will be chosen). Then provide options for the user to delete the selected laptop or to cancel deletion. Option 6: Exit the program. The "laptops.txt" file should contain information about at least 40 laptops. And the following are the minimum number of input information about each laptop that you need to provide (i.e. you can add extra information for each laptop if you wish) A short description Brand Price Screen size RAM size Hard drive size Processor type Condition (New/Used) Available units in stock . . The system should perform the following processes: 1. Read the input information from the text file 2. Provide statistical information about the status of the store (each in a separate Sub or Function procedure): 1. The total value of all laptops in stock 2. Number of new vs. used laptops 3. Number of laptops from each brand 4. Minimum price, maximum price, and average price of laptops 3. Using "Menu-driven programming provide the following options to the user. Option 1: Search (Allow the user to search for a keyword from the description of the laptops.) Option 2: Filter the laptops based on the following properties, and show the filtered results to the user o Option 2.1: Brands Option 2.2: Price ranges (e.g. Under $300, $300 to $600, $600 & Above) o Option 2.3: RAM size o Option 2.4: Condition Option 3: Save the results (When the user is satisfied with the results, write the output to a "results.txt" text file) Option 4: Edit a laptop's information: ask the user to search for a particular laptop description (first occurrence will be chosen). Then provide options for the user to edit each information item for the laptop selected. . O des brand price SIZE Ram Hard drive condition units in stock asus >=12=250=14=500=151000 intel 19 dell >=300600 rayzen 7 rayzen 9 Great laptop Hp 299 12.3 4 250 GB i5 New In Stock Great laptop Lenovo 459 14.5 8 500 GB i7 New In Stock Great laptop Acer 439 15 8 512 GB i7 Used Out of Stock Great laptop Lenovo 659 15.6 16 1 TB i9 New In Stock Great laptop Asus 339 13.5 8 250 GB i5 New In Stock Great laptop Dell 900 15.6 16 3 TB i9 New In Stock Great laptop Dell 699 15.6 16 3 TB i9 Used In Stock Great laptop Dell 900 15.6 16 3 TB i7 New Out of Stock Great laptop Asus 319 15.6 16 500 GB i5 New In Stock Great laptop Acer 549 14.5 16 500 GB i9 New In Stock Great laptop Hp 589 15.3 8 1 TB i7 New In StockStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started