Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a stacktrace for this code for an upvote please quickly assignment is due soon starter code: #define list of flowers myFlowers = ['daffodil', 'lavendar',

Create a stacktrace for this code for an upvote please quickly assignment is due soon

starter code:

#define list of flowers myFlowers = ['daffodil', 'lavendar', 'lily', 'daisy', 'rose', 'hydrangea', 'dahlia', 'sunflower'] #Function that determines if given flower is one of the top three favorites def favoriteFlower(): #check if given flower is in the top three, return True (boolean) if is return print("Is lily one of my favorite flowers? ", favoriteFlower("lily",myFlowers)) print("Is orchids one of my favorite flowers? ", favoriteFlower("orchids",myFlowers)) print("Is rose one of my favorite flowers? ", favoriteFlower("rose",myFlowers))

code that needs stack trace:

# List of Flowers

myFlowers = ['daffodil', 'lavendar', 'lily', 'daisy', 'rose', 'hydrangea', 'dahlia', 'sunflower']

# function that determine that if the given flower is one of the top three favorites

def favoriteFlower(flower, my_flower): # function Definition

topThree = my_flower[0:3] # slicing first 3 elements of given list and storing in another list 'topThree'

# [0:3] means start slicing from index 0 and stop at index 3(excluding index 3) which contains index 0,1,2

if flower in topThree: # checking if given flower is available in list 'topThree'

return True # if available return True

else: # if not available

return False # return False

print("Is lily one fo my favorite flowers? ", favoriteFlower("lily", myFlowers))

print("Is orchids one fo my favorite flowers? ", favoriteFlower("orchids", myFlowers))

print("Is rose one fo my favorite flowers? ", favoriteFlower("rose", myFlowers))

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions