dimanche 26 mai 2019

Why is my code only outputting the answers for the 1st and last inputs?

Here, I am supposed to calculate the numerical value of a letter. I am able to calculate it, but when I enter 3 different inputs, I only receive the 1st and the last.

I have tried using different letters, I don't really know what to try, as im pretty new to python. Decided to make an account as I have been stuck on this for about half an hour.

line1 = ["A","B","C"]
list1 = []
for i in line1:
  if i == "A":
    list1.append(1)
else:
  if i == "B":
    list1.append(2)
  else:
    if i == "C":
      list1.append(3)
    else:
      if i == "D":
        list1.append(4)
      else:
        if i == "E":
          list1.append(5)
        else:
          if i == "F":
            list1.append(6)
          else:
            if i == "G":
              list1.append(7)
            else:
              if i == "H":
                list1.append(8)
              else:
                if i == "I":
                  list1.append(9)
                else:
                  if i == "J":
                    list1.append(10)
                  else:
                    if i == "K":
                      list1.append(11)
                    else:
                      if i == "L":
                        list1.append(12)
                      else:
                        if i == "M":
                          list1.append(13)
                        else:
                          if i == "N":
                            list1.append(14)
                          else:
                            if i == "O":
                              list1.append(15)
                            else:
                              if i == "P":
                                list1.append(16)
                              else:
                                if i == "Q":
                                  list1.append(17)
                                else:
                                  if i == "R":
                                    list1.append(18)
                                  else:
                                    if i == "S":
                                      list1.append(19)
                                    else:
                                      if i == "T":
                                        list1.append(20)
                                      else:
                                        if i == "U":
                                          list1.append(21)
                                        else:
                                          if i == "V":
                                            list1.append(22)
                                          else:
                                            if i == "W":
                                              list1.append(23)
                                            else:
                                              if i == "X":
                                                list1.append(24)
                                              else:
                                                if i == "Y":
                                                  list1.append(25)
                                                else:
                                                  if i == "Z":
                                                    list1.append(26)

print(list1)

I expect my output to be 1, 2, and 3 as I am inputting "A", "B", "C"

Aucun commentaire:

Enregistrer un commentaire