-
Notifications
You must be signed in to change notification settings - Fork 0
/
udacity.py
97 lines (75 loc) · 1.73 KB
/
udacity.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#7.1
def bigger(x,y):
if x>=y:
d=x
if y>=x:
d=y
return d
#print bigger(9,9)
#8.1
def is_friend(name):
if name[0] == 'D':
return True
else:
return False
#print is_friend('Diane')
#print is_friend('Ned')
#9.1
#def biggest(a,b,c):
if a>=b:
if a>=c:
x = a
elif c>=a:
x = c
elif b>=c:
x = b
else:
x = c
print x
#biggest(3,3,1)
#11.1
#i = 0
#while i != 10:
# i = i + 2
# print i
#11.3
def print_numbers(num):
i=1
while i <= num:
print i
i = i + 1
#print_numbers(3)
#12.1
def factorial(n):
x = n
while n > 1:
n = n-1
x = x * n
#print x
#print n
return x
#print factorial(5)
#15.1
def get_next_target(page):
start_link = page.find('<a href=')
if start_link > 0:
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote + 1)
url = page[start_quote + 1:end_quote]
return url, end_quote
else:
return None
url, endpos = get_next_target(page)
#print url,',', endpos
#16.1
def print_all_links(page):
start_link = page.find('<a href=')
while start_link > 0: # what goes as the test condition for the while?
url, endpos = get_next_target(page)
if url != 'None': # test whether the url you got back is None
print url
page = page[endpos:] # advance page to next position
else:
break
# if there was no valid url, then '''get_next_target''' did not find a link then do something else. What do you need to do?
print print_all_links('this is a <a href="http://udacity.com">link!</a> sdfsafd this is a <a href="http://udacity.com">link!</a> ddfawefef this is a <a href="http://udacity.com">link!</a>')