Jump to content

Hello, I need a little bit of help.

I know it's not complete but this is what I have at the momment:

pantry = input('What is in the pantry? ')
recipe = input('What does the recipe require? ')
recipe2 = recipe.lower()
pantry2 = pantry.lower()
recipe3 = recipe2.split()
pantry3 = pantry2.split()
x = [] 
for i in recipe3:
  if i not in pantry3:
    x.append(i)
p = []   
for i in recipe3:
    if i in pantry3:
    p.append(i)
  print("".join(pantry3))
    
   
This program needs to do this:

Your program reads in your pantry contents and a list of ingredients from the recipe. Both of these should be read in separated by commas. You should output either You have all the ingredients! or print out You need: followed by the missing ingredients in alphabetical order, printed one ingredient per line.

Your program should work like this:

 
 
 
 
 
What is in the pantry? flour,baking powder,butter,egg,sugar,milk,oil,vanilla extract,lemon juice,icing sugar,raspberry
What does the recipe require? raspberry,flour,baking powder,egg,sugar,milk,oil,vanilla extract,icing sugar
You have all the ingredients!
 

Here is another example:

 
 
 
 
 
What is in the pantry? butter,flour,baking powder,chocolate chips
What does the recipe require? flour,baking powder,butter,egg,sugar,chocolate chips
You need:egg
sugar
 

And the last example:

 
 
 
 
 
What is in the pantry? flour,baking powder,butter,milk
What does the recipe require? heavy cream,vanilla beans,egg,vanilla sugar
You need:
eggheavy creamvanilla beansvanilla sugar

 

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/209879-python-help/
Share on other sites

Link to post
Share on other sites

pantry = input('What is in the pantry? ').lower().split(',')recipe = input('What does the recipe require? ').lower().split(',')for item in pantry:    if item in recipe:        del recipe[recipe.index(item)]if recipe:    recipe.sort()    print "You need:\n" + ",".join(recipe)else:    print "You have all the ingredients!"

I came up with this

 

Last thing if you don't mind,

The above code produces this:

 

What is in the pantry? flour,baking powder,butter,milk
What does the recipe require? heavy cream,vanilla beans,egg,vanilla sugar
You need:
egg heavy cream vanilla beans vanilla sugar
 
It needs to produce this:
What is in the pantry? flour,baking powder,butter,milk
What does the recipe require? heavy cream,vanilla beans,egg,vanilla sugar
You need:
egg
heavy cream
vanilla beans
vanilla sugar

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/209879-python-help/#findComment-2856204
Share on other sites

Link to post
Share on other sites

 

Change

 

print "You need:\n" + ",".join(recipe)

to

print "You need:\n" + "\n".join(recipe)

I'm sorry to ask but I have 1 last question:

This:

line=input('Enter line: ')
lines=[]
for i in line:
  lines.append(i)
lines.reverse()
line3=','.join(lines)
if line == line3:
  print('This sequence can make a hairpin')
elif line!=line3:
  print('This sequence cannot make a hairpin')
 
 
It should produce this, but at the momment it only says "THis sequence cannot make a hairpin"
The code should produce this:
 
Enter line: AAGGAA
This sequence can make a hairpin
 
 
Enter line: UGAG
This sequence cannot make a hairpin
 
Enter line: GUGCCACGGCACCGUG
This sequence can make a hairpin
 
Enter line: GUACCACGGCACCGUG
This sequence cannot make a hairpin
 
 

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/209879-python-help/#findComment-2856301
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×