Alternate (Simpler) Solution for Apprentice Python Final Activity MethodPython for Security Professionals Course

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATION
Already a Member Login Here

Home Forums Courses Python for Security Professionals Course Alternate (Simpler) Solution for Apprentice Python Final Activity Method

This topic contains 5 replies, has 6 voices, and was last updated by  bladerunner 2 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #47803

    HiddenLotus
    Participant

    When I watch the videos I sort of try things on my own, and this is what I came up with intuitively. It seems much more simple than the sol’n from the video. Could someone tell me if this is worse in any way?

    def remove_letter(): #Remove a selected letter from a string
            print("Remove Letter")
            baseString = str(raw_input("Enter String"))
            rem = str(raw_input("Enter Letter to Remove"))
            newString = ""
            remLetter = rem[0]
            for let in baseString:
                    if let==remLetter:
                            continue
                    else:
                            newString = newString+let
            print newString
            return

    Maybe I’m missing something in terms of secure coding?

    #47815

    Adam
    Participant

    What if ‘rem’ is None (empty)?

    #50655

    NotCorrect
    Participant

    I like this overall solution much better. I too was yelling at my screen when the instructor started
    hacking up the code to make it work when this would do it much more simply.

    BTW : The empty ‘rem’ item is still an issue in the original code too. No error/bounds checking but its just for learning.

    #50919

    jakaprana
    Participant

    I like your solution because is simple and give the correct output. The solution from video if we enter string aasdf and enter letter a, the output will be asdf instead of sdf.

    #79337

    alex.rothos
    Participant

    I think the exercises are good but the suggested solutions could be more polished… like yours.

    #107948

    bladerunner
    Participant

    Or, you can try:
    def remove_letter(): #Remove a selected letter from a string
    remove = str(raw_input(“Enter letter to remove: “))
    remove = remove[0]
    global saved_string
    edited_str = saved_string.replace(remove,””)
    print “Edited string is: %s” %edited_str
    return edited_str

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Our Revolution

We believe Cyber Security training should accessible for everyone, everywhere. Everyone deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is the world's largest community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel