python3上print的语法问题

2024-09-30 03:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

def main():

    birthRate = (60 / 7)    # Births in a minute
    deathRate = (60 / 13)       # Deaths in a minute
    immigrantRate = (60 / 45)       # New immigrants in a minute
    minutesInaYear = (24 * 60 * 365)        # The number of seconds in a years
    minutesInaLeapYear = (24 * 60 * 366)
    currentPopulation = 312032486
    totalRate = (birthRate - deathRate + immigrantRate)

    populationIncreaseInaYear = (totalRate * minutesInaYear) # Calculates the increase in population after a year

    populationInaYear = (currentPopulation + populationIncreaseInaYear) # Total population after a year

    populationInTwoYears = (currentPopulation + (2 * populationIncreaseInaYear))

    populationInThreeYears = (currentPopulation + (3 * populationIncreaseInaYear))

    populationInFourYears = (currentPopulation + (4 * populationIncreaseInaYear))

    populationInFiveYears = ((populationInFourYears +  (totalRate * minutesInaYear))

    print("The population after one year is: " , populationInaYear)  '''PRINT FUNCTION DOESN'T WORK?'''

    print("The population after two years is: " , populationInTwoYears)
    print("The population after three years is: " , populationInThreeYears)
    print("The population after four years is: " , populationInFourYears)
    print("The population after five years is: " , populationInFiveYears)

main()

为什么打印不起作用?即使我用一个数字替换括号中的所有内容,它也会说打印的“t”处有语法错误。发生什么事?你知道吗


Tags: theinismainyearpopulationprintafter
3条回答

populationInFiveYears行的开头有一个额外的“(”。你知道吗

您需要关闭上一行的圆括号。正确的代码是:

populationInFiveYears = ((populationInFourYears +  (totalRate * minutesInaYear)))

行中有一个不匹配的圆括号:

populationInFiveYears = ((populationInFourYears +  (totalRate * minutesInaYear))

删除“=”后面的第一个开括号“(”,或在行的末尾添加另一个右括号“)”。你知道吗

相关问题 更多 >

    热门问题