Skip to content

Instantly share code, notes, and snippets.

@SharafatKarim
Created November 16, 2022 04:05
Show Gist options
  • Save SharafatKarim/bfdef4bbd24bb87105aaec84396d1475 to your computer and use it in GitHub Desktop.
Save SharafatKarim/bfdef4bbd24bb87105aaec84396d1475 to your computer and use it in GitHub Desktop.
A simple program to help to find the best item! Suppose first column refers to the price, second one amount and the third refers to validity. Validity (third column) is an optional thing and may not be present. You have to find the best value (Amount divided by price) out of all of them. Then sort them.
Price = [9,13,7,18,10,76,10,76,33,63,113,19,49,23,49,23,19,31,51,42,66,29,30,36,116,91]
Value = [100,100,150,200,250,300,250,300,300,300,300,300,400,400,400,400,500,512,512,512,512,512,1000,1000,1000,1000]
Validity = []
Price = []
Value = []
def Validity_to_store():
print("Do you also want to store validity data? ")
k = input()[0]
if k == "y" or k == "Y":
return True
return False
def greetings():
print("Hello!")
print("Enter your data and when you're done, give 0 as an input for price! ")
def user_entry():
i = 1
while i > 0:
print(f"Enter price for item {i}: ")
Price.append(eval(input()))
if Price[-1] == 0:
break
print(f"Enter Value for item {i}: ")
Value.append(eval(input()))
if Validity_to_store_result:
print(f"Enter Validity for item {i}: ")
Value.append(eval(input()))
i += 1
def table_draw(Price, Value):
print("-------------------------------------------")
print(" table")
print("-------------------------------------------")
print(" price amount")
print("-------------------------------------------")
for i in range(len(Value)):
print(" ",Price[i]," ",Value[i])
print("-------------------------------------------")
def table_draw_three(Price, Value, Extra):
print("--------------------------------------------------------------------------")
print(" table")
print("--------------------------------------------------------------------------")
print(" price amount value")
print("--------------------------------------------------------------------------")
for i in range(len(Value)):
print(" ",Price[i]," ",Value[i]," ",Extra[i])
print("--------------------------------------------------------------------------")
def sorting_by_data_value(Price, Value):
Price2 = Price
Value2 = Value
Price1 = []
Value1 = []
Value_store = []
for i in range(len(Value2)):
max_data= Value2[0]/Price2[0]
max_value= Value2[0]
max_price= Price2[0]
for j in range(len(Value2)):
if Value2[j] == 0:
continue
elif Value2[j]/Price2[j] >= max_data:
max_data = Value2[j]/Price2[j]
max_value= Value2[j]
max_price= Price2[j]
Value1.append(max_value)
Price1.append(max_price)
Value_store.append(max_data)
for j in range(len(Value2)):
if max_value== Value2[j] and max_price== Price2[j]:
Value2[j] = 0
break
table_draw_three(Price1, Value1, Value_store)
greetings()
Validity_to_store_result = Validity_to_store()
user_entry()
table_draw(Price, Value)
print("Let's sort it: ")
sorting_by_data_value(Price,Value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment