Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. ######### Simple function contrsuct
  2. """
  3. def printfunc():
  4. print("Welcome to functions Anik!")
  5. printfunc()
  6. """
  7.  
  8. ######### Function with one argument
  9.  
  10. """
  11. def oneargfunc(name):
  12. print("доброе утра,", name)
  13. oneargfunc("Аник")
  14. """
  15.  
  16. ######### Square function
  17. """
  18. def squarfunc(num):
  19. return num*num
  20.  
  21. a = float(input("Enter any value :"))
  22.  
  23. print(squarfunc(a))
  24.  
  25. """
  26. ########## Factorial function
  27. """
  28. def fact(num):
  29. facto = 1
  30. while(num>1):
  31. facto = facto*num
  32. num = num - 1
  33. return facto
  34. n1 = int(input("Enter an integer:"))
  35. print(fact(n1))
  36.  
  37. # using math package
  38. import math
  39. def fact(num):
  40. return(math.factorial(num))
  41. n1 = int(input("Enter an integer:"))
  42. print(fact(n1))
  43.  
  44. """
  45.  
  46. ######## Fibonacci using function
  47. """
  48. def fibo(num1, num2, lim):
  49. fib = 0
  50. if num1<num2:
  51. print(num1)
  52. else:
  53. print(num2)
  54. for i in range(1, lim):
  55. fib = num1 + num2
  56. print(fib)
  57. num1 = num2
  58. num2 = fib
  59. n1 = int(input("Enter the first number:"))
  60. n2 = int(input("Enter the second number:"))
  61. n = int(input("Enter the number of terms:"))
  62. fibo(n1, n2, n)
  63.  
  64. """
  65.  
  66. ####### Fibonacci using recursion
  67. """
  68. def recurfibo(lim):
  69. if lim <= 1:
  70. return lim
  71. else:
  72. print(return(recurfibo(lim-1)+ recurfibo(lim-2)))
  73.  
  74. n = int(input("Enter the number of terms:"))
  75. print(recurfibo(n))
  76.  
  77. """
  78.  
  79. ###### Arithmetic Progression function
  80.  
  81. """
  82. def arith(initial, common_factor, terms):
  83. print(initial)
  84. for i in range(1, terms):
  85. new = initial + i*common_factor
  86. i = i+1
  87. print(new)
  88. ini = float(input("Enter the initial number:"))
  89. com_factor = float(input("Enter the common factor:"))
  90. n = int(input("Enter the number of terms:"))
  91. print(arith(ini, com_factor, n))
  92. """
  93.  
  94. ###### Lists with functions
  95. """
  96. n = int(input("Enter the number of elements you want in the list:"))
  97. l = []
  98. for i in range(0,n):
  99. print("Enter element number", i, ":")
  100. i = int(input())
  101. l.append(i)
  102. print("The list you entered is :", l)
  103.  
  104. def revlist(your_list):
  105. rev = your_list[::-1]
  106. return rev
  107.  
  108. print("The reversed list is :", revlist(l))
  109. """
  110.  
  111. ###### Create list and sqaure each element
  112.  
  113. """
  114. import math
  115. n = int(input("Enter the number of elements you want in the list:"))
  116. l = []
  117. for i in range(0,n):
  118. print("Enter element number", i, ":")
  119. i = int(input())
  120. l.append(i)
  121. print("The list you entered is :", l)
  122.  
  123. def listsqr(your_list):
  124. sqr_list = []
  125. for j in your_list:
  126. sqr_list.append(math.pow(j,2))
  127. return sqr_list
  128.  
  129. print(listsqr(l))
  130. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement