When would 2 variables be equal but not have the same identity?

What is the symbol for identity comparison?


In [ ]:

Which of the values below return True when used in the following statement?


In [ ]:
num_wheels >= 1024 and num_wheels < 2456

a.) num_wheels = 2456 b.) num_wheels = 1765 c.) num_wheels = 1024 d.) num_wheels = 8000 e.) num_wheels = 1028 f.) num_wheels = 1020

Fix the if statements below so that the checks are correct and the right statements are printed for the age and drivers info.

You may also want to look at the precedence section in the lecture to ensure it is right in all situations.

You DO NOT need to edit variables, just if statements.


In [25]:
age = 23
has_license = True
min_drive_age = 17
cheap_ins_age = 25

def age_check(age):
    if age >= 18:
        print("Yay, you can drink legally!")
        return True
    else:
        return False
def drive_check(age, has_license):
    if age < min_drive_age and has_license:
        print("Not legally able to drive but have a license? Do you think I am a fool?")
        return False
    if age >= min_drive_age and not has_license:
        print("You can drive but you need to get your license!")
        return False
    elif age < cheap_ins_age and has_license and age >= min_drive_age: #precedence can be used here to make things cleaner
        print("You can drive, but insurance is not gonna be cheap")
        return True
    elif age >= cheap_ins_age and has_license:
        print("Go you, cheap insurance all round!")
        return True
    else:
        return False

In [26]:



---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-26-5f98c1bd9d8e> in <module>()
      1 from nose.tools import assert_equal
      2 
----> 3 assert_equal(True, age_check(age))
      4 assert_equal(True, drive_check(age, has_license))
      5 assert_equal(False, drive_check(18, False))

/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/case.py in assertEqual(self, first, second, msg)
    818         """
    819         assertion_func = self._getAssertEqualityFunc(first, second)
--> 820         assertion_func(first, second, msg=msg)
    821 
    822     def assertNotEqual(self, first, second, msg=None):

/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/case.py in _baseAssertEqual(self, first, second, msg)
    811             standardMsg = '%s != %s' % _common_shorten_repr(first, second)
    812             msg = self._formatMessage(msg, standardMsg)
--> 813             raise self.failureException(msg)
    814 
    815     def assertEqual(self, first, second, msg=None):

AssertionError: True != False

Write the output of the variable str_two once the following code block has run:

str_one = "Hello"
str_two = str_one
str_one = "Hi"
print(str_two)

In [27]:



Out[27]:
'Hello'

Explain the difference between mutable and immutable


In [ ]: