Exercise twenty-nine: Reverse Print to get into positive territory, and output

Original link: http://www.cnblogs.com/pinpin/p/9984214.html

Requirements: Get input, and yes a few number, and reverse printing of the digits

  . 1 NUM = INPUT ( " Enter a positive number ")
   2  IF num.isdigit ():
   . 3      str1 = STR (NUM)
   . 4      Print ( " input is a positive number median {} " .format (len (str1)))
   . 5      List1 List = (str1)
   . 6      list1.reverse ()
   . 7      Print (List1)
   . 8  the else :
   . 9      Print ( " Please enter a positive number .")

Results of the:

Positive numbers 864 
enter a positive number is 3 digits 
[ '4', '6', '8']

Suppose we set the number can not be more than five
  . 1 NUM = int (INPUT ( " Enter a positive number: "))
   2  IF len (STR (NUM))>. 6:
   . 3      Print ( " digital input not more than five ")
   . 4  
  . 5 A NUM = // 10000 
  . 6 B 10000% NUM = // 1000 
  . 7 C = 1000% NUM // 100 
  . 8 D NUM = 100% // 10 
  . 9 E 10% NUM =
 10  
. 11  IF ! A = 0:
 12 is      Print ( " . 5-digit ", e, D, C, B, A)
 13 is elif B = 0:!
 14      Print ( " . 4 digits ", E, D, C, B)
 15C = 0 elif:!
 16      Print ( " . 3-digit ", E, D, C)
 . 17 elif D = 0:!
 18 is      Print ( " 2-digit ", E, D)
 . 19 elif E = 0:!
 20 is      Print ( " digit ", e)

Results of the:

Positive numbers: 12464 
5 digits 46421

Reproduced in: https: //www.cnblogs.com/pinpin/p/9984214.html

Guess you like

Origin blog.csdn.net/weixin_30612769/article/details/94790419