# By Sam the Great from forums # That freaking superhero has been frequenting Udacity # as his favorite boss battle fight stage. The 'Udacity' # banner keeps breaking, and money is being wasted on # repairs. This time, we need you to proceduralize the # fixing process by building a machine to automatically # search through debris and return the 'Udacity' banner # to the company, and be able to similarly fix other goods. # Write a Python procedure fix_machine to take 2 string inputs # and returns the 2nd input string as the output if all of its # characters can be found in the 1st input string and "Give me # something that's not useless next time." if it's impossible. # NOTE: # If you are experiencing difficulties taking # this problem seriously, please refer back to # "Superhero flyby", the prequel, in Problem Set 11. # TOOLS: # if statement # while loop # string operations # Unit 1 Basics # BONUS: # # 5***** # If you've graduated from CS101, # Gold # try solving this in one line. # Stars! # def fix_machine(debris, product): phrase=product n=-1 while n<len(product): if debris.find(product[n])==-1: phrase="Give me something that's not useless next time." break n=n+1 return phrase print fix_machine('aaaaa', 'abaa') ### WRITE YOUR CODE HERE ### ### TEST CASES ### print "Test case 1: ", fix_machine('UdaciousUdacitee', 'Udacity') == "Give me something that's not useless next time." print "Test case 2: ", fix_machine('buy me dat Unicorn', 'Udacity') == 'Udacity' print "Test case 3: ", fix_machine('AEIOU and sometimes y... c', 'Udacity') == 'Udacity' print "Test case 4: ", fix_machine('wsx0-=mttrhix', 't-shirt') == 't-shirt'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question