> For the complete documentation index, see [llms.txt](https://meirian.gitbook.io/python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://meirian.gitbook.io/python/getting-started/challenges.md).

# Challenges

You can attempt these challenges either within the Jupyter Binder, or using another [online Python compiler](/python/getting-started/access/online.md).

### Python: The Calculator

Use Python to perform the following operations:

1. 15 - 21
2. 42 x 6
3. 57 ÷ 3
4. 27^2
5. The floor of 59 ÷ 3
6. The remainder of 59 ÷ 3
7. 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?

1. Time elapsed since the start of the year.
2. Serial number of a piece of lab equipment.
3. A lab specimen’s age.
4. Current population of a city.
5. 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. `1.0 + float("1")`
2. `float("1") + float("1.1")`
3. `1.0 + int("3.1")`
4. `1.0 + int(float("3.1")) % 2`
5. `int(1.0) + int(float("1.1"))`
6. `2.0 * "1"`

### Data Coercion C**hallenge 2**

What will these do? What will be the final data type in each case?

1. `str(4.0)`
2. `int(str(4.0))`
3. `float(str(3.5))`
4. `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?

1. `76trombones = "big parade"`
2. `more$ = 1000000`
3. `class = "Computer Science 101"`
4. `Price_of_tea_in_china`
5. `my name = "Scooby Doo"`
6. `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

You are given two positive integers, `a` and `b`, which each correspond to the sides of a right-angle triangle. Print the integer value corresponding to the square of the hypotenuse, `c^2`, of that right triangle. That is, given sides `a` and `b`, print `c^2`\
&#x20;![](https://thumbs.gfycat.com/ImaginativeSkinnyChick-max-1mb.gif)

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.
