How to do the function for input list of stock in python
like [p(1), p(2), . . . , p(n)], for example [ 23,
53, 55, 42, 31, 40 ]
like [p(1), p(2), . . . , p(n)], for example [ 23,
53, 55, 42, 31, 40 ]
def main():
i = [n]
i, n = input("Enter any number: ")
print " The first input is", i, " and the index is", n
>>> numbers = [0,1,2,3,4,5,6,7,8,9] >>> for i, num in enumerate(numbers): ... print "The number is %s and the index is %s" % (num, i) ... The number is 0 and the index is 0 The number is 1 and the index is 1 The number is 2 and the index is 2 The number is 3 and the index is 3 The number is 4 and the index is 4 The number is 5 and the index is 5 The number is 6 and the index is 6 The number is 7 and the index is 7 The number is 8 and the index is 8 The number is 9 and the index is 9 >>>
p=[] #sets up p as a list
while True: #infinite loop for data input
i=input("Enter any number (0 to quit): ")
if i==0: break #if user enters nothing break out of infinite loop
p.append(i) #append i as the next item in the list
#Once we've broken out of the loop, print of the values you've entered:
print p
#or if you want to be a bit fancy
for n,i in enumerate(p):
print "index ", n, "value ", i, " which is equal to ", p[n]
Comment