Added week 7

This commit is contained in:
2026-04-20 09:35:37 +08:00
parent 9b90ac4340
commit 734ca9d761
10 changed files with 166 additions and 0 deletions

15
week7/Exercises/ex1.py Normal file
View File

@@ -0,0 +1,15 @@
def main():
print('==Exercise 1==')
counter=0
total=0
while counter<100:counter+=1;total+=counter
print(f"Total: {total}")
print('==End Of Ex1==')
return 0
if __name__ == '__main__':
main()

21
week7/Exercises/ex2.py Normal file
View File

@@ -0,0 +1,21 @@
def main():
print('==Exercise 2==')
lst=[10, 99, 98, 85, 45, 59, 65, 66, 76, 12, 35, 13, 100, 80, 95]
print(f"List:{lst}")
itr,lenlst = 0,len(lst)
while itr<lenlst:
if lst[itr]==100: print(f"There is a 100 at index no: {itr}")
itr+=1
print('==End Of Ex2==')
return 0
def iterhelper(lst,lambda_exec):
itr,lenlst = 0,len(lst)
while itr<lenlst:lambda_exec(lst[itr]);itr+=1
if __name__ == '__main__':
main()

20
week7/Exercises/ex3.py Normal file
View File

@@ -0,0 +1,20 @@
def main():
print('==Exercise 3==')
lst1=["Joe", "Sarah", "Mike", "Jess", "", "Matt", "", "Greg"]
print(f"List:{lst1}")
lst2=[]
itr,lenlst = 0,len(lst1)
while itr<lenlst:
if lst1[itr]: lst2.append(lst1[itr])
itr+=1
print(f"New List:{lst2}")
print('==End Of Ex3==')
return 0
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,4 @@
import ex1,ex2,ex3
ex1.main()
ex2.main()
ex3.main()