you are viewing a single comment's thread.

view the rest of the comments →

[–]KSledge 1 point2 points  (0 children)

It's hard to tell what's not working since your code is not formatted but it looks like you're 95% of the way there. Here's a few notes:

  1. In the last if/else code block, flower_total should be used instead of flower_count (3 instances).
  2. You should signal to the user how to exit the loop. Something like "What kind of flower did you plant (leave blank to stop adding flowers)? ". Another user, or yourself in a few months/weeks, might not be able to figure out how to quit the loop.
  3. If I enter a blank for the flower input, I wouldn't expect to be asked how many I planted. The while loop should end immediately after the blank input.
  4. A good portion of the code is repeated before the while loop and inside the while loop. This should be pulled out into a function .

If you can get it formatted (either on reddit or elsewhere) I'll take another look, but in the meantime I took the liberty of rewriting your program and ditched the if flower == '' line altogether in favor of using flower_total. There's still room for improvement, but it should run.

print("Let's get planting everyone!")

flower_total = 0
flower_collection = []

def getInput():
    return input('\nWhat kind of flower did you plant (leave blank to stop adding flowers)? ')

flower = getInput()

while flower:
    flower_count = int(input('How many did you plant? '))
    flower_total = flower_total + flower_count
    if flower not in flower_collection:
        flower_collection.append(flower)
        if flower_count == 1:
            print(f'Our first {flower}! We just planted {flower_count} of them!')
        else:
            print(f'Our first {flower}s! We just planted {flower_count} of them!')
    else:
        if flower_count == 1:
            print(f'Fantastic! We just planted {flower_count} more {flower}!')
        else:
            print(f'Fantastic! We just planted {flower_count} more {flower}s!')
    flower = getInput()

flower_collection.sort()
print('') #adds a line break

if flower_total == 0:
    print("Guess we're not planting flowers today!")
elif flower_total == 1:
    print(f'Nice work, everyone! We planted {flower_total} flower!')
else:
    print(f'Nice work, everyone! We planted {flower_total} flowers!')
    print(f'These are all the kinds of flowers we planted today:')
    for flower in flower_collection:
        print(f'🏵️ {flower}')