-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExam_1.py
149 lines (124 loc) · 3.29 KB
/
Exam_1.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Jacob Auman
# First exam Due 1/20/23
properDivisor = []
def is_integer(num):
if num == round(num):
return True
else:
return False
def marvelNumber(num):
if num < 0:
num = num * (-1)
for i in range(1, int(num) + 1):
divisor = num / i
i = i + 1
# Check if each divisor is valid
if divisor != num and is_integer(divisor) == True:
properDivisor.append(divisor)
if sum(properDivisor) == num:
return True
else:
return False
print(marvelNumber(28))
def askForInput():
while input('Would you like to try again? Y/N \n') != 'N':
num = input('Enter your number ')
if marvelNumber(num) == True:
print(f'{num} is a Marvel Number!')
else:
print(f'{num} is not Marvel Number.')
# Verification and Validation
#
# print(f'Testing Integer {num}')
# print(is_integer(num))
#
# print(f'Testing Marvel {num}')
# print(marvelNumber(num))
# '''
# A marvel number is a positive integer that is equal to the
# sum of its proper divisors. The smallest marvel number is 6,
# which is the sum of 1, 2, and 3. In other words, a marvel number is a
# number where all of the numbers it is divisible by *OTHER THAN ITSELF*
# added up equal the number – this does include 1.
#
#
# If the number is a marvel number the function should return True, if it is not
# the function should return False.
#
# Parameters
# ----------
# num : int
#
# Returns
# -------
# boolean
# True if num is a marvel number
# False if num is not a marvel number
#
# Tip: You may want to use some sort of loop to find all
# of the possible divisors and do your adding as you find
# divisors, not at the very end.
#
# '''
def agesAndStages(yearOld):
yearOld= float(yearOld)
if yearOld < 1:
stage = "baby"
elif 1 <= yearOld < 3:
stage = "toddler"
elif 3 <= yearOld < 5:
stage = "preschool"
elif 5 <= yearOld < 13:
stage = "gradeschooler"
elif 13 <= yearOld < 18:
stage = "teenager"
elif 18 <= yearOld:
stage = "adult"
return stage
print(agesAndStages(int(input('Input age '))))
# '''
# Returns the appropriated message considering the
# age of a person based in the following rules:
# < 1 years old --> "baby"
# 1-2 years old --> "toddler"
# 3-4 years old --> "preschool"
# 5-12 years old --> "gradeschooler"
# 13-18 years old --> "teenager"
# > 18 --> adult
#
# Parameters
# ----------
# yearOld : float
#
#
# Returns
# -------
# String with the appropriated message considering the
# rules above described.
#
# '''
# Output Validation
# if agesAndStages(0) == "baby":
# print("True")
# else:
# print("False")
# if agesAndStages(1) == "toddler":
# print("True")
# else:
# print("False")
# if agesAndStages(2) == "toddler":
# print("True")
# else:
# print ("False")
# if agesAndStages(3) == "preschool":
# print("True")
# else:
# print ("False")
# if agesAndStages(5) == "gradeschooler":
# print("True")
# else:
# print ("False")
# if agesAndStages(21) == "adult":
# print("True")
# else:
# print ("False")