list - How to take any number of inputs in python without defining any limit? -
now, thing supposed take unknown amount of input user on 1 run can enter 10 terms on run can enter 40. , cannot ask user enter value of n can run range loop , start storing input in list. if somehow can have created loop not case. so, question how define endpoint user? or how pass unknown number of arguments function?
def fibi(n):     while n<0 or n>=50:         print "enter value of n greater 0 less 50"         n = int(raw_input())     if n==0:         return n     else:         a, b = 0, 1         in range(n):             a, b = b, + b     return   main calling function starts
n =[] ???? //this loop calling fibi function , printing output on each diff line in n:     print (fibi(n[i]))   sample input:each entry should on new line
1 2 3 4 5 . . . n   sample output
1 1 2 3 5      
this how read many integer inputs user:
inputs = [] while true:     inp = raw_input()     if inp == "":         break     inputs.append(int())   if want pass unknow number of arguments function, can use *args:
def function(*args):     print args function(1, 2, 3)   this print (1, 2, 3).
i think can use list purpose:
def function(numbers):     ... function([1, 2, 3])      
Comments
Post a Comment