Practice and reinforce the concepts from Lesson 3
In this activity, you will:
Total Time: 30-40 minutes
:information_source: Important Click the link here and make a copy of Colab Notebook into your Google Drive for coding.
Time: 10 minutes
Create 4 variables with different data types. Follow these steps:
:bulb: Use meaningful variable names that describe what the data represents. For example,
user_age
is better than justa
.
Example of string data types
python
user_name = "Yong Sheng" print(type(user_name))
Expected output:
arduino
<class 'str'>
Example of integer data types
python
weight_in_kg = 70 print(type(weight_in_kg))
Expected output:
arduino
<class 'int'>
Example of float data types
python
height_in_m = 1.75 print(type(height_in_m))
Expected output:
arduino
<class 'float'>
Example of boolean data types
python
gender_male = True print(type(gender_male))
Expected output:
arduino
<class 'bool'>
:computer: Question 2: Calculate Average Scores
Time: 10 minutes
You are a class teacher who needs to calculate the average scores for 3 subjects.
Follow these steps:
- Create three variables in one line:
subject1
,subject2
,subject3
- Assign different scores to each subject (you choose the values)
- Calculate the average using the formula: (subject1 + subject2 + subject3) / 3
- Print the result tip Hint You can create multiple variables in one line like this:
a, b, c = 10, 20, 30
Time: 15 minutes
You are a company's CEO creating a salary calculator for your employees.
Write a program following these steps:
input()
and store it in variable name
id
hours
rate_per_hour
int()
pay = int(hours) * int(rate_per_hour)
:bulb: Testing Values Try with these test values:
- Hours: 50
- Rate per hour: 7
Expected output:
The employee name is: Adibah
The employee ID number is: 123456
The amount of salary need to pay is: RM350
TypeError when calculating
int()
NameError: variable not defined
Wrong calculation results
/
, multiplication uses *
:warning: Important Before submitting:
- Test all your code in the Colab notebook
- Make sure all outputs match the expected results
- Save your Colab notebook to your Google Drive
:link: Submit your exercise here
Your submission helps us track your learning progress!