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]
3 years ago
10

Building a String Library

Computers and Technology
1 answer:
maw [93]3 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
An increase in the Money Supply will increase the Aggregate Price Level and will also increase which of the following?
Pavlova-9 [17]

your answer is b hope this helps


7 0
3 years ago
Introduction to graphic design please help! Define the four terms: design ,art,decoration , and visual literacy. Describe how th
erastovalidia [21]
Graphic design involves activities , usually done on the computer in which pictures, graphs, text and other elements are combined as a edit to books, magazines, advertisements. 
Activities which are part from this job are:
Design: the creation of ideas, plans and finally creation of object, pictures,...
Art: expressing the imagination through different ways of expression/ 
Decoration: adding something to the graphic design in order to look and act nicer
Visual literacy: the ability to understand existing trends and to learn new ones
8 0
4 years ago
Write an interface, PointingDevice, containing: an abstract method, getXCoord that returns an int an abstract method, getYCoord
vaieri [72.5K]

Answer:

Following are the code in java language

abstract interface PointingDevice // interface  PointingDevice,

{

// abstract method getXCoord()

public abstract int getXCoord();

// abstract method getYCoord()

public abstract int getYCoord();    

// abstract method attentionRequired()

public abstract boolean attentionRequired();  

// abstract method setResolution( )

public abstract double setResolution(double a);  

}

Explanation:

In this code we have declared a abstract interface "PointingDevice" which contains the four abstract method getXCoord of type int , getYCoord() of type int , attentionRequired() of type boolean and setResolution() of type double .

These method have only declaration not definition any interface or class which inherit the inteface PointingDevice must define all these four method otherwise it also be abstract .

4 0
3 years ago
The fact that the impact of changes in the elements making up an IT (software) project are not proportional or intuitive is rela
Furkat [3]

Answer:

Multidimensionality

Explanation:

Multidimensionality is the ability to exhibit many diverse characteristics thereby giving programs the ability to manipulate the storage and presentation of data in various ways without disrupting the integrity and reliability of the data. It is very important that users have the capability to customize and change their views of data and user information to suit their specific needs and allow users to carry out any type of analysis within the database.

5 0
3 years ago
You have been asked to configure a client-side virtualization solution with three guest oss. Each one needs internet access. How
ArbitrLikvidat [17]

The most cost-effective way to configure a client-side virtualization solution is by using one (1) physical NIC, three (3) virtual NICs, and one (1) virtual switch.

<h3>What is virtualization?</h3>

Virtualization refers to the creation of an abstraction layer over computer hardware through the use of a software, in order to enable the operating system (OS), storage device, server, etc., to be used by end users.

In this scenario, the most cost-effective way to configure a client-side virtualization solution is by using one (1) physical network interface card (NIC), three (3) virtual network interface cards (NICs), and one (1) virtual switch.

Read more on virtualization here: brainly.com/question/14229248

#SPJ1

4 0
2 years ago
Other questions:
  • What was the name of the first computer (machine) language?
    5·2 answers
  • Click _______ to view each individual record of a mail merge document.
    5·2 answers
  • Common input devices include the keyboard, ____, and integrated video cameras.
    12·1 answer
  • Name three actions you can perform on an inserted image.
    7·2 answers
  • A(n) ____ occurs when a situation results in service disruptions for weeks or months, requiring a government to declare a state
    6·1 answer
  • In the mouse properties window you can
    6·1 answer
  • Why is it necessary to have usernames and passwords if one is working on a network?​
    12·1 answer
  • Type the correct answer in the box.
    15·1 answer
  • Everyone say bye to brainly cause I’m reporting it for being against the law
    10·2 answers
  • HELPPPPP!!! Performance Check: Mini-Quiz
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!