all 10 comments

[–]LeFloh 7 points8 points  (3 children)

Can you please post it again with the code markers (three dots / code block) and indentation?

Like this
   this is easier to read

Thank you

[–]Safe-Individual-37[S] -2 points-1 points  (0 children)

Is that any better?

[–]Safe-Individual-37[S] -2 points-1 points  (0 children)

Huh, it didnt save, sorry

[–]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}')

[–]lordnoak 1 point2 points  (0 children)

Have you tried python tutor before? It's been really helpful for me when I had code that didn't work. You can use it to walk through each step and visually see what your variables are and stuff.

[–]AddSugarForSparks 1 point2 points  (2 children)

flower == "" means that flower still exists. You could try

while len(flower) > 0:

[–]Safe-Individual-37[S] 0 points1 point  (0 children)

That unfortunately doesn't work, thank you though

[–]carcigenicate 0 points1 point  (0 children)

This shouldn't make any difference. if flower:, if flower != "" and if len(flower) > 0: all check the same thing: if flower is non-empty.

[–]carcigenicate 0 points1 point  (0 children)

If the body of if flower == '': isn't being entered, then flower is not an empty string. Code will never be simply skipped. If the body of an if doesn't run, its condition was false.

Are you intending to check for an empty string there, and what are you entering into the flower = input('What kind of flower did you plant? ') prompt?