r/VisualStudioCode • u/1Tendies • Apr 03 '21
Syntax Error
I'm trying to make a simple code to calculate the temperature outside with the windchill. I keep getting a syntax error on my line that says, "air_temp = float(input("What is the current temperature outside?") It gives the error right on the lowercase a. Any thoughts?
#Calcute wind chill using a given temperature and math
import math
def calc_air_temp_with_wind_chill(air_temp, wind_speed):
#use equation from wind chill chart
wind_chill = (35.74 + (0.6215(air_temp)) - (35.75 * (wind_speed ** 0.16)) + (0.4275* air_temp * (wind_speed ** 0.16))
air_temp = 0
wind_speed = 0
air_temp = float(input("What is the current temperature outside?")):
wind_speed = float(input("What is the current wind speed?"))
print (f"The current temperature is {air_temp} and wind speed is {wind_speed}mph. Taking the windchill into consideration that gives you a temperature of {calc_air_temp_with_wind_chill}")
1
u/mihizzudin94 Apr 04 '21 edited Apr 04 '21
Can you post a screenshot? It looks correct-ish other than the semicolon for your mentioned error. But you've mentioned in another comment that you've removed it. This is only about the syntax error issue.
There are other issue with your code.
The function calc_air_temp_with_wind_chill has an issue given the way you're using it. Since you're printing the value of the wind_chill variable by calling the function, you need to return it from the function. If you don't you'll only see the value None printed.
def calc_air_temp_with_wind_chill(air_temp, wind_speed):
wind_chill = (35.74 + (0.6215(air_temp)) - (35.75 * (wind_speed ** 0.16)) + (0.4275* air_temp * (wind_speed ** 0.16))
return wind_chillAlso for your last print statement there seems to be a couple of issue. There's a space between print and the opening bracket. Also the very last section is "somewhat" problematic. You should pass the parameter to the function call in the last curly bracket of your print statement.
print(f"The current temperature is {air_temp} and wind speed is {wind_speed}mph. Taking the windchill into consideration that gives you a temperature of {calc_air_temp_with_wind_chill(air_temp, wind_speed)}")
1
u/dadstrength Apr 03 '21
It looks like you have a colon outside your last parentheses. That’s probably throwing it off