From f69b705445d85f56ce79261223b43a63e6ac541a Mon Sep 17 00:00:00 2001 From: ViburPLP <159889417+ViburPLP@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:45:49 +0300 Subject: [PATCH 1/2] Update conditions.py --- conditions.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/conditions.py b/conditions.py index 8ff3d8e..de2b284 100644 --- a/conditions.py +++ b/conditions.py @@ -1,21 +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.") +age= int(input("How old are you?")) +if age >=18: + print('You are eligible to vote') else: - print("You are not eligible to vote.") + print ('You are not eligible to vote') From 85b722a39e55f2a79e46ee821605dabd41c75cca Mon Sep 17 00:00:00 2001 From: ViburPLP <159889417+ViburPLP@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:47:36 +0300 Subject: [PATCH 2/2] Update functions.py --- functions.py | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/functions.py b/functions.py index c80ee3c..d9fab38 100644 --- a/functions.py +++ b/functions.py @@ -1,32 +1,12 @@ def fibonacci(n): - """ - This function generates the Fibonacci sequence up to a specified term n using iteration. + fibo_seq= [0, 1] + while len(fibo_seq) < n: + fibo_seq.append(fibo_seq[-1] + fibo_seq[-2]) + return fibo_seq[:n] + +n= int (input("input number of terms in the fibonacci sequence")) - Args: - n: The number of terms in the Fibonacci sequence. +fibo_seq=fibonacci(n) - Returns: - A list containing the Fibonacci sequence up to n terms. - """ - fibonacci_sequence = [] - if n <= 0: - return fibonacci_sequence - elif n == 1: - fibonacci_sequence.append(0) - 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) - -# Print the Fibonacci sequence -print(fibonacci_sequence) +print(f'fibonacci sequence up to term {n}: {fibo_seq}') +