Question
Please find the Error/Bug in this python code: And clearly TYPE what the Error/Bug is, Where it occurs And how to resolve this Error/Bug Dont
Please find the Error/Bug in this python code:
And clearly TYPE what the Error/Bug is, Where it occurs
And how to resolve this Error/Bug
Dont have the data file. I dont need you to resolve the error/bug in the code, just need you to write out and tell me what the error/bug is.
Please TYPE
# -*- coding: utf-8 -*- import os
path = "/Users/user1/data/baby_names/" myyear = input("Please provide the year to be searched:") babyname = input("Please provide the baby name to be searched:") babyname = babyname.capitalize()
baby_counts = count_babies(myyear, babyname)
print("There were {0} boys and {1} girls with that name in {2}".format( baby_counts[0], baby_counts[1], myyear))
def count_babies(year, baby):
file = "yob" + year + ".txt" bnames = []
if file not in os.listdir(path): print("These are not the files you are looking for, move along") return 0 else: f = open(path + file) f.readline() for each in f: fields = each.split(',') bnames.append(fields) f.close() print("Imported " + file)
mcount = 0 fcount = 0 for fields in bnames: if baby in fields[0]: if 'M' in fields[1]: mcount = int(fields[2]) else: fcount = int(fields[2])
return [mcount, fcount]
Here it is with proper indentation
# -*- coding: import os utf-8 -*- path "/Users/user1/data/baby_names/ myyear input("Please provide the year to be searched:" babyname nputC "Please provide the baby name to be searched: babyname babyname.capitalize) baby counts count babies(myyear, babyname) print("There {0} boys and {1} girls with that in {2}", format( were name baby_counts[0] baby_counts1], myyear)) def count babiesCyear, baby): file -"yob" + year + ".txt" if file not in os.listdir(path): printC"These are not the files you are looking for, move along" return 0 else: f open path +file) f.readlineO for each in f fields each.split(',' bnames.append(Fields) f.closeO printC"Imported "+file) mcount -0 fcount - 0 for fields in bnames if baby in fields[8] if M' in fields[1]: mcountint(fields [2]) else: fcount int(fields [2]) return mcount, fcount]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started