I am trying to search for a number in a tuple using a while loop in Python. The program finds the element , but it does not stop and continues to run until the end of the tuple. Here is my code:
numbers=(2,4,6,8,10,12)
x= int(input("Enter a number to search: "))
i=0
while i < len(numbers):
if numbers[i] == x:
print("Number found at index", i)
i+=1
Even when the number is found , the loop keeps running.
What i want:
Stop the loop as soon as the element is found
Also know if there is more pythonic way to do this
Expected output example: If user enters 6
Output: Number found at index 2
How to fix this code and improve it?