[Python] Write a program that first takes in word pairs that consist of a name and a phone...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I have the following prompt:


    A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes in word pairs that consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Assume the search name is always in the list.
    ​

    Ex:


    If the input is: Joe,123-5432 Linda,983-4123 Frank,867-5309 Frank the output is: 867-5309
    ​

    my code:

    pn = str(input()).split()

    search = str(input())

    i=0

    for i in range(len(on)):

    if pn == (search):

    print([i+1])


    The input is getting split into a name and number. When the code goes to check if the names are the same, it always returns false. I've tried using the re.split() method, but it didn't work.

    Continue reading...

Compartilhe esta Página