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
0464 - Cifre K
(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 == === Rezolvare ver. 1 === <syntaxhighlight lang="python" line> def obtine_cifra_valabila(): while True: cifra = input("Introduceti cifra: ") if cifra.isdigit() and 0 <= int(cifra) <= 9: return int(cifra) print("Cifra introdusa nu este valida. Introduceti o cifra intre 0 si 9.") def numara_aparitii_cifra(cifra): aparitii = 0 while True: numar = int(input("Introduceti un numar (0 pentru a opri citirea): ")) if numar == 0: break if numar % 2 == 0: aparitii += str(numar).count(str(cifra)) return aparitii if __name__ == "__main__": # Obține cifra validă cifra = obtine_cifra_valabila() # Numără aparițiile cifrei în numerele pare aparitii = numara_aparitii_cifra(cifra) # Afisează rezultatul print("Datele sunt introduse corect.") print(f"Cifra {cifra} a aparut de {aparitii} ori in numerele pare citite.") </syntaxhighlight> === Rezolvare ver. 2 === <syntaxhighlight lang="python" line> # citim cifra while True: cifra = input("Introduceti cifra: ") if cifra.isdigit() and 0 <= int(cifra) <= 9: break print("Cifra introdusa nu este valida. Introduceti o cifra intre 0 si 9.") # citim numere pana la intalnirea lui 0 aparitii = 0 while True: numar = input("Introduceti un numar (0 pentru a opri citirea): ") if numar == "0": break # verificam daca numarul este par if int(numar) % 2 == 0: # numaram aparitiile cifrei in numarul par aparitii += str(numar).count(cifra) print("Datele sunt introduse corect.") # afisam numarul de aparitii print(f"Cifra {cifra} a aparut de {aparitii} ori in numerele pare citite.") </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