Python Array Example - Create array with fixed size elements

Published November 16, 2021


In this python array example, Ask the user to enter numbers. If the user enter number between 10 to 100 store them in array other wise display message "Outside the Range". If the list contains five items then display  message "Thank you " and disply entered list items

 

from array import *
nums=array('i',[])

while len(nums)<5:
   num=int(raw_input("Enter a number between 10 and 100: "))
   if num>=10 and num <=100:
       nums.append(num)
   else: 
      print("Outside the Range")

for i in nums:
   print(i)

 

In the above program

Created array num

Output:

Enter a number between 10 and 100: 21
Enter a number between 10 and 100: 23
Enter a number between 10 and 100: 400
Outside the Range
Enter a number between 10 and 100: 12
Enter a number between 10 and 100: 34
Enter a number between 10 and 100: 45
21
23
12
34
45

 


Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

20 Views

Subscribe For Daily Updates

Flutter Questions
Android Questions