Solution to Practice Problem Set 2 ---------------------------------- 1(a) Output with the line changed: 110001. This is not the binary equivalent of 35; it is the binary equivalent of 49. The change is causing the program to output the reverse of the binary equivalent of the given nonnegative integer. 1(b) The following error message is produced: Traceback (most recent call last): File "None", line 4, in TypeError: unsupported operand type(s) for +: 'int' and 'str' The reason for the error message is that the change cause the program to add an int type object to a str type object, which is not supported in Python. 2. n = int(raw_input("Type a positive integer. ")) reverse = "" while n > 0: reverse = reverse + str(n % 10) n = n/10 print reverse 3(a) Line 1 10 Line 2 10 3(b) Line 2 11 Line 3 11 3(c) Line 2 21 Line 3 21 4. n = int(raw_input("Enter a number: ")) evenCount = 0 oddCount = 0 while n > 0: if n % 2 == 0: evenCount = evenCount + 1 else: oddCount = oddCount + 1 n = int(raw_input("Enter a number: ")) print "Even numbers:", evenCount, " Odd numbers:", oddCount 5. Line 2 Line 2 Line 1 6. 1. int 8 2. float 8.5 3. float 8.0 4. str "8.5" 5. str "hello100" 6. str "10 + 20" 7. bool False 8. float 2.0 9. int 337 10. int 34 11. bool True 12. float 17.0 13. float 8.0 14. bool True 15. bool True 16. str "0 + 20" 17. float 2.0 18. float 300.1 19. float 1.0 20. float 12.0 7. Line 1 10 15 Line 2 10 14 Line 2 11 13 Line 2 12 12