Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######### Simple function contrsuct
- """
- def printfunc():
- print("Welcome to functions Anik!")
- printfunc()
- """
- ######### Function with one argument
- """
- def oneargfunc(name):
- print("доброе утра,", name)
- oneargfunc("Аник")
- """
- ######### Square function
- """
- def squarfunc(num):
- return num*num
- a = float(input("Enter any value :"))
- print(squarfunc(a))
- """
- ########## Factorial function
- """
- def fact(num):
- facto = 1
- while(num>1):
- facto = facto*num
- num = num - 1
- return facto
- n1 = int(input("Enter an integer:"))
- print(fact(n1))
- # using math package
- import math
- def fact(num):
- return(math.factorial(num))
- n1 = int(input("Enter an integer:"))
- print(fact(n1))
- """
- ######## Fibonacci using function
- """
- def fibo(num1, num2, lim):
- fib = 0
- if num1<num2:
- print(num1)
- else:
- print(num2)
- for i in range(1, lim):
- fib = num1 + num2
- print(fib)
- num1 = num2
- num2 = fib
- n1 = int(input("Enter the first number:"))
- n2 = int(input("Enter the second number:"))
- n = int(input("Enter the number of terms:"))
- fibo(n1, n2, n)
- """
- ####### Fibonacci using recursion
- """
- def recurfibo(lim):
- if lim <= 1:
- return lim
- else:
- print(return(recurfibo(lim-1)+ recurfibo(lim-2)))
- n = int(input("Enter the number of terms:"))
- print(recurfibo(n))
- """
- ###### Arithmetic Progression function
- """
- def arith(initial, common_factor, terms):
- print(initial)
- for i in range(1, terms):
- new = initial + i*common_factor
- i = i+1
- print(new)
- ini = float(input("Enter the initial number:"))
- com_factor = float(input("Enter the common factor:"))
- n = int(input("Enter the number of terms:"))
- print(arith(ini, com_factor, n))
- """
- ###### Lists with functions
- """
- n = int(input("Enter the number of elements you want in the list:"))
- l = []
- for i in range(0,n):
- print("Enter element number", i, ":")
- i = int(input())
- l.append(i)
- print("The list you entered is :", l)
- def revlist(your_list):
- rev = your_list[::-1]
- return rev
- print("The reversed list is :", revlist(l))
- """
- ###### Create list and sqaure each element
- """
- import math
- n = int(input("Enter the number of elements you want in the list:"))
- l = []
- for i in range(0,n):
- print("Enter element number", i, ":")
- i = int(input())
- l.append(i)
- print("The list you entered is :", l)
- def listsqr(your_list):
- sqr_list = []
- for j in your_list:
- sqr_list.append(math.pow(j,2))
- return sqr_list
- print(listsqr(l))
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement