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
0994 - Fibo Verif 1
(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!
= Restricţii şi precizări = * <code>1 ≤ n ≤ 10</code> * elementele şirului vor avea cel mult <code>9</code> cifre == Exemplul 1 == fiboverif1.txt: 8 13 1 8 24 21 55 47 8 fiboverif2.txt: 13 1 8 21 55 8 == Exemplul 2 == fiboverif1.txt: 0 13 1 8 24 21 55 47 8 9 Output consola: Numărul n trebuie să fie între 1 și 10. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def validate_input(n, sir): # Verificare pentru n if not (1 <= n <= 10): print("Numărul n trebuie să fie între 1 și 10.") return False # Verificare pentru fiecare element din șir for x in sir: if not (1 <= x <= 999999999): print("Elementele șirului trebuie să fie numere naturale cu cel mult 9 cifre.") return False return True def fibo(numar): a, b = 0, 1 while a <= numar: if a == numar: return True a, b = b, a + b return False def main(): # Citire date de intrare din fisier with open("fiboverif1.txt", "r") as f: n = int(f.readline()) sir = list(map(int, f.readline().split())) # Verificare validitate input if not validate_input(n, sir): return # Afișare elemente din șir care sunt termeni ai șirului lui Fibonacci rezultat = [str(x) for x in sir if fibo(x)] # Scriere rezultat in fisier with open("fiboverif2.txt", "w") as f: f.write(" ".join(rezultat)) if __name__ == "__main__": main() </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