Home > Back-end >  problem with displaying only one value on the screen
problem with displaying only one value on the screen

Time:10-29

I'm currently working on a project that should display the cost of nickel. When you insert the year you want to have, it should print out what month you want to have out of that year. If you insert the first three letters of the month you should see all months displayed.

I was trying to convert it to a string to make it understand that it is what i want to display. `

nickel2015 = [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00]


yearinput = str(input("Please enter year to get data:"))

if "2015" in yearinput:
    monthinput = str(input("Please enter month to get data:"))
    if monthinput.find("jan"):
        print(nickel2015[0])
    if monthinput.find("feb"):
        print(nickel2015[1])
    if monthinput.find("mar"):
        print(nickel2015[2])
    if monthinput.find("apr"):
        print(nickel2015[3])
    if monthinput.find("may"):
        print(nickel2015[4])
    if monthinput.find("jun"):
        print(nickel2015[5])
    if monthinput.find("jul"):
        print(nickel2015[6])
    if monthinput.find("aug"):
        print(nickel2015[7])
    if monthinput.find("sep"):
        print(nickel2015[8])
    if monthinput.find("oct"):
        print(nickel2015[9])
    if monthinput.find("nov"):
        print(nickel2015[10])
    if monthinput.find("dec"):
        print(nickel2015[11])

`

CodePudding user response:

The method .find() returns 0 if it finds something, else it returns -1.

This should be your code:

nickel2015 = [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00]


yearinput = str(input("Please enter year to get data:"))

if "2015" in yearinput:
    monthinput = str(input("Please enter month to get data:"))
    if monthinput.find("jan") == 0:
        print(nickel2015[0])
    if monthinput.find("feb") == 0:
        print(nickel2015[1])
    if monthinput.find("mar") == 0:
        print(nickel2015[2])
    if monthinput.find("apr") == 0:
        print(nickel2015[3])
    if monthinput.find("may") == 0:
        print(nickel2015[4])
    if monthinput.find("jun") == 0:
        print(nickel2015[5])
    if monthinput.find("jul") == 0:
        print(nickel2015[6])
    if monthinput.find("aug") == 0:
        print(nickel2015[7])
    if monthinput.find("sep") == 0:
        print(nickel2015[8])
    if monthinput.find("oct") == 0:
        print(nickel2015[9])
    if monthinput.find("nov") == 0:
        print(nickel2015[10])
    if monthinput.find("dec") == 0:
        print(nickel2015[11])
  • Related