Python variable data types are set by the type of data being applied to them. In the case of 'raw_input', you'll be appending a string type to your 'amounts' list. You'll need to cast to a float if you want it as thus...
ref = raw_input('please enter reference number : ')
tint = input('enter the number of items: ')
total = input('Enter the required total : ')
i = 1
id = []
amounts = []
while i <= tint :
print 'Enter item : ' ,
tempID = [raw_input()]
id.append(tempID)
print 'Enter amount: ',
value = [raw_input()]
amounts.append(value)
i = i +1
#now i want to get the sum of amounts divide by 100 and times it by total#
#and place back into another list.
Also, you almost never need to use a counter in python as you can use for loops. In the above example you can simply do:- for i in range(int(tint)) or you could do:- while len(id) <= tint and len(amounts) <= tint:
You can also just use the input directly in the append without saving it to a variable first eg.
What error is the Python console throwing at you? I can't tell but are you sure you're casting all the char*'s to floats before you're attempting arithmetic functions on them?
Also you should use the forums's 'code' function; Python code blocks are defined by tabification so it's difficult to tell whether you're doing it correctly or not.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.