-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-Fibonacci Sequence.py
More file actions
36 lines (29 loc) · 1.81 KB
/
5-Fibonacci Sequence.py
File metadata and controls
36 lines (29 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def main():
# Corrected Code: Initialize the first two terms of the Fibonacci sequence
number = 0 # Original: number = 0 # First term in the sequence
number_two = 1 # Original: number_two = 1 # Second term in the sequence
# Corrected Code: Get user input for the number of terms in the Fibonacci sequence
number_of_terms = int(input("Enter the number of terms for the Fibonacci sequence: "))
# Original: number_three = int(input("Enter a number for what a you are looking for the sequenence : "))
# Remove extra variable; only `number_of_terms` is needed for loop count
# Original: number_four = number_three
# Corrected Code: Check if input is valid (should be > 0)
if number_of_terms <= 0: # Original: if number_four == 0:
print("The number of terms should be greater than 0.")
# Original: print("should be greater than 0")
else:
print("Fibonacci sequence:") # Added to make output clear for user
# Use a `for` loop for fixed iterations to generate sequence terms
for _ in range(number_of_terms): # Original: while n < number_four:
print(number, end=" ") # Print the current term (in one line)
# Original: # No print statement here to print sequence term correctly
# Calculate the next term in the Fibonacci sequence
next_term = number + number_two # Original: result = number + number_two
# Update terms for the next iteration
number = number_two # Original: # Missing code to update terms
number_two = next_term # Original: # Missing code to update terms
# Run the main function
if __name__ == "__main__":
main()
# Original: if __name__ == "__main__":
# main()