Module #3 Assignment
# 1.Function that takes in person name, and print out greeting
name_list = ["Jake Smith", "Jonas Bourbon", "James McGrill"]
def greeting(full):
print(f"Hello {full}!")
for names in name_list:
greeting(names)
Hello Jake Smith!
Hello Jonas Bourbon!
Hello James McGrill!
# Full Names
def greeting_firstlast(first, last):
print(f"Hello {first} {last}!")
greeting_firstlast("Jake", "Smith")
greeting_firstlast("Jonas", "Bourbon")
greeting_firstlast("James", "McGrill")Hello Jake Smith!
Hello Jonas Bourbon!
Hello James McGrill!
# Addition Calculator
def add(a, b):
print(f"The first number is: {a}")
print(f"The second number is: {b}")
print(f"The sum of the two numbers is: {a + b}")
add(2, 3)
add(4, 5)
add(6, 7)The first number is: 2
The second number is: 3
The sum of the two numbers is: 5
The first number is: 4
The second number is: 5
The sum of the two numbers is: 9
The first number is: 6
The second number is: 7
The sum of the two numbers is: 13# Return Calculator
def add(a, b):
return a + b# 2. Expression intended for the square root of 16
print(pow(16, (1/2)))4.0The expression has already yielded the correct answer# 3. Define the variable x and y as lists of numbers, and z as a tuple
x = [1, 2, 3, 4, 5]
y = [11, 12, 13, 14, 15]
z = (21, 22, 23, 24, 25)print(3 * x)[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]print(x + y)[1, 2, 3, 4, 5, 11, 12, 13, 14, 15]print(x - y)TypeError: unsupported operand type(s) for -: 'list' and 'list'print(x[1])2print(x[0])1print(x[-1])5print(x[:])[1, 2, 3, 4, 5]print(x[2:4])[3, 4]print(x[:2])[1, 2]print(x[::2])[1, 3, 5]x[3] = 8
print(x)[1, 2, 3, 8, 5]z[3] = 8
print(z)TypeError: 'tuple' object does not support item assignment
Comments
Post a Comment