Answer the following questions in Python. Do all calculations in Python. Your answers should have a pattern similar to this:

if 3 < (5 * 2):
    print('3 is less than 5 times 2')
else:
    print('3 is not less than 5 times 2')

Which is greater: $10^5$ or $3^9$?


In [4]:
if 10**5 > 3**9:
    print('10^5 is greater')
else:
    print('3^9 is greater')


10^5 is greater

Demonstrate the $0.25 \neq 0.35$


In [8]:
if 0.25 != 0.35:
    print('0.25 != 0.35')
else:
    print('hmmm')


0.25 != 0.35

Using the // operator, show that 3 is not divisible by 2.


In [9]:
if 3 // 2 != 3 / 2:
    print('3 is not divisble by 2')
else:
    print('it is divisible by 2')


3 is not divisble by 2

Using a set of if if statements, print whether a variable is odd or even and negative or positive. Use the variable name x and demonstrate your code works using x = -3, but ensure it can handle any integer (e.g., 3, 0, -100). Make sure your print statements use the value of x, not the name of the variable. For example, you should print out -3 is negative, not x is negative.


In [15]:
x = -3

if x // 2 == x / 2:
    print('{} is even'.format(x))
else:
    print('{} is odd'.format(x))
if x < 0:
    print('{} is negative'.format(x))
elif x > 0:
    print('{} is positive'.format(x))
else:
    print('{} is 0'.format(x))


-3 is odd
-3 is negative