Don't excute my code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Don't excute my code (/thread-21436.html) Pages:
1
2
|
RE: Don't excute my code - ichabod801 - Oct-01-2019 (Oct-01-2019, 01:48 PM)jefsummers Wrote: In the last code snippet above I believe it should be in knights.items(). Yes, that is correct. RE: Don't excute my code - RavCOder - Oct-01-2019 Excuse me again, but I'm trying to learn how to use dictionaries and I'm having trouble understanding them. Unfortunately I lack the logic in solving these questions that I find on sites like HackerRank. I am trying, compared to before, to think but I still struggle because sometimes I don't understand the deliveries. Perhaps this is the first problem then writing the code I think comes to itself. Thanks again, RavCoder RE: Don't excute my code - RavCOder - Oct-01-2019 So I tried to code again (also thanks to some help that I found on the internet), but now it gives me this error can you help me? n = int(input()) address_book = {} for i in range (0, n): name , phoneNumber = input().split() address_book [name] = phoneNumber if (name is address_book.keys()): print(name + "=" + phoneNumber) else: print('Not found')
RE: Don't excute my code - ichabod801 - Oct-01-2019 You want name in, not name is. RE: Don't excute my code - RavCOder - Oct-01-2019 Ok it's works but I have still a error :
RE: Don't excute my code - jefsummers - Oct-01-2019 First problem - you execute the if(name is address_book... statement every time you read a name when building the address book. De-indent that whole block to fix, but read further (you won't de-indent if you follow the below). After that you have properly built the address book, but you are not input'ing the names to look up. You need to do that somewhere between lines 6 and 8. Putting a while True: at line 7, not indented, followed by name=input() will start the cycle to get names to look up. Right after you read the name, you need to check if it is empty ("") and break out of your loop if it is. In the next if statement you mean in, not is. (current line 8) phone_number is meaningless at this point. You want to look up the number in that address book you worked so hard for. So, your print statement should be similar to print(name+" = "+address_book[name])Almost there... RE: Don't excute my code - RavCOder - Oct-02-2019 Thanks everyone, I resolved it |