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

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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