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
1475 - Numere 14
(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 ver. 1 === <syntaxhighlight lang="python" line> def validare_numar_numere(numere, nr_de_numere): """Verifică dacă numărul de numere corespunde cu valoarea indicată.""" if len(numere) != nr_de_numere: raise ValueError("Numărul de numere nu corespunde cu valoarea indicată.") def validare_cifre_impare(numere): """Verifică dacă numărul are un număr impar de cifre.""" for numar in numere: if len(numar) % 2 == 0: raise ValueError("Numărul {} nu are număr impar de cifre".format(numar)) def calculare_suma_cifre_impare(numere): """Calculează suma cifrelor impare din mijlocul numerelor.""" suma_cifre_impare = 0 for numar in numere: middle_index = len(numar) // 2 middle_digit = int(numar[middle_index]) if middle_digit % 2 != 0: suma_cifre_impare += middle_digit return suma_cifre_impare if __name__ == '__main__': try: with open('numere14.in', 'r') as fin: nr_de_numere = int(fin.readline()) numere = fin.readline().split() validare_numar_numere(numere, nr_de_numere) validare_cifre_impare(numere) suma_cifre_impare = calculare_suma_cifre_impare(numere) with open('numere14.out', 'w') as fout: fout.write(str(suma_cifre_impare)) print("Datele introduse sunt corecte. Suma cifrelor impare a fost calculată și scrisă în fișierul numere14.out.") except ValueError as e: print("Eroare la validarea datelor de intrare:", str(e)) </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