#! /usr/bin/env python3 from ast import literal_eval with open('test.txt') as file: for line in file: name, values = line.split('=') values = literal_eval(values) if sum(values) == 0: pass else: print(f'District: {name}') print(f'Hal received {values[3]} votes AVG: - {values[3]/sum(values):.2%}.')test.txt
Output:p3624=[454, 434, 175, 178, 82, 92, 6]
p3635=[0, 0, 0, 0, 0, 0, 0]
p3628=[45, 44, 175, 178, 82, 92, 6]
Output:District: p3624
Hal received 178 votes AVG: - 12.53%.
District: p3628
Hal received 178 votes AVG: - 28.62%.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags