Sort by

recency

|

2715 Discussions

|

  • + 0 comments

    Any toughts on why all the tests are Passed but getting Runtime error?

    if __name__ == '__main__':
        n = int(input())
    my_dict = {}
    for _ in range(n*2):
        s = str(input())
        if " " in s:
            nameAndPhone = s.split(" ")
            name = nameAndPhone[0]
            phone = nameAndPhone[1]
            my_dict[name] = phone
        else:
            if s in my_dict:
                print(f"{s}={my_dict[s]}")
            else:
                print("Not found")
    
  • + 0 comments

    Here's what I have for Python 3:

    import sys
    
    entries = int(input())
    friends = {}
    
    # The first n lines
    for _ in range(entries):
        name, number = input().split(' ')
        friends[name] = number
    
    # The remaining lines
    for line in sys.stdin:
        name = line.strip()
        if name in friends:
            print(f"{name}={friends.get(name)}")
        else:
            print("Not found")
    
  • + 1 comment

    code in python

    n = int(input().strip())
    my_contact = {}
    
    # Store contacts
    for _ in range(n):
        name, number = input().strip().split()
        my_contact[name.lower()] = int(number)
    
    # Search contacts until EOF (End of Input)
    try:
        while True:
            search_name = input().strip()
            key = search_name.lower()
            if key in my_contact:
                print(f"{search_name}={my_contact[key]}")
            else:
                print("Not found")
    except EOFError:
        pass
    
  • + 0 comments

    JS solution

    function processData(input) {
        //Enter your code here
        const persArray = input.split('\n'); //get lines as array
        const nPpl = Number(persArray[0]); //first input line is nPpl
        var phonebook = new Map(); 
        
        for (let i = 1; i <= nPpl; i++){
            let details = persArray[i].split(' '); //get array [name,num]
            phonebook.set(details[0],details[1])
        }
        
        for (let i = nPpl + 1; i < persArray.length; i++){
            let person = persArray[i];
            let num = phonebook.get(person);
            if (num) {
                console.log(person + '=' + num)
            } else{console.log('Not found')}
        }
    } 
    
  • + 0 comments

    Here's my solution using Javascript, though I got an error on submission:

    function processData(input) {
        //Enter your code here
        let phoneBookEntries = [];
        phoneBookEntries.push(input);    
        let entries = phoneBookEntries[0].split('\n');
        
        let numberOfPairs = parseInt(entries);
        
        let phoneBook = new Map();
        
        for(let i = 0; i<= numberOfPairs; i++){
            let[name, number] = entries[i].split(" ");
            phoneBook.set(name, number);
            console.log("The phonebook:", phoneBook);
        }
            
        for (let i = numberOfPairs; i<entries.length; i++){
            let query = entries[i];
            if(phoneBook.has(query)){
                 return query + "=" + phoneBook.get(query);
            } else {
                 return "Not found";
             }
        }
        
    }
    

    What I'm I missing in my code? On console.log, I'm only getting the last key in the phoneBook map