0
import pywapi
import string
zip = input(" ZIP Code: ")
cs = input("City, State: ")
weather_com_result = pywapi.get_weather_from_weather_com('zip')
print "Weather.com says: It is " + .lower(weather_com_result['current_conditions']['text']) + " and " + weather_com_result['current_conditions'] + ['temperature'] + "F now in" ['cs'] + "./n/n"

It gives me an error with 'cs'. Anyone know why?

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked Sep 7, 2016 at 2:31
2
  • Sailormanenzo: There is no need to leave thanks in the question. If there is an answer which best helped you to a solution, indicate it by ticking the large checkmark next to it on the left. Commented Sep 7, 2016 at 17:37
  • Oh yes I see it now. Commented Sep 7, 2016 at 18:03

2 Answers 2

1

Change your print statement like below (I mean the format) instead of using string concat operation. I would not say its not correct to write that way but the below way is always a better operation since you will have the control on string type as well.

import pywapi
import string
zip = input(" ZIP Code: ")
cs = raw_input("City, State: ")
weather_com_result = pywapi.get_weather_from_weather_com('zip')
print "Weather.com says: It is %s and %s F now in %s \n \n." %(str(lower(weather_com_result['current_conditions']['text'])), str(weather_com_result['current_conditions']['temperature']), str(cs))

However if you still need it in the concat way use the below sample syntax.

import pywapi
import string
zip = input(" ZIP Code: ")
cs = raw_input("City, State: ")
weather_com_result = pywapi.get_weather_from_weather_com('zip')
print "Weather.com says: It is ." + str.lower('abc') + " and " + 'def' + 'ghi' + "F now in " + str('ijk') + ".\n\n"

Errors in your program

Your print statement has a variable

weather_com_result['current_conditions'] + ['temperature'] it should be weather_com_result['current_conditions']['temperature']

Let me know if you have any questions.

answered Sep 7, 2016 at 6:07
6
  • When I use the first option I get: Traceback (most recent call last): File "weather1.py", line 5, in <module> cs = input("City, State: ") File "<string>", line 1, in <module> NameError: name 'NYC' is not defined Commented Sep 9, 2016 at 2:27
  • Also on the second option Commented Sep 9, 2016 at 17:39
  • Try using raw_input instead of input. Let me know if you are still having issues, Looks like pywapi is something custom that you have written. So I did not test the whole stuff. Just looked at the traceback. Commented Sep 10, 2016 at 5:58
  • Yes pywapi is a program made by someone from GitHub Commented Sep 10, 2016 at 18:52
  • Traceback (most recent call last): File "weather.py", line 8, in <module> print "Weather.com says: It is %s and %s F now in %s \n \n." %(str(lower(weather_com_result['current_conditions']['text'])), str(weather_com_result['current_conditions']['temperature']), str(cs)) NameError: name 'lower' is not defined Commented Sep 10, 2016 at 22:52
2

You must replace ['cs'] with + cs.

For the formatting, you can use the % syntax. Then, you will not have errors like this.

Jacobm001
11.9k7 gold badges48 silver badges58 bronze badges
answered Sep 7, 2016 at 5:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.