I want to add a number to an array with its own numbers but want to avoid duplicate numbers
I tried using a for and a while loop but its not working
I want to add a number to an array with its own numbers but want to avoid duplicate numbers
I tried using a for and a while loop but its not working
 
    
    Try something like this:
import random
# Example array
arr = [2, 4, 6, 8, 10]
# Generate a random number that is not in the array
while True:
    num = random.randint(1, 100)  # Choose a random integer between 1 and 100
    if num not in arr:  # Check if the number is not in the array
        break  # Exit the loop if the number is not in the array
# Add the new number to the array
arr.append(num)
print(arr)  # Print the updated array
