migration from cloud service
This commit is contained in:
48
week4/ex1.py
Normal file
48
week4/ex1.py
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
|
||||
def main():
|
||||
print('==Exercise 1==')
|
||||
SEPREATE_VAR_WORD_ALL="all"
|
||||
SEPREATE_VAR_WORD_WORK="work"
|
||||
SEPREATE_VAR_WORD_AND="and"
|
||||
SEPREATE_VAR_WORD_NO="no"
|
||||
SEPREATE_VAR_WORD_PLAY="play"
|
||||
SEPREATE_VAR_WORD_MAKE="make"
|
||||
SEPREATE_VAR_WORD_JACK="Jack"
|
||||
SEPREATE_VAR_WORD_A="a"
|
||||
SEPREATE_VAR_WORD_DULL="dull"
|
||||
SEPREATE_VAR_WORD_BOY="boy"
|
||||
SEPREATE_VAR_WORD_DOT="."
|
||||
|
||||
print(SEPREATE_VAR_WORD_ALL.capitalize(),
|
||||
SEPREATE_VAR_WORD_WORK,
|
||||
SEPREATE_VAR_WORD_AND,
|
||||
SEPREATE_VAR_WORD_NO,
|
||||
SEPREATE_VAR_WORD_PLAY,
|
||||
SEPREATE_VAR_WORD_MAKE,
|
||||
SEPREATE_VAR_WORD_JACK,
|
||||
SEPREATE_VAR_WORD_A,
|
||||
SEPREATE_VAR_WORD_DULL,
|
||||
SEPREATE_VAR_WORD_BOY,
|
||||
end=SEPREATE_VAR_WORD_DOT)
|
||||
|
||||
print('pls ignore the following line if youre using windows\' default cmd prompt e.g. cmd.exe. using bash to make it display properly.')
|
||||
|
||||
print('\033[3m\t',
|
||||
SEPREATE_VAR_WORD_ALL.capitalize(),
|
||||
SEPREATE_VAR_WORD_WORK,
|
||||
SEPREATE_VAR_WORD_AND,
|
||||
SEPREATE_VAR_WORD_NO,
|
||||
SEPREATE_VAR_WORD_PLAY,
|
||||
SEPREATE_VAR_WORD_MAKE,
|
||||
SEPREATE_VAR_WORD_JACK,
|
||||
SEPREATE_VAR_WORD_A,
|
||||
SEPREATE_VAR_WORD_DULL,
|
||||
SEPREATE_VAR_WORD_BOY,
|
||||
end=SEPREATE_VAR_WORD_DOT)
|
||||
|
||||
print('==End Of Ex1==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
27
week4/ex2.py
Normal file
27
week4/ex2.py
Normal file
@@ -0,0 +1,27 @@
|
||||
def main():
|
||||
print('==Exercise 2==')
|
||||
print('formula: s=3.14 * (1+a/b)^3')
|
||||
flag = True
|
||||
while flag:
|
||||
a = input("pls input number a:")
|
||||
try:
|
||||
a = int(a)
|
||||
flag=False
|
||||
except :
|
||||
print("pls input a number!")
|
||||
flag=True
|
||||
while flag:
|
||||
b = input("pls input number b:")
|
||||
try:
|
||||
b = int(b)
|
||||
flag=False
|
||||
except :
|
||||
print("pls input a number!")
|
||||
|
||||
print(f"The result for S= {3.14*(1+(a+b)**3)}")
|
||||
|
||||
print('==End Of Ex2==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
26
week4/ex3.py
Normal file
26
week4/ex3.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def main():
|
||||
print('==Exercise 3==')
|
||||
flag=True
|
||||
while flag:
|
||||
a = input("pls input first side length:")
|
||||
try:
|
||||
a = float(a)
|
||||
flag=False
|
||||
except :
|
||||
print("pls input a float!")
|
||||
flag=True
|
||||
while flag:
|
||||
b = input("pls input another side length:")
|
||||
try:
|
||||
b = float(b)
|
||||
flag=False
|
||||
except :
|
||||
print("pls input a float!")
|
||||
|
||||
print(f"The lenth of the hypotenuse= {sum([i**2 for i in [a,b]])**0.5}")
|
||||
|
||||
print('==End Of Ex3==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
33
week4/ex4.py
Normal file
33
week4/ex4.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def main():
|
||||
from random import randint
|
||||
print('==Exercise 4==')
|
||||
LIST_A = [1,2.0,'c',{"id":4}]
|
||||
LIST_B = [randint(1,100) for i in range(10)]
|
||||
LIST_C = [*[chr(i+65) for i in range(10)],27,28.0]
|
||||
|
||||
print('Lists Initial Values:')
|
||||
print(f'{i["idtf"]}: {i["value"]}' for i in [
|
||||
{"idtf":"List A","value":LIST_A},
|
||||
{"idtf":"List B","value":LIST_B},
|
||||
{"idtf":"List C","value":LIST_C},
|
||||
])
|
||||
|
||||
print('a range of items: ',LIST_C[:-3])
|
||||
print('reverse print of list: ',LIST_C[::-1])
|
||||
|
||||
popped_item = LIST_C.pop(3)
|
||||
print(f'Deleted 4th item(index=3)={popped_item} from list C: {LIST_C}')
|
||||
|
||||
LIST_C.insert(5,LIST_A)
|
||||
print(f'Insert items from list A to list C start from pos5(index=4): {LIST_A}')
|
||||
|
||||
LIST_B.sort()
|
||||
print('sorting List B:',LIST_B)
|
||||
|
||||
print('number of similar items in the list B: ',sum([1 if LIST_B[i] in LIST_B[i+1:] else 0 for i in range(len(LIST_B))]))
|
||||
|
||||
print('==End Of Ex4==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
12
week4/ex5.py
Normal file
12
week4/ex5.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def main():
|
||||
print('==Exercise 5==')
|
||||
scores = [90,36,78,59,85,98,73,88,100,65]
|
||||
scores.sort()
|
||||
scores = scores[::-1]
|
||||
print(scores,"\nMax score:",max(scores),"\nAvg score:",sum(scores)/len(scores))
|
||||
|
||||
print('==End Of Ex5==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
6
week4/run_all.py
Normal file
6
week4/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()
|
||||
Reference in New Issue
Block a user