-1

I started making a project that is showing which bands I like, then ask what artist/band's albums they want to see rated by me. I've got it to show what albums I like but then whenever I try to get Python to show how I rated each song in a specific album for the band/artist, it doesn't do anything. It just ends.

What is happening and how do I fix it?

Also how do I convert the album = input("\nWhich album would you like to see the songs rated?") to be only lowercase so it is easier? Like if it ask Which album would you like to see the songs rated? and I put Vessel, won't Python not interpret the list name and not paste the list?

import time

top_albums = ["1.) Vessel", "2.) Regional at Best", "3.) Twenty One 
Pilots", "4.) Blurryface"]

twenty_one_pilots = ["Example 1"]
regional_at_best = ["Example 2"]
vessel = ["Example 3"]
blurryface = ["Example 4"]

for top_album in top_albums:
    print(top_album)

time.sleep(2)

album = input("\nWhich album would you like to see the songs rated?")


if album == twenty_one_pilots:
    print(twenty_one_pilots)

elif album == regional_at_best:
    print(regional_at_best)

elif album == vessel:
    print(vessel)

elif album == blurryface:
    print(blurryface)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 2
    You're comparing a string an a list. – Norrius Mar 09 '18 at 18:12
  • Strings you enter into `input()` are *not variable references*. You are given a *string*, so `album = 'vessel'`, not the list object. You probably want to learn about *dictionaries* instead. And about `str.lower()` to produce a lowercased version of a string. – Martijn Pieters Mar 09 '18 at 18:15

2 Answers2

0

If you want to get the contents of a list based on the list name, it may be more appropriate to use a dictionary. Minimal example:

my_bands = { "vessel" : ["album 1", "album 2"], "21 pilots" : ["album 1", "album 2"] }

band = input("\nEnter a band name to see their albums: ")

print(my_bands[band])

To include ratings, your lists can be lists of tuples with album names and ratings, for example. But hopefully this can get you started in the right direction.

As has been said elsewhere, you can use .lower() on a string to convert to lowercase. So the last line above would be print(my_bands[band.lower()]).

0

python doesn't interpret strings as code, meaning that your code won't run as expected. To do what you want, perform eval() on album.

In regard to your second question, use .lower() to convert the string to lowercase like this:

album = input("…").lower()
Adi219
  • 4,712
  • 2
  • 20
  • 43