dimanche 31 octobre 2021

Python dictionary; receive user input; enter error code when out of range

I am making a dictionary! I am trying to get the user to select a number between 1 - 10 to generate the Korean word for it. I am able to get the user input to print out the correct translation but I want my code to tell the user to try again if a number between 1 - 10 is not selected. Heeelp.

#1 is key
#all keys need to be unique
#Hana is value
print ("Welcome to the Korean Converter!")

user = int(input("Enter a number between 1 and 10: "))
        
koreanConversion = {
    1: "Hana",
    2: "Tul",
    3: "Set",
    4: "Net",
    5: "Ta Sut",
    6: "Yuh Sut",
    7: "Il Jop",
    8: "Yu Dulb",
    9: "Ah Hop",
   10: "Yul"

}


print (koreanConversion[user])


#else: 
 #   user = int(input("Please try again: "))
 #if (koreanConversion[user]) != [user]
  #   print("Please try again.")

Aucun commentaire:

Enregistrer un commentaire