Advertisement
angryatti

Array Even or Odd + Read from File

Jun 18th, 2022 (edited)
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def readfile(file):
  2.     with open(file,"r",encoding="utf-8") as read:
  3.         templist=list()
  4.         arrayofcucc=list()
  5.         for row in read:
  6.             templist=row.strip().split(",")
  7.             for i in range(0,len(templist),1):
  8.                 if templist[i].isnumeric() == True:
  9.  
  10.                     arrayofcucc.append(int(templist[i]))
  11.                 else:
  12.                     print("The file contains text or special character that won't being listed")
  13.        
  14.     return arrayofcucc
  15.  
  16. def checkeven(lst):
  17.     return [str(a)+" even" if a %2 ==0 else str(a)+" odd" for a in lst ]
  18.  
  19. lstdefault=list()
  20.  
  21. lstdefault=readfile("num.txt")
  22.  
  23. lst = [1,4,10,12,15]
  24.  
  25. choice=input("From file or forced? 1) 2)")
  26.  
  27. if choice=="1":
  28.     print(checkeven(lstdefault))
  29. elif choice=="2":
  30.     print(checkeven(lst))
  31. else:
  32.     print("No array or file selected")
  33.  
  34. #__________________________________
  35. # Txt contain any length of number separated with ","
  36. 1,2,3,5,111,122,1110
  37. 40,20,30
  38. 100,200,300
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement