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
0296 – Proporționale
(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 citeste_numar_elemente(): while True: try: numar_elemente = int(input("Introduceti numarul de elemente (maxim 100): ")) if numar_elemente < 1 or numar_elemente > 100: raise ValueError break except ValueError: print("Numarul de elemente trebuie sa fie un numar intre 1 si 100.") return numar_elemente def citeste_siruri(numar_elemente): while True: try: sir_1 = list(map(int, input("Introduceti elementele primului sir, separate prin spatiu: ").split())) sir_2 = list(map(int, input("Introduceti elementele celui de-al doilea sir, separate prin spatiu: ").split())) if len(sir_1) != numar_elemente or len(sir_2) != numar_elemente: raise ValueError for i in range(numar_elemente): if sir_1[i] < 1 or sir_1[i] > 9999 or sir_2[i] < 1 or sir_2[i] > 9999: raise ValueError break except ValueError: print("Elementele trebuie sa fie numere naturale nenule cu cel mult 4 cifre si sa fie exact {} elemente in fiecare sir.".format(numar_elemente)) return sir_1, sir_2 def sorteaza_siruri(sir_1, sir_2): sir_1.sort() sir_2.sort() def verifica_proportionalitate(sir_1, sir_2, numar_elemente): for i in range(numar_elemente): if sir_1[i] * sir_2[numar_elemente-1-i] != sir_1[numar_elemente-1-i] * sir_2[i]: return False return True if __name__ == '__main__': # Citim numarul de elemente numar_elemente = citeste_numar_elemente() # Citim cele doua siruri sir_1, sir_2 = citeste_siruri(numar_elemente) # Sortam cele doua siruri sorteaza_siruri(sir_1, sir_2) # Verificam daca sirurile sunt proportionale proportional = verifica_proportionalitate(sir_1, sir_2, numar_elemente) # Afisam rezultatul if proportional: print("DA") else: print("NU") print("Datele sunt introduse corect.") </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