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
3567 - Cod 24
(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 incrementare_cifre(n): return [(int(d) + 1) % 10 if d != '9' else 9 for d in str(n)] def interschimbare_cifre(n): n[-2], n[-1] = n[-1], n[-2] return n def validare_interval(n): return 1000 <= n <= 9999 if __name__ == "__main__": with open("cod24.in") as f: n = int(f.readline().strip()) if not validare_interval(n): print("Numărul nu se încadrează în intervalul permis!") exit(1) n = incrementare_cifre(n) n = interschimbare_cifre(n) with open("cod24.out", "w") as f: f.write("".join(str(d) for d in n)) print("Datele au fost introduse corect.") </syntaxhighlight> === Rezolvare ver. 2 === <syntaxhighlight lang="python" line> # citim codul din fisierul de intrare with open("cod24.in") as f: n = int(f.readline().strip()) if n < 1000 or n > 9999: print("Numarul nu se incadreaza in intervalul permis!") else: #continuam cu prelucrarea datelor # incrementam cifrele codului n = [(int(d) + 1) % 10 if d != '9' else 9 for d in str(n)] # interschimbam ultimele doua cifre n[-2], n[-1] = n[-1], n[-2] # scriem noul cod in fisierul de iesire with open("cod24.out", "w") as f: f.write("".join(str(d) for d in n)) print("Datele au fost 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