Python Forum

Full Version: Solving a problem need help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys I would love to get some help on the following problem. :)

List Manipulator
Our player is having trouble with his friend list and some guys are disappearing without a reason so he asks you to create a program that will figure out what is going on and at the end will bring him a report.
On the first line you will receive all his friends separated by ", ". On the next lines until the "Report" command you will receive commands. The commands could be:
• Blacklist {name}
• Find the name in the friend list and change it to "Blacklisted" and print on the console:
• "{name} was blacklisted."
• If the name is not in the friend list print:
• "{name} was not found."
• Error {index}
• Check if the username at the given index is not "Blacklisted" or "Lost". If it isn't, change the username to "Lost" and print on the console:
• "{name} was lost due to an error."
• Change {index} {newName}
• Check if the user at index position is in range of the array. If he is, change the current username with the new one and print on console:
• "{currentName} changed his username to {newName}."
After you receive "Report" print on the console the count of blacklisted names, the count of lost names, and the friend list separated by a single space.
Input
• The first input line will contain the usernames that need to be stored.
• On the next input lines until "Report" you will receive commands.
Output
• The output should be in the following format:
• "Blacklisted names: {blacklistedNamesCount}"
• "Lost names: {lostNamesCount}"
• "{name1} {name2} .. {nameN}"
Please, don't create multiple threads.
We are glad to hello, but you need to show some effort. Post the code you have so far, if you get error - post the full traceback. Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
(Nov-07-2020, 06:21 PM)buran Wrote: [ -> ]Please, don't create multiple threads.
We are glad to hello, but you need to show some effort. Post the code you have so far, if you get error - post the full traceback. Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
https://pastebin.com/q8GeUj7x

friend_names = input().split(", ")
command = input().split()
lost_names = 0
def in_blacklist(blacklist, names_is):
    return True if names_is in blacklist else False
def in_friendlist(friendlist, name_is1):
    return True if name_is1 in friendlist else False
 
while not command == "Report":
    command_type = command[0]
    name = command[1]
 
    if command_type == "Blacklist":
        while not command[1]=="":
            if in_blacklist(friend_names,name):
                print(f"{name} was blacklisted")
            elif not in_friendlist(friend_names, name):
                print(f"{name} was not found.")
 
    if command_type == "Error":
        if name is not in_blacklist(friend_names,name):
            print(f"{name} was lost due to an error.")
    if command_type == "Change":
        index = friend_names[0]
        if index = 
That is what I have so far :)
Not sure if it is correct in any way shape or form. Just tried to do something but can't solve the problem
Your last line is not complete.
Apart from that - what problem have you identified? Did you get error. Does it do something that you not expect? Be more specific...
(Nov-07-2020, 06:28 PM)totoandreev Wrote: [ -> ]
(Nov-07-2020, 06:21 PM)buran Wrote: [ -> ]Please, don't create multiple threads.
We are glad to hello, but you need to show some effort. Post the code you have so far, if you get error - post the full traceback. Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
https://pastebin.com/q8GeUj7x

friend_names = input().split(", ")
command = input().split()
lost_names = 0
def in_blacklist(blacklist, names_is):
    return True if names_is in blacklist else False
def in_friendlist(friendlist, name_is1):
    return True if name_is1 in friendlist else False
 
while not command == "Report":
    command_type = command[0]
    name = command[1]
 
    if command_type == "Blacklist":
        while not command[1]=="":
            if in_blacklist(friend_names,name):
                print(f"{name} was blacklisted")
            elif not in_friendlist(friend_names, name):
                print(f"{name} was not found.")
 
    if command_type == "Error":
        if name is not in_blacklist(friend_names,name):
            print(f"{name} was lost due to an error.")
    if command_type == "Change":
        index = friend_names[0]
        if index = 
That is what I have so far :)
Not sure if it is correct in any way shape or form. Just tried to do something but can't solve the problem

I just don't know how to continue solving it. It is a problem that I can't solve myself that's why I wanted to ask for someone's help. So they can solve it and I can look at the solution and understand it.
(Nov-07-2020, 06:41 PM)buran Wrote: [ -> ]Your last line is not complete.
Apart from that - what problem have you identified? Did you get error. Does it do something that you not expect? Be more specific...

Just don't know how to solve it. I can't do it on my own.