update,
This commit is contained in:
26
ttng1234/Q2/step3.py
Normal file
26
ttng1234/Q2/step3.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
test_list = [ 21,9,17,10 ]
|
||||
|
||||
def triangular_sequence(test_number):
|
||||
# test_number represent the number that sequence should stop at.
|
||||
|
||||
# Initialize the sequence with the first number
|
||||
sequence = [1]
|
||||
|
||||
# Generate the Triangular sequence
|
||||
keep_find = True
|
||||
i = 2
|
||||
while keep_find:
|
||||
next_num = sequence[-1] + i
|
||||
keep_find = next_num < test_number
|
||||
sequence.append(next_num)
|
||||
i = i + 1
|
||||
|
||||
return next_num == test_number
|
||||
|
||||
def check_mathematical_series(n: int) -> str:
|
||||
print(triangular_sequence(n))
|
||||
|
||||
for n in test_list:
|
||||
check_mathematical_series(n)
|
Reference in New Issue
Block a user