Python - For every value in text file? -
with code writing, have split text file using commas, , each value in there, want make integer. have tried splitting text file , turning integer not work. there way of saying values in file, thing? also, amount of values isn't concrete, depends on user of programme (it 'shopping list' programme. current code:
totalcosts=open("totalcosts.txt","r") prices=totalcosts.read() print(prices) prices.strip().split(",") intprices=int(newprices) print(len(intprices)) if len(intprices)==1: print("your total cost is: "+intprices +" pounds") elif len(intprices)>1: finaltotal = sum([int(num) num in intprices.split(",")]) print("your total cost is: "+ finaltotal +" pounds")
prices file values contained in, i've stripped of whitespace , split it. need continue on from. thank xx
results = [int(i) in results]
python 3 can do:
results = list(map(int, results))
Comments
Post a Comment