How can I convert the film_name parameter to lowercase using the lower() method in Python?

36 Views Asked by At

I want to convert the film_name parameter to lowercase using the lower() method. This ensures that the function can perform a case-insensitive search when checking if the film is a winner.

I tried the following:

def won_golden_globe(film_name):
  golden_globes = ["Jaws", "Star Wars: Episode IV - A New Hope", "E.T. the Extra-Terrestrial", "Memoirs of a Geisha"]
  film_name==film_name.lower()
  while film_name or film_name.lower in golden_globes:
    return True
  else:
      return False
z= won_golden_globe("jaws")
print (z)

I expected that it would print "True", it printed "False" instead

1

There are 1 best solutions below

1
Berc07 On

You should store the movie names as lowercase, or also transform it to lower.

There are 2 little problem with your code:

  1. You used "==" instead of '=' while making the film_name lower
  2. You made lowercase the parameter of your function, but not your list

Here is the corrected code:


def won_golden_globe(film_name):
    golden_globes = ["Jaws", "Star Wars: Episode IV - A New Hope", "E.T. the Extra-Terrestrial", "Memoirs of a Geisha"]
    film_name = film_name.lower()
    for film in golden_globes: # i used for loop, because it makes easier to iterate over the list
        if film.lower() == film_name:
            return True
    return False 

z= won_golden_globe("jaws")
print (z)

I hope it helps.