【问题标题】:I keep getting a syntax error and it highlights tempvals[day+1] but I am not sure why i am getting this error [closed]我不断收到语法错误,它突出显示 tempvals[day+1] 但我不确定为什么会收到此错误 [关闭]
【发布时间】:2012-12-06 01:35:31
【问题描述】:

输入:是给定的值,例如 sig 和 rho_c 列出所有的日子 使用 for 循环查找每一天的时间 节省时间 找出温度的变化。对于每一天 找出每一天的温度值 找出你需要的 A 值 绘制数据图 输出:日与温度的关系图。

Aice = 1
Anoice=0.
Tice =273.
Tnoice=293.
dt = 86400.
S = 342.5
rho_c =206000000.
epsilon_tow =.62
sig =5.6710E-8
Tint=288.

import numpy as N
tempvals= N.zeros((3000,))   #creates an array to store temp. values                     
tempvals[0]= Tint            #set the first value of array to Tint
times=N.zeros((3000,))       #creates array to store time values
    for day in range(3000):      #Creates the values of day and goes through
                             #calculates for every day time, A,dT,T 
        time = (dt)*day
        times[day] = time
        if tempvals[day] <= Tice:
            A=Aice
        elif tempvals[day] >=Tnoice:
            A=Anoice
        else :
            A=(((tempvals[day]-Tice)/(Tnoice-Tice)*(Anoice-Aice))+Aice)
        dT =(((S*(1-A))-((epsilon_tow*sig*(tempvals[day]**4))/rho_c )*dt

        if day <2999  
                 tempvals[day+1]= T+dT
                 tempvals[day]= T


        plot(day,T)                    #plots graph of day valueson x axis and
                                       #T values on as y-axis
        plot.title(T)                  #creates title of the graph

【问题讨论】:

    标签: python syntax numpy


    【解决方案1】:

    您在上一行中缺少:

    if day < 2999: # <- need a colon here  
        tempvals[day+1]= T+dT
    

    编辑:您在这一行中也有不匹配的括号/括号:

    dT =(((S*(1-A))-((epsilon_tow*sig*(tempvals[day]**4))/rho_c )*dt # missing parens
    

    这行看起来应该更像:

    dT = ((S*(1-A))-((epsilon_tow*sig*(tempvals[day]**4))/rho_c))*dt
    

    【讨论】:

    • 它突出显示冒号并表示语法无效
    • 在此之前的行中还有不匹配的括号。
    • 一般来说,当 Python 给你一个 SyntaxError 的一行看起来非常好时,看看它上面的行,看看它是否遗漏了什么。与来到 SO 并等待其他人进行调试相比,这是一种调试代码的更快方法。
    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 2020-09-04
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    相关资源
    最近更新 更多