Challenges
During the workshop, activities are provided so that you can engage and test out the content shown for yourself. These are referred to as challenges.
You can attempt these challenges either within the Jupyter Binder, or using another online Python compiler.
Python: The Calculator
Use Python to perform the following operations:
15 - 21
42 x 6
57 ÷ 3
27^2
The floor of 59 ÷ 3
The remainder of 59 ÷ 3
8 ÷ 2(2 + 2)
Data Types
What type of data (integer, floating point number, or character string) would you use to represent each of the following?
Time elapsed since the start of the year.
Serial number of a piece of lab equipment.
A lab specimen’s age.
Current population of a city.
Average population of a city over time.
Try to come up with more than one good answer for each problem. For example, in 1., when would using a decimal make more sense than using an integer?
To answer these prompts, join the poll: https://joinmyquiz.com and enter the game code provided by your trainer.
Data Coercion Challenge 1
Which of the following will print 2.0? If they don't, what do they print instead? Try to make a prediction before testing this for yourself.
1.0 + float("1")
float("1") + float("1.1")
1.0 + int("3.1")
1.0 + int(float("3.1")) % 2
int(1.0) + int(float("1.1"))
2.0 * "1"
Data Coercion Challenge 2
What will these do? What will be the final data type in each case?
str(4.0)
int(str(4.0))
float(str(3.5))
int(float(str(3.2)))
Methods
Visit this link: https://docs.python.org/3/library/stdtypes.html#string-methods. Look up the following methods and figure out how they work:
str.upper()
str.title()
str.capitalize()
Create an example for each method. When would this be useful?
Variable Names
In this list of variable names, which ones are legal?
76trombones = "big parade"
more$ = 1000000
class = "Computer Science 101"
Price_of_tea_in_china
my name = "Scooby Doo"
A_good_grade_is_A+
Which ones are technically legal, but generally frowned upon, and how could we make these better?
Family
Create three variables:
One called
family_name
that points to the family's name (make that a string maybe?).One called
family_count
that stores the number of members in your family.One called
family_age
that stores the average age of your family.
Then print the following:
"Our family name is ___. We have ___ members and we are, on average, ___ years old."
Note: you can use your housemates or family of friends for this challenge.
Optional, Extension Challenge
Hint: if a = 3
and b = 5
, then the answer is 34
. Do the same for a = 2
and b = 6
.
Final Quiz
Time to test your memory!
To participate in the quiz, join here: https://joinmyquiz.com and enter the game code provided by your trainer.
Last updated