Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0215 - Gen Mat 6
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rezolvare == <syntaxhighlight lang="python" line="1"> # 0215- Gen Mat 6 def verificare_restrictii(n): # functia de verificare a restrictiilor if nr_cifre(n) == 5: return True else: return False def nr_cifre(numar): # functie care returneaza numarul de cifre ale unui numar dat ca parametru numar_cifre = 0 while numar > 0: numar_cifre += 1 numar //= 10 return numar_cifre def genmat6(n): # functia de rezolvare numar = n # creem o copie a lui n pentru a putea folosi copia fara a modifica n cand ii extragem cifrele matrice = [] nr_linii = nr_cifre(n) + 1 # numarul de linii si de coloane este 1 + numarul cifrelor lui n for i in range(1, nr_linii+1): # creem matricea corespunzatoare linie = [] for j in range(1, nr_linii+1): linie.append(0) matrice.append(linie) for linie in range(1, nr_linii+1): # parcurgem intai matricea pe linie # in problema, numaratoarea incepe de la 1 dar matricea noastra este numerotata de la 0 # deci aplicam +1 si -1 unde e necesar for coloana in range(1, nr_linii+1): if linie + coloana > linie * 2: # introducem deasupra diagonalei principale matrice[linie-1][coloana-1] = numar % 10 # ultima cifra numar //= 10 # trecem la cifra urmatoare numar = n # deoarece am creat copia, n ramane nemodificat si il putem reutiliza pentru completarea coloanelor for coloana in range(1, nr_linii+1): # parcurgem matricea pe coloane for linie in range(1, nr_linii+1): if linie + coloana < linie * 2: # doar sub diagonala principala matrice[linie-1][coloana-1] = numar % 10 # introducem ultima cifra numar //= 10 # trecem la cifra urmatoare for linie in matrice: # afisarea for element in linie: print(element, end=" ") print() if __name__ == '__main__': # ne asteptam ca datele de intrare sa fie gresite fapt care ar genera o eroare de tipul ValueError # pe care o tratam corespunzator try: nr = int(input("Introduceti numarul: ")) # citirea lui nr if verificare_restrictii(nr): # verificam restrictiile print("Datele de intrare corespund restrictiilor impuse.") genmat6(nr) # apelam functia de rezolvare else: print("Datele de intrare nu corespund restrictiilor impuse.") except ValueError: print("Datele de intrare nu corespund restrictiilor impuse.") </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width