Riju21

15_practice3_square_root_asciil_val

Mar 27th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import math
  2.  
  3. # find ASCII value
  4. # ---------------------------
  5.  
  6. # number to char: char(var)
  7. # char to no: ord(var)
  8.  
  9. # x = 'CAT'
  10. # toList = [i for i in x]
  11. # result = 0
  12. # for i in toList:
  13. #     result+=ord(i)
  14. # print(result)
  15.  
  16.  
  17. # find it is square root or not
  18. #---------------------------------
  19.  
  20. y = [4, 10, 64, 99, 25]
  21.  
  22. for i in y:
  23.     # find the square root value & convert into string
  24.     rootVal = str(math.sqrt(i))
  25.     #convert into list
  26.     rootvalToList = rootVal.split('.')
  27.     #convert the str list into int list
  28.     rootvalListToInt = list(map(int, rootvalToList))
  29.     # check the 2nd index is 0 or not
  30.     if rootvalListToInt[1] == 0:  
  31.          print('yes')
  32.     else:
  33.         print('no')
Advertisement
Add Comment
Please, Sign In to add comment