forked from Hamzah133/Python_Basics_Test
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbasic_functions.py
More file actions
83 lines (66 loc) · 2.72 KB
/
Copy pathbasic_functions.py
File metadata and controls
83 lines (66 loc) · 2.72 KB
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
def add(num1, num2):
pass # Implement addition
def subtract(num1, num2):
pass # Implement subtraction
def multiply(num1, num2):
pass # Implement multiplication
def divide(num1, num2):
pass # Implement division with zero division check
def fizz_buzz(number):
pass # Implement FizzBuzz logic
def fibonacci(n):
pass # Implement Fibonacci sequence logic
def triangle(n):
pass # Implement triangle generation logic
def return_list_stats(numbers):
"""Given the list 'numbers', use the relevant functions to return a
dictionary of statics for the list. This dictionary must have
the following keys:
unique_numbers : a set containing unique numbers from the list 'numbers',
max : largest number in the list 'numbers',
min : smallest number in the list 'numbers',
average : average of the numbers in the list 'numbers',
even_pairs : a list of tuples that have neighboring pairs
that sum up to an even number in the list 'numbers',
odd_pairs : a list of tuples that have neighboring pairs
that sum up to an even number in the list 'numbers',
even_numbers : a tuple of all the even numbers in the list
'numbers',
odd_numbers : a tuple of all the odd numbers in the list
'numbers',
number_of_even_numbers : the total number of even numbers in the
list 'numbers',
number_of_odd_numbers : the total number of even numbers in the list
'numbers'
"""
pass
# TODO: (Bonus) Implement the pascal_triangle function below
def pascal_triangle(n):
"""
Generates Pascal's triangle and returns the final row as a list.
Parameters:
n (int): The row number of Pascal's triangle to generate (0-based index).
Returns:
list: The final row of Pascal's triangle as a list.
Formula for Pascal's Triangle:
Each element in Pascal's triangle can be calculated using the following formula:
C(n, k) = n! / (k! * (n-k)!)
Where:
- n is the row number (0-based index)
- k is the column number (0-based index)
- C(n, k) represents the value at row n and column k in Pascal's triangle
- n! represents the factorial of n
To generate a row of Pascal's triangle, iterate over the columns from 0 to n.
Calculate each element using the formula and store them in a list to form the row.
Repeat this process for each row up to the desired row number.
Example:
* Input: n = 6
* Output:
* 1
* 1 1
* 1 2 1
* 1 3 3 1
* 1 4 6 4 1
* 1 5 10 10 5 1
"""
pass