Question: Q1 # GRADED # # (a) Using a for loop, iterate through the list x # and print an item if its divisible by 2

Q1

# GRADED # # (a) Using a for loop, iterate through the list x # and print an item if its divisible by 2 and less than 6 # (b) Using a for loop, iterate through the dictionary y # and print a single string of the form "company, ceo" # e.g. "CEO: Apple, Name: Tim Cook" will be the third entry x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = { 'Satya Nadella': 'Microsoft', 'Jeff Bezos': 'Amazon', 'Tim Cook': 'Apple'

Q2

# GRADED

# Write a function that takes a name and returns # "Your name is " # Example: # print_name("Sharat") should return "Your name is Sharat" # Hint: You string formatting functionality. https://pyformat.info/ def print_name(name): formatted_result = None # Replace with format string return formatted_result

data = {'first': 'Your name is', 'last': 'Michael'}

'{first} {last}'.format(**data)

print_name("Michael")

Q3.

# GRADED

# Provided below are functions that are completely defined (add_numbers),

# partially defined (sub_numbers) and not defined (mult_numbers)

# (a) Complete sub_numbers so that it return difference of two numbers

# (b) Write a function called mult_numbers to multiply two numbers

def add_numbers(a, b):

result = a + b

return result

def sub_numbers(a, b):

# Write code to return sum of a and b

result = a-b

return result

# Uncomment the following when you have done the exercise

# a^2-b^2 = (a+b)*(a-b)

# e.g 5^2 - 4^2 = (5+4)(5-4) = 9

# print(mult_numbers(add_numbers(5,4), sub_numbers(5,4)))

# Should print 9

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!