iam trying to display a list of items but im facing a problem with the function pulp.value() it's not working and i didn't know where does the probleme come from if someone can help me please
my lists:
exams={'Exam PL':30,
'Exam Graphe':30,
'Exam Angular':60,
'Exam English':90,
'Frensh Exam':60,}
slots=[('A',0,30),('A',30,60),
('A',90,60),('B',0,30),
('B',30,90),('B',120,30),
('C',0,90),('C',90,60),]
assign={(exam,slot):pulp.LpVariable('%r in slot %r'%(exam,slot),cat=pulp.LpBinary) for exam in exams for slot in slots}
the assign function :
for slot in slots:
problem.addConstraint
(sum(assign[(exam,slot)]
for exam in exams)<= 1)
my loop to display:
print('Exam assignement:')
print('-'*72)
for(exam,slot),assigned in sorted(assign.items()):
if pulp.value(assigned):
print('Exam %r assigned to Slot %r' %(exam,slot))
print('')
the if condition is not working i didn't know why in the example where i took it from it's working fine
Related
Using multiple if conditions to filter a list works. However, I am looking for a better alternative. As a beginner Python user, I fail to make the filter() and lambda () functions work even after using this resource: https://www.geeksforgeeks.org/python-filter-list-of-strings-based-on-the-substring-list/. Any help will be appreciated.
The following code block (Method 1) works.
mylist = ['MEPS HC-226: MEPS Panel 23 Three-Year Longitudinal Data File',
'HC-203: 2018 Jobs File',
'HC-051H 2000 Home Health',
'NHC-001F Facility Characteristics Round 1',
'HC-IC Linked Data 1999',
'HC-004 1996 Employment Data/Family-Level Weight (HC-004 replaced by HC-012)',
'HC-030 1998 MEPS HC Survey Data (CD-ROM)']
sublist1 = []
for element in mylist:
if element.startswith(("MEPS HC", "HC")):
if "-IC" not in element:
if "replaced" not in element:
if "CD-ROM" not in element:
sublist1.append(element)
print(sublist1)
(Output below)
['MEPS HC-226: MEPS Panel 23 Three-Year Longitudinal Data File', 'HC-203: 2018 Jobs File', 'HC-051H 2000 Home Health']
However, issues are with the following code block (Method 2).
sublist2 = []
excludes = ['-IC', 'replaced', 'CD-ROM']
for element in mylist:
if element.startswith(("MEPS HC", "HC")):
sublist2 = mylist(filter(lambda x: any(excludes in x for exclude in excludes), mylist))
sublist2.append(element)
print(sublist2)
TypeError: 'list' object is not callable
My code block with multiple if conditions (Method 1) to filter the list works. However, I could not figure out why the code block with filter() and lambda functions (Method 2) does not work. I was expecting the same results I got from Method 1. I am open to other solutions as an alternative to Method 1.
I have a dash python web application and I would like to restrict the access of this application to a single user at a given point in time. How can I achieve that? Is there a way to get an event when a second user tries to access it?
I've implemented something similar some time ago.
Basically, i changed the rendered layout, based on time conditions.
For my case, i wanted to make my app working within working hours. ( from 08:00 to 19:00).
#app.callback(Output("page-content", "children"), [Input("url", "pathname")])
def render_page_content(pathname):
# ---------------------------------------------------
if pathname == "/":
# define working time for MILF services
day_of_week = date.today().strftime("%A")
now = datetime.datetime.now()
working_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
if day_of_week in working_days and (now.hour >= 8) and (now.hour < 19):
# if working time is ok, render App page
layout = html.Div([tab01.layout])
else:
# if working time is closed, render an Info Page
layout = dcc.Markdown('''
### APP is not working now... See you soon !
###### Opening time : Monday - Friday
###### Opening hours : 08:00 - 19:00
'''),
return layout
When conditions are not met, i print the message : "APP is not working now... See you soon !"
I'm new to python. I'm trying to make a project that orders and sets up combo meals. The problem is that when printing our the receipt, the receipt prints out four times. May I ask for help on how to fix this? I have tried rearranging the code, and trying multiple if statements but none have seem to work.
cart=[]
mains_total=[]
sides_total=[]
drinks_total=[]
sides=[]
drinks=[]
everything_total=[]
stuff={"steak": int(900), "salmon": int(850), "chicken": int(300)}
stuff2={"baked potato": int(80), "mashed potato": int(75), "steamed vegetables": int(50)}
stuff3={"ice tea": int(55), "root beer": int(60), "water": int(20)}
def system():
print("Thanks for using our service, please select an option.\n(1) mains\n(2) sides\n(3) drinks\n(4)
check-out\n(5) exit")
print("Please order one of each category.")
customer_input=int(input("Please type your answer here:"))
if customer_input==1:
print("steak=900")
print("salmon=850")
print("chicken=300")
global mains_order
mains_order=input("What would you like to order?:")
cart.append(mains_order)
system()
if customer_input==2:
print("baked potato=80")
print("mashed potato=75")
print("steamed vegetables=50")
global sides_order
sides_order=input("What would you like to order?:")
sides.append(sides_order)
system()
if customer_input==3:
print("ice tea=55")
print("root beer=60")
print("water=20")
global drinks_order
drinks_order=input("What would you like to order?:")
drinks.append(drinks_order)
system()
if customer_input==4:
for items in cart:
mains_total.append(stuff[items])
global total_sum
total_sum=sum(mains_total)
for items in sides:
sides_total.append(stuff2[items])
global total_sides
total_sides=sum(sides_total)
for items in drinks:
drinks_total.append(stuff3[items])
global total_drinks
total_drinks=sum(drinks_total)
print(cart, total_sum)
print(sides, total_sides)
print(drinks, total_drinks)
everything_total.append(total_sum)
everything_total.append(total_sides)
everything_total.append(total_drinks)
global total_everything
global total_everything
total_everything=(sum(everything_total))
print(total_everything)
global price_input
price_input=int(input("How much would you like to pay?:"))
if '300' '75' '55' in everything_total:
discounted_price=total_everything/100*10
print("this is your discounted price:", discounted_price)
if price_input<total_everything:
print("Sorry you have insuficient funds. Please restate your order and try agian.")
else:
print(cart, total_sum)
print(sides, total_sides)
print(drinks, total_drinks)
print("price total", total_everything)
print("price paid", price_input)
system()
I have been coding in Python for a 2 months or so, but I mostly ask for help from a more experienced friend when I run in to these kinds of issues. I should also, before I begin, specify that I use Python solely for a personal project; any questions I ask will relate to each other through that.
With those two things out of the way, I have a database of weaponry items that I created using the following script, made in Python 3.X:
#Start by making a list of every material, weapontype, and upgrade.
Materials=("Unobtanium","IvorySilk","BoneLeather","CottonWood","Tin","Copper","Bronze","Gold","Cobalt","Tungsten")
WeaponTypes=("Knife","Sword","Greatsword","Polearm","Battlestaff","Claw","Cane","Wand","Talis","Slicer","Rod","Bow","Crossbow","Handbow","Pistol","Mechgun","Rifle","Shotgun")
Upgrades=("0","1","2","3","4","5","6","7","8","9","10")
ForgeWInputs=[]
#Go through every material...
for m in Materials:
#And in each material, go through every weapontype...
for w in WeaponTypes:
#And in every weapontype, go through each upgrade...
for u in Upgrades:
ForgeWInputs.append((m,w,u))
#We now have a list "ForgeWInputs", which contains the 3-element list needed to
#Forge any weapon. For example...
MAT={}
MAT["UnobtaniumPD"]=0
MAT["UnobtaniumMD"]=0
MAT["UnobtaniumAC"]=0
MAT["UnobtaniumPR"]=0
MAT["UnobtaniumMR"]=0
MAT["UnobtaniumWT"]=0
MAT["UnobtaniumBuy"]=0
MAT["UnobtaniumSell"]=0
MAT["IvorySilkPD"]=0
MAT["IvorySilkMD"]=12
MAT["IvorySilkAC"]=3
MAT["IvorySilkPR"]=0
MAT["IvorySilkMR"]=3
MAT["IvorySilkWT"]=6
MAT["IvorySilkBuy"]=10
MAT["IvorySilkSell"]=5
MAT["CottonWoodPD"]=8
MAT["CottonWoodMD"]=8
MAT["CottonWoodAC"]=5
MAT["CottonWoodPR"]=0
MAT["CottonWoodMR"]=3
MAT["CottonWoodWT"]=6
MAT["CottonWoodBuy"]=14
MAT["CottonWoodSell"]=7
MAT["BoneLeatherPD"]=12
MAT["BoneLeatherMD"]=0
MAT["BoneLeatherAC"]=3
MAT["BoneLeatherPR"]=3
MAT["BoneLeatherMR"]=0
MAT["BoneLeatherWT"]=6
MAT["BoneLeatherBuy"]=10
MAT["BoneLeatherSell"]=5
MAT["TinPD"]=18
MAT["TinMD"]=6
MAT["TinAC"]=3
MAT["TinPR"]=5
MAT["TinMR"]=2
MAT["TinWT"]=12
MAT["TinBuy"]=20
MAT["TinSell"]=10
MAT["CopperPD"]=6
MAT["CopperMD"]=18
MAT["CopperAC"]=3
MAT["CopperPR"]=2
MAT["CopperMR"]=5
MAT["CopperWT"]=12
MAT["CopperBuy"]=20
MAT["CopperSell"]=10
MAT["BronzePD"]=10
MAT["BronzeMD"]=10
MAT["BronzeAC"]=5
MAT["BronzePR"]=3
MAT["BronzeMR"]=3
MAT["BronzeWT"]=15
MAT["BronzeBuy"]=30
MAT["BronzeSell"]=15
MAT["GoldPD"]=10
MAT["GoldMD"]=30
MAT["GoldAC"]=0
MAT["GoldPR"]=5
MAT["GoldMR"]=10
MAT["GoldWT"]=25
MAT["GoldBuy"]=50
MAT["GoldSell"]=25
MAT["CobaltPD"]=30
MAT["CobaltMD"]=10
MAT["CobaltAC"]=0
MAT["CobaltPR"]=10
MAT["CobaltMR"]=0
MAT["CobaltWT"]=25
MAT["CobaltBuy"]=50
MAT["CobaltSell"]=25
MAT["TungstenPD"]=20
MAT["TungstenMD"]=20
MAT["TungstenAC"]=0
MAT["TungstenPR"]=7
MAT["TungstenMR"]=7
MAT["TungstenWT"]=20
MAT["TungstenBuy"]=70
MAT["TungstenSell"]=35
WEP={}
WEP["KnifePD"]=0.5
WEP["KnifeMD"]=0.5
WEP["KnifeAC"]=1.25
WEP["SwordPD"]=1.0
WEP["SwordMD"]=1.0
WEP["SwordAC"]=1.0
WEP["GreatswordPD"]=1.67
WEP["GreatswordMD"]=0.67
WEP["GreatswordAC"]=0.5
WEP["PolearmPD"]=1.15
WEP["PolearmMD"]=1.15
WEP["PolearmAC"]=1.15
WEP["CanePD"]=1.15
WEP["CaneMD"]=1.15
WEP["CaneAC"]=0.7
WEP["ClawPD"]=1.1
WEP["ClawMD"]=1.1
WEP["ClawAC"]=0.8
WEP["BattlestaffPD"]=1.15
WEP["BattlestaffMD"]=1
WEP["BattlestaffAC"]=1.25
WEP["TalisPD"]=1.15
WEP["TalisMD"]=0.7
WEP["TalisAC"]=1.15
WEP["WandPD"]=0.0
WEP["WandMD"]=1
WEP["WandAC"]=1.33
WEP["RodPD"]=0.0
WEP["RodMD"]=1.67
WEP["RodAC"]=0.67
WEP["SlicerPD"]=0.67
WEP["SlicerMD"]=0.67
WEP["SlicerAC"]=0.67
WEP["BowPD"]=1.15
WEP["BowMD"]=1.15
WEP["BowAC"]=0.85
WEP["CrossbowPD"]=1.4
WEP["CrossbowMD"]=1.4
WEP["CrossbowAC"]=1
WEP["PistolPD"]=0.65
WEP["PistolMD"]=0.65
WEP["PistolAC"]=1.15
WEP["MechgunPD"]=0.2
WEP["MechgunMD"]=0.2
WEP["MechgunAC"]=1.5
WEP["ShotgunPD"]=1.3
WEP["ShotgunMD"]=1.3
WEP["ShotgunAC"]=0.4
WEP["RiflePD"]=0.75
WEP["RifleMD"]=0.75
WEP["RifleAC"]=1.75
WEP["HandbowPD"]=0.8
WEP["HandbowMD"]=0.8
WEP["HandbowAC"]=1.2
UP={}
UP["0PD"]=1.0
UP["1PD"]=1.1
UP["2PD"]=1.2
UP["3PD"]=1.3
UP["4PD"]=1.4
UP["5PD"]=1.5
UP["6PD"]=1.6
UP["7PD"]=1.7
UP["8PD"]=1.8
UP["9PD"]=1.9
UP["10PD"]=2.0
UP["0MD"]=1.0
UP["1MD"]=1.1
UP["2MD"]=1.2
UP["3MD"]=1.3
UP["4MD"]=1.4
UP["5MD"]=1.5
UP["6MD"]=1.6
UP["7MD"]=1.7
UP["8MD"]=1.8
UP["9MD"]=1.9
UP["10MD"]=2.0
UP["0AC"]=1.0
UP["1AC"]=1.1
UP["2AC"]=1.2
UP["3AC"]=1.3
UP["4AC"]=1.4
UP["5AC"]=1.5
UP["6AC"]=1.6
UP["7AC"]=1.7
UP["8AC"]=1.8
UP["9AC"]=1.9
UP["10AC"]=2.0
UP["0PR"]=1.0
UP["1PR"]=1.1
UP["2PR"]=1.2
UP["3PR"]=1.3
UP["4PR"]=1.4
UP["5PR"]=1.5
UP["6PR"]=1.6
UP["7PR"]=1.7
UP["8PR"]=1.8
UP["9PR"]=1.9
UP["10PR"]=2.0
UP["0MR"]=1.0
UP["1MR"]=1.1
UP["2MR"]=1.2
UP["3MR"]=1.3
UP["4MR"]=1.4
UP["5MR"]=1.5
UP["6MR"]=1.6
UP["7MR"]=1.7
UP["8MR"]=1.8
UP["9MR"]=1.9
UP["10MR"]=2.0
UP["0WT"]=1.0
UP["1WT"]=0.95
UP["2WT"]=0.9
UP["3WT"]=0.85
UP["4WT"]=0.8
UP["5WT"]=0.75
UP["6WT"]=0.7
UP["7WT"]=0.65
UP["8WT"]=0.6
UP["9WT"]=0.55
UP["10WT"]=0.5
def ForgeW(Material,WeaponType,UpgradeLevel):
"""The ForgeW function Forges a Weapon from its base components into a lethal tool."""
#Get the appropriate material stats...
OrePD=MAT[Material+"PD"]
OreMD=MAT[Material+"MD"]
OreAC=MAT[Material+"AC"]
#And weapon type stats...
SmithPD=WEP[WeaponType+"PD"]
SmithMD=WEP[WeaponType+"MD"]
SmithAC=WEP[WeaponType+"AC"]
#And apply the upgrade...
UpgradePD=UP[UpgradeLevel+"PD"]
UpgradeMD=UP[UpgradeLevel+"MD"]
UpgradeAC=UP[UpgradeLevel+"AC"]
#Then, add them all together.
ProductPD=(OrePD*SmithPD)*UpgradePD
ProductMD=(OreMD*SmithMD)*UpgradeMD
ProductAC=(OreAC*SmithAC)*UpgradeAC
return(ProductPD,ProductMD,ProductAC)
#Recall that ForgeW simply needs its three inputs, which we have a list of. So, let's make our
#database of weapon information.
OmniWeapData={}
#Go through every set of inputs we have...
for Inputs in ForgeWInputs:
#And create a key in the dictionary by combining their three names. Then, set that
#key equal to whatever ForgeW returns when those three inputs are put in.
OmniWeapData[Inputs[0]+Inputs[1]+Inputs[2]] = ForgeW(Inputs[0],Inputs[1],Inputs[2])
I would like to refer to the database created by this code and pull out weapons at random, and frankly I have no idea how. As an example of what I would like to do...
Well, hum. The code in question should spit out a certain number of results based on the complete products of the ForgeW function - if I specify, either within the code or through an input, that I would like 3 outputs, it might output a GoldKnife0, a TinPolearm5, and a CobaltGreatsword10. If I were to run the code again, it should dispense new equipment - not the same three every time.
I apologize if this is too much or too little data - it's my first time asking a question here.
"Take this... it may help you on your quest."
There is a library called random with a method called choice().
e.g.
import random
random.choice([1,2,3])
>>> 2
It sounds like you need one item from Materials, one item from WeaponTypes, and one from Upgrades.
Also, rarely is there ever a need for a triple nested FOR statement. This should get you started.
I wrote a program using c# that list all running process in window, i want to list all running process in window, and in each process, i want to list all running thread (both name and id). i can't find any function on Window Api to list thread name, how can i do it ?
Example: plz look at this picture:
lh4.googleusercontent.com/HwP6dpts5uRPJIElH7DgUd3x95aQKO36tynkfsaDMBbM=w607-h553-no
in the image, i want to list
FireFox ID: 123
Google Chorme ID 456
...
Explorer ID 789
Documents ID 654
Temp ID 231
...
Thankyou !
You can use the Systems.Diagnostic namespace and then use:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Source
More info