Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grocery List Program
#2
The algorithm is independent of the code. In other words, you should be able to describe your algorithm in words and then think about implementation.

So you might say, "25% of the food budget will be spent on breakfast and lunch, and the remaining 50% will be spent on dinner foods. For each meal, we will maximize the budget while trying to buy as many different things as possible."

But let's talk about the code you have because I think that the code you've written is going to make things more difficult for you.

The biggest problem with your code right now is that depending on the number of people specified, you create different variables:

if peopleInFamly == 1:
    (Calculator())
    agesOfPeopleInFamly11 = int(input("How Old Are You "))
    genderOfPeople = input("What Gender Are You ") 
#If There Is 2 People In your famly
elif peopleInFamly == 2:
    agesOfPeopleInFamly12 = int(input("How Old Is the first person in your famly "))
    genderOfPeople12 = input("What Gender is the first person in your famly ")
    agesOfPeopleInFamly22 = int(input("How Old Is the Second person in your famly "))
    genderOfPeople = input("What Gender is the Second person in your famly ")
#If There Is 3 People In your famly
elif peopleInFamly == 3:
    agesOfPeopleInFamly13 = int(input("How Old Is the first person in your famly "))
    genderOfPeople = input("What Gender is the first person in your famly ")
    agesOfPeopleInFamly23 = int(input("How Old Is the Second person in your famly "))
    genderOfPeople = input("What Gender is the Second person in your famly ")
    agesOfPeopleInFamly33 = int(input("How Old Is the Third person in your famly "))
    genderOfPeople = input ("What Gender is the Thrid person in your famly ")
You're going to get a headache doing something like this. Instead, you could use parallel lists for each thing:
ages = []
genders = []
peopleInFamly = int(input("How Many People Are In Your Famly "))
for x in range(peopleInFamily):
   age = int(input("How old..."))
   ages.append(age)
   gender = input("What gender...")
   genders.append(genders)
That whole big if/elif block asking for ages and genders goes down to about 10 lines.

also, instead of asking how many weeks then prompting for the dollar amount, how about just ask "how much money do you have?" then ask "How many weeks should that last?" Then do the dollar per week calculation?

You could also simplify things by using dict's instead of lists for defining food items but this is a start.
Reply


Messages In This Thread
Grocery List Program - by TFish - Jan-09-2018, 05:53 PM
RE: Grocery List Program - by mpd - Jan-09-2018, 11:10 PM
RE: Grocery List Program - by TFish - Jan-10-2018, 04:00 AM
RE: Grocery List Program - by mpd - Jan-10-2018, 12:35 PM
RE: Grocery List Program - by TFish - Jan-10-2018, 03:14 PM
RE: Grocery List Program - by mpd - Jan-10-2018, 03:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Program to find Mode of a list PythonBoy 6 1,222 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Create a program that PING a list of IPs skaailet 7 6,569 Mar-26-2020, 10:46 PM
Last Post: snippsat
  how to open program file .exe from list SayHiii 2 2,501 Dec-11-2019, 01:28 AM
Last Post: SayHiii
  creating a list during program execution. hobbyprogrammer 2 2,460 Jan-26-2019, 09:06 PM
Last Post: hobbyprogrammer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020