Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a menu where the user can select multiple options from the list. and apply a final discount. with this parameters:
All books published after 2000 have 10% discount. • Buy books worth more than £30 in total, get a 5% discount on the total.

The following books are available • xxxx (1851) £15.20 • xxxx (2010) £13.14 • xxxx (1980) £11.05 • xxxxx (1976) £10.24 • xxxxx (1889) £12.87 • xxxxx (1895) £10.43 • xxxx (1954) £8.12 • xxxx (1886) £7.32 • xxxxx (1843) £4.23 • xxxx (1859) £6.32 • xxx (1861) £13.21

This is my first try at coding, please go easy on me. Thanks in advance.

What I have tried:

menu = 3
while menu == 3:
    print ("Select book option")
    print ("1 Moby Dick (1851)- £15.20")
    print ("2 The Terrible Privacy of Maxwell Sim (2010) - £13.14")
    print ("3 Still Life With Woodpecker (1980) - £11.05")
    print ("4 Sleeping Murder (1976) - £10.24")
    print ("5 Three Men in a Boat (1889) - £12.87")
    print ("6 The Time Machine (1895) - £10.43")
    print ("7 The Caves of Steel (1954) - £8.12")
    print ("8 Idle Thoughts of an Idle Fellow (1886) - £7.32")
    print ("9 A Christmas Carol (1843) - £4.23")
    print ("10 A Tale of Two Cities (1859) - £6.32")
    print ("11 Great Expectations (1861) - £13.21")
    
def option():
    while True:
        option = int(input('select an option from 1 to 11 '))
        if option > 11 or option < 1:
            print ("Option not avialable. Try again! ")
            option()
        elif option == 1:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter Y to add another option or N to finish: ')
            if cont == "N":
                   exit
            elif cont == "Y":
                   menu = 3
                   
            else:
                   break
        elif option == 2:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter Y to add another option or N to finish: ')
            def dis10(option, dis):
                option = 13.14
                dis = option * 0.1
                dis10 = option - dis
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 3:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 4:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 5:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 6:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 7:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 8:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        if option == 9:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 10:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
        elif option == 11:
            print ("You select option 1 Moby Dick (1851)- £15.20")
            cont = input('Enter "Y" to add another option or "N" to finish: ')
            if cont == "N":
               exit
            elif cont == "Y":
               menu = 3
            else:
                   break
def totaldis(total_amount, totaldis):
    totaldis = total_amount - 
Posted
Updated 27-Feb-18 5:04am

1 solution

You need to learn how to use modules (6. Modules — Python 3.4.8 documentation[^]) and loops (see 4. More Control Flow Tools — Python 3.4.8 documentation[^]). As it is you have a lot of duplicate code which just makes your program more difficult to read. Start with a list that contains the names of the books and their price - see 5. Data Structures — Python 3.4.8 documentation[^] for some of the different options. You can then construct your menu dynamically by listing the entries in the list, preceded by their position as the selection value. When the user enters a number, that will allow you to show the details of the appropriate item.

As the user chooses each item you need to keep a running total of the amount spent (either before the discount is applied, after, or both). Then When the user selcts "no more" you can check whether the additional 5% discount should be applied.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900