joelnazarene

frepy

Jul 12th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.68 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import math
  4. import os
  5. import random
  6. import re
  7. import sys
  8.  
  9.  
  10. #
  11. # Complete the 'calculateNTetrahedralNumber' function below.
  12. #
  13. # The function is expected to return an INTEGER_ARRAY.
  14. # The function accepts following parameters:
  15. #  1. INTEGER startvalue
  16. #  2. INTEGER endvalue
  17. #
  18.  
  19. def calculateNTetrahedralNumber(startvalue, endvalue):
  20.     # Write your code here
  21.     lis = []
  22.     for i in range(startvalue,endvalue + 1):
  23.         a=int((i*(i+1)*(i+2))/6)
  24.         lis.append(a)
  25.     return lis
  26. if __name__ == '__main__':
  27.  
  28. =================================================
  29.  
  30. #!/bin/python3
  31.  
  32. import math
  33. import os
  34. import random
  35. import re
  36. import sys
  37.  
  38.  
  39. #
  40. # Complete the 'sumOfNFibonacciNumbers' function below.
  41. #
  42. # The function is expected to return an INTEGER.
  43. # The function accepts INTEGER n as parameter.
  44. #
  45.  
  46. def sumOfNFibonacciNumbers(n):
  47.     # Write your code here
  48.     if n == 0 or n == 1:
  49.         return 0
  50.    
  51.     fib = [0,1]
  52.     for i in range(n-2):
  53.         a = fib[-1]
  54.         b = fib[-2]
  55.         c = a + b
  56.         fib.append(c)
  57.     sum = 0
  58.     for i in fib:
  59.         sum = sum + i
  60.  
  61.     return sum
  62. if __name__ == '__main__':
  63.  
  64.  
  65. ==========================================================================
  66.  
  67. #!/bin/python3
  68.  
  69. import math
  70. import os
  71. import random
  72. import re
  73. import sys
  74.  
  75.  
  76. #
  77. # Complete the 'Integer_Math' function below.
  78. #
  79. # The function accepts following parameters:
  80. #  1. INTEGER Side
  81. #  2. INTEGER Radius
  82. #
  83.  
  84. def Integer_Math(Side, Radius):
  85.     # Write your code here
  86.     s = Side
  87.     r = Radius
  88.     ars = s*s
  89.     vc = s*s*s
  90.     ac = 3.14*r*r
  91.     vs = ((r*r*r)*4*(3.14))/3
  92.     print("Area of Square is",ars)
  93.     print("Volume of Cube is",vc)
  94.     print("Area of Circle is",ac)
  95.     print("Volume of Sphere is",vs)
  96.  
  97. if __name__ == '__main__':
  98.  
  99. =========================================================================
  100.  
  101. #!/bin/python3
  102.  
  103. import math
  104. import os
  105. import random
  106. import re
  107. import sys
  108.  
  109.  
  110.  
  111. #
  112. # Complete the 'Float_fun' function below.
  113. #
  114. # The function accepts following parameters:
  115. #  1. FLOAT f1
  116. #  2. FLOAT f2
  117. #  3. INTEGER Power
  118. #
  119.  
  120. def Float_fun(f1, f2, Power):
  121.     # Write your code here
  122.         print("#Add")
  123.         print(f1+f2)
  124.         print("#Subtract")
  125.         print(f1-f2)
  126.         print("#Multiply")
  127.         print(f1*f2)
  128.         print("#Divide")
  129.         print(f2/f1)
  130.         print("#Remainder")
  131.         print(f1%f2)
  132.         print("#To_The_Power_Of")
  133.         print(f1**Power)
  134.         print("#Round")
  135.         a = f1**Power
  136.         print("%.4f"%a)
  137.  
  138.  
  139. if __name__ == '__main__':
  140.     f1 = float(input().strip())
  141.  
  142.     f2 = float(input().strip())
  143.  
  144.     Power = int(input().strip())
  145.  
  146.     Float_fun(f1, f2, Power)
  147.  
  148.  
  149.  
  150.  
  151. ===================================================
  152. #!/bin/python3
  153.  
  154. import math
  155. import os
  156. import random
  157. import re
  158. import sys
  159.  
  160.  
  161.  
  162. #
  163. # Complete the 'resume' function below.
  164. #
  165. # The function is expected to print a STRING.
  166. # The function accepts following parameters:
  167. #  1. STRING first
  168. #  2. STRING second
  169. #  3. STRING parent
  170. #  4. STRING city
  171. #  5. STRING phone
  172. #  6. STRING start
  173. #  7. STRING strfind
  174. #  8. STRING string1
  175. #
  176.  
  177. def resume(first, second, parent, city, phone, start, strfind, string1):
  178.     # Write your code here startswith
  179.     f = first.strip()
  180.     s = second.strip()
  181.     p = parent.strip()
  182.     c = city.strip()
  183.     f = f.capitalize()
  184.     s = s.capitalize()
  185.     p = p.capitalize()  
  186.     print(f+" "+s+" "+p+" "+c)
  187.     print(phone.isdecimal())
  188.     print(phone.startswith(start))
  189.     ss = first+second+parent+city
  190.     print(ss.count(strfind))
  191.     print(string1.split())
  192.     print(city.index(strfind))
  193. if __name__ == '__main__':
  194.  
  195. =============================================================
  196. #!/bin/python3
  197.  
  198. import math
  199. import os
  200. import random
  201. import re
  202. import sys
  203.  
  204.  
  205.  
  206. #
  207. # Complete the 'sliceit' function below.
  208. #
  209. # The function accepts List mylist as parameter.
  210. #
  211.  
  212. def sliceit(mylist):
  213.     # Write your code here
  214.     print(mylist[1:3])
  215.     print(mylist[1::2])
  216.     mylist1 = mylist.reverse()
  217.     print(mylist[0:3])
  218. if __name__ == '__main__':
  219.  
  220. ===================================================================
  221. #!/bin/python3
  222.  
  223. import math
  224. import os
  225. import random
  226. import re
  227. import sys
  228.  
  229.  
  230.  
  231. #
  232. # Complete the 'generateList' function below.
  233. #
  234. # The function accepts following parameters:
  235. #  1. INTEGER startvalue
  236. #  2. INTEGER endvalue
  237. #
  238.  
  239. def generateList(startvalue, endvalue):
  240.     # Write your code here
  241.     x = range(startvalue,endvalue+1)
  242.     lis = []
  243.     for n in x:
  244.         lis.append(n)
  245.     print(lis[:3])  
  246.     lis.reverse()
  247.     print(lis[:5])
  248.     lis.reverse()
  249.     print(lis[::4])
  250.     lis.reverse()
  251.     print(lis[::2])
  252. if __name__ == '__main__':
  253.  
  254. =========================================================
  255.  #!/bin/python3
  256.  
  257. import math
  258. import os
  259. import random
  260. import re
  261. import sys
  262.  
  263.  
  264.  
  265. #
  266. # Complete the 'calculateGrade' function below.
  267. #
  268. # The function is expected to return a STRING_ARRAY.
  269. # The function accepts 2D_INTEGER_ARRAY students_marks as parameter.
  270. #
  271.  
  272. def calculateGrade(students_marks):
  273.     # Write your code here
  274.    
  275.     sum1 = 0
  276.     avgl = []
  277.     avgl1 = []
  278.     for i in students_marks :
  279.       sum1 = 0
  280.       for j in i:
  281.         sum1 = sum1 + j
  282.       len1 = len(i)
  283.       avg = sum1/5
  284.       avgl.append(avg)
  285.       avgl1.append(str(avg))
  286.     avgt = []
  287.     for k in avgl:
  288.         if k >= 90:
  289.             avgt.append("A+")
  290.         elif k >= 80 and k <90:
  291.             avgt.append("A")
  292.         elif k >= 70 and k <80:
  293.             avgt.append("B")            
  294.         elif k >= 60 and k <70:
  295.             avgt.append("C")
  296.         elif k >= 50 and k <60:
  297.            
  298.             avgt.append("D")
  299.         else :
  300.             avgt.append("F")                          
  301.     return avgt
  302.  
  303.  
  304. if __name__ == '__main__':
  305. ===============================================================================
  306.  
  307.  
  308. #!/bin/python3
  309.  
  310. import math
  311. import os
  312. import random
  313. import re
  314. import sys
  315.  
  316.  
  317.  
  318. #
  319. # Complete the 'setOperation' function below.
  320. #
  321. # The function is expected to return a union, intersection, difference(a,b), difference(b,a), symmetricdifference and frozen set.
  322. # The function accepts following parameters:
  323. #  1. List seta
  324. #  2. List setb symmetric_difference
  325. #
  326.  
  327. def setOperation(seta, setb):
  328.     # Write your code here
  329.     a = set(seta)
  330.     b = set(setb)
  331.     uab = a.union(b)
  332.     iab = a.intersection(b)
  333.     dab = a.difference(b)
  334.     dba = b.difference(a)
  335.     sab = a.symmetric_difference(b)
  336.     a =  frozenset(a)
  337.     return uab,iab,dab,dba,sab,a
  338.  
  339. if __name__ == '__main__':
  340.  
  341. =================================================================================
Add Comment
Please, Sign In to add comment