user3742457
user3742457

Reputation: 3

Python Loops and counter

Here's my code;

mood = 0
if mood == 5: 
     mood = 4
# I don't want the mood going over four

Here is how the mood increases;

moode = raw_input("how are you").lower()
if 'bad' in moode:
    mood += 1
    print ('You have said that %s times today')%(mood)

The problem is that if you say it 5 times, she replies 'you have said it 5 times' but I don't want mood to go over four?

Upvotes: 0

Views: 68

Answers (1)

Martin Konecny
Martin Konecny

Reputation: 59601

You need to check the value of mood after you increment it.

mood = 0
if 'bad' in moode:
    mood += 1
    if mood > 4:
        mood = 4
    print ('You have said that %s times today')%(name)

or as @arsajii mentioned - don't even both incrementing if it's already 4 or above

mood = 0
if 'bad' in moode:
    if mood < 4:
        mood += 1
    print ('You have said that %s times today')%(name)

Upvotes: 2

Related Questions