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
0510 - Sort Prime
(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> def este_prim(numar): if numar <= 1: return False for i in range(2, int(numar ** 0.5) + 1): if numar % i == 0: return False return True if __name__ == "__main__": while True: try: n = int(input("Introduceti numarul de elemente din vector (1-1000): ")) if 1 <= n <= 1000: break else: print("Numarul de elemente trebuie sa fie intre 1 si 1000. Va rugam reintroduceti.") except ValueError: print("Va rugam introduceti un numar valid.") vector = [] for _ in range(n): while True: try: numar = int(input("Introduceti un numar natural: ")) if numar >= 0 and numar <= 1000000000: vector.append(numar) break else: print("Numarul trebuie sa fie intre 0 si 1000000000. Va rugam reintroduceti.") except ValueError: print("Va rugam introduceti un numar valid.") valorile_prime = [numar for numar in vector if este_prim(numar)] valorile_prime.sort() # Sort1ăm valorile prime în ordine crescătoare print("Valorile prime din vector, în ordine crescătoare, sunt:") print(*valorile_prime) </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