migration from cloud service
This commit is contained in:
26
week3/ex1.py
Normal file
26
week3/ex1.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def main():
|
||||
print('==Exercise 1==')
|
||||
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 A+B={a+b}")
|
||||
|
||||
print('==End Of Ex1==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
12
week3/ex2.py
Normal file
12
week3/ex2.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def main():
|
||||
list = ['My', 'Name', 'Is', 'James']
|
||||
|
||||
print('==Exercise 2==')
|
||||
print(f'Raw print: {list}')
|
||||
print(f'Spaced print: {list}',sep=" ")
|
||||
print(f'stared print: {list}',sep="**")
|
||||
print('==End Of Ex2==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
39
week3/ex3.py
Normal file
39
week3/ex3.py
Normal file
@@ -0,0 +1,39 @@
|
||||
def main():
|
||||
usingJSON = False
|
||||
al = []
|
||||
print('==Exercise 3==')
|
||||
if not usingJSON:
|
||||
print('''I have a method to input all 5 floats in one time using JSON.
|
||||
Pls set usingJSON = True in source code to try it.''')
|
||||
for i in range(5):
|
||||
flag=True
|
||||
while flag:
|
||||
a = input(f"pls input float {i+1}:")
|
||||
try:
|
||||
a = float(a)
|
||||
flag=False
|
||||
al.append(a)
|
||||
except :
|
||||
print("pls input a float!")
|
||||
print(al)
|
||||
else:
|
||||
import json
|
||||
print("In this case you need to enter a JSON string of the whole list.")
|
||||
flag=True
|
||||
while flag:
|
||||
a = input("pls input float[] JSON:")
|
||||
try:
|
||||
a = json.loads(a)
|
||||
states = [True if type(i)==float else False for i in a]
|
||||
if False in states:
|
||||
print(f"Error! not a float[]!\nCurrent Input:{a}")
|
||||
raise ValueError("Not a float[]")
|
||||
flag=False
|
||||
al.append(a)
|
||||
except :
|
||||
print("pls input a proper float[]!")
|
||||
print('==End Of Ex3==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
12
week3/ex4.py
Normal file
12
week3/ex4.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def main():
|
||||
totalMoney = 1000
|
||||
quantity = 3
|
||||
price = 450
|
||||
|
||||
print('==Exercise 4==')
|
||||
print('I have {0} dollars so I can buy {1} football for {2:.2f} dollars.'.format(totalMoney,quantity,price))
|
||||
print('==End Of Ex4==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
14
week3/ex5.py
Normal file
14
week3/ex5.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def main():
|
||||
list1 = ["M", "na", "i", "Ke"]
|
||||
list2 = ["y", "me", "s", "lly"]
|
||||
|
||||
list3 = [f'{list1[i]}{list2[i]}' for i in range(len(list1))]
|
||||
|
||||
|
||||
print('==Exercise 5==')
|
||||
print(list3)
|
||||
print('==End Of Ex5==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
15
week3/ex6.py
Normal file
15
week3/ex6.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def main():
|
||||
list1 = ["Hello ", "take "]
|
||||
list2 = ["Dear", "Sir"]
|
||||
|
||||
mtx = [[0,0],[0,1],[1,0],[1,1]]
|
||||
|
||||
list3 = [f'{list1[mtx[i][0]]}{list2[mtx[i][1]]}' for i in range(len(mtx))]
|
||||
|
||||
print('==Exercise 6==')
|
||||
print(list3)
|
||||
print('==End Of Ex6==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
7
week3/run_all.py
Normal file
7
week3/run_all.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import ex1,ex2,ex3,ex4,ex5,ex6
|
||||
ex1.main()
|
||||
ex2.main()
|
||||
ex3.main()
|
||||
ex4.main()
|
||||
ex5.main()
|
||||
ex6.main()
|
||||
Reference in New Issue
Block a user