Handling selections for a vending machine To summarise, the code is based of a vending machine and allows the user to choose an item once chosen, it will add 1 to the item to display how many total items the user has. 

However, it is incredibly long and more or less it essentially repeats the same code again which is inefficient. How can I compress this code into smaller sections?

if selection == 1:
    item = "Chocolate"
    print ("1 for Diary Milk 2 for Maltesars 3 for Kit Kat:")
    selection = int(input("Please enter your option:"))
    if selection == 1:
        item = "Diary Milk"
        itemValue = itemValue + 1
    elif selection == 2:
        item = "Maltesars"
        itemValue = itemValue + 1

    elif selection == 3:
        item = "Kit kat"
        itemValue = itemValue + 1

elif selection ==2:
    item = "Gum"
    print ("1 for Airwaves 2 for Extra Pepermint 3 for Wriggley's Summer fruit:")
    selection = int(input("Please enter your option:"))
    if selection == 1:
        item = "Airwaves"
        itemValue = itemValue+1
    elif selection == 2:
        item = "Extra Pepermint"
        itemValue = itemValue+1

    elif selection == 3:
        item = "Wriggley's Summer fruit"

elif selection ==3:
    item = "Fizzy Drink"
    print ("1 for Coke 2 for Tango Cherry 3 for Dr Pepper:")
    selection = int(input("Please enter your option:"))
    if selection == 1:
        item = "Coke"
        itemValue = itemValue+1
    elif selection == 2:
        item = "Tango Cherry"
        itemValue = itemValue+1
    elif selection == 3:
        item = "Dr Pepper"
        itemValue = itemValue+1
The biggest thing you can do is to use string formatting to remove redundancy. Now instead of having to repeatedly type "1 for Coke 2 for Tango Cherry 3 for Dr Pepper:, you factor out the common parts, put the foods in a list, and use that list to populate the string. I also removed your first assignment to item, (ie item = "Gum") for each, because they immediately get removed. Finally, all three circumstances can be combined by indexing into a list of lists.

format_string = "1 for {0} 2 for {1} 3 for {2}:"

items = [["Diary Milk", "Maltesars", "Kit kat"],
         ["Airwaves","Extra Pepermint","Wriggley's Summer fruit"],
         ["Coke", "Tango Cherry", "Dr Pepper"]]

print(format_string.format(*items[selection - 1]))
new_selection = int(input("Please enter your option:"))
item = items[selection - 1][new_selection - 1]
itemValue += 1


Taken together, this reduces your code from 50 lines, to 10.