Question

Create a simple program in Python to accomplish the following tasks: In this project, you will...

Create a simple program in Python to accomplish the following tasks:

In this project, you will create a program that will determine the price of an order. The user will enter the number of flower bulbs they would like to purchase. If the user enters 25 or more, they will get a $1.50 discount on the price of each bulb. The original price of each bulb is $5.00. The program will calculate the price of the order of bulbs by multiplying the number of bulbs by the price, either discounted or original. The program will loop so that users can run the program as many times as they would like to see the price of different order of bulbs. If a -1 is entered, then the program will exit.

The program will have a method called discount() that will accept one integer as a parameter, the number of bulbs, and will return True or False depending on whether discount applies, number is greater or equal to 25, (True) or does not apply (False).

The program’s main method will ask for a number of bulbs, it will then pass that number to the method discount(). This method will return the True or False value depending on if the number of bulbs is greater than or equal to 25. The main method will then use the returned Boolean value to determine the price of each bulb and then will calculate the total cost of the bulbs. The main method will keep looping until a -1 is entered.

When building this solution, first place all logic into the main method and have it run once. Once it works that way, add your loop and then move the decision logic out to the discount() method.

Here is a typical program run.

Input: Enter a number: 10

Output: The total cost of the bulbs is $50.00

Input: Enter a number: 30

Output: The total cost of the bulbs is $105.00

Input: Enter a number: -1

Output: Goodbye or nothing

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Code:

def dicount(n):

if n>=25:

return True

return False

def main():

bulbs = int(input("Enter a number: "))

while(bulbs!=-1):

cost = bulbs*5

if(dicount(bulbs)):

cost = cost-bulbs*1.50

print("The total cost of the bulbs is $%.2f"%cost)

bulbs = int(input("Enter a number: "))

print("Goodbye")

main()

Add a comment
Know the answer?
Add Answer to:
Create a simple program in Python to accomplish the following tasks: In this project, you will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT