Skip to the content.

3.4 HW

3.4 HW and Popcorn Hacks

Tri 1 Documentation

#Popcorn Hack 1

# Lyrics of "I Want It That Way"
lyrics = """
You are my fire
The one desire
Believe when I say
I want it that way

But we are two worlds apart
Can't reach to your heart
When you say
That I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

Am I your fire?
Your one desire
Yes, I know it's too late
But I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

Now I can see that we've fallen apart
From the way that it used to be, yeah
No matter the distance
I want you to know
That deep down inside of me

You are my fire
The one desire
You are, you are, you are, you are

Don't wanna hear you say
Ain't nothin' but a heartache
Ain't nothin' but a mistake
(Don't wanna hear you say)
I never wanna hear you say
I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

'Cause I want it that way
"""
#How many times does the title is in the lyrics
title = "I want it that way"
title_count = lyrics.lower().count(title.lower())
print("The title '" + title + "' appears " + str(title_count) + " times in the lyrics.")

#50th word in lyrics
words = lyrics.split()
index_50th_word = lyrics.find(words[49])
print("The index of the 50th word is '" + words[49] + "'" + ".")


#Replacing first verse with last verse
verses = lyrics.strip().split("\n\n")
first_verse = verses[0]
last_verse = verses[-1]
lyrics_modified = lyrics.replace(first_verse, last_verse, 1)
print("\nModified Lyrics:")
print(lyrics_modified)

#Creating new verse
new_verse = verses[1] + "\n\n" + verses[2]
print("\nNew Verse:")
print(new_verse)
The title 'I want it that way' appears 8 times in the lyrics.
The index of the 50th word is 'but'.

Modified Lyrics:

'Cause I want it that way

But we are two worlds apart
Can't reach to your heart
When you say
That I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

Am I your fire?
Your one desire
Yes, I know it's too late
But I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

Now I can see that we've fallen apart
From the way that it used to be, yeah
No matter the distance
I want you to know
That deep down inside of me

You are my fire
The one desire
You are, you are, you are, you are

Don't wanna hear you say
Ain't nothin' but a heartache
Ain't nothin' but a mistake
(Don't wanna hear you say)
I never wanna hear you say
I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way

'Cause I want it that way


New Verse:
But we are two worlds apart
Can't reach to your heart
When you say
That I want it that way

Tell me why
Ain't nothin' but a heartache
Tell me why
Ain't nothin' but a mistake
Tell me why
I never wanna hear you say
I want it that way
const flower = "Sunflower";
const animal = "Monkey";
const newCreature = `${flower}${animal}`;

console.log("The new creature is: " + newCreature);
console.log(`The new creature is: ${newCreature}`);

const creatureName = newCreature;
const color = "Red";
const habitat = "forest";

let story = `
In a dense ${habitat}, where the sunlight filtered through the trees and vibrant flowers blossomed, lived a unique creature known as the ${creatureName}. This fascinating being combined the beauty of a ${flower} with the cleverness of a ${animal}.

One day, a traveler exploring the ${habitat} came across the ${creatureName}. Curious, he approached and asked, "What makes you so special?"

The ${creatureName} replied with a smile, "I blend the charm of a ${flower} with the sharpness of a ${animal}. I can guide you through these woods and show you hidden wonders!"

Intrigued, the traveler agreed. Together, they set off on an adventure, discovering hidden glades and sparkling streams. The ${creatureName} shared stories about the forest, revealing its secrets."
`;

console.log(story);




  File "/tmp/ipykernel_89504/1565471567.py", line 19
    Intrigued, the traveler agreed. Together, they set off on an adventure, discovering hidden glades and sparkling streams. The ${creatureName} shared stories about the forest, revealing its secrets."
                                                                                                                                                                                                        ^
SyntaxError: unterminated string literal (detected at line 19)
def text_analyzer(input_string):
  
    print("Original String:", input_string)

    total_characters = len(input_string)
    print("Total Characters:", total_characters)


    words = input_string.split()
    longest_word = max(words, key=len)
    print(f"Longest Word: {longest_word} ({len(longest_word)} characters)")

    # Display the string reversed
    reversed_string = input_string[::-1]
    print("Reversed String:", reversed_string)

  
    cleaned_input = ''.join(filter(str.isalnum, input_string))
    middle_index = len(cleaned_input) // 2
    middle_character = cleaned_input[middle_index]
    print("Middle Character:", middle_character)

    word_count = len(words)
    print("Total Words:", word_count)

    letter_frequency = {}
    for char in input_string:
        if char.isalnum():  
            char = char.lower()  
            if char in letter_frequency:
                letter_frequency[char] += 1
            else:
                letter_frequency[char] = 1

  
    most_frequent_letter = max(letter_frequency, key=letter_frequency.get)
    print(f"Most Frequent Letter: {most_frequent_letter} ({letter_frequency[most_frequent_letter]} times)")




user_input = input("Enter a string for analysis: ")
text_analyzer(user_input)
Original String: testing 
Total Characters: 8
Longest Word: testing (7 characters)
Reversed String:  gnitset
Middle Character: t
Total Words: 1
Most Frequent Letter: t (2 times)