-
Notifications
You must be signed in to change notification settings - Fork 0
/
score_functions.py
82 lines (62 loc) · 1.59 KB
/
score_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def display_results(score):
if score > 90:
print("{} points! Fantastic job!!".format(score))
elif score > 80:
print("{} points! Great!".format(score))
elif score > 70:
print("{} points! Not too bad!".format(score))
elif score > 60:
print("{} points! We could do better!".format(score))
elif score > 50:
print("{} points! Almost!".format(score))
else:
print("{} is not so good. Better luck next time!".format(score))
print("Example 1")
userinput = int(input("What did you get?"))
display_results(userinput)
print("*********************")
print("Example 2")
scores = [34, 55, 98, 73, 65, 88, 10]
for mark in scores:
display_results(mark)
print("*********************")
print("Example 3")
def square_and_add_three(value):
answer = (value * value) + 3
return answer
print("Did I make it?")
my_value = square_and_add_three(12)
print(my_value)
print("*********************")
print("Example 4")
print("x \t f(x)")
for x in range(-5, 6):
fx = square_and_add_three(x)
print("{} \t {}".format(x, fx))
print("*********************")
print("Example 5\n")
def main():
fun1()
fun2()
fun3()
fun1()
fun3()
def fun1():
print("This is function 1")
def fun2():
print("This is function 2")
def fun3():
print("This is function 3")
main()
print("*********************")
print("Example 6\n")
print("Factorial example")
def factorial_func(n):
num = 1
while n >= 1:
num = num * n
n = n - 1
print(num)
return num
number = int(input("Enter a number to calculate the factorial:\n"))
factorial_func(number)