-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw1.py
79 lines (49 loc) · 1.32 KB
/
hw1.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
import os
def product_of_five():
file = open("num.txt", "r")
number = file.read()
max = 0
for index, value in enumerate(number):
if index < 996:
current = int(value) * int(number[index + 1]) * int(number[index + 2]) * int(number[index + 3]) * int(number[index + 4])
if current > max:
max = current
print("The max is: " + str(max))
file.close()
def depth_first():
print("depth first")
root = "/~/"
for current_directory, sub_directory_list, list_of_files in os.walk(root):
print("Directory name: " + current_directory)
print("Sub dirs: " + sub_directory_list)
def alphabet(x):
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for index, value in enumerate(alpha):
if x == value:
return index + 1
return 0
def file():
counter = 0
word = 0
file = open("names.txt", "r")
list = file.read()
list = list.split(',')
list = sorted(list)
for index, value in enumerate(list):
for index2, value in enumerate(list[index]):
word = word + alphabet(list[index][index2])
word = word * (index + 1)
counter = counter + word
word = 0
print("The sum is: " + str(counter))
file.close()
def main():
option = int(input("What program do you want (1 - 3): "))
if option == 1:
product_of_five()
elif option == 2:
depth_first()
elif option == 3:
file()
if __name__ == "__main__":
main()