-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboomGame.py
More file actions
73 lines (59 loc) · 1.42 KB
/
boomGame.py
File metadata and controls
73 lines (59 loc) · 1.42 KB
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
#Question 3
in_file = "our_input.txt"
out_file = "output.txt"
tom = open(in_file, 'r')
out = open(out_file, 'w')
for line in tom:
out.write(str(len(line.split()))+'\n')
out.close()
#**************************************************************
#Question 5
k = 3
n = 100
boom = k
end = n
count = 1
while (count < n+1):
if (str(boom) in str(count) and count % boom == 0):
print ("boom-boom!")
elif (count % boom == 0 or str(boom) in str(count)):
print("boom!")
else:
print(count)
count += 1
#**************************************************************
#Question 6
input_str = input("Please enter a positive integer: ")
#Add the rest of your code here.
#It should handle any positive integer or an arithmetic expression
#at the end, length, start and seq should hold the answers
num = str(eval(input_str))
count = 0
odds = ""
index = -1
seqtemp = ""
ind = 0
length = 0
start = -1
seq = None
for i in num:
if int(i) % 2 != 0:
count += 1
odds += i
else:
if len(odds) > len(seqtemp):
seqtemp = odds
index = ind - count
count = 0
odds = ""
ind += 1
if len(odds) > len(seqtemp):
seqtemp = odds
index = ind - len(odds)
if len(seqtemp) > 0 :
length = len(seqtemp)
start = index
seq = seqtemp
print("The maximal length is", length)
print("Sequence starts at", start)
print("Sequence is", seq)