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
12 changes: 12 additions & 0 deletions conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@
# - 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."
voting_age = 18

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

if age >= voting_age:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

except ValueError:
print("Invalid input: Please enter a valid integer for your age.")
18 changes: 12 additions & 6 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ def fibonacci(n):
A list containing the Fibonacci sequence up to n terms.
"""
if n <= 1:
if n ==0:
return[]
else:
return[0]
# Complete here
else:
a, b = # complete here
for _ in range(2, n + 1):
a, b = 0,1
fibonacci_sequence=[]# complete here
for _ in range(2, n + 1):
c = a + b
fibonacci_sequence.append(c)
a, b=b, c
# Complete here
return # add the variable to be returned
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 = []
for i in range(num_terms):
fibonacci_sequence.append(fibonacci(i))
fibonacci_sequence=fibonacci(num_terms)

# Print the Fibonacci sequence
print(fibonacci_sequence)
Expand Down