How many times the substring notice appears

Assignment Help Other Subject
Reference no: EM133091480

Lab - Strings, Substrings and Files

Exercises

Question 1. Write a program to count and display how many times the substring notice appears in the string:
If you notice this notice you'll notice this notice is not worth noticing.

Question 2. Write a program that splits each line of the following limerick into two halves and displays them on alternating lines with dashes taking up the space of the 'left' half (before the 'right' half is printed):
The limerick packs laughs astronomical
Into space that is quite economical
But the good ones I've seen
Very seldom are clean
And the clean ones so seldom are comical.
Your output should look like this:
The limerick packs
-------------------laughs astronomical
Into space that i
-----------------s quite economical
But the good
-------------ones I've seen
Very seldo
----------m are clean
And the clean ones s
--------------------o seldom are comical.

Question 3. Write a program that opens the provided file alice_in_wonderland.txt and reads it into a list of lines (don't forget to close the file when you've done so!).Then, ask the user to enter a word to search for. Once you have a word, search through all the lines of text in the book counting how many times that word occurs in a case-insensitive manner, and then display the final count.

For example, if the user entered the word what then your output should be:
Please enter a word to count occurrences of: what
The word 'what' appears 44 times in this book.

Question 4. Write a program that takes a string from the user and converts it into MiXeDCaSe- that is, each alphabetical character in the string should alternate between upper and lower case (don't try to change digits or punctuation into upper or lower case).

For example, your output should look like this:

Please enter a string: I know you are, but what am I?
I KnOwyOuaRe, BuTWhAtaM I?

Question 5. Here's a function that calculates the prime numbers between an interval and returns a list of those values:

defget_primes_in_range(start, end):
prime_list = []

fornum in range(start, end + 1):
if num> 1:
found_divisor = False
fori in range(2, int(num/2)+1):
if (num % i == 0):
found_divisor = True
break

if (found_divisor == False):
prime_list.append(num)

return prime_list

So if you ran get_primes_in_range(2, 10) it would return you the list [2, 3, 5, 7, 9]

Write a program that asks the user for two integer values and a string for a filename. Then run the get_primes_in_range() function with the values the user provided and get the returned list.

Finally, open a new file for writing with the filename the user provided and write each prime number in the list to the file.

For example, a run of the program might go like this:

Enter the prime range starting value: 10
Enter the prime range ending value: 20
Filename to write the primes to: primes.txt

Question 6. CHALLENGE TASK: Write a program that programmatically prints out the following poem. Think about how you might go about it - design it on paper if you like. It's definitely a problem, but not a terribly hard one - and when you break it down there's really only just a handful of steps involved.

So solve it - for Science!

Once you've done this, try modifying your code to work on any string, without adding the letters per loop (i.e. ‘A', ‘B', ‘C' etc.). If you run this with the phrase "The quick brown fox jumps over the lazy dog" - which is just a test phrase that contains every letter in the alphabet - then you end up with the following:

The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lzy dog
The quick rown fox jumps over the lzy dog
The quikrown fox jumps over the lzy dog
The quikrown fox jumps over the lzyog
Thquikrown fox jumps ovrthlzyog
Thquikrown ox jumps ovrthlzyog
Thquikrown ox jumps ovrthlzy o
T quikrown ox jumps ovr t lzy o
T qukrown ox jumps ovr t lzy o
T qukrown ox umps ovr t lzy o
T qurown ox umps ovr t lzy o
T qurown ox umps ovr t zy o
T qurown ox ups ovr t zy o
T qu row ox ups ovr t zy o
T qurw x ups vr t zy
T qurw x us vr t zy
T u rw x us vr t zy
T u w x us v t zy
T u w x u v t zy
u w x u v zy
w x vzy
w x zy
x zy
zy
z

Reference no: EM133091480

Questions Cloud

Work-based problems from past or present work : Discuss below 7 work-based problems from past or present work situations, if you can, please provide an example for each problem.
How much will the special order suit cost : If direct materials represent 50% of total cost and direct labor another 20%, how much will the special order suit cost if a regular swimsuit costs $90
Defines capital budgeting : Explain in detail what defines capital budgeting. Then explain how two of the considerations above affect capital budgeting.
Calculate mr levesque maximum deductible rrsp contribution : Mr. Levesque supports the church that he attends with monthly donations of $200 throughout 2021. Calculate Mr Levesque maximum deductible RRSP contribution
How many times the substring notice appears : Calculates the prime numbers between an interval and returns a list of those values and Write a program that takes a string from the user and converts
Marketing Excellence-Disney : Review the "Marketing Excellence: Disney" case study uploaded. Why do you believe that Disney has been so successful?
Design a comprehensive research investigation : Design a comprehensive research investigation that would provide answers to this challenge. Identify the factors that impact financial performance.
Create the journal entries for these three dates : On July 7, it returned $200 worth of merchandise. On July 8, it paid the full amount due. Please create the journal entries for these three dates
How school leaders can inform communities : What are some factors related to school safety that should be considered in a school/district budget? Include a brief discussion on how school leaders can infor

Reviews

Write a Review

Other Subject Questions & Answers

  What are critical common components to all religions

What are critical common components to all religions/beliefs in regards to healing, such as prayer, meditation, belief, etc.? Explain.

  Read grisso article on evaluating assessment properties

Provide a complete list of criteria that could be used in selecting appropriate assessments for the juvenile sex offender case. This should simply be a bullet point list of criteria. Include your rationale based on what you learned from the media ..

  Discuss compares a newer treatment to the standard

The phase III trial tests a treatment that has been shown to help patients. It usually compares a newer treatment to the standard

  Explain what a dominant strategy is in game theory

Describes how game theory helps explain the "medical arms race" among hospitals up to about 20 years ago. Explain what a "dominant strategy" is in game theory

  Explain possibilities that may cause people to feel confused

Explain the three possibilities that may cause people to feel confused or ambivalent about how they "fit" into a rank category (When we are trying to figure).

  How do you desire to serve the population professionally

Virtual Academic Scholarship Applicants Only: Please describe your academic and professional goals in the field of social work. What specific population(s) interest(s) you? How do you desire to serve the population(s) professionally

  Distinguish between reliability and character-based trus

Distinguish between reliability and character-based trust. Why is character-based trust critical in collaborative relationships?

  Eplain unique challenges or factors involved with group

develop a 10- to 15-slide microsoft powerpoint presentation that discusses the unique challenges or factors involved

  Discuss the anatomy and physiology of your activity

Next, discuss the anatomy and physiology of your activity. What specific muscles/areas of the body did this activity focus on

  Contributed to an innovation in art

The availability of paint in metallic tubes in the 19th century made “en plein-air” possible for Impressionist artists. Identify a 20th or 21st century invention that has contributed to an innovation in art and explain why.

  Risk identification-risk analysis

A 4 1/2 month old boy was brought to the emergency room by his mother. His mother reported that he had a fever and poor appetite.

  Compare and contrast the quality of selection tools

Compare and contrast the quality of selection tools and assessment used in staffing - determine who to promote to sales manager. Vincent and Peter are sales

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd