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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started