Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> Favorite number: 0 Input is zero; cannot divide by zero! >>> ================================ RESTART ================================ >>> Favorite number: 0 Unknown error occurred! >>> def print_HI(): print("Hello, World!") >>> print_HI() Hello, World! >>> def print_Hello_name(): name = input("Please enter your name: ") while len(name) == 0: print("Your name cannot be blank.") name = input("Please enter your name: ") print("Hello,", name) >>> print_Hello_name() Please enter your name: Your name cannot be blank. Please enter your name: Your name cannot be blank. Please enter your name: Michael Hello, Michael >>> ================================ RESTART ================================ >>> Please enter your name: Your name cannot be blank. Please enter your name: Your name cannot be blank. Please enter your name: Michael Hello, Michael >>> ================================ RESTART ================================ >>> Please enter your name: Your name cannot be blank. Please enter your name: Michael Hello, Michael after function call >>> ================================ RESTART ================================ >>> before function call Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 2, in print_Hello_name() NameError: name 'print_Hello_name' is not defined >>> def print_Hello_name(): name = input("Please enter your name: ") while len(name) == 0: print("Your name cannot be blank.") name = input("Please enter your name: ") print("Hello,", name) >>> print_Hello_name() Please enter your name: Michael Hello, Michael >>> print_Hello_name >>> ================================ RESTART ================================ >>> before function call Please enter your name: Michael Hello, Michael after function call Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 12, in print(name, ", the program is ending.", sep='') NameError: name 'name' is not defined >>> ================================ RESTART ================================ >>> Favorite number: cat Unable to convert input into a float! ve1 = could not convert string to float: 'cat' Traceback (most recent call last): File "C:\Users\mil28\Desktop\QQ624.py", line 14, in print('ve2 = ', ve) NameError: name 've' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: Michael array: [1, 2, 3, 4, 5] Hello, Michael after function call Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 15, in print(name, ", the program is ending.", sep='') NameError: name 'name' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: m Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 12, in print_Hello_name() File "C:/Users/mil28/Desktop/hello.py", line 5, in print_Hello_name print('array:', array) NameError: name 'array' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: m array: [1, 2, 3, 4, 5] Hello, m after function call Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 15, in print(name, ", the program is ending.", sep='') NameError: name 'name' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: m Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 13, in print_Hello_name() File "C:/Users/mil28/Desktop/hello.py", line 5, in print_Hello_name print('array:', array) NameError: name 'array' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: m Traceback (most recent call last): File "C:/Users/mil28/Desktop/hello.py", line 14, in print_Hello_name() File "C:/Users/mil28/Desktop/hello.py", line 5, in print_Hello_name print('array:', array) NameError: name 'array' is not defined >>> ================================ RESTART ================================ >>> before function call Please enter your name: m array: [1, 2, 3, 4, 5] Hello, m after function call >>> ================================ RESTART ================================ >>> before function call Please enter your name: m array: [1, 2, 3, 4, 5] Hello, m after function call [1, 2, 3, 4, 5, 6] >>> ================================ RESTART ================================ >>> before function call Please enter your name: m Hello, m after function call [1, 2, 3, 4, 5, 6] >>> ================================ RESTART ================================ >>> before function call Please enter your name: m ['a', 'b', 'c', 6] Hello, m after function call [1, 2, 3, 4, 5] >>> def greet_user(name): print("Hello,", name) >>> greet_user("Michael") Hello, Michael >>> greet_user() Traceback (most recent call last): File "", line 1, in greet_user() TypeError: greet_user() missing 1 required positional argument: 'name' >>> greet_user("Michael", "Lipschultz") Traceback (most recent call last): File "", line 1, in greet_user("Michael", "Lipschultz") TypeError: greet_user() takes 1 positional argument but 2 were given >>> name Traceback (most recent call last): File "", line 1, in name NameError: name 'name' is not defined >>> def greet_user2(greeting, name): print(greeting, ", ", name, sep='') >>> greet_user2("Hi", "Michael") Hi, Michael >>> greet_user2(1, 2) 1, 2 >>> def add_5(num): num = num +5 print('in add_5:', num) >>> x = 0 >>> add_5(x) in add_5: 5 >>> x 0 >>> def add_5v2(values): values.append(5) print('in add_5v2:', values) >>> y = [1,2,3,4] >>> add_5v2(y) in add_5v2: [1, 2, 3, 4, 5] >>> y [1, 2, 3, 4, 5] >>> def add_5v3(values): values = values[:] + [5] print('in add_5v3:', values) >>> y = [1,2,3,4] >>> add_5v3(y) in add_5v3: [1, 2, 3, 4, 5] >>> y [1, 2, 3, 4] >>> z = (1, 2, 3) >>> add_5v3(z) Traceback (most recent call last): File "", line 1, in add_5v3(z) File "", line 2, in add_5v3 values = values[:] + [5] TypeError: can only concatenate tuple (not "list") to tuple >>> ================================ RESTART ================================ >>> text = cat after function: cat >>> def print_even_odd(num): if num % 2 == 0: print('even') return print('odd') >>> print_even_odd(2) even >>> print_even_odd(3) odd >>> a = print_even_odd(5) odd >>> a >>> print(a) None >>> b = add_5v3([1,2,3]) Traceback (most recent call last): File "", line 1, in b = add_5v3([1,2,3]) NameError: name 'add_5v3' is not defined >>> def add_5v3(values): values = values[:] + [5] print('in add_5v3:', values) >>> b = add_5v3([1,2,3]) in add_5v3: [1, 2, 3, 5] >>> print(b) None >>> c = None >>> def is_even(num): if num % 2 == 0: return True return False >>> is_even(2) True >>> is_even(3) False >>> a = is_even(3) >>> a False >>> if is_even(3): print('3 is even') >>> if not is_even(3): print('3 is not even') 3 is not even >>> def is_even2(num): if num % 2 == 0: return 'even' return 'odd' >>> is_even2(2) 'even' >>> def is_even3(num): if num == 0: return 0 elif num %2 == 0: return 'even' else: return 'odd' >>> is_even3(3) 'odd' >>> is_even3(0) 0 >>> def sum_avg_diff(num1, num2): s = num1 + num2 a = s / 2 d = num1 - num2 return s, a, d >>> total, average, difference = sum_avg_diff(2, 4) >>> total 6 >>> average 3.0 >>> difference -2 >>> value = sum_avg_diff(2, 4) >>> value (6, 3.0, -2) >>> total, everythingelse = sum_avg_diff(2, 4) Traceback (most recent call last): File "", line 1, in total, everythingelse = sum_avg_diff(2, 4) ValueError: too many values to unpack (expected 2) >>> is_even2('asdf') Traceback (most recent call last): File "", line 1, in is_even2('asdf') File "", line 2, in is_even2 if num % 2 == 0: TypeError: not all arguments converted during string formatting >>> is_even2(2) 'even' >>> a = is_even2(2) >>> ================================ RESTART ================================ >>> >>>