-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbiggest.py
70 lines (59 loc) · 3.03 KB
/
biggest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Define a procedure, biggest, that takes three
# numbers as inputs and returns the largest of
# those three numbers.
def biggest(a,b,c):
if a>=b:
if a>=c:
return a
else:
return c
else:
if b>=c:
return b
else:
return c
# 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.
# Letters that are present in the 1st input string may be used
# as many times as necessary to create the 2nd string (you
# don't need to keep track of repeat usage).
# 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! #
### WRITE YOUR CODE HERE ###
def fix_machine(debris, product):
word = list(product)
#find the fist letter from the debris -> if yes, find the next
length=len(product)
count=0
last_same=0
while last_same!=-1:
last_same=debris.find(word[count])
count+=1
if count==length:
return product
else:
return "Give me something that's not useless next time."
### 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'