samedi 30 septembre 2017

Check after random sample in python

This is my first little project and first question so sorry for the formatting. I have two lists containing recipe names as strings. I want to ask the user how many meals from each list they want and then take a random selection.

I then want to check if a meal was chosen by the selection and display the price of the meal which I would store in a variable.

My idea was to add the random sample to a new list and to check the contents via an if in statement. If the recipe was inside the new list then it would print the variable containing the price.

When I check the new list for the recipe however, it doesn't think it is in the list. Is there something I've missed or a better way to do this? Thank you.

My code so far:

import random
Vegetarian = ["Jungle Curry", "Chickpea Curry", "Dhal", "Buddha Bowl", 
"Chickpea Salad", "Lazy Noodles", "Fry Up"]
Meat = ["Chilli", "Butter Chicken", "Lamb and Hummus"]

v = int(raw_input("How many vegetarian meals this week? > "))
m = int(raw_input("How many meaty meals? > "))

Veg1 = random.sample(Vegetarian, v)
Meat2 = random.sample(Meat, m)

veg_week = []
meat_week = []

veg_week.append(Veg1)
meat_week.append(Meat2)

jungle_curry = 10
chickpea_curry = 10

if "Jungle Curry" and "Chickpea Curry" in veg_week:
    print jungle_curry + chickpea_curry




Aucun commentaire:

Enregistrer un commentaire