← Previous Next →

Print battery charge

Created by Antoine Angot

Instructions

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 paramater, display a Bar to represent how much the battery is “filled” (from 0 to 10 bars), and prints the remaining percentage.

Examples

  • battery_charge(40) must print this output:
[❚❚❚❚      ]
40%
  • battery_charge(42) must print this output:
[❚❚❚❚      ]
42%
  • battery_charge(58) must print this output:
[❚❚❚❚❚❚    ]
58%

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

References

  • The round builtin function.

Results