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
0234 - Med Poz
(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> def validare_date(n: int, a: list[list[int]]) -> bool: # Verificare dimensiunea matricei if not (2 <= n <= 20): return False # Verificare interval valori elemente for i in range(n): for j in range(n): if not (-100 <= a[i][j] <= 100): return False return True def media_aritmetica_pozitive_sub_diagonala(n: int, a: list[list[int]]) -> float: suma_pozitive_sub_diagonala = 0 numar_elemente_pozitive_sub_diagonala = 0 # Parcurgere elemente sub diagonala principală for i in range(1, n): for j in range(i): # Dacă elementul este strict pozitiv, se adună la suma S if a[i][j] > 0: suma_pozitive_sub_diagonala += a[i][j] numar_elemente_pozitive_sub_diagonala += 1 # Daca nu s-au găsit elemente pozitive sub diagonală, se returnează None if numar_elemente_pozitive_sub_diagonala == 0: return None # Altfel, se calculează și se returnează media aritmetică else: return suma_pozitive_sub_diagonala / numar_elemente_pozitive_sub_diagonala if __name__ == '__main__': # Citire date de intrare with open('medpoz.in', 'r') as fin: n = int(fin.readline()) a = [] for i in range(n): linie = list(map(int, fin.readline().split())) a.append(linie) # Verificare date de intrare if not validare_date(n, a): with open('medpoz.out', 'w') as fout: fout.write("Datele nu corespund restricțiilor impuse.") else: # Calcul și afișare rezultat rezultat = media_aritmetica_pozitive_sub_diagonala(n, a) if rezultat is None: print("NU EXISTA") else: with open('medpoz.out', 'w') as fout: fout.write("Datele sunt introduse corect.\n") fout.write(f"{rezultat:.3f}") </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