Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions conditions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
# Python Conditional Statements
#example is https://plpacademy.powerlearnproject.org/course-module/62fbec9d28ac4762bc524f92/week/62fe1efd28ac4762bc524f9c/lesson/62fe1fbd28ac4762bc524f9f



# Create a Python program that:


# - Prompts a user to enter their age.
# - Uses a conditional statement to check if the age is greater than or equal to 18.
# - Prints "You are eligible to vote" if true, otherwise "You are not eligible to vote."



age = int(input("Enter your age: "))


if age >= 18:
print("You are eligible to vote.")
else:
Expand Down
36 changes: 10 additions & 26 deletions functions.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
def fibonacci(n):
"""
This function generates the Fibonacci sequence up to a specified term n using iteration.

Args:
n: The number of terms in the Fibonacci sequence.

Returns:
A list containing the Fibonacci sequence up to n terms.
"""
fibonacci_sequence = []
def generate_fibonacci(n):
if n <= 0:
return fibonacci_sequence
return []
elif n == 1:
fibonacci_sequence.append(0)
return [0]
elif n == 2:
return [0, 1]
else:
fibonacci_sequence.extend([0, 1]) # If n is greater than 1, add the first two terms (0 and 1) to the sequence
a, b = 0, 1
sequence = [0, 1]
for _ in range(2, n):
c = a + b
fibonacci_sequence.append(c)
a, b = b, c
return fibonacci_sequence

# Get the number of terms from the user
num_terms = int(input("Enter the number of terms: "))

# Generate the Fibonacci sequence
fibonacci_sequence = fibonacci(num_terms)
sequence.append(sequence[-1] + sequence[-2])
return sequence

# Print the Fibonacci sequence
n = int(input("Enter the number of terms: "))
fibonacci_sequence = generate_fibonacci(n)
print(fibonacci_sequence)