Print battery charge

Created by Antoine Angot

Write a function named battery_charge that graphically represents a battery’s charge. Your function doesn't need to return anything, but just show how much a battery is charged.

This function will takes an int between 0 and 100 as a parameter, display a bar to represent how much the battery is "filled" (from 0 to 10 bars), then prints the percentage.

The number of bars should be rounded, meaning that both 9% and 11% are represented by one bar.


>>> battery_charge(0)
[          ]
>>> battery_charge(5)
[          ]
>>> battery_charge(9)
[❚         ]
>>> battery_charge(11)
[❚         ]
>>> battery_charge(100)

If the character causes you problems in your editor or terminal, feel free to use a simple | instead.


  • The round builtin function.

There's no corrections yet, hit the `Submit` button to send your code to the correction bot.

Keyboard shortcuts:

  • Ctrl-Enter: Send your code to the correction bot.
  • Escape: Get back to the instructions tab.

See solutions