Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. '''
  2. Descriere: Determina daca un numar natural este patrat perfect
  3. Input: numarul natura nr
  4. Output: True daca este patrat perfect, False in caz contrar
  5. '''
  6. def squareNumber (nr):
  7. import math
  8. if int(sqrt(nr))*int(sqrt(nr))==nr:
  9. return True
  10. return False
  11.  
  12. '''
  13. Descriere: Determina daca cifra data este o cifra prima
  14. input: cifra cif
  15. output: True daca este o cifra prima, False in caz contrar
  16. '''
  17. def isPrime(cif):
  18. if cif==2 or cif==3 or cif==5 or cif==7:
  19. return True
  20. return False
  21.  
  22.  
  23. '''
  24. Descriere: Determina daca numarul nr este format numai din cifre prime
  25. Input: numarul natural nr
  26. Output: True daca este format numai din cifre prime, False in caz contrar
  27. '''
  28. def numberIsPrime(nr):
  29. while nr!=0:
  30. if isPrime(nr%10)==False:
  31. return False
  32. nr=nr//10
  33. return True
  34.  
  35. '''
  36. Descriere: Determina daca lungimea actuala este mai mare decat lungimea salvata
  37. Input: lungimea actuala lenght, lungimea maxima maxLenght, pozitia inceputului sirului first, finalul sirului last si pozitia actuala in parcurgere poz
  38. '''
  39. def lenght (lenght, maxLenght, first, last,poz):
  40. if lenght>maxLenght:
  41. maxLenght=lenght
  42. last=poz-1
  43. first=poz-maxLenght
  44.  
  45. '''
  46. Descriere: Citeste o lista de numere naturale
  47. ouput: returneaza o lista citita de numere intregi
  48. '''
  49. def readingList(list,n):
  50. n=int(input())
  51. list=[]
  52. for i in range (n):
  53. val=int (input ("Dati valorea de pe poz "+str(i)))
  54. list.apprend(val)
  55. return list
  56. '''
  57. Descriere: Afiseaza o lista de numere naturale
  58. Input: lista de elemente list, pozitia de inceput listStart si pozitia de oprire listStop
  59. '''
  60. def showList(list,listStart,listStop):
  61. for i in range(listStart,listStop):
  62. print(list[i],end=",")
  63. print (list[len(list)],end="\n")
  64.  
  65.  
  66. '''
  67. Descriere: Programul principal in care se vor realiza cerintele
  68. '''
  69.  
  70. def main():
  71. list=[]
  72. list=readingList(list,n)
  73. for i in range(n):
  74. if squareNumber(list[i])==True:
  75. lenghtSquare+=1
  76. else:
  77. lenght(lenghtSquare,lenghtSquareMax,firstSquare,lastSquare,i)
  78. lenghtSquare=0
  79. if numberIsPrime(list[i])==True:
  80. lenghtPrime+=1
  81. else:
  82. lenght(lenghtPrime,lenghtPrimeMax,firstPrime,lastPrime,i)
  83. lenghtPrime=0
  84. lenght(lenghtSquare,lenghtSquareMax,firstSquare,lastSquare,n)
  85. lenght(lenghtPrime,lenghtPrimeMax,firstPrime,lastPrime,n)
  86. showList(list,firstSquare,lastSquare)
  87. showList(list,firstPrime,lastPrime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement