Question

In: Computer Science

PYTHON CODE Step one: Copy and paste these lyrics into a multistring line "Do you ever...

PYTHON CODE

Step one: Copy and paste these lyrics into a multistring line

"Do you ever feel like a plastic bag
Drifting through the wind
Wanting to start again?
Do you ever feel, feel so paper-thin
Like a house of cards, one blow from caving in?

Do you ever feel already buried deep
Six feet under screams but no one seems to hear a thing
Do you know that there's still a chance for you
'Cause there's a spark in you?

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

You don't have to feel like a wasted space
You're original, cannot be replaced
If you only knew what the future holds
After a hurricane comes a rainbow

Maybe a reason why all the doors are closed
So you could open one that leads you to the perfect road
Like a lightning bolt your heart will glow
And when it's time you'll know

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
It's always been inside of you, you, you
And now it's time to let it through, -ough, -ough

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
Boom, boom, boom
Even brighter than the moon, moon, moon"

Step two: Then display and record the following statistics...

  • The total word count
  • The total character count
  • The average word length
  • The average sentence length
  • A word distribution of all words
  • A word distribution of words ending in "ly"
  • The Top 10 longest words

Solutions

Expert Solution

Python code:

from collections import Counter
from string import punctuation
import re

str1 = '''Do you ever feel like a plastic bag
Drifting through the wind
Wanting to start again?
Do you ever feel, feel so paper-thin
Like a house of cards, one blow from caving in?

Do you ever feel already buried deep
Six feet under screams but no one seems to hear a thing
Do you know that there's still a chance for you
'Cause there's a spark in you?

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

You don't have to feel like a wasted space
You're original, cannot be replaced
If you only knew what the future holds
After a hurricane comes a rainbow

Maybe a reason why all the doors are closed
So you could open one that leads you to the perfect road
Like a lightning bolt your heart will glow
And when it's time you'll know

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
It's always been inside of you, you, you
And now it's time to let it through, -ough, -ough

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
Boom, boom, boom
Even brighter than the moon, moon, moon'''

# Display the lyrics
print(str1)

# Total words
total_words = (len(str1.replace('\\', '').split()))
print("\nThe total words are: ", total_words)

# Total characters
total_chars = len(str1)
print("\nThe total characters are: ", total_chars)

# Average word length
words = str1.split()
avg = sum(map(len, words))/len(words)
avg = round(avg,2)
print("\nThe average word length is: ", avg)

# Average sentence length (if every period/full stop is considered as sentence)
#sents = str1.split('.')
# Average sentence length (if every line break is considered as sentence)
sents = str1.split('\n')
avg_len = sum(len(x.split()) for x in sents) / len(sents)
avg_len = round(avg_len,2)
print("\nThe average sentence length is: ", avg_len)

# Word distribution of all words
s1 = re.sub(r'[^\w\s]','',str1)
word = []
word = s1.split()
wfreq =[word.count(w) for w in word]
wlist = (dict(zip(word,wfreq)))
print("\nThe word distribution of all words are: ", wlist)

# Word distribution of words ending in "ly"
table = str.maketrans(punctuation, ' ' * len(punctuation))
x = str1.translate(table).lower()
c = Counter(i for i in x.split() if i.endswith('ly'))
print("\nThe word distribution of words ending with 'ly' are: ",c)

# Top 10 longest words
s = re.sub(r'[^\w\s]','',str1)
w1 = []
w1 = s.split()
wfreq1 =[len(w) for w in w1]
wlist1 = (dict(zip(w1,wfreq1)))
sorted_d = sorted(wlist1.items(), key=lambda x: x[1], reverse=True)
print("\nThe top 10 longest words are: ", sorted_d[0:10])

Output:

Do you ever feel like a plastic bag
Drifting through the wind
Wanting to start again?
Do you ever feel, feel so paper-thin
Like a house of cards, one blow from caving in?

Do you ever feel already buried deep
Six feet under screams but no one seems to hear a thing
Do you know that there's still a chance for you
'Cause there's a spark in you?

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

You don't have to feel like a wasted space
You're original, cannot be replaced
If you only knew what the future holds
After a hurricane comes a rainbow

Maybe a reason why all the doors are closed
So you could open one that leads you to the perfect road
Like a lightning bolt your heart will glow
And when it's time you'll know

You just gotta ignite the light and let it shine
Just own the night like the 4th of July

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
It's always been inside of you, you, you
And now it's time to let it through, -ough, -ough

'Cause, baby, you're a firework
Come on, show 'em what you're worth
Make 'em go, "Ah, ah, ah"
As you shoot across the sky

Baby, you're a firework
Come on, let your colors burst
Make 'em go, "Ah, ah, ah"
You're gonna leave 'em all in awe, awe, awe

Boom, boom, boom
Even brighter than the moon, moon, moon
Boom, boom, boom
Even brighter than the moon, moon, moon

The total words are:  364

The total characters are:  1863

The average word length is:  4.09

The average sentence length is:  5.52

The word distribution of all words are:  {'Do': 4, 'you': 15, 'ever': 3, 'feel': 5, 'like': 4, 'a': 16, 'plastic': 1, 'bag': 1, 'Drifting': 1, 'through': 2, 'the': 16, 'wind': 1, 'Wanting': 1, 'to': 5, 'start': 1, 'again': 1, 'so': 1, 'paperthin': 1, 'Like': 2, 'house': 1, 'of': 4, 'cards': 1, 'one': 3, 'blow': 1, 'from': 1, 'caving': 1, 'in': 5, 'already': 1, 'buried': 1, 'deep': 1, 'Six': 1, 'feet': 1, 'under': 1, 'screams': 1, 'but': 1, 'no': 1, 'seems': 1, 'hear': 1, 'thing': 1, 'know': 2, 'that': 2, 'theres': 2, 'still': 1, 'chance': 1, 'for': 1, 'Cause': 4, 'spark': 1, 'You': 3, 'just': 2, 'gotta': 2, 'ignite': 2, 'light': 2, 'and': 2, 'let': 6, 'it': 3, 'shine': 2, 'Just': 2, 'own': 2, 'night': 2, '4th': 2, 'July': 2, 'baby': 3, 'youre': 9, 'firework': 6, 'Come': 6, 'on': 6, 'show': 3, 'em': 12, 'what': 4, 'worth': 3, 'Make': 6, 'go': 6, 'Ah': 6, 'ah': 12, 'As': 3, 'shoot': 3, 'across': 3, 'sky': 3, 'Baby': 3, 'your': 4, 'colors': 3, 'burst': 3, 'Youre': 4, 'gonna': 3, 'leave': 3, 'all': 4, 'awe': 9, 'dont': 1, 'have': 1, 'wasted': 1, 'space': 1, 'original': 1, 'cannot': 1, 'be': 1, 'replaced': 1, 'If': 1, 'only': 1, 'knew': 1, 'future': 1, 'holds': 1, 'After': 1, 'hurricane': 1, 'comes': 1, 'rainbow': 1, 'Maybe': 1, 'reason': 1, 'why': 1, 'doors': 1, 'are': 1, 'closed': 1, 'So': 1, 'could': 1, 'open': 1, 'leads': 1, 'perfect': 1, 'road': 1, 'lightning': 1, 'bolt': 1, 'heart': 1, 'will': 1, 'glow': 1, 'And': 2, 'when': 1, 'its': 2, 'time': 2, 'youll': 1, 'Boom': 3, 'boom': 6, 'Even': 3, 'brighter': 3, 'than': 3, 'moon': 9, 'Its': 1, 'always': 1, 'been': 1, 'inside': 1, 'now': 1, 'ough': 2}

The word distribution of words ending with 'ly' are:  Counter({'july': 2, 'only': 1})

The top 10 longest words are:  [('paperthin', 9), ('hurricane', 9), ('lightning', 9), ('Drifting', 8), ('firework', 8), ('original', 8), ('replaced', 8), ('brighter', 8), ('plastic', 7), ('through', 7)]

How to run the code:

1) Copy paste the code in a file and save it as "test.py"

2) Then to run the code got to the command prompt and change the directory to where the file is saved and type "python test.py"

or

If using IDLE, press F5

3) Get the output.


Related Solutions

write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
Using R Studio Use the two iid samples. (You can copy and paste the code into...
Using R Studio Use the two iid samples. (You can copy and paste the code into R). They both come from the same normal distribution. X = c(-0.06, 1.930, 0.608 -0.133,0.657, -1.284, 0.166, 0.963, 0.719, -0.896) Y = c(0.396, 0.687, 0.809, 0.939, -0.381, -0.042, -1.529, -0.543, 0.758, -2.574, -0.160, -0.713, 0.311, -0.515, -2.332, -0.844, -0.942, 0.053, 0.066, 0.942, -0.861, -0.186, -0.947, -0.110, 0.634, 2.357, 0.201, -0.428, -1.661, 0.395) (a) Report 95% confidence interval for the mean of X. Should we...
It is straightforward to copy-paste code to achieve repetitive actions, what is the downside of such...
It is straightforward to copy-paste code to achieve repetitive actions, what is the downside of such an approach?
R studio questions Write up your answers and paste the R code Copy and paste all...
R studio questions Write up your answers and paste the R code Copy and paste all plots generated. First create a sample drawn from a normal random variable. R has many distributions for which you can get probabilities and draw random numbers. We are going to use the normal. Go to help in R and type in rnorm. You will see a write up for functions associated with the normal distribution. dnorm is the density; pnorm is the probability distribution...
For your company Uber: (Please answer step by step) (Dont copy/paste information please) What is your...
For your company Uber: (Please answer step by step) (Dont copy/paste information please) What is your company's innovation process? What is the life cycle for the company's industry? Which type of innovation does your company use? Explain why or why not you believe this is the appropriate innovation type. What is the company's growth strategy? Select a foreign country where your company currently does not operate and perform a CAGE Distance framework between your home country and the selected foreign...
For your company Amazon: (Please answer step by step) (Dont copy/paste information please) What is your...
For your company Amazon: (Please answer step by step) (Dont copy/paste information please) What is your company's innovation process? What is the life cycle for the company's industry? Which type of innovation does your company use? Explain why or why not you believe this is the appropriate innovation type. What is the company's growth strategy? Select a foreign country where your company currently does not operate and perform a CAGE Distance framework between your home country and the selected foreign...
Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste...
Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste the whole solution I was left with. Thank you in advance ! Lab 5 – Class Statistics Write a program which will uses the file Lab5Data.txt containing student names and the points they had earned at the end of the class. The program should use one or more arrays to create a report with the following information: -A table containing the student name, total...
Please do not go to a website and copy and paste a bunch of stuff that...
Please do not go to a website and copy and paste a bunch of stuff that does not answer the question. *ICD 10 PCS* 1. Research and discuss the guidelines that apply to the coding of CABGs, Pacemaker insertions, and also to the Coding of a Debridement.
For your company Amazon: (Please answer step by step) (Dont copy/paste information please) State company's vision,...
For your company Amazon: (Please answer step by step) (Dont copy/paste information please) State company's vision, mission, and values. What is your company's strategy? Perform a stockholder's impact analysis for your company. Prepare the PESTEL model for your company. Prepare the Five Forces Model for your company's industry. Prepare the SWOT analysis for your company. What are your company's competitive advantages? Which KPIs does your company use to measure performance? What is your company's business model? What is your company's...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever noticed that some stores ask you for your zip code before “ringing up” your transaction? Suppose you have been given three (3) text files (named kroger.txt, publix.txt, and ingles.txt) from popular grocery stores, containing zip codes of customers at each store. Additionally, you have been given a file named zipDirectory.txt which contains the zip code and city name (each on its own line). This...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT