Recycling Bin Helper Program

Recycling correctly helps reduce waste and protects the environment. Different types of waste need to be placed in different bins, but remembering which item goes in which bin can sometimes be confusing.

In this Python challenge, you will create a simple recycling assistant that asks the user questions about an item they want to throw away and then tells them which bin it belongs in.

This challenge is ideal for beginners who want to practise:

  • Using variables
  • Getting user input
  • Using conditional statements (if, elif, else)
  • Making decisions in a program
  • Creating user-friendly text-based applications

The Recycling Bins

Our program will based on the following recycling scheme where each household has access to 5 bins of different colours:

Bin Waste Type
Blue Bin Plastics, plastic films, glass bottles, drink cartons (Tetra Pak) and cans.
Green Bin Paper, cardboard, books and cardboard packaging.
Grey Bin Food waste, plate scrapings, mouldy food, pet food, tea bags and coffee grounds.
Brown Bin Garden waste including grass clippings, leaves, dead flowers/plants and windfall fruit.
Black Bin General rubbish such as crisp packets, used nappies and polystyrene.

Python Challenge

To solve this challenge, we will write a Python program that ask the user about the item they are about to throw away. If it’s a recognised item, our program will try to decide straight away in which bin the item should go to.

For instance, we know that newspapers, magazines, books, leaflets and postcards should all end up in the green bin. so we can use some Python code to identify if the the item being thrown away belong to this list of items:

item = input("What are you recycling today?").lower()
if item in ["newspaper","magazine","book","leaflet","postcard"]:
   print("This " + item + " goes in the green bin.")

If this item is not in this list we can check if it belongs to other lists of recognisable items for the different recycling bins. To do so we will use elif statements:

item = input("What are you recycling today?").lower()
if item in ["newspaper","magazine","book","leaflet","postcard"]:
   print("This " + item + " goes in the green bin.")
elif item in ["plastic bottle","drink carton","tetra pak","metallic can","aluminium can","glass bottle"]:
   print("This " + item + " goes in the blue bin.")
elif ...
   ...

Your Turn…

Use the online Python IDE that you will find at the bottom of this blog post to complete the code and cater for a list of items for each of the 5 recycling bins of our recycling scheme.

Unrecognised items…

Now that you have completed the code to cater for all 5 bins, you can test it and see if gives you the right advise for different items.
You will quickly realise that using this approach it is not very practical to list every single possible item and that the program may not recognise the items the user want to throw, especially if this item is either not mentioned in the given list or is described differently.

So in this case we will get our program to ask the user a series of questions to determine what type of item they are disposing of.

For example the program could ask the following questions and use the following decision tree:

Python Code

Complete the following code online:

Extension Challenge 1

Some items should not end up in our bins but instead should be brought to the nearest recycling centre. These includes batteries, chemicals, and all forms of eWaste. Could you tweak your code to inform the user to not throw these items in any of their bins but instead bring them to their local recycling centre.


Extension Challenge 2

The above challenge is based on using selection in our code (If statements).

Your extra challenge is to use iteration (using a loop) within your code. You will tweak your code to allow the user to recycle multiple items by repeating the program until they choose to quit.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 2.4 / 5. Vote count: 19

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!