Question

Write a Python program for the Express (less than 10 items) lane at a supermarket. Use...

Write a Python program for the Express (less than 10 items) lane at a supermarket. Use the main function and a value-returning function named subtotal

The main function must prompts for the number of different items in the customer's cart and uses a loop to execute the subtotal function for each item. It must also catch the value returned by subtotal and add it to the total then prints the total after all items have been processed

The subtotal function needs to be defined with no parameters. prompts for the unit price and quantity of each item calculates and prints the subtotal and then returns the subtotal to main

sample

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

Program Screenshots:

Sample Output:

Code to be Copied:

#define the main function

def main():

    #print the header message of program

    print("Express checkout. Maximum 10 items")

    #set the total value to 0

    total=0

    #prompt for the number of items

    num_items=int(input("How many different items do you have? "))

    #if num_items greater than 10

    #set the value to Max 10

    if(num_items>10):

        num_items=10

    #use for-loop to repeat until num_items

    for i in range(num_items):

        #add the total to the subtotal

        #by calling the function

        total+=subtotal()

    #print the total value

    print("Total: $",total)

    #print the end message

    print("Thank you. We appreciate your business")

#define the sub function subtota;()

def subtotal():

    #prompt and read the quantity of item

    print("Enter quantity of item #",end=" ")

    quantity=eval(input())

    #prompt and read the unit_price of item

    print("Enter unit price of this item: ",end=" ")

    unit_price=eval(input())

    #compute the subtotal

    subtotal = unit_price * quantity

    #print the subtotal

    print("Sub total: ",subtotal)

    #return subtotal to the main function

    return subtotal

#call the main method

main()

Add a comment
Know the answer?
Add Answer to:
Write a Python program for the Express (less than 10 items) lane at a supermarket. Use...
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