-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graham - Week 3 HW.py
38 lines (29 loc) · 1.02 KB
/
Graham - Week 3 HW.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
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 30 11:03:54 2016
@author: Graham Cooke
"""
#Website to be anaylyzed
website = "example.site.domain/main/home"
#stores the location of the most recently found slash
#-1 is a placholder to indicate that no slash has been found
slash = -1
#main loop
#sets the range of index to length of website(minus 1 due to starting at 0)
#to the end(-1), and to interate backwards through the range
for index in range(len(website)-1, -1, -1):
#print(index)
#look for the last slash from the left and stores the location
if website[index] == "/":
slash = index
#looks for the last period from the left
if website[index] == ".":
#if there was a slash, print from the last period to the next slash
if slash != -1:
print(website[index:slash])
break
#if therewas no slash, print from the period to the end
else:
print(website[index:])
break
print("End")