1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
almond37 [142]
2 years ago
10

Building a String Library

Computers and Technology
1 answer:
maw [93]2 years ago
6 0
Code:

def myAppend( str, ch ):
# Return a new string that is like str but with
# character ch added at the end
return str + ch

def myCount( str, ch ):
# Return the number of times character ch appears
# in str.

# initiaalizing count with 0
count = 0

# iterating over every characters present in str
for character in str:
# incrementing count by 1 if character == ch
if character == ch:
count += 1

# returning count
return count


def myExtend( str1, str2 ):
# Return a new string that contains the elements of
# str1 followed by the elements of str2, in the same
# order they appear in str2.

# concatenating both strings and returning its result
return str1 + str2

def myMin( str ):
# Return the character in str with the lowest ASCII code.

# If str is empty, print "Empty string: no min value"
# and return None.
if str == "":
print("Empty string: no min value")
return None

# storing first character from str in char
char = str[0]

# iterating over every characters present in str
for character in str:
# if current character is lower than char then
# assigning char with current character
if character < char:
char = character
# returning char
return char


def myInsert( str, i, ch ):
# Return a new string like str except that ch has been
# inserted at the ith position. I.e., the string is now
# one character longer than before.

# Print "Invalid index" if
# i is greater than the length of str and return None.

if i > len(str):
print("Invalid index")
return None

# str[:i] gives substring starting from 0 and upto ith position
# str[i:] gives substring starting from i and till last position
# returning the concatenated result of all three
return str[:i]+ch+str[i:]

def myPop( str, i ):
# Return two results:
# 1. a new string that is like str but with the ith
# element removed;
# 2. the value that was removed.
# Print "Invalid index" if i is greater than or
# equal to len(str), and return str unchanged and None
if i >= len(str):
print("Invalid index")
return str, None

# finding new string without ith character
new_str = str[:i] + str[i+1:]

# returning new_str and popped character
return new_str, str[i]

def myFind( str, ch ):
# Return the index of the first (leftmost) occurrence of
# ch in str, if any. Return -1 if ch does not occur in str.

# finding length of the string
length = len(str)

# iterating over every characters present in str
for i in range(length):
# returning position i at which character was found
if str[i]==ch:
return i
# returning -1 otherwise
return -1


def myRFind( str, ch ):
# Return the index of the last (rightmost) occurrence of
# ch in str, if any. Return -1 if ch does not occur in str.

# finding length of the string
length = len(str)

# iterating over every characters present in str from right side
for i in range(length-1, 0, -1):
# returning position i at which character was found
if str[i]==ch:
return i
# returning -1 otherwise
return -1

def myRemove( str, ch ):
# Return a new string with the first occurrence of ch
# removed. If there is none, return str.

# returning str if ch is not present in str
if ch not in str:
return str

# finding position of first occurence of ch in str
pos = 0

for char in str:
# stopping loop if both character matches
if char == ch:
break
# incrementing pos by 1
pos += 1

# returning strig excluding first occurence of ch
return str[:pos] + str[pos+1:]

def myRemoveAll( str, ch ):
# Return a new string with all occurrences of ch.
# removed. If there are none, return str.

# creating an empty string
string = ""

# iterating over each and every character of str
for char in str:
# if char is not matching with ch then adding it to string
if char!=ch:
string += char
# returning string
return string

def myReverse( str ):
# Return a new string like str but with the characters
# in the reverse order.

return str[::-1]
You might be interested in
Suzy lives alone in New York, whereas her family lives in Florida. It is difficult for Suzy to visit her family very frequently,
Luda [366]
Answer:

<span>Skype.

---> Skype can most probably help Suzy given that the application allows for people to message, talk and video chat. This means that Suzy can see her family through video call, and see their face.

Best of wishes! xx :)</span>
4 0
3 years ago
Read 2 more answers
Write a program. in QBAsSIC
goblinko [34]

Answer:

The program is as follows:

<em>5 INPUT A,B</em>

<em>6 PROD = A * B</em>

<em>7 PRINT PROD</em>

<em>8 TOTAL = A + B</em>

<em>9 PRINT TOTAL</em>

<em>10 DIFF = A - B</em>

<em>11 PRINT DIFF</em>

<em>12 END</em>

Explanation:

This gets input for the two numbers

<em>5 INPUT A,B</em>

This calculates the product

<em>6 PROD = A * B</em>

This prints the calculated product

<em>7 PRINT PROD</em>

This calculates the sum

<em>8 TOTAL = A + B</em>

This prints the calculated sum

<em>9 PRINT TOTAL</em>

This calculates the difference

<em>10 DIFF = A - B</em>

This prints the calculated difference

<em>11 PRINT DIFF</em>

This ends the program

<em>12 END</em>

5 0
2 years ago
. Alex discovered a bunch of SATA drives in a box at the office and needs to check the contents. What can he do so that Windows
ZanzabumX [31]

You have to make sure the BIOS boot is set to the normal hard drive first, then plug in the SATA cable and power properly

8 0
3 years ago
A ______________ is a document created when planning resource management to help promote teamwork and clarify team communication
Ivahew [28]

Answer: team contract

Explanation:

A team contract is a document created when planning resource management to help promote teamwork and clarify team communications. This document helps to sort out which are the most important matters and needs more importance to be given.

It help to guide and give proper management of resources for a project or an organization. It also ensures that the members of the team abide by its set of rules defined within the team contract.

5 0
2 years ago
Difference between multiterm access and single term access for webassign
NemiM [27]

The difference between single term access and multi term access is that multi-term access is for more than one term to courses using the same textbook edition and the Single term access<span> lasts for the duration of a Single  course in Web Assign. </span>

Multi-term access is also known as "Lifetime of Edition"

<span />
4 0
3 years ago
Other questions:
  • To gain one pound of fat, how many extra calories would you need to consume?
    12·1 answer
  • The part of the computer that contains the brain, or central processing unit, is also known as the A. monitor. B. keyboard. C. m
    13·2 answers
  • The second step when using the problem-solving process is to
    7·1 answer
  • Which of the following is true regarding packaged software and custom software? Group of answer choices Packaged software are ap
    13·1 answer
  • Dang was accepted to a biology program with a rigorous schedule and a high tuition, but good professors. What would be a benefit
    10·2 answers
  • 2. Integer plot function (find a smart way to code big integers) Write a program BigInt(n) that displays an arbitrary positive i
    8·1 answer
  • Edhesive unit 4 test answers
    15·1 answer
  • 6. Python indexes lists beginning with the number 1.<br> True<br><br> False
    15·1 answer
  • Mobile apps are replacing the old__________<br><br>​
    7·2 answers
  • The lower band and upper band of integer data type​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!