Below you’ll see some example python code that asks the user how many hours per day they spend on their phone.
It will then calculate and display some (pretty scary) stats of how much of their life they’re arguably wasting away.
Press Ctrl + Enter to run the code.
Click on your score in the top right corner of the code editor to see what your code needs to do.
Any line of code that starts with a
# is a comment: it doesn’t affect how the program runs, it’s just there to help explain what the code does.
- Change the percentage to show
2decimal places instead of
Line 11 uses a function called
round()which is currently set to round to 1 decimal places. Try changing the number inside the brackets.
- Create a variable called
hours_per_yearand set the value to how many hours the user will spend on their phone in a year (365 days).
You’ll need to multiply
In python you can use the
*operator to multiply two numbers.
- Add a line that displays: “
In one year, you will spend ... hours on your phone” where
...is rounded to a whole number
You’ll need to use the
round()function to round to
You’ll also need to use the
str()function so that you can include your number inside
KPRIDE stands for Keywords, Predict, Run, Investigate, Debug and Extend and it’s a way of helping you explore and understand python code. Click on the image below for a set of KPRIDE activities for this python skill.