2752 - Cifre Zecimale: Difference between revisions

From Bitnami MediaWiki
No edit summary
Tag: visualeditor
No edit summary
Tag: visualeditor
Line 19: Line 19:
     return k.isdigit() and 1 <= int(k) <= 180
     return k.isdigit() and 1 <= int(k) <= 180


def cifre_zecimale():
def cifre_zecimale(k):
     if k <= 9:
     if k <= 9:
         C = k
         C = k

Revision as of 08:49, 19 March 2023

Cerință

Se consideră șirul de cifre zecimale obținut prin scrierea consecutivă a numerelor naturale de la 10 la 99. Pentru un k dat, să se afișeze cifra ce apare în acest șir pe poziția k.

Date de intrare

Programul citește de la tastatură numărul k.

Date de ieșire

Programul va afișa pe ecran valoarea C, reprezentând cifra situată pe poziția k în șir de mai sus.

Restricții de precizări

  • 1 ⩽ k ⩽ 180

Exemplul 1

Intrare
5
Ieșire
Datele introduse corespund restricțiilor impuse.
1

Rezolvare vers. 1

<syntaxhighlight lang="python" line="1" start="1"> def validare(k):

   return k.isdigit() and 1 <= int(k) <= 180

def cifre_zecimale(k):

   if k <= 9:
       C = k
   else:
   
       i = (k - 10) // 10  
       r = (k - 10) % 10
       zecime = 10 + i
       C = int(str(zecime)[r])
   
   print("Cifra cautata este:", C)


if __name__ == '__main__':

   k = int(input("Introduceti numarul k: "))

if validare(k):

   k = int(k)
   print("Datele introduse corespund restricțiilor impuse.")
   cifre_zecimale(k)

else:

   print("Datele introduse nu corespund restricțiilor impuse.")

</syntaxhighlight>