Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help
#11
(Aug-15-2017, 04:27 PM)nilamo Wrote: How do you know that a Ryanair is a 6?

Unless you put it somewhere in your program (or if it's standardized, use a library/service), how do you expect python to know that whatever a "Ryanair" is means whatever meaning you attach to "6"?  To python, they're just unrelated strings/numbers.

No I want to make a program so if a user types in Ryanair it comes back with the number 6 and then if someone types in AAL it comes back with 11 ect ect ect for every airline
Reply
#12
(Aug-15-2017, 04:31 PM)777CAIN Wrote: No I want to make a program so if a user types in Ryanair it comes back with the number 6 and then if someone types in AAL it comes back with 11 ect ect ect for every airline

Ok, but those numbers are meaningless.  Unless you create a dictionary that maps all of those things to whatever number they represent, that is.
Reply
#13
(Aug-15-2017, 04:42 PM)nilamo Wrote:
(Aug-15-2017, 04:31 PM)777CAIN Wrote: No I want to make a program so if a user types in Ryanair it comes back with the number 6 and then if someone types in AAL it comes back with 11 ect ect ect for every airline

Ok, but those numbers are meaningless.  Unless you create a dictionary that maps all of those things to whatever number they represent, that is.

You lost me... i just want to make a program (im new to coding) where someone puts a word and it comes back as a number thats all.
Reply
#14
items = {
    "Ryanair": 6,
    "AAL": 11
}

thing = input("Check which? ")
if thing in items:
    print(items[thing])
else:
    print("Invalid input")
How's that?  It's just a map of keys to the number they associate to, and prints it when someone types in the key.
Reply
#15
(Aug-15-2017, 04:49 PM)nilamo Wrote:
items = {
    "Ryanair": 6,
    "AAL": 11
}

thing = input("Check which? ")
if thing in items:
    print(items[thing])
else:
    print("Invalid input")
How's that?  It's just a map of keys to the number they associate to, and prints it when someone types in the key.

Thank you so much thats how i wanted it to work!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020