Write a Python program string_functions.py that defines several functions. Each function re-implements Python's built-in string methods.1. my_compare(str1, str2): Takes two strings as parameters (str1, str2) and 
returns a -1 if str1 is alphabetically less than str2, returns a 0 if str1 is alphabetically equal to str2, and returns a 1 if str1 is alphabetically greater than str2. 
2. is_char_in(string, char): Takes a string and a character as parameters and returns True if the character is in the string or False if it is not.3. is_char_not_in(string, char): Takes a string and a character as parameters and returns True if the character is NOT in the string or False if it is.4. my_count(string, char): Takes a string and a character as parameters and returns an integer count for each occurrence of the character. For example, if the function takes in 'abracadabra' and 'a', the function should return 5.5. my_endswith(string, char): Takes a string and a character as parameters and returns True if the character is the last character in the string or False if it is not. For example, if the function takes in 'quartz' and 'z', the function should return True. If the function takes in 'quartz' and 'q', the function should return False.6. my_find(string, char): Takes a string and a character as parameters and returns the first index from the left where the character is found. If it does not find the character, return -1. For example, if the function takes in ‘programming’ and ‘g’, it should return 3. Do not use str.find() for this.7. my_replace(string, char1, char2): Takes a string and two characters (char1 and char2) as parameters and returns a string with all occurrences of char1 replaced by char2. 
For example, if the string is ‘bamboozle’ and char1 is ‘b’ and char2 is ‘t’ then your function should return ‘tamtoozle’.8. my_upper(string): Takes a string as a parameter and returns it as a string in all uppercase. For example, 'victory' would be 'VICTORY'. Hint: Use the ord(c) function to get the ASCII / Unicode code-point. For example, ord('a') returns the integer 97. Use chr(i) function to convert an integer back to a character. For example, chr(97) returns the string 'a'. You cannot use the built-in string function str.upper() for this.9. my_lower(string): Takes a string as a parameter and returns it as a string in all lowercase. Hint: Similar to the previous item, use ord() and chr(). Do not use str.lower() for this. 
Extra Credit (10 points): my_title(string): Takes a string and returns a string with the first character capitalized for every word. For example, if the input to the function is "I like Python a lot", the function should return the string "I Like Python A Lot".Note- You may not use Python's built-in string methods - e.g., str.find(), str.replace(), str.lower(), lstrip(), startswith(), endswith(), join() … - to implement yours. However, you *should* use them to test your functions to see if they produce the same results. You can do this in the main or in another defined function which is called by the main. You can use all other Python functions.

Answers

Answer 1

Answer:

def my_compare(str1, str2):

   mylist = sorted([str1, str2])

   if str1 == str2:

       return 0

   elif str1 == mylist[0]:

       return -1

   elif str1 == mylist[1]:

       return 1

def is_char_in(string, char):

   if char in string:

       return True

   return False

def is_char_not_in(string, char):

   if char not in string:

       return True

   return False

def my_count(string, char):

   return string.count(char)

def my_endswith(string, char):

   return string.endswith(char)

def my_find(string, char):

   if char in string:

       return string.index(char)

   else:

       return -1

def my_replace(string, char1, char2):

   lst = [i for i in string]

   print(lst)

   for i, v in enumerate(lst):

       if v==char1:

           lst[i] = char2

   return "".join(lst)

Explanation:

Above are defined functions similar to the string built-in functions in python. To use them, type in the function name and pass in the required arguments. Save the file name as "string_functions" with a ".py" file extension and use the functions in other files by importing all the function as "import string_functions" or import individual functions with "from string_function import 'function_name' ".


Related Questions

which devices are used in networking

Answers

Answer:

Hub.

Switch.

Router.

Bridge.

Gateway.

Modem.

Repeater.

Access Point.

Explanation:

3. Answer the following questions.
a. How does computer number system play
calculations?
a vital role in a
computer​

Answers

Answer:

Computers use the binary number system to store data and perform calculations.

Explanation:

Where in the computer is a variable such as "X" stored?

Answers

Answer:

The value of "x" is stored at "main memory".

Explanation:

Simply Central processing unit, input device and output device can not store the data.

BOTH QUESTIONS ONLY FILL IN C++ CODEWrite a copy constructor for CarCounter that assigns origCarCounter.carCount to the constructed object's carCount. Sample output for the given program:Cars counted: 5Sample program:#include using namespace std;class CarCounter { public: CarCounter(); CarCounter(const CarCounter& origCarCounter); void SetCarCount(const int count) { carCount = count; } int GetCarCount() const { return carCount; } private: int carCount;};CarCounter::CarCounter() { carCount = 0; return;}// FIXME add copy constructorvoid CountPrinter(CarCounter carCntr) { cout << "Cars counted: " << carCntr.GetCarCount(); return;}int main() { CarCounter parkingLot; parkingLot.SetCarCount(5); CountPrinter(parkingLot); return 0;}QUESTION #2!!!!!!!!!!!!!!!!_______________----------------------------------------------_______________________________Overload the + operator as indicated. Sample output for the given program:First vacation: Days: 7, People: 3Second vacation: Days: 12, People: 3Sample program:#include using namespace std;class FamilyVacation{ public: void SetNumDays(int dayCount); void SetNumPeople(int peopleCount); void Print() const; FamilyVacation operator+(int moreDays) const; private: int numDays; int numPeople;};void FamilyVacation::SetNumDays(int dayCount) { numDays = dayCount; return;}void FamilyVacation::SetNumPeople(int peopleCount) { numPeople = peopleCount; return;}// FIXME: Overload + operator so can write newVacation = oldVacation + 5,// which adds 5 to numDays, while just copying numPeople. void FamilyVacation::Print() const { cout << "Days: " << numDays << ", People: " << numPeople << endl; return;}int main() { FamilyVacation firstVacation; FamilyVacation secondVacation; cout << "First vacation: "; firstVacation.SetNumDays(7); firstVacation.SetNumPeople(3); firstVacation.Print(); cout << "Second vacation: "; secondVacation = firstVacation + 5; secondVacation.Print(); return 0;}

Answers

Answer:

im lost tell me a question then ill answer

Explanation:

Most operating systems perform these tasks. coordinating the interaction between hardware and software allocating RAM to open programs creating and maintaining the FAT modifying word processing documents correcting spreadsheet formulas displaying the GUI

Answers

Answer:

The answer are A.) Coordinating the interaction between hardware and software And B.) Allocating RAM to open programs

Explanation:

Hope this helps :)

Tasks that are been performed by most operating systems are;

Coordinating the interaction between hardware and software.Allocating RAM to open programs.

An operating system can be regarded as system software which helps in running of computer hardware as well as software resources and mange them.

This system provides common services for computer programs.

It should be noted that  operating system coordinating the interaction between hardware as well software.

Therefore, operating system, allocate RAM to open programs.

Learn more about operating system at:

https://brainly.com/question/14408927

2.4 Code Practice: Question 2
Write a program that accepts a number as input, and prints just the decimal portion. Your program should also work if a negative number is inputted by the user.

Sample Run
Enter a number: 15.789
Sample Output
0.789
Hints:
You'll likely need to use both the int() and float() commands in your program.
Make sure that any number the user inputs is first stored as a float.
You'll need to use at least two variables in your program: one that stores the original value entered by the user, and one that represents the integer value entered by the user.
These two variables can be subtracted from one another, to leave just the decimal portion remaining.
Don't forget to have your program print the decimal portion at the end!

Answers

num = float(input("Enter a number: "))

num1 = int(num)

print(num - num1)

I hope this helps!

Following are the C++ program to calculate the decimal part:

Program Explanation:

Defining the header file. Defining the main method. Inside the method, a float variable "num" is declared that inputs the value. In the next step, an integer variable "x" is declared that converts float value into an integer that holds the whole part number.In the next step, "num" is declared that removes the whole number part from the decimal value, and prints its value.

Program:

#include <iostream>//header file

using namespace std;

int main()//main method  

{

float num;//defining a string variable

cout<<"Enter password: ";//print message

cin>>num;//input float value

int x=int(num);//defining integer variable that converts float value into integer that hold whole part number

num=num-x;//remove whole number part from the decimal value  

cout<<num;//print decimal number

  return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/17554487

Complete the sentence.
Python converts your code into bytecode when you run your program. This process is an intermediate step in a process called______

Answers

Answer:

Compilation

Explanation:

" Python is an interpreted, high-level, general-purpose programming language. It is is dynamically typed and garbage-collected. "

But first it does a compilation for a file with the extension `.pyc`, so the answer is compilation, even though python is being interpreted

Python converts your code into bytecode when you run your program. This process is an intermediate step in a process called Compilation.

What is code?

The line of code returns the ASCII code.

ASCII, has the full form American Standard Code for Information Interchange. It consists of a 7-bit code in which every single bit represents a unique alphabet.

Python is a high-level computer programming language. It is dynamically used.

First, it does a compilation for a file with the extension `.pyc`

Python converts your code into bytecode when you run your program. This process is an intermediate step in a process called Compilation.

Learn more about code.

https://brainly.com/question/2596551

#SPJ2

20 POINTS Which of the following statements is true of subroutines? Check all that apply.

They can be used in multiple places.

They can be used in one place only.

They save a programmer time since they are reusable.

They can be used only once.

They can contribute to excessive use of a computer’s resources.

Answers

Answer:

1,3,5?

Explanation:

how does computer number system play a Vital role in a computer calculation. ​

Answers

Answer:

When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. A computer can understand the positional number system where there are only a few symbols called digits and these symbols represent different values depending on the position they occupy in the number

Explanation: SAME AS

What symbol following a menu command lets you know that a dialog box will be displayed? an ellipse an arrow a check mark a radio button

Answers

cords   and  batteries or electric radio

Answer:

It would be an ellipse

fun fact about London(me): when it comes to relationships she becomes clingy to the person shes dating

Answers

Answer:

that's a good fact about yourself the more love that better

laptop components that can be replaced relatively easily include the ____ and the ____

first part
screen
power supply
RAM

second part
hard disk
keyboard
touchpad​

Answers

Answer:

Power supply and Hard disk

Explanation:

Write a complete program that reads a string and displays the vowels. The vowels are A, E, I, O, U and a, e, i, o, u. Here are three sample runs:Sample Run 1Enter a string: Welcome to PythonThe vowels are eoeooSample Run 2Enter a string: Student UnionThe vowels are ueUioSample Run 3Enter a string: AREIOUaeiouRTEThe vowels are AEIOUaeiouENote: your program must match the sample run exactly.using python

Answers

text = input("Enter a string: ")

new_text = ""

vowels = "aeiou"

for x in text:

   if x.lower() in vowels:

       new_text += x

print(new_text)

I hope this helps!

What is the part of a CSS declaration that describes the HTML tag?
A.the selector
B.the pointer
C.the value
D.the property

Answers

Answer:

a selector

Explanation:

Answer:

A. the selector

what are the types of slide show in powerpoint? define.​

Answers

Answer:

normal view

slide sorter view

master view

notes page view

Compress
00eb:0000:0000:0000:d8c1:0946:0272:879
IPV6 Address

Answers

Answer:

Compress

00eb:0000:0000:0000:d8c1:0946:0272:879

IPV6 Addres

Explanation:

When you read in data from a file using the read() method the data is supplied to Python in the form of:
A. A list of Strings
B. A String
C. A list of lists
D. Raw ASCII values

Answers

Answer:

B. A String

Explanation:

Remember, there are other methods or ways to read data from a file such as readlines(), and the for ... in loop method.

However, if you read in data from a file using the read () method the data would be supplied to Python in the form of a String (or single String). This is the case because a String supports only characters, unlike lists that could contain all the data types.

Using the read() method in python is used to read in files such as text files, csv and other file types. The read() method will render the read in data as as a string.

In general, the read in data from the file is supplied in the form of a string, however, depending on the version of python which is being used, the string type may vary.

When using python 2, the data is supplied as a bytestring while the data is supplied a unicode string in python 3.

Hence, the read() method renders data as a string.

Learn more : https://brainly.com/question/19973164

Iman manages a database for a website that reviews movies. If a new movie is going to be added to the database what else will need to be added.

Answers

Answer:

The answer would be a record.

Explanation: Took the test

Ms office suite comes with its own set of pictures in the​

Answers

Answer:

clipart ...........................

Explanation:

clipart is the correct answer for the above question.

Which of the following statements about computational thinking are true? Select 3 options.

Answers

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

In this question the choices are missing, the choices of this question are:

The result of computational thinking is a problem broken down into its parts to create a generalized model and possible solutions, Computational thinking involves the techniques of decomposition, pattern recognition, abstraction, and algorithm development. Computational thinking is basically synonymous with programming. Computational thinking is a set of techniques used to help solve complex problems or understand complex systems Understanding all of the minor details about a problem is critical in computational thinking

The correct 3 choices about computational thinking that are true are given below:

1.The result of computational thinking is a problem broken down into its parts to create a generalized model and possible solutions.  

2. Computational thinking involves the techniques of decomposition, pattern recognition, abstraction, and algorithm development.

4. Computational thinking is a set of techniques used to help solve complex problems or understand complex systems.

Answer:

-The result of computational thinking is a problem broken down into its parts to create a generalized model and possible solutions.  

-Computational thinking involves the techniques of decomposition, pattern recognition, abstraction, and algorithm development.

- Computational thinking is a set of techniques used to help solve complex problems or understand complex systems.

Explanation:

I just took the test got a 100%

Write a program that uses two input statements to get two words as input. Then, print the words on one line separated by a space. Your program's output should only include the two words and a space between them.

Hint: To print both words on one line, remember that you can concatenate (add) two phrases by using the + symbol. Don't forget that you'll need to add a space between the words as well.

Sample Run

Enter a word: Good
Enter a word: morning
Good morning

Answers

word1 = input("Enter a word: ")

word2 = input("Enter a word: ")

print(word1 + " " + word2)

I hope this helps!

Information System (IS) designed to provide reports to managers for tracking operations, monitoring and control is ________

Answers

Answer:

Management Information System(MIS)

Explanation:

management information system can be regarded as an information system

that is engaged in decision-making as well as the coordination and control and analysis of information in an organization. It involves processes as well as people and technology when studying the management information systems in organizational view.

In Management Information System(MIS) data can be gotten from the database, as well as the compilation of reports, this report could be inventory-level reports,

financial statements/analysis so that routine decision can be made by the manager. It should be noted that Management Information System(MIS) is the Information System (IS) designed to provide reports to managers for tracking operations, monitoring and control.

who wants 100 points? comment buh. i don't rlly care buh.

Answers

Answer:

I do

Explanation:

Answer:

hey bae I do heheheheeheh

Need help with 4.7 lesson practice edhesive

Answers

Answer:

Question 4 => 4th answer: The first line should be for x in range (7, 10):

Question 5 => 2nd answer: 14 16 18 20 22 24 26 28 30 32

Explanation:

Question 4

"for" loops always need a variable (like "x") defined to iterate with different values.  for x in range (7, 10): makes x to take values 7, 8, 9 and 10 successively  and execute print(x) each time.

Question 5

The expression x in range (7, 16) makes x to take values from 7 up to 16 inclusive. So for each iteration it will execute print x*2 which prints the double of the actual value for x. Starting with x=7, it will print 14, then with x=8 will print 16, and so on. All values are shown on the table below:

X       Prints

7        14

8        16

9        18

10       20

11       22

12       24

13       26

14       28

15       30

16       32

The code segments are illustrations of loops.

4: The first line should be for x in range(7,10):5: The output is 14 16 18 20 22 24 26 28 30

The syntax of a for loop is:

for variable in range (begin,end+1):

The loop in question (4) is given as:

for range (7,10)

This means that, the variable is missing.

So, the first line of the code segment should be

for x in range(7,10):

For question 5, the value of x would range from 7 to 15.

The print statement prints twice x, followed by a space.

So, the output would be 14 16 18 20 22 24 26 28 30

Read more about loops at:

https://brainly.com/question/19323897

Some of the latest smartphones claim that a user can work with two apps simultaneously. This would be an example of a unit that uses a __________ OS.

Answers

Answer:

MULTITASKING OS

Explanation:

MULTITASKING OPERATING SYSTEM is an operating system that enables and allow user of either a smartphone or computer to make use of more that one applications program at a time.

Example with MULTITASKING OPERATING SYSTEM smartphones user can easily browse the internet with two applications program like chrome and Firefox at a time or simultaneously

Therefore a user working with two apps simultaneously is an example of a unit that uses a MULTITASKING OS.

In a three-tier architecture, the component that runs the program code and enforces the business processes is the:_______.

Answers

Answer:

Application Server

Explanation:

The Application Server is a component in computer engineering that presents the application logic layer in a three-tier architecture.

This functionality allows client components to connect with data resources and legacy applications.

In this process of interaction, the Application Server runs the program code from Tier 1 - Presentation, through Tier 2 - Business Logic to Tier 3 - Resources, by forcing through the business processes.

Individuals who break into computer systems with the intention of doing damage are called​ _____________.

a. white hats
b. ​e-criminals
c. hackers
d. keyloggers
e. black hats

Answers

I think the answer is hackers

The individuals who made the unethical entry into a person's system with intentions of damage are termed, hackers. Thus, option C is correct.

What is a computer system?

A computer system has been given as the network connection of the hardware and the software equipped with the objects that are used for the operation of the computer.

The computer system with the internet connection has been able to make the connection to the world. as well the invention mediates the work with ease as well.

The system thereby has the access to the passwords and the personal details of an individual as well. There are individuals who try to make access the computer system in an unethical way and intended to damage the system.

The computer viruses are used for the following purpose and were drawn by the hackers. Thus, option C is correct.

Learn more about the computer system, here:

https://brainly.com/question/14253652

#SPJ2

Question No. 5:
Convert the following by showing all the steps necessary
a) (1001111) 2 = ( ) 10
b) (11000001) 2 = ( ) 16
c) (E16) 16 = ( ) 10
d) (56) 10 = ( ) 16
e) (63) 10 = ( ) 2

Answers

Answer:

The answers are:

[tex]a) (1001111)_2 = (79 )_{10}\\b) (11000001)_2 = (C1 )_{16}\\c) (E16)_{16} = ( 3606)_{10}\\d) (56)_{10} = (38 )_{16}\\e) (63)_{10}= (111111 )_2[/tex]

Explanation:

a. (1001111) 2 = ( ) 10

In order to convert a base 2 number to base 10 number system the place values are used.

the procedure is as follows:

[tex](1001111)_2\\=(1*2^6)+(0*2^5)+(0*2^4)+(1*2^3)+(1*2^2)+(1*2^1)+(1*2^0)\\=(1*64)+(0*32)+(0*16)+(1*8)+(1*4)+(1*2)+(1*1)\\=64+0+0+8+4+2+1\\=79[/tex]

b) (11000001) 2 = ( ) 16

In order to convert a base 2 number into base 16, group of 4-bits are made starting from right to left

The groups from the given number are:

1100 0001

Then the groups are changed in to decimal/hexa

So,

[tex](1100)_2 = (1*2^3)+(1*2^2)+(0*2^1)+(0*2^0)\\=(1*8)+(1*4)+(0*2)+(0*1)\\=8+4+0+0=12=C\\\\0001=1[/tex]

Writing in the same order in which groups were:

[tex](C1)_{16}[/tex]

c) (E16) 16 = ( ) 10

[tex](E16)_{16}\\=(E*16^2)+(1*16^1)+(6*16^0)\\=(E*256)+(1*16)+(6*1)\\=3584+16+6\\=3606[/tex]

d) (56) 10 = ( ) 16

Dividing by 16 and noting remainders

16        56

           3 - 8

So,

The number in base 16 is 38

e) (63) 10 = ( ) 2

Dividing by 2

2         63

2         31 - 1

2         15 - 1

2          7 -  1

2          3 -  1

            1 - 1

So the  number after converting in base 2 is:

111111

Hence,

The answers are:

[tex]a) (1001111)_2 = (79 )_{10}\\b) (11000001)_2 = (C1 )_{16}\\c) (E16)_{16} = ( 3606)_{10}\\d) (56)_{10} = (38 )_{16}\\e) (63)_{10}= (111111 )_2[/tex]

(plsssssssssssssssssssssssssssssssssssssss helpp meee)
think about system you know,list the parts of the system,describe some ways that the parts are connected to the whole​

Answers

Answer:

A computer is a complex machine. While most of it works on a microscopic level, it certainly has recognizable macroscopic components that contribute to its uses. A computer can be used to do just about anything from simple calculations to preparing reports to sending rockets into space to simulating the spread of cancer in body organs. Some of the parts are, the motherboard, the power supply, the central processing unit, the optical drive ect. The motherboard plays roles like storing some simple information when the computer is off, such as the system time. The power supply, as you might have already guessed is the powerhouse of the computer. The CPU mainly does arithmetic and logical tasks. It will make a bunch of calculations to ensure the functions of the computer are carried out efficiently. An optical drive is used to read CDs and DVDs, which can be used to listen to music or watch movies. They can also be used to install software, play games, or write new information into a disk.

Explanation: O///O sorry if this is bad....

What are the different types of store-based and nonstore-based retail locations? Provide a real example (store name) for each different type.

Answers

Explanation:

For Store-based retail locations; they've been grouped on the basis of:

ownership, andthe type of merchandise offered  

I. On the basis of ownership, we have:

Independent retailer locationchain retail locationfranchise location

II. On the basis of merchandise offered, we have:

departmental store locationconvenience store locations supermarket locations

For Non-Store retail locations, ie. retailing that does not a physical store. These include;

direct sellingmail orderonline retailing outlets

Other Questions
beliefs and practices of judaism PLEASE HELP URGENT WILL GIVE BRAINLIEST Jester and (I, me) play in this school yard.Many of (we, us) are preparing for this trip.Sita gave (she, her) an interesting book to read.Out father went to visit (they, them) at the seaside.Peter and (he, him) are at the junction waiting for (me, us).Was it (he, him) who gave us this bat?I think it was (she, her) who spoke to (they, them).Please tell (she, her) we are interested in buying the house.I hope you will give (we, us) some help.(He, him) likes to visit the seaside. 11Which statement correctly describes both gases and liquids?" Use the 3 trig ratios to find each unknown side length. Round all answers to 1 decimal please help me conjugate these. Do you think Coolidge was an effective president How did the Roman temples adapt Ionic columns? In general, the ( more / less ) your car is worth, the ( more / less ) youll pay to insure it. Please help on this question what is the advantage of increasing the length of the handles of a wheelbarrow? Select the correct navigational path to create the function syntax to use the IF function.Click the Formula tab on the ribbon and look in the gallery.Select the range of cells.Then, begin the formula with the , click , and click OK.Add the arguments into the boxes for Logical Test, Value_if_True, and Value_if_False. Select the correct answer.Which practice is normal for devotees after they offer prayers to the kami?A. seeking spiritual adviceB. offering foodC. a request for blessingsD. thanking the gods for life The magnitude of one Kelvin, one Celsius degree, and one degree on the absolute temperature scale is the same. true or false . please explain it ..... This function of political parties is conducted by the party out of power to try and throw those in power out of power and put those out of power in power . O Governing O Informing O Watchdog Nominating what is 58+673421-34 What are the following is example of physical property (-2 ab) (-3 abc) (-c) PLEASE HELP ME!!! A LOT OF POINTSIn your own words the summary of what the Sherman's plan was... (The Great Compromise). please help! I need it fast! a fisherman had 37 fishes in a bucket but he tripped and spilled over some fishes in the water, after that he had 13 fishes left. how many fishes drowned??? I need help with this question. I want this to be simplifed