2017年12月23日 星期六

a025: 數字倒轉

a025: 數字倒轉

'''
給你一個正整數,請你將所有數字倒轉之後輸出,
例如給你12345,則輸出54321。
輸入說明:
輸入一個正整數 N。
輸出說明:
將 N 的所有數字倒轉之後輸出,開頭的 0 請不要輸出。
範例輸入:help

輸入1:
12345

輸入2:
1997
範例輸出 :

輸出1:
54321

輸出2:
7991

'''
#假設有個字串,
#s = 'Hello Python' 想要反轉,也就是想要得到'nohtyP olleH',
#但型別str並無提供方法reverse, s.reverse()
#不過還好,輕輕鬆鬆便能以切片(slice)解決,print(s[::-1])


X=int(input("輸入一個大於1的正整數 N > "))
X=str(X)
print(X[::-1])




============= RESTART: F:/Python_APSC/a026.py ======================
輸入一個大於1的正整數 N > 1222
2221
>>> 
============= RESTART: F:/Python_APSC/a026.py ======================
輸入一個大於1的正整數 N > 54321
12345
>>> 

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...