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
2214 - Cifre 001
(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_numere(): while True: try: numar1 = int(input("Introduceți primul număr: ")) # Citeste primul numar de la utilizator numar2 = int(input("Introduceți al doilea număr: ")) # Citeste al doilea numar de la utilizator if numar1 <= 0 or numar2 <= 0: raise ValueError("Introduceți numere naturale pozitive.") # Ridica o eroare daca numerele nu sunt naturale pozitive break except ValueError as e: print(f"Eroare: {e}") # Afiseaza eroarea daca numerele introduse nu sunt valide return numar1, numar2 def determina_nr_cifre(numar): return len(str(numar)) # Determina numarul de cifre al unui numar prin convertirea la string si apoi determinarea lungimii acestuia def transforma_in_lista_cifre(numar): return [int(x) for x in str(numar)] # Transforma un numar intr-o lista de cifre prin convertirea la string si apoi convertirea fiecarei cifre la integer def determina_nr_coincidente(cifre1, cifre2): nr_coincidente = 0 for i in range(len(cifre1)): if cifre1[i] == cifre2[i]: # Verifica daca cifra de pe aceeasi pozitie din cele doua liste coincide nr_coincidente += 1 return nr_coincidente if __name__ == "__main__": numar1, numar2 = citeste_numere() # Citeste numerele de la utilizator nr_cifre1 = determina_nr_cifre(numar1) # Determina numarul de cifre al primului numar nr_cifre2 = determina_nr_cifre(numar2) # Determina numarul de cifre al celui de-al doilea numar if nr_cifre1 != nr_cifre2: print("Cele două numere nu au același număr de cifre.") else: cifre1 = transforma_in_lista_cifre(numar1) # Transforma primul numar intr-o lista de cifre cifre2 = transforma_in_lista_cifre(numar2) # Transforma al doilea numar intr-o lista de cifre nr_coincidente = determina_nr_coincidente(cifre1, cifre2) # Determina numarul de cifre care coincid pe aceeasi pozitie print("Datele sunt introduse corect.") print(f"Numerele au {nr_coincidente} cifre care coincid pe aceeași poziție.") </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