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
1290 - CifreGen3
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!
== Cerința == Se dau două numere n m. Să se genereze toate numerele cu exact n cifre mai mici decât m cu proprietatea că prima și ultima cifră sunt egale. == Date de intrare == Programul citește de la tastatură numerele n m. == Date de ieșire == Programul va afișa pe ecran numerele generate, câte unul pe linie, în ordine crescătoare. == Restricții și precizări == *1 ≤ n ≤ 7 *0 < m < 6 == Exemplu 1 == ;Intrare 3 3 ;Iesire 101<br> 111<br> 121<br> 202<br> 212<br> 222 == Rezolvare == <syntaxhighlight lang="python" line> def generate_numbers(n, m): numbers = [] for i in range(10**(n-1), 10**n): num_str = str(i) if num_str[0] == num_str[-1] and all(int(digit) < m for digit in num_str): numbers.append(num_str) return numbers def read_input(): n, m = map(int, input("Enter n and m: ").split()) if not (1 <= n <= 7): raise ValueError("1 ≤ n ≤ 7") if not (0 < m < 6): raise ValueError("0 < m < 6") return n, m def main(): try: n, m = read_input() numbers = generate_numbers(n, m) for num in numbers: print(num) except ValueError as e: print("Error:", e) 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