Python Array Example - Check array elements availability count
Published November 16, 2021In this python array example, Create an Array which contains 10 numbers (one can be multiple times), display whole array to user, then ask user to enter one of the numbers from the array and then display a message that how many times that number appears in the list
Let's write program
from array import * nums = array('i', [1, 7, 5, 7, 2,22,7,92,100]) for i in nums: print(i) num = int(raw_input("Enter a number: ")) if nums.count(num) == 1: print(num, " Is in the list once") else: print(num, " is in the list ", nums.count(num), " times") |
Output:
1 7 5 7 2 22 7 92 100 Enter a number: 7 (7, ' is in the list ', 3, ' times') |
Article Contributed By :
|
|
|
|
799 Views |