2017年12月23日 星期六

a024: 所有位數和

a024: 所有位數和
'''
給你一個正整數,請你求出所有位數的和是多少,
例如12345,因為1+2+3+4+5=15,則輸出15。

輸入說明:
請輸入一個正整數 N。
輸出說明:
請輸出 N 所有位數的和是多少。

輸入1:
12345

輸入2:
1997
範例輸出 :

輸出1:
15

輸出2:
26
'''
X=[]
X=int(input("輸入一個大於1的正整數 N > "))
X=str(X)
sum1=0
for i in range(len(X)):
    sum1=sum1+int(X[i])

print(sum1)


======== RESTART: F:/Python_APSC/a024-9.py =====================
輸入一個大於1的正整數 N > 1234566
27
>>> 
===== RESTART: F:/Python_APSC/a024-9.py =====================
輸入一個大於1的正整數 N > 1997
26
>>> 

沒有留言:

張貼留言

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> &...