Skip to content

Commit eeff30d

Browse files
committed
Practice
1 parent 843f067 commit eeff30d

File tree

10 files changed

+268274
-0
lines changed

10 files changed

+268274
-0
lines changed

Day11/names.txt

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Darth
2+
Luke
3+
Darth
4+
Lea
5+
Darth
6+
Lea
7+
Lea
8+
Luke
9+
Darth
10+
Lea
11+
Darth
12+
Darth
13+
Lea
14+
Lea
15+
Darth
16+
Lea
17+
Darth
18+
Lea
19+
Luke
20+
Darth
21+
Lea
22+
Lea
23+
Darth
24+
Lea
25+
Darth
26+
Darth
27+
Lea
28+
Lea
29+
Luke
30+
Luke
31+
Lea
32+
Darth
33+
Darth
34+
Luke
35+
Lea
36+
Darth
37+
Darth
38+
Lea
39+
Lea
40+
Lea
41+
Lea
42+
Lea
43+
Luke
44+
Darth
45+
Luke
46+
Lea
47+
Lea
48+
Lea
49+
Lea
50+
Luke
51+
Lea
52+
Darth
53+
Lea
54+
Lea
55+
Darth
56+
Lea
57+
Lea
58+
Darth
59+
Darth
60+
Lea
61+
Darth
62+
Lea
63+
Darth
64+
Luke
65+
Lea
66+
Luke
67+
Darth
68+
Darth
69+
Luke
70+
Darth
71+
Lea
72+
Darth
73+
Lea
74+
Luke
75+
Lea
76+
Lea
77+
Lea
78+
Lea
79+
Lea
80+
Darth
81+
Lea
82+
Lea
83+
Lea
84+
Lea
85+
Lea
86+
Lea
87+
Lea
88+
Luke
89+
Lea
90+
Lea
91+
Lea
92+
Lea
93+
Lea
94+
Lea
95+
Darth
96+
Luke
97+
Darth
98+
Lea
99+
Lea
100+
Darth

Day11/q40.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Python program to find power of a number
2+
3+
4+
class Power:
5+
def pow(self, x, n):
6+
if x == 0 or x == 1 or n == 1:
7+
return 1
8+
if x == -1:
9+
if n % 2 == 0:
10+
return 1
11+
else:
12+
return -1
13+
if n == 0:
14+
return 1
15+
if n < 0:
16+
return 1/self.pow(x, -n)
17+
val = self.pow(x, n/2)
18+
if n % 2 == 0:
19+
return val * val
20+
return val*val*x
21+
22+
print(Power().pow(2,-3))

Day11/q41.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Write a function that takes an ordered list of numbers
2+
# (a list where the elements are in order from smallest to
3+
# largest) and another number. The function decides whether
4+
# or not the given number is inside the list and returns
5+
# (then prints) an appropriate boolean.
6+
7+
8+
def Search(alist, item):
9+
first = 0
10+
last = len(alist)-1
11+
found = False
12+
while first <= last and not found:
13+
midpoint = (first + last)//2
14+
if alist[midpoint] == item:
15+
found = True
16+
else:
17+
if item < alist[midpoint]:
18+
last = midpoint-1
19+
else:
20+
first = midpoint+1
21+
return found
22+
23+
24+
t = [0, 1, 2, 8, 13, 17, 19, 32, 42, ]
25+
print(Search(t, 3))
26+
print(Search(t, 13))

Day11/q42.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Given a .txt file that has a list of a bunch of names, count
2+
# how many of each name there are in the file, and print out
3+
# the results to the screen.
4+
5+
count =0
6+
with open('Day11\\names.txt','r') as f:
7+
line = f.readlines()
8+
for l in line:
9+
count += 1
10+
print(count)

0 commit comments

Comments
 (0)