Try it:

Convert and use different types of data
Python Data types: Convert and use different types of data

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.

Challenges:

  1. Change the percentage to show 2 decimal places instead of 1

    Line 11 uses a function called round() which is currently set to round to 1 decimal places. Try changing the number inside the brackets.

  2. Create a variable called hours_per_year and set the value to how many hours the user will spend on their phone in a year (365 days).

    You’ll need to multiply hours by 365.
    In python you can use the  * operator to multiply two numbers.

  3. 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 1 decimal place
    You’ll also need to use the str() function so that you can include your number inside print()

KPRIDE

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.

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.