Python Lesson 1 Problem Set

Ethan Witkowski

Open a new Jupyter notebook, and complete the exercises.

1. Arithmetic

Complete simple calculations using Python.

a.

$5 \times 4$

Answer
   
5*4
Output:
20

b.

$100 \div 20$

Answer
   
100/20
Output:
5.0
    

c.

$3^3$

Answer
   
3**3
Output:
27

d.

$\cfrac{(2+4)}{2}$

Answer
   
(2+4)/2
Output:
3.0

2. Variable Assignment

Assign calculated values to variables.

a.

Assign x to be $\cfrac{(2+4)}{2}$
Assign y to be $100 \div 20$
Add x + y

Answer
   
x = (2+4)/2  
y = 100/20
x + y
Output:
8.0

b.

Assign y to be x.
Print y. Before doing so, answer what this will output.

Answer
   
y = x
print(y)
Output:
3.0

c.

Assign x to be x + y.
Print x. Before doing so, answer what this will output.

Answer
   
x = x + y
print(x)
Output:
6.0

3. Functions & Data Types

Use functions on different types of variables.

a.

Assign n to be 3.7.
Print n's variable type.
Print the rounded value of n.
Assign n to be an integer.
Print n. Before doing so, answer what this will output.

Answer
   
n = 3.7
print(type(n))
print(round(n))  
n = int(n)
print(n)
Output:
class 'float'
4
3 (Remember: changing float to integer will always round down.)

b.

Assign founder_name to the string "Jack Bogle".
Print founder_name.
Assign founding_year to a new line and the string "1975".
Print founding_year.

Answer
   
founder_name = "Jack Bogle"
print(founder_name)
founding_year = "\n1975"
print(founding_year)
Output:
Jack Bogle

1975