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
MODS ONLY answer this, I have something for you. I'm reporting this to make it easier
aliya0001 [1]

Answer:

whyyyyy

have  a good day :)

Explanation:

7 0
3 years ago
2) List three (3) negative impact of Technology on society
Nataly [62]

Answer:

1. social media and mobile devices may lead to psychological.

2. They may contribute to more serious health conditions such as depression.

3. The overuse of technology may have a more significant impact on developing children and teenagers.

Explanation:

may this help you have a good day

5 0
3 years ago
For this exercise, you are going to complete the printScope() method in the Scope class. Then you will create a Scope object in
iragen [17]

Answer:

Explanation:

The following is the entire running Java code for the requested program with the requested changes. This code runs perfectly without errors and outputs the exact Sample Output that is in the question...

public class ScopeTester

{

public static void main(String[] args)

{

       Scope scope = new Scope();

       scope.printScope();

}

}

public class Scope

{

private int a;

private int b;

private int c;

public Scope(){

a = 5;

b = 10;

c = 15;

}

public void printScope(){

       System.out.println("a = " + a);

       System.out.println("b = " + b);

       System.out.println("c = " + c);

       System.out.println("d = " + getD());

       System.out.println("e = " + getE());

}

public int getA() {

return a;

}

public int getB() {

return b;

}

public int getC() {

return c;

}

public int getD(){

int d = a + c;

return d;

}

public int getE() {

int e = b + c;

return e;

}

}

4 0
2 years ago
By far, the largest social network for gaming is:answer twitter. linkedin. myspace. facebook. youtube
Firdavs [7]
<span>By far, the largest social network for gaming is Facebook. The correct option among all the options that are given in the question is the fourth option or the penultimate option. Facebook is also the most popular social networking website around the world. I hope that this is the answer that has come to your help.</span>
7 0
3 years ago
Write a SELECT statement that returns four columns from the Invoices table, named Number, Total, Credits, and Balance: Number Co
AleksAgata [21]

Answer and Explanation:

For returning four columns from the  Invoices table, named Number, Total, Credits, and Balance the SELECt statement is as follows

Select     Invoice Number     As     Number

              Invoice Total          As      Total

Payment total + credit total  As      Credits

Invoice total

(Payment total + credit total) As     Balance

These are displayed as above

7 0
3 years ago
Other questions:
  • Which aspects of a project do project makers oversee?
    12·2 answers
  • I just started game development using unity, I’m trying to control my sphere moving on a flat surface using the W,A,S,D keys, if
    11·1 answer
  • Your school computer library has a network that connects computers and devices within a few small rooms. what type of network do
    7·1 answer
  • The part of the poppet valve that contacts the valve seat is called the A. face. B. margin. C. head. D. stem.
    6·2 answers
  • What is a defult? pls help if you wouldn't mind
    11·2 answers
  • The components of hardware include:
    6·2 answers
  • For 8.6 code practice: Question 1 It keeps says it's an infinite loop and it will not work can someone give me the code that wil
    9·1 answer
  • In the Create Sparkline dialog, the _______ box refers to the cell range where you want the Sparklines to appear.
    9·1 answer
  • A small network that consists of devices connected by Bluetooth, such as a smartphone and a computer, is referred to as a ______
    14·1 answer
  • What name is given to any changes to the original data such as users manually modifying data, programs processing and changing d
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!