语法错误-突出显示一个变量Python

语法错误-突出显示一个变量Python,python,variables,syntax,Python,Variables,Syntax,我是Python编码的初学者。我写这段代码的目的是让用户在两个表格中看到世界人口信息,然后几个选项就是男女比例最高、最低的句子,等等 我遇到并修复了多个错误。最后一个我似乎无法修复的错误只是一个语法错误,但我无法找出错误所在。它会弹出一个框,显示语法错误并突出显示我的局部变量,bothSexes\u total。显示的选项打印一个表 def main(): print("Welcome user.") #greetings Ages0_14= open("Ages0-14.txt

我是Python编码的初学者。我写这段代码的目的是让用户在两个表格中看到世界人口信息,然后几个选项就是男女比例最高、最低的句子,等等

我遇到并修复了多个错误。最后一个我似乎无法修复的错误只是一个语法错误,但我无法找出错误所在。它会弹出一个框,显示语法错误并突出显示我的局部变量,
bothSexes\u total
。显示的选项打印一个表

def main():
    print("Welcome user.") #greetings
    Ages0_14= open("Ages0-14.txt", "r") #open files needed
    Ages15_64= open("Ages15-64.txt", "r")
    Ages65= open("Ages65.txt", "r")
    countries, males0_14, females0_14= get_lists(Ages0_14) #makes 3 lists from 1st file
    empty, males15_64, females15_64= get_lists(Ages15_64) #2 lists from 2nd file
    empty2, males65, females65= get_lists(Ages65) #2 lists from 3rd file
    print_menu()
    choice= input("Type the letter of the choice you would like to make.") #user makes choice

    if choice== "A" or choice== "a": #option a: display country's information
        country_input= input("Choose a country you would like to know the population information of.")
        country=(countries.index(country_input) #find index of country

        # I get an error here:
        bothSexes_total=(int(females0_14[country])+ int(females15_64[country])+ int(females65[country])+ int(males0_14[country])+ int(males15_64[country])+ int(males65[country]))
            male_total=(males0_14[country]+ males15_64[country]+ males65[country]) #male total from all ages
            female_total=(females0_14[country]+ females15_64[country]+ females65[country]) #female total from all ages
            both0_14=(int(males0_14[country])+ int(females0_14[country])) #total of both sexes from 1st file
            both15_64=(int(males15_64[country])+ int(females15_64[country])) #total of both sexes from 2nd file
            both65=(int(males65[country])+ int(females65[country])) #total of both sexes from 3rd file
            print(format("Country","20s")+ format("Age","20s")+ format("Both Sexes","20s")+ format("Male","20s")+ format("Female","20s")+ format("%Both","20s")+ format("%Male","20s")+ format("%Female","20s")+ format("Male to Female Ratio","20s")) #headers
                                    #name                   age                     both sexes             males                              females                                  %both
            print(format(countries[country], "20s")+ format("Total","20s")+ format(bothSexes_total, "20d")+ format(male_total, "20d")+ format(female_total, "20d")+ format(100, "20d")+ format(100, "20d")+ format(100, "20d")+ format(male_total/ female_total) #total age groups                                                 %males                        %females                                                 ratio
            print(format(countries[country], "20s")+ format("0-14","20s")+ format(both0_14, "<20d")+ format(males0_14[country], "<20d")+ format(females0_14[country], "<20d")+ format(males0_14[country]+ females0_14[country])/totalSexes_both, "<20d")+ format((males0_14[country])/male_total, "<20d")+ format((females0_14[country])/female_total, "<20d")+ format((male0_14/female0_14)*100, "20d") #1st file
            print(format(countries[country], "20s")+ format("15-64","20s")+ format(both15_64, "<20d")+ format(males15_64[country], "<20d")+ format(females0_14[country], "<20d")+ format(males15_64[country]+ females15_64[country])/totalSexes_both, "<20d")+ format((males15_64[country])/male_total, "<20d")+ format((females15_64[country])/female_total, "<20d")+ format((male15_64/female15_64)*100, "20d") #2nd file
            print(format(countries[country], "20s")+ format("64+", "20s")+ format(both65, "<20d")+ format(males65[country], "<20d")+ format(females65[country], "<20d")+ format(males65[country]+ females65[country])/totalSexes_both, "<20d")+ format((males0_14[country])/male_total, "<20d")+ format((females0_14[country])/female_total, "<20d")+ format((male65/female65)*100, "20d") #3rd file
def main():
打印(“欢迎用户”)#问候语
Ages0_14=打开(“Ages0-14.txt”,“r”)#需要打开文件
Ages15_64=打开(“Ages15-64.txt”,“r”)
Ages65=打开(“Ages65.txt”、“r”)
国家,男性0_14,女性0_14=获取列表(年龄0_14)#从第一个文件中创建3个列表
空,男性15_64,女性15_64=从第二个文件中获取2个列表(年龄15_64)
empty2,males65,females65=从第三个文件中获取两个列表(年龄65)#
打印菜单()
choice=输入(“键入您希望做出的选择的字母。”)#用户做出选择
如果选项==“A”或选项==“A”:#选项A:显示国家信息
country_input=input(“选择一个您想了解其人口信息的国家。”)
country=(countries.index(country_输入)#查找国家索引
#我在这里得到一个错误:
两者合计=(int(女性0_14[国家])+int(女性15_64[国家])+int(女性65[国家])+int(男性0_14[国家])+int(男性15_64[国家])+int(男性65[国家])
男性总数=(男性14[国家]+男性15[国家]+男性65[国家])#所有年龄段的男性总数
女性总数=(女性0_14[国家]+女性15_64[国家]+女性65[国家])#所有年龄段的女性总数
从第一档开始,男女人数之和分别为int(男性14[国家])+int(女性14[国家])#
第二份文件中的男女总数分别为15_64=(int(男性15_64[国家])+int(女性15_64[国家])#
both65=(int(男性65[国家])+int(女性65[国家])#第三档男女总数
打印(格式(“国家”、“20岁”)+格式(“年龄”、“20岁”)+格式(“两性”、“20岁”)+格式(“男性”、“20岁”)+格式(“女性”、“20岁”)+格式(“双方”、“20岁”)+格式(“男性”、“20岁”)+格式(“女性”、“20岁”)+格式(“男女比例”、“20岁”)#
#姓名年龄男女均为男性女性均为%
打印(格式(国家[国家],“20s”)+格式(“总计”,“20s”)+格式(两种格式,总计,“20d”)+格式(男总计,“20d”)+格式(女总计,“20d”)+格式(100,“20d”)+格式(100,“20d”)+格式(男总计/女总计)#总年龄组%男性%女性比率

print(format(format)(format(format)(国家[国家],“20s”)+format(format)(“0-14”,“20s”)+format(both0_14)”,您忘记了在前一行关闭paren。

请记住,在python中,每当返回错误并突出显示特定单词/短语时,错误很可能在突出显示的单词/短语之前。因此,假设我有:

name = input("enter your name"

print(name)
然后突出显示
打印
,然后错误是之前的错误,正如您所看到的,我忘记关闭输入函数的括号

希望这有帮助


~bobbeh

更具体地说,
country=(countries.index(country\u输入)
有两个打开的参数和一个关闭的参数。