-2

How can I make this line work? print('Average state population:', totalPop/50)

it won't let me because the 50 is an int.

def main ():
file = open ('StateCensus2010.txt', 'r')
name = file.readline()
abb = file.readline()
pop = file.readline()
minPop = pop
minName = name
maxPop = pop
maxName = name
totalPop = pop
totalPop += pop   
for state in range (49):
    name = file.readline()
    abb = file.readline()
    pop = file.readline()
    if pop < minPop:
        minPop = pop
        minName = name
    if pop > maxPop:
        maxPop = pop
        minName = name
print(' State with MAX population:',maxName, maxPop)
print('State with MIN population:', minName, minPop)
print('Average state population:', totalPop/50)
Tania L
  • 1
  • 1

1 Answers1

0

You should use either print('Average state population: {}'.format(totalPop/50)) or print('Average state population:', str(totalPop/50)), but preferably the first. This uses string formatting which automatically converts types to strings.

DW42
  • 101
  • 7