2015-10-13 55 views
-5

如何編寫Python腳本,可以從1基本Python-通過連續編號

+3

歡迎來到StackOverflow!如果您發佈了一些代碼,證明您試圖解決問題,您將有更好的機會獲得答案。 – Cinnam

回答

0

更新回答評論讀取用戶輸入的列表 號碼並顯示每個數倍數的數增量乘以給定的數字

def mult_func(s): 
num_lst = s.split(',') # Split the user input into a list by comma (,) 
    # enumerate generates an integer relevant to the number of iterations starting at 0 
    # eg. 1st num, i = 0, 2nd num, i = 1, 3rd num, i = 2, etc 
    for i, num in enumerate(num_lst): 
     value = float(num)*(i+1) 
     print('{0} x {1} = {2}'.format(float(num), (i+1), value)) 

if __name__ == '__main__': 
    # The user entered numbers have to be separeted by commas (,) 
    mult_func(input('Enter a list of numbers: ')) 
+0

謝謝你的幫助!它幫助了很多。但我的意思是,例如,用戶間數(n)然後n * 1 = <乘法結果>, n * 2 = <乘法結果>,n * 3 = n * 4,n * 5 等 – Kaleb