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
19 changes: 8 additions & 11 deletions conditions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# 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."
# Prompts the user to enter their age
age = int(input("Enter your age: "))

# Use a conditional statement to check if the age is greater than or equal to 18
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
15 changes: 9 additions & 6 deletions functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Functions & Fibonacci Sequence
# Question
# Write a Python program to generate the Fibonacci sequence up to a specified term n. The Fibonacci sequence starts with 0 and 1, and each subsequent term is the sum of the two preceding terms.
#We have provided you with in-complete code, from the Knowledge learned from week 1 to week 3 please complete the missing parts to achieve the goal of the question.
def fibonacci(n):
Expand All @@ -12,14 +10,19 @@ def fibonacci(n):
Returns:
A list containing the Fibonacci sequence up to n terms.
"""
fib_sequence = []
if n <= 1:
# Complete here
print("Please enter a positive integer.")
elif n == 1:
fib_sequence.append(0)
else:
a, b = # complete here
a, b = 0, 1
fib_sequence.extend([a, b])
for _ in range(2, n + 1):
c = a + b
# Complete here
return # add the variable to be returned
fib_sequence.append(c)
a, b = b, c
return fib_sequence # Return the generated Fibonacci sequence

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