Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Descriere: Determina daca un numar natural este patrat perfect
- Input: numarul natura nr
- Output: True daca este patrat perfect, False in caz contrar
- '''
- def squareNumber (nr):
- import math
- if int(sqrt(nr))*int(sqrt(nr))==nr:
- return True
- return False
- '''
- Descriere: Determina daca cifra data este o cifra prima
- input: cifra cif
- output: True daca este o cifra prima, False in caz contrar
- '''
- def isPrime(cif):
- if cif==2 or cif==3 or cif==5 or cif==7:
- return True
- return False
- '''
- Descriere: Determina daca numarul nr este format numai din cifre prime
- Input: numarul natural nr
- Output: True daca este format numai din cifre prime, False in caz contrar
- '''
- def numberIsPrime(nr):
- while nr!=0:
- if isPrime(nr%10)==False:
- return False
- nr=nr//10
- return True
- '''
- Descriere: Determina daca lungimea actuala este mai mare decat lungimea salvata
- Input: lungimea actuala lenght, lungimea maxima maxLenght, pozitia inceputului sirului first, finalul sirului last si pozitia actuala in parcurgere poz
- '''
- def lenght (lenght, maxLenght, first, last,poz):
- if lenght>maxLenght:
- maxLenght=lenght
- last=poz-1
- first=poz-maxLenght
- '''
- Descriere: Citeste o lista de numere naturale
- ouput: returneaza o lista citita de numere intregi
- '''
- def readingList(list,n):
- n=int(input())
- list=[]
- for i in range (n):
- val=int (input ("Dati valorea de pe poz "+str(i)))
- list.apprend(val)
- return list
- '''
- Descriere: Afiseaza o lista de numere naturale
- Input: lista de elemente list, pozitia de inceput listStart si pozitia de oprire listStop
- '''
- def showList(list,listStart,listStop):
- for i in range(listStart,listStop):
- print(list[i],end=",")
- print (list[len(list)],end="\n")
- '''
- Descriere: Programul principal in care se vor realiza cerintele
- '''
- def main():
- list=[]
- list=readingList(list,n)
- for i in range(n):
- if squareNumber(list[i])==True:
- lenghtSquare+=1
- else:
- lenght(lenghtSquare,lenghtSquareMax,firstSquare,lastSquare,i)
- lenghtSquare=0
- if numberIsPrime(list[i])==True:
- lenghtPrime+=1
- else:
- lenght(lenghtPrime,lenghtPrimeMax,firstPrime,lastPrime,i)
- lenghtPrime=0
- lenght(lenghtSquare,lenghtSquareMax,firstSquare,lastSquare,n)
- lenght(lenghtPrime,lenghtPrimeMax,firstPrime,lastPrime,n)
- showList(list,firstSquare,lastSquare)
- showList(list,firstPrime,lastPrime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement