Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions