Issue with array syntax python

Viewed 33

error code

    def rainfall():
  print('Hello, and thank you for using the H20 Weather Program.')
  years = int(input('How many years of rainfall would you like to track')
  months = ["January","February","March"]
print(months)
  for x in years:
    for y in months:
      float(input = ("How much rainfall was there in ",y))
rainfall()

I'm getting a syntax error with the list (see image). I checked the syntax and It's identical to what I have. It works when I define the list outside the function, but It's for a class and the whole program is supposed to be contained in a function.

2 Answers
def rainfall():
  print('Hello, and thank you for using the H20 Weather Program.')
  years = int(input('How many years of rainfall would you like to track')
  months = ["January","February","March"]
print(months)
  for x in years:
    for y in months:
      float(input = ("How much rainfall was there in ",y))
rainfall()

So it seems like the issue with this code is 1. the indentation. Python establishes whats in the function based on indentation. 2. float(input = ("words")) will cause an error because you're trying to use input("words") but you're not assigning anything so the = isn't necessary.The final code should look like this:

1.def rainfall():
2.  print('Hello, and thank you for using the H20  Weather Program.')
3.  years = int(input('How many years of rainfall would you like to track')
4.  months = ["January","February","March"]
5.  print(months)
6.  for x in years:
7.    for y in months:
8.      answer = float(input("How much rainfall was there in ",y))
9.rainfall()

Don't sweat the mistakes coding is hard and takes time. Good luck!

def rainfall():
  print("Hello, and thank you for using the H20 Weather Program.")
  years = int(input("How many years of rainfall would you like to track"))
  months = ["January","February","March"]
  print(months)
  for x in years:
    for y in months:
      number = float(input = ("How much rainfall was there in ",y))
rainfall()

Try this one

Related