# Need help breaking this infinite whileloop

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or

def months_forecast(month): if month == "jan" "feb" "march": percent = 0.10 elif month == "apr" "may" "jun": percent = 0.15 elif month == "jul" "aug" "sep": percent = 0.20 else: percent = 0.25 return percent response = input("Would you like to start this program") while response == "yes": last_name = input("please enter your last name ") month = input("Month of the year ") sales = float(input("How many sales did you have ")) response = input("Would you like to start this program") percent = months_forecast(month) next_month_sales = sales * ( 1 + percent) print("This is your percent ", percent) print("This is your next months sales \$" , next_month_sales)

project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!

The method is which you are writing your while loop may not be the best. You start the program asking,
if you want to start the program”, then you set the condition of the while-loop to be True while `response == yes`. Instead, try this:

``````def months_forecast(month):
if month = "jan" "feb" "march":
percent = 0.10
elif month = "apr" "may" "jun":
percent = 0.15
elif month = "jul" "aug" "sep":
percent = 0.20
else:
percent = 0.25
return percent

while True:
response = input("Would you like to start this program (yes or no)?: ")
if response == 'yes':
month = input("Month of the year ")
sales = float(input("How many sales did you have "))
percent = months_forecast(month)
next_month_sales = sales * (1 + percent)
print(f"This is your next months sales \${next_month_sales}")
else:
print('Goodbye!')
break
``````

This way, the program will break if the user does not enter yes

## Screen Shot

Let me know if this answers your question or helps you out.

Best regards,

1 Like

In addition to the proposed changes in seraph776’s post above, you also need to have a look at the conditions in your `months_forecast` function.
In its current form, it doesn’t match any month and just goes to the else block.

``````// You wrote:
if month == "jan" "feb" "march":

// Consider changing it to:
if month in ("jan","feb","march"):

// Instead of a tuple, you can use a list or a set as well.
// Similarly, the elif conditions should also be corrected.
``````
1 Like

Good catch mtrmk! I overlooked that correction ~ Thank you!

What should I change the elif statements too?

``````# You wrote:
elif month == "apr" "may" "jun":

# It should be:
elif month in ("apr", "may", "jun"):
``````
1 Like