Skip to content

Commit a564f39

Browse files
author
steven.chen3
committed
commit helloworld first time
1 parent a49d61c commit a564f39

9 files changed

Lines changed: 157 additions & 0 deletions

File tree

helloworld/child1/__init__.py

Whitespace-only changes.

helloworld/child1/sub/__init__.py

Whitespace-only changes.

helloworld/child1/sub/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
def add(a: int, b: int) -> int:
3+
return a + b
4+
5+
6+
def sub(a: int, b: int) -> int:
7+
return a - b
8+
9+
10+
if __name__ == '__main__':
11+
print('This is utils')

helloworld/ex_grade_10.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tip = 'Please input a grade: '
2+
str_grade = input(tip)
3+
grade = int(str_grade)
4+
5+
if grade < 0 or grade > 100:
6+
print("Invalid grade")
7+
elif grade <= 59:
8+
print('Not pass')
9+
elif grade <= 75:
10+
print('Pass')
11+
elif grade <= 85:
12+
print('Good')
13+
else:
14+
print("Excellent")

helloworld/ex_list_22.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def get_user_input() -> list:
2+
result_list = []
3+
while True:
4+
s_grade = input("Enter a grade(type 'exit' to quit):")
5+
if s_grade == 'exit':
6+
break
7+
8+
result_list.append(int(s_grade))
9+
10+
return result_list
11+
12+
13+
def get_average(grade_list: list) -> float:
14+
count = len(grade_list)
15+
16+
if count == 0:
17+
return 0
18+
19+
total = 0
20+
for g in grade_list:
21+
total = total + g
22+
23+
return total / count
24+
25+
26+
def get_grades_above_average(grade_list: list, average: float) -> list:
27+
res_list = []
28+
for g in grade_list:
29+
if g > average:
30+
res_list.append(g)
31+
32+
return res_list
33+
34+
35+
grade_list = get_user_input()
36+
average = get_average(grade_list)
37+
grades_above_average = get_grades_above_average(grade_list, average)
38+
39+
print(f'Average: {average}')
40+
print(f'Grades above average: {grades_above_average}')

helloworld/ex_recursive_19.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# sample 1: print sequence
2+
def print_sequence(n: int):
3+
print(n)
4+
5+
next_num = n - 1
6+
if next_num > 0:
7+
print_sequence(next_num)
8+
9+
10+
print_sequence(10)
11+
12+
13+
# sample 2: summary a sequence
14+
def summary(n):
15+
if n == 1:
16+
return 1
17+
18+
return n + summary(n - 1)
19+
20+
21+
print(summary(100))
22+
23+
24+
# sample 3: n!
25+
def nn(n):
26+
if n == 1:
27+
return 1
28+
29+
return n * nn(n - 1)
30+
31+
32+
print(nn(4))
33+

helloworld/ex_sum_12.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tip = 'Enter number '
2+
s_num1 = input(tip + '1: ')
3+
s_num2 = input(tip + '2: ')
4+
5+
start = int(s_num1)
6+
stop = int(s_num2) + 1
7+
8+
result = 0
9+
for num in range(start, stop):
10+
result = num + result
11+
12+
print(f'Summary: {result}')
13+
14+
15+
# 1: num + result -> result
16+
# 2: num + result -> result
17+
# 3: num + result -> result

helloworld/ex_while_14.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
tip = 'Please enter a grade(type "exit" to quit): '
2+
3+
summary = 0
4+
count = 0
5+
running = True
6+
while running:
7+
s_grade = input(tip)
8+
if s_grade == 'exit':
9+
running = False
10+
else:
11+
grade = int(s_grade)
12+
13+
if grade < 0 or grade > 100:
14+
print('Invalid grade')
15+
else:
16+
summary = summary + grade
17+
count = count + 1
18+
19+
if grade < 59:
20+
print('Not pass')
21+
elif grade < 75:
22+
print('Pass')
23+
elif grade < 85:
24+
print('Good')
25+
else:
26+
print("Excellent")
27+
28+
average = summary / count
29+
print(f'Average: {average}')

helloworld/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
3+
4+
def main():
5+
args = sys.argv[1:]
6+
7+
for arg in args:
8+
print(arg)
9+
10+
11+
if __name__ == '__main__':
12+
main()
13+

0 commit comments

Comments
 (0)