From ee2b9b781859d50fb30c2450a6faead99168f702 Mon Sep 17 00:00:00 2001 From: dennisobare Date: Tue, 19 Mar 2024 11:41:51 +0300 Subject: [PATCH] Completed the conditions and functions assignments --- conditions.py | 5 +++++ functions.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/conditions.py b/conditions.py index 1499e63..84ebf42 100644 --- a/conditions.py +++ b/conditions.py @@ -7,5 +7,10 @@ # - Prompts a user to enter their age. +age = int(input("How old are you? ")) # - Uses a conditional statement to check if the age is greater than or equal to 18. +if age >= 18: # - Prints "You are eligible to vote" if true, otherwise "You are not eligible to vote." + print("You are eligible to vote.") +else: + print("You are not eligible to vote.") diff --git a/functions.py b/functions.py index 0d458e4..de120dd 100644 --- a/functions.py +++ b/functions.py @@ -13,21 +13,21 @@ def fibonacci(n): A list containing the Fibonacci sequence up to n terms. """ if n <= 1: - # Complete here + return [0, 1] else: - a, b = # complete here - for _ in range(2, n + 1): + fibonacci_list = [0,1] + a, b = 0, 1 + for _ in range(2, n): c = a + b - # Complete here - return # add the variable to be returned + fibonacci_list.append(c) + a, b = b, c + return fibonacci_list # 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)