Learn to Program 4 : String Functions

[ad_1]
Get the Code Here :

Best Python Book :

Interactive Tutorial with Quiz Here :

1st Video :

Support me on Patreon :

This time in my Learn to Program series we’ll cover many string functions and how they can help use solve complex programming problems. We’ll do more with exceptions. We’ll start to explore lists. We’ll create our first function. And, we’ll create an acronym generator and explore the basics of encryption.

Thank you to Patreon supports like the following for helping me make this video

@kyleaisho
@thetwistedhat
vjFaLk


Posted

in

by

Tags:

Comments

30 responses to “Learn to Program 4 : String Functions”

  1. 2Moods Avatar

    If I give an integer to the function isfloat it returns True. Am I missing something? 14:42
    In fact, it seems to always return True no matter what is given.

  2. Hellkite78753 Avatar

    The dark theme is okay, it works fine.

  3. Cheang Wai Bin Avatar

    What does this block of code do? Is it to fix the alphabet in the range of upper and lower case of alphabet? But how why is it 26?
    if char.isupper():
    if char_code > ord('Z'):
    char_code -= 26
    elif char_code < ord('A'):
    char_code += 26
    else:
    if char_code > ord('z'):
    char_code -= 26
    elif char_code < ord('a'):
    char_code += 26
    And why during the decrytion code, `if char.isalpha` is true? char refer to secret_message which was a string with numbers isn't it?

  4. Jake Ambrose Avatar

    dang i liked light way better now i see all the dust on my screen lol

  5. Sujan Shirol Avatar

    If I enter the msg as 'abc' , the encrypted msg is like 'IJK' & decrypted msg is like 'GHI'. What might be the problem?

  6. The Creative Avatar

    Which theme is this

  7. Sirin Öngörur Avatar

    As always, great vids. I´m so impatient so your short vids are a blessing and motivates me to keep learning. Of course I had to solve your first problem really complicated.

    MyString=input("Please enter a string: ").upper()

    MyList=MyString.split()

    for x in range (0,len(MyList)):
    print(MyString[MyString.find(MyList[x])], end="")
    print("")

    🙂

  8. Onyeka Nwaogu Avatar

    This one was a tad too fast for me! I'll have to go over it several times with additional research 🙂

  9. Lol stars Avatar

    in 9:00 why you wrote print() in bottom ? without it also the code works

  10. hleek2003 Avatar

    can this be used in shifting numeric values in a list?

  11. hleek2003 Avatar

    can this be used in shifting arrays of equations ?

  12. Aries Duke Avatar

    my solution for the acronym problem:
    strList = input('Enter the string: ').split()
    for i in strList:
    print(i[0].upper(), end='')

    my solution for the cipher problem:
    key = int(input('key: '))
    string = input('string: ')
    for i in string:
    if i.isalpha(): # if letter – change it
    if i.islower():
    print(chr( 97+(ord(i)-97+key)%26 ), end='') # cipher for lowercase, modular math (or whatever it's called in your language)
    else:
    print(chr( 65+(ord(i)-65+key)%26), end='') # cipher for uppercase, modular math
    else:
    print(i,end='') # if not a letter – print as it is

    So split() creates a list Automatically? I guess so becouse it worked. Also I'm not sure about the cipher solution but I haven't found any mistakes in its results and, to my surprise it even worked with negative keys…

  13. Asker ville Avatar

    Thats the way i did the first problem. My question is: Does the function split creates automatic a list?
    s=str(input("type something in: "))

    s=s.upper()
    l=s.split()
    l=list(l)
    for i in l:
    print(i[0], end = "")

    print ()

  14. Aasim Baig Avatar

    Problem is :
    we will take string by user in variable S
    now we want to separate Alphabets , Numbers and Special Characters and store them in S1, S2, S3 respectively
    How should I approach this problem?
    for eg given input : Abc123!@#
    output should be :
    S1=Abc
    S2=123
    S3=!@#
    how can i separate ?
    please help me!

  15. Aasim Baig Avatar

    rand_string=input("Enter the string : ")
    rand_string=rand_string.upper()
    rand_string=rand_string.split()
    for i in rand_string:
    print(" ".join(i[0]),end="")

    easy pzy 🙂

  16. Sam Viena Avatar

    CAn you elaborate more on the ord() and whats "unicode" lastly why does A-Z have the numbers 65-90 in unicode?

  17. Gerben Veenstra Avatar

    A solution to the problem: "Translate any string into a 'secret' unicode string and apply a shift chosen by the user and then let the user translate that string."

    See below: (extra prints are for overview in the console)
    ——————————————————————————————–
    print()

    original_message = input("Please enter a word or phrase: ")
    key = int(input("Enter a unique value to hide your message: "))

    for char in original_message:
    char_code = ord(char)
    print(char_code + key, end=" ")

    print("n")

    secret_message = (input("Please enter your code including spaces: "))
    secret_message_map = map(int, secret_message.split())

    for set in secret_message_map:
    msg_code = chr(set – key)
    print(msg_code, end="")

    print()
    ——————————————————————————————–
    Give it a try!

  18. ALLAINE GAMING Avatar

    I do that all the time Mr derek!!

  19. ryan Nichols Avatar

    yes thank you for the dark theme! i detest light coloured IDE's

  20. Jay Larry Avatar

    Hi, i enjoyed the tutorial. On the section of acronyms, I want to know about long sentences i.e.

    How would I go about getting an acronym for "Learning and Programming from the Beginning". that ignores "and", "the", "from"
    outputs: LPB

  21. charlicopter Avatar

    All else being equal: are fewer lines of code better? or does the AST not care?
    There seems to be a threshold of diminishing returns where you wind up just making your code really cryptic without increasing efficiency…

  22. bradley wilkendorf Avatar

    Had to get a little help but other than that…

    acronym_enter = input("Please enter something to be turned into an acronym : ")
    acronym_split = acronym_enter.split()
    acronym = " "
    for i in acronym_split:
    acronym += i[0]

    print(acronym.upper())

  23. manish adwani Avatar

    first we are checking whether it's a char or not then if char code > ord(A), why? because below 65 it that wouldn't be char even

  24. Balla Baby Avatar

    YESS!!!! Got the first problem right. No hints or anything. On to the next!

  25. boirokk Avatar

    Thanks for the tuts. I like the way you give us something to practice. I pledged to your Patreon. Thanks Again!

  26. jchoover111 Avatar

    I notice that the isfloat() function you made will return True for ints, also. I realize that ints are technically floats of the form 3.000…, but they are technically different. Also, I can see this being fixed very easily. But should we bother fixing it? Does it matter?

  27. HiggsBoson Avatar

    This is the version I made and it works just as good.

    message = input("Enter the message you would like to encrypt: ")

    code = ""
    key = int(input("How many spaces should we shift: "))

    for i in message:
    if i.isalpha():
    num = ord(i)
    new = num + key
    letter = chr(new)
    code += letter
    else:
    code += i

    print("Your encrypted message is: ", code)

  28. jasevl Avatar

    acronym = str(input("Enter a string: ")).split()
    for c in acronym:
    print(c[0].upper(), end="")

  29. Patrick Parsons Avatar

    At 3:05, out of curiosity, what are you doing to so quickly type in the list? you get the cursor between Bunch and the double-quote and then bam you added a comma. Did you just copy and paste that comma and space?
    ["Bunch(cursor)"]
    to
    ["Bunch", (curosr)]

Leave a Reply

Your email address will not be published. Required fields are marked *