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
0001 - Sum
(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 == <syntaxhighlight lang="python" line="1"> # 0001 - sum def verificare(nr1, nr2): # functia de verificare a datelor de intrare if nr1 == int(nr1) and nr2 == int(nr2) and nr1 < 1000000000 and nr2 < 1000000000: return True else: return False def sum1(nr1, nr2): # functia de rezolvare suma = int(nr1 + nr2) # calculam suma fout = open("sumout.txt", "a") # o afisam fout.write(str(suma)) fout.close() if __name__ == '__main__': file_out = open("sumout.txt", "w") # deschidem fisierul in care scriem solutia cu optiunea w (write) # ne asteptam ca datele de intrare sa fie gresite fapt care ar genera o eroare de tipul ValueError # pe care o tratam corespunzator try: file_in = open("sumin.txt", "r") # deschidem fisierul din care citim cu optiunea r (read) numere = file_in.read() numere = numere.split(" ") # citim numerele separate prin spatiu numar_1 = float(numere[0]) numar_2 = float(numere[1]) file_in.close() # inchidem fisierul if verificare(numar_1, numar_2) is True: # verificam datele de intrare file_out.write("Datele de intrare corespund restrictiilor impuse. \n") file_out.close() sum1(numar_1, numar_2) # apelam functia de rezolvare else: file_out.write("Datele de intrare nu corespund restrictiilor impuse.") except ValueError: file_out.write("Datele de intrare nu corespund restrictiilor impuse.") </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