Example 01 – TypeError: cannot concatenate ‘str’ and ‘int’ objects
import random lucky_number = random.randint(1,10) msg = 'My lucky number is ' print msg + lucky_number
Reason: The value of lucky_number is int and msg is string. If we want to join them together (i.e., concatenate them to form a new string), we need to use function str() to convert the value of lucky_number into a string. The correct statement is print msg + str(lucky_number)
Example 02 – TypeError: pow expected 2 arguments, got 1
import math lucky_number = math.pow(2) if lucky_number > 10: print 'Good Job!'
Reason: The function pow expects two arguments (base and power) and we invoked it using only one argument.