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
0098 - Maxim4
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
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!
== Explicație rezolvare == Programul de mai sus conține două funcții, funcția '''afis_max_si_nr_aparitii_max(n, vector)''' și funcția '''citire_conform_restrictiilor(n, vector)''', care se vor rula în interiorul main-ului ('''if __name__ == '__main__' ''', linia 24) după citirea numărului n (linia 26) și celor n numere pe care le vom pune în șirul „vector” (linia 27), pe care le citim prin deschiderea fișierului maxim4.in (linia 25).<br> După ce am citit toate datele de intrare, se va apela funcția '''citire_conform_restrictiilor(n, vector)''' care primește doi parametri: n și vector. Funcția verifică n între 0 și 100 (linia 11), dacă elementele vectorului „vector” sunt mai mici decât 1000 (liniile 14-15) și dacă n este lungimea vectorului „vector” (linia 18). Dacă oricare dintre condiții este încălcată, se va afișa pe ecran mesajul „Datele nu corespund restricțiilor impuse.” și se va ieși din program cu comanda exit(). Dacă toate condițiile sunt respectate, se va afișa mesajul „Datele sunt introduse corect.” (linia 21) și se va continua programul.<br> Dacă s-au introdus corect datele, se va apela funcția '''afis_max_si_nr_aparitii_max(n, vector)''' care primește ca parametrii numărul n și vectorul „vector”, apoi:<br>-> se calculează valoarea maximă din lista „vector” utilizând funcția predefinită din Python „max()” și se pune în variabila „maxim” (linia 4);<br>-> se numără de câte ori apare valoarea maximă „maxim” în lista „vector” utilizând metoda „count()” a listei;<br>-> se deschide fișierul de ieșire "maxim4.out" în modul de scriere ("w") utilizând contextul "with open()" pentru a se asigura că fișierul este închis corect la finalul execuției și se scrie valoarea maximă „maxim” și numărul de apariții ale acesteia „nrmax” în fișierul de ieșire utilizând metoda "write()". Valorile sunt scrise într-un format specific folosind interpolarea de șiruri f"{}" pentru a înlocui variabilele „maxim” și „nrmax” în șirul de caractere.
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