[Tutor] Finding the largest gap in tuple between two lists.

2018-11-18 Thread Harry Oneill
Hello there everyone i hope you are all doing fantastic.

Im currently working on a little program that is designed to do a basic 
function to help me to trade efficiently within the game Star Citizen:

#1 take two inputs ( location and destination )
#2 Find what product is best to buy at location to sell at destination
#3 Print the results

currently i have figured out how to get python to take the two inputs and 
provide me with the lowest buy price and highest sell price.

However the information i want to produce is what has the largest profit margin 
possible between the two locations so i need to compare what items are 
available in both locations and then see what one has the largest price 
difference then display that items name.

Below is  the code i have currently made for this.


Current_Location = input("Where are you currently located? :").lower()
Current_Destination = input("Where are you planning to travel? :").lower()

def Find_Lowest_Buy_Olisar():
print("Finding lowest buy price for OLISAR...")
print(*Sort_Buying_Olisar[:1], sep='\n')
def Find_Highest_Sell_Olisar():
print("Finding highest sell price for OLISAR...")
print(*Sort_Selling_Olisar[:1], sep='\n')
def Find_Lowest_Buy_Levski():
print("Finding lowest buy price for LEVSKI...")
print(*Sort_Buying_Levski[:1], sep='\n')
def Find_Highest_Sell_Levski():
print("Finding highest sell price for LEVSKI...")
print(*Sort_Selling_Levski[:1], sep='\n')

Buying_Olisar = [('Medical Supply', 17.01), ('Waste', 0.005),]
Sort_Buying_Olisar = sorted_by_second = sorted(Buying_Olisar, key=lambda tup: 
tup[1])

Selling_Olisar = [('Agricium', 25.60), ('Aluminum', 1.25), ('Beryl', 4.26), 
('Chlorine', 1.57), ('Corundum', 2.53), ('Diamond', 6.90), ('Distilled 
Spirits', 4.95), ('Fluorine', 2.80), ('Gold', 6.07), ('Hydrogen', 1.02), 
('Iodine', 0.41), ('Laranite', 28.91), ('Processed Food', 1.39), ('Quartz', 
1.44), ('Scrap', 1.67), ('Stims', 3.40), ('Titanium', 8.27), ('Tungsten', 
3.90),]
Sort_Selling_Olisar = sorted(Selling_Olisar, key=lambda tup:(-tup[1], tup[0]))

Buying_Levski = [('Agricultural Supply', 1.11), ('Aluminum', 1.20), 
('Hydrogen', 0.98), ('Iodine', 0.38), ('Quartz', 1.37), ('Waste', 0.005),]
Sort_Buying_Levski = sorted_by_second = sorted(Buying_Levski, key=lambda tup: 
tup[1])

Selling_Levski = [('Agricium', 25.60), ('Altruciatoxine', 11.63), ('Beryl', 
4.25), ('Chlorine', 1.56), ('Corundum', 2.53), ('Diamond', 6.07), ('Distilled 
Spirits', 4.95), ('Fluorine', 2.80), ('Gold', 6.07), ('Laranite', 28.25), 
('Medical Supply', 18.00), ('Processed Food', 1.38), ('Scrap', 1.68), ('Stims', 
3.40), ('Titanium', 8.27), ('Tungsten', 3.90), ('Widdow', 24.00),]
Sort_Selling_Levski = sorted(Selling_Levski, key=lambda tup:(-tup[1], tup[0]))


if Current_Location == "olisar":
Find_Lowest_Buy_Olisar()
elif Current_Location == "levski":
Find_Lowest_Buy_Levski()
else:
print("Unknown location please try again.")

if Current_Destination == "olisar":
Find_Highest_Sell_Olisar()
elif Current_Destination == "levski":
Find_Highest_Sell_Levski()
else:
print("Unknown location please try again.")


Any input would be hugely appreciated.

Kind regards,

Harry O'Neill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Variable change within library depending on user input.

2019-03-03 Thread Harry Oneill
Hey there everybody hope your doing great.

I was here a few months ago and got pointed in the right direction very kindly 
by one of the tutors. Im a little stuck again now and have been researching for 
a while and can't come up with a solution to my problem.

The below program is designed to take two user inputs, item purchase location 
and sale location and then to compare some dictionaries of those locations and 
calculate the most profitable item to buy.

Initially i designed this to work with just two locations and am now struggling 
to add a third.


 Author : Harry O'Neill
 Program : Find most profitable sale between two trade hubs within the star 
citizen game client.

 Waste has been remove as it's literally garbage anyway.


 taking user information
user_purchase_location = input("Were are you planning to buy your 
goods?").lower()
user_sale_destination = input("Where are you planning to sell your 
goods?").lower()

 dicts of items available to buy and sell at locations along with UEC price.
buying_olisar = {'Medical Supply': 17.01,}
selling_olisar = {'Agricium': 25.60, 'Aluminum': 1.25, 'Beryl': 4.26, 
'Chlorine': 1.57, 'Corundum': 2.53, 'Diamond': 6.90, 'Distilled Spirits': 4.95, 
'Fluorine': 2.80, 'Gold': 6.07, 'Hydrogen': 1.02, 'Iodine': 0.41, 'Laranite': 
28.91, 'Processed Food': 1.39, 'Quartz': 1.44, 'Scrap': 1.67, 'Stims': 3.40, 
'Titanium': 8.27, 'Tungsten': 3.90,}
buying_levski = {'Agricultural Supply': 1.11, 'Aluminum': 1.20, 'Hydrogen': 
0.98, 'Iodine': 0.38, 'Quartz': 1.37,}
selling_levski = {'Agricium': 25.60, 'Altruciatoxine': 11.63, 'Beryl': 4.25, 
'Chlorine': 1.56, 'Corundum': 2.53, 'Diamond': 6.07, 'Distilled Spirits': 4.95, 
'Fluorine': 2.80, 'Gold': 6.07, 'Laranite': 28.25, 'Medical Supply': 18.00, 
'Processed Food': 1.38, 'Scrap': 1.68, 'Stims': 3.40, 'Titanium': 8.27, 
'Tungsten': 3.90, 'Widdow': 24.00,}
buying_arc_corp_mining_area_157 = {'Chlorine': 1.44, 'Flurine': 2.63, 
'Hydrogen': 0.97, 'Iodine': 0.34}
selling_arc_corp_mining_area_157 = {'Altruciatoxine': 11.80, 'distilled 
spirits': 4.95, 'medical suppies': 18.05, 'processed food': 1.36, 'stims': 
3.40, 'Widdow': 24.0}


 Sorting the dict into ascending value instead of alphabetical
sort_buying_olisar = sorted(buying_olisar, key=lambda tup: tup[1])
sort_selling_olisar = sorted(selling_olisar, key=lambda tup:(tup[1], tup[0]))
sort_buying_levski = sorted(buying_levski, key=lambda tup: tup[1])
sort_selling_levski = sorted(selling_levski, key=lambda tup:(tup[1], tup[0]))
sort_buying_arc_corp_mining_area_157 = sorted(buying_arc_corp_mining_area_157, 
key=lambda tup: tup[1])
sort_selling_arc_corp_mining_area_157 = 
sorted(selling_arc_corp_mining_area_157, key=lambda tup:(tup[1], tup[0]))

 picking two dicts (buy/sell) and filtering them to print only common 
elements.
def common(curr, other):
return set(curr.keys()).intersection(set(other.keys()))
tradable_items = common(buying_levski, selling_olisar)

 calculating the prices between possible sales.
prices = {k: selling_olisar[k] - buying_levski[k] for k in tradable_items}

 finding the most profitable material
import operator
most_profitable_resourse = max(prices.items(), key=operator.itemgetter(1))[0]


profit_ammount = prices
profit_sorted = (f'{profit_ammount[most_profitable_resourse]:.2f}')
print("The most profitable item to buy at " + user_purchase_location + " is " + 
most_profitable_resourse + " and will make a net profit of " + profit_sorted + 
" per unit when sold at " + user_sale_destination + ".")




The two areas i am struggling to alter to allow this to work with more than two 
locations are below


tradable_items = common(buying_levski, selling_olisar)

and

prices = {k: selling_olisar[k] - buying_levski[k] for k in tradable_items}

i need to have the variables to alter based on the user input where as 
currently they are fixed as buying/selling levski/olisar.

I have tried to create a second variable as follows:

user_purchase_location_1 = 'buying_'+user_purchase_location+''
user_sale_destination_1 = 'selling_'+user_sale_destination+''

these produce the correct information that could be used in the above two lines 
however when altered like this:

def common(curr, other):
return set(curr.keys()).intersection(set(other.keys()))
tradable_items = common(user_purchase_location_1, user_sale_destination_1)

 calculating the prices between possible sales.
prices = {k: user_sale_destination_1[k] - user_purchase_location_1[k] for k in 
tradable_items}


However they produce this error that i am unsure how to resolve.

Traceback (most recent call last):
  File "/home/floppypoppy/PycharmProjects/Star Citizen Trading Program/Star 
Citizen trading NEW.py", line 33, in 
tradable_items = common(user_purchase_location_1, user_sale_destination_1)
  File "/home/floppypoppy/PycharmProjects/Star Citizen Trading Program/Star 
Citizen trading NEW.py", line 32, in common
return set(curr.keys()).intersection(set(other.keys()