Added week 7
This commit is contained in:
16
week7/Assignment/ex1.py
Normal file
16
week7/Assignment/ex1.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
def main():
|
||||||
|
print('==Assignment 1==')
|
||||||
|
|
||||||
|
lst=["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]
|
||||||
|
|
||||||
|
iterhelper(lst,lambda x:print(f"Hello!, {x}"))
|
||||||
|
|
||||||
|
print('==End Of Assi1==')
|
||||||
|
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()
|
||||||
24
week7/Assignment/ex2.py
Normal file
24
week7/Assignment/ex2.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
def main():
|
||||||
|
print('==Assignment 2==')
|
||||||
|
|
||||||
|
flag=True
|
||||||
|
while flag:
|
||||||
|
a = input("pls input number:")
|
||||||
|
try:
|
||||||
|
a = int(a)
|
||||||
|
flag=False
|
||||||
|
except :
|
||||||
|
print("pls input a number!")
|
||||||
|
|
||||||
|
counter=0
|
||||||
|
total=0
|
||||||
|
|
||||||
|
while counter<a:counter+=1;total+=counter
|
||||||
|
|
||||||
|
print(f"Total from 1 to a: {total}")
|
||||||
|
|
||||||
|
print('==End Of Assi2==')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
20
week7/Assignment/ex3.py
Normal file
20
week7/Assignment/ex3.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
def main():
|
||||||
|
print('==Assignment 3==')
|
||||||
|
|
||||||
|
list1 = [12, 15, 32, 42, 55, 75, 122, 132, 150, 180, 200]
|
||||||
|
|
||||||
|
iterhelper(list1)
|
||||||
|
|
||||||
|
print('==End Of Assi5==')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def iterhelper(lst):
|
||||||
|
itr,lenlst = 0,len(lst)
|
||||||
|
while itr<lenlst:
|
||||||
|
x = lst[itr]
|
||||||
|
if(x%5==0):print(x)
|
||||||
|
if(x>=150):break
|
||||||
|
itr+=1
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
24
week7/Assignment/ex4.py
Normal file
24
week7/Assignment/ex4.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
def main():
|
||||||
|
print('==Assignment 4==')
|
||||||
|
|
||||||
|
flag=True
|
||||||
|
while flag:
|
||||||
|
a = input("pls input number:")
|
||||||
|
try:
|
||||||
|
a = int(a)
|
||||||
|
flag=False
|
||||||
|
except :
|
||||||
|
print("pls input a number!")
|
||||||
|
|
||||||
|
counter=0
|
||||||
|
total=1
|
||||||
|
|
||||||
|
while counter<a:counter+=1;total*=counter
|
||||||
|
|
||||||
|
print(f"{a}!= {total}")
|
||||||
|
|
||||||
|
print('==End Of Assi4==')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
16
week7/Assignment/ex5.py
Normal file
16
week7/Assignment/ex5.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
def main():
|
||||||
|
print('==Assignment 5==')
|
||||||
|
|
||||||
|
a,s = 5,1 #Custom star nums using a(max width) and s(step)
|
||||||
|
|
||||||
|
c,r = 1,False
|
||||||
|
while c>0:
|
||||||
|
print("*"*c)
|
||||||
|
c+= -s if r else s
|
||||||
|
r = r or c>=a
|
||||||
|
|
||||||
|
print('==End Of Assi5==')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
6
week7/Assignment/run_all.py
Normal file
6
week7/Assignment/run_all.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import ex1,ex2,ex3,ex4,ex5
|
||||||
|
ex1.main()
|
||||||
|
ex2.main()
|
||||||
|
ex3.main()
|
||||||
|
ex4.main()
|
||||||
|
ex5.main()
|
||||||
15
week7/Exercises/ex1.py
Normal file
15
week7/Exercises/ex1.py
Normal 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
21
week7/Exercises/ex2.py
Normal 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
20
week7/Exercises/ex3.py
Normal 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()
|
||||||
4
week7/Exercises/run_all.py
Normal file
4
week7/Exercises/run_all.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import ex1,ex2,ex3
|
||||||
|
ex1.main()
|
||||||
|
ex2.main()
|
||||||
|
ex3.main()
|
||||||
Reference in New Issue
Block a user