n=int(input("Enter the number till you want to check: "))
primes = []
for i in range (2, n+1):
for j in range(2, i):
if i%j == 0:
break
else:
primes.append(i)
print("Prime Numbers: ",primes)
print("Count of prime numbers: ", len(primes))
Output:
Enter the number till you want to check: 11
Prime Numbers: [2, 3, 5, 7, 11]
Count of prime numbers: 5
Elements in lists maintain their ordering unless they are explicitly commanded to be re-ordered. They can be of any data type, they can all be the same, or they can be mixed. Elements in lists are always accessed through numeric, zero-based indices.
In a dictionary, each entry will have a key and a value, but the order will not be guaranteed. Elements in the dictionary can be accessed by using their key.
Lists can be used whenever you have a collection of items in an order. A dictionary can be used whenever you have a set of unique keys that map to values.
Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.