All Articles

[Py] For Loop

unsplash-film

For iterator makes life easier. Let’s see how you can make your life easier. What you need to do is to turn a word “Gee” into a given string input. For example, if you provide string “Wow” input, then every ”Gee” part should be changed to “Wow”.

new_gee = input()  # Wow

Below is the lyrics of Gee, a title song by Girls Generation. Don’t let your fingers do all the job!!!!!

    **<Lyrics of Gee>**

    It's way too bright, my eyes are blinded

    I can't stop to breathe, I'm a girl falling in love

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Baby Baby Baby

    Oh I'm too shy, I can't even glance at you

    I've fallen in love, I'm a shy girl

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Bab Bab Bab Bab Bab Bab

    How did this happen? (How did it happen?)

    My beating heart (My beating heart)

    (Thump, thump thump) It just thuds and thuds, I can't even sleep

    I, I must look like a fool

    I don't want anyone but him, Yeah, I'm a fool looking right at him

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    Oh, It's too pretty, your soul's too pretty

    It's love at first sight, I'm a girl that knows what I feel

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Baby Baby Baby

    It's too warm, I can't touch it

    This love is heated, I'm a girl that can feel the heat

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Bab Bab Bab Bab Bab Bab

    I like it however it is (However it is)

    I'm so shy (Shy me)

    (I dunno, dunno, dunno)

    I don't know and I everyday I just want to see you,

    Of course my close friends tease,

    You really, You really can't stop

    I'm a fool but I still look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    The things I can't say, I'm too shy,

    I don't have the courage, How could this be good?

    My beating heart, I'm anxious as I look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yea

First thing’s first, variable song_gee contains Gee lyrics in F-string format.

new_gee = input()

song_gee = f""" It's way too bright, my eyes are blinded

    I can't stop to breathe, I'm a girl falling in love

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Baby Baby Baby

    Oh I'm too shy, I can't even glance at you

    I've fallen in love, I'm a shy girl

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Bab Bab Bab Bab Bab Bab

    How did this happen? (How did it happen?)

    My beating heart (My beating heart)

    (Thump, thump thump) It just thuds and thuds, I can't even sleep

    I, I must look like a fool

    I don't want anyone but him, Yeah, I'm a fool looking right at him

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    Oh, It's too pretty, your soul's too pretty

    It's love at first sight, I'm a girl that knows what I feel

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Baby Baby Baby

    It's too warm, I can't touch it

    This love is heated, I'm a girl that can feel the heat

    Gee Gee Gee Gee Baby Baby Baby

    Gee Gee Gee Gee Bab Bab Bab Bab Bab Bab

    I like it however it is (However it is)

    I'm so shy (Shy me)

    (I dunno, dunno, dunno)

    I don't know and I everyday I just want to see you,

    Of course my close friends tease,

    You really, You really can't stop

    I'm a fool but I still look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    The things I can't say, I'm too shy,

    I don't have the courage, How could this be good?

    My beating heart, I'm anxious as I look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling Gee Gee Gee Gee Gee

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

     """

Then, I used split() method which splits a string into a list(splitSong) to swap every word of “Gee” into given a input string. Lastly, join() method turns the list into a string.

splitSong = song_gee.split()

for idx, value in enumerate(splitSong, start = 0):
  if splitSong[idx] == "Gee":
    splitSong[idx] = new_gee
    result = ' '.join(splitSong)

    print(result)

Of course. There are so many ways to complete it other than for iterator . One is Concatenating Text Strings.

    new_gee = input()

  print(f""" It's way too bright, my eyes are blinded

    I can't stop to breathe, I'm a girl falling in love

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    Oh I'm too shy, I can't even glance at you

    I've fallen in love, I'm a shy girl

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    {new_gee} {new_gee} {new_gee} {new_gee} Bab Bab Bab Bab Bab Bab

    How did this happen? (How did it happen?)

    My beating heart (My beating heart)

    (Thump, thump thump) It just thuds and thuds, I can't even sleep

    I, I must look like a fool

    I don't want anyone but him, Yeah, I'm a fool looking right at him

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling {new_gee} {new_gee} {new_gee} {new_gee}

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    Oh, It's too pretty, your soul's too pretty

    It's love at first sight, I'm a girl that knows what I feel

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    It's too warm, I can't touch it

    This love is heated, I'm a girl that can feel the heat

    {new_gee} {new_gee} {new_gee} {new_gee} Baby Baby Baby

    {new_gee} {new_gee} {new_gee} {new_gee} Bab Bab Bab Bab Bab Bab

    I like it however it is (However it is)

    I'm so shy (Shy me)

    (I dunno, dunno, dunno)

    I don't know and I everyday I just want to see you,

    Of course my close friends tease,

    You really, You really can't stop

    I'm a fool but I still look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling {new_gee} {new_gee} {new_gee} {new_gee}

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    The things I can't say, I'm too shy,

    I don't have the courage, How could this be good?

    My beating heart, I'm anxious as I look at you,

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling {new_gee} {new_gee} {new_gee} {new_gee}

    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

    It's so bright, my eyes are blinded No No No No No

    I'm so surprised Oh Oh Oh Oh Oh

    I'm shocked, my body's trembling {new_gee} {new_gee} {new_gee} {new_gee}
    Sparkling eyes Oh Yeah Sweet scent Oh Yeah Yeah Yeah

     """)

We are creating wealth every time we write a code