2021-11-04
Max. 25 points
Name:
| Task | Max. | Achieved |
|---|---|---|
| 1 | 2 | |
| 2 | 6 | |
| 3 | 2 | |
| 4 | 5 | |
| 5 | 10 | |
| Sum | 25 |
x = 5
y = 2 * x**2 + 2 * x - 7
print(y)
n = 10
d = 6
work = True
while work:
if n / d == 0:
print (d)
work = False
d -= 1
s = "Everyone wants to become a great programmer."
print (s[3], s[-2])
for loop as while loop.
for i in range(0, 10, 3):
print(f'{i} * {i} = {i * i}')
i = 0
while i < 10:
print(f'{i} * {i} = {i * i}')
i += 3
needle
should be searched in all of the files in the list of relative
filenames. The program should count the non-overlapping
occurrences of needle in all the given files and print it
to standard output. The comparison must not be case sensitive. Use the
string class' S.count(sub[, start[, end]]) -> int
method which returns the number of non-overlapping occurrences of substring
sub in string S[start:end].
#!/usr/bin/env python
filenames = input('Files: ')
needle = input('Needle: ').lower()
matches = 0
filenames = filenames.split(',') # create list of filenames
for filename in filenames:
with open(filename) as f:
content = f.read().lower()
matches += content.count(needle)
print(matches)