diff --git a/conditions.py b/conditions.py index 8ff3d8e..9632f50 100644 --- a/conditions.py +++ b/conditions.py @@ -1,21 +1,9 @@ -# 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: - print("You are not eligible to vote.") +def main(): + age = int(input("Enter your age: ")) + if age >= 18: + print("You are eligible to vote.") + else: + print("You are not eligible to vote.") + +if __name__ == "__main__": + main() diff --git a/functions.py b/functions.py index c80ee3c..0bee930 100644 --- a/functions.py +++ b/functions.py @@ -1,32 +1,17 @@ -def fibonacci(n): - """ - This function generates the Fibonacci sequence up to a specified term n using iteration. +def generate_fibonacci_sequence(n): + fibonacci_sequence = [0, 1] # Initialize the sequence with the first two terms + for i in range(2, n): + next_term = fibonacci_sequence[-1] + fibonacci_sequence[-2] + fibonacci_sequence.append(next_term) + return fibonacci_sequence[:n] - Args: - n: The number of terms in the Fibonacci sequence. - - Returns: - A list containing the Fibonacci sequence up to n terms. - """ - fibonacci_sequence = [] +def main(): + n = int(input("Enter the number of terms for the Fibonacci sequence: ")) if n <= 0: - return fibonacci_sequence - elif n == 1: - fibonacci_sequence.append(0) + print("Please enter a positive integer.") 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 - 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) + fibonacci_sequence = generate_fibonacci_sequence(n) + print("Fibonacci Sequence up to term", n, ":", fibonacci_sequence) -# Print the Fibonacci sequence -print(fibonacci_sequence) +if __name__ == "__main__": + main()