Advertisement
ZEdKasat

Functions Excercises

Nov 25th, 2021
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #QUE 1
  2. def numberListInput(list_of_names):
  3.     for x in range(len(list_of_names)):
  4.         print(x+1, list_of_names[x]) # x+1 because numbering starts with 0
  5.  
  6. #Que 2.1
  7. def factorial(number):
  8.     fact = 1
  9.     for x in range(number):
  10.         fact = fact * (x+1)
  11.     return fact
  12. #Que 2.2
  13. def factorialFrom1toN(N):
  14.     for x in range(N):
  15.         print(factorial(x+1))
  16.  
  17. def checkCircular(list1, list2):
  18.     if len(list1) != len(list2):
  19.         return False
  20.    
  21.     while list1[0] !=
  22.  
  23.  
  24. #QUE 3
  25. def circularly_identical(list1, list2):
  26.      
  27.     # doubling list
  28.     list3 = list1 * 2
  29.      
  30.     # traversal in twice of list1
  31.     for x in range(0, len(list1)):
  32.         z = 0
  33.          
  34.         # check if list2 == list1 curcularly
  35.         for y in range(x, x + len(list1)):
  36.             if list2[z]== list3[y]:
  37.                 z+= 1
  38.             else:
  39.                 break
  40.              
  41.         # if all n elements are same circularly
  42.         if z == len(list1):
  43.             return True
  44.      
  45.     return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement