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
tatuchka [14]
3 years ago
15

The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case a

nd punctuation. But something is not working. Fill in the code to try to find the problems, then fix the problems.
import re
def compare_strings(string1, string2):
#Convert both strings to lowercase
#and remove leading and trailing blanks
string1 = string1.lower().strip()
string2 = string2.lower().strip()

#Ignore punctuation
punctuation = r"[.?!,;:-']"
string1 = re.sub(punctuation, r"", string1)
string2 = re.sub(punctuation, r"", string2)

#DEBUG CODE GOES HERE
print(___)

return string1 == string2

print(compare_strings("Have a Great Day!", "Have a great day?")) # True
print(compare_strings("It's raining again.", "its raining, again")) # True
print(compare_strings("Learn to count: 1, 2, 3.", "Learn to count: one, two, three.")) # False
print(compare_strings("They found some body.", "They found somebody.")) # False

Computers and Technology
1 answer:
Korolek [52]3 years ago
4 0

Answer:

There is a problem in the given code in the following statement:

Problem:

punctuation = r"[.?!,;:-']"

This produces the following error:

Error:

bad character range

Fix:

The hyphen - should be placed at the start or end of punctuation characters. Here the role of hyphen is to determine the range of characters. Another way is to escape the hyphen - using using backslash \ symbol.

So the above statement becomes:

punctuation = r"[-.?!,;:']"  

You can also do this:

punctuation = r"[.?!,;:'-]"  

You can also change this statement as:

punctuation = r"[.?!,;:\-']"

Explanation:

The complete program is as follows. I have added a print statement print('string1:',string1,'\nstring2:',string2) that prints the string1 and string2 followed by return string1 == string2  which either returns true or false. However you can omit this print('string1:',string1,'\nstring2:',string2) statement and the output will just display either true or false

import re  #to use regular expressions

def compare_strings(string1, string2):  #function compare_strings that takes two strings as argument and compares them

   string1 = string1.lower().strip()  # converts the string1 characters to lowercase using lower() method and removes trailing blanks

   string2 = string2.lower().strip()  # converts the string1 characters to lowercase using lower() method and removes trailing blanks

   punctuation = r"[-.?!,;:']"  #regular expression for punctuation characters

   string1 = re.sub(punctuation, r"", string1)  # specifies RE pattern i.e. punctuation in the 1st argument, new string r in 2nd argument, and a string to be handle i.e. string1 in the 3rd argument

   string2 = re.sub(punctuation, r"", string2)  # same as above statement but works on string2 as 3rd argument

   print('string1:',string1,'\nstring2:',string2)  #prints both the strings separated with a new line

   return string1 == string2  # compares strings and returns true if they matched else false

#function calls to test the working of the above function compare_strings

print(compare_strings("Have a Great Day!","Have a great day?")) # True

print(compare_strings("It's raining again.","its raining, again")) # True

print(compare_strings("Learn to count: 1, 2, 3.","Learn to count: one, two, three.")) # False

print(compare_strings("They found some body.","They found somebody.")) # False

The screenshot of the program along with its output is attached.

You might be interested in
As part of their extensive kitchen remodel, the Lees told their electrical contractors that they would need plenty of outlets fo
Vanyuwa [196]

The kind of wire and circuit breaker are:  grounding wire such as fairly large bare copper wire.

<h3>What is the best wire for the above?</h3>

A 20A, 120V small-appliance branch circuit is known to be  used in the case above.

Note that Electric range circuits needs about 50-amp, 240-volt made for circuit that is said to supplies the power to the range or oven via  a 6-3 electrical wire.

Learn more about circuit breaker from

brainly.com/question/8976395

#SPJ1

5 0
2 years ago
If you want to access your home network from your distant garage, a ________ might help boost the signal.
Kryger [21]
Wireless range extender.
6 0
2 years ago
An administrator needs to set up an authentication server for users connecting to a network through a VPN. What kind of server c
nalin [4]

Answer:

RADIUS

Explanation:

RADIUS is the networking protocol that is used for the purpose of authentication to access the network resources. The full form of RADIUS is Remote Authentication Dial In User Service. It is used by different organizations, which setup their own network that can be accessible through VPN, DSL or modems through different networks. The purpose of this protocol is to establish the security and authentication mechanism by organization itself.

So, If an administrator needs to set up an authentication server for users connecting to a network through a VPN, he should establsih the RADIUS based Server.

3 0
3 years ago
Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create
zaharov [31]

Answer:

See attached file.

Explanation:

See attached file for detailed code.

Download txt
7 0
3 years ago
After you divide the viewfinder appropriately you locate the subject? PLZ ANSWER MY TEST DO BY TONIGHT
Sloan [31]
The Answer is A: <span>along one of the division lines. </span>
4 0
2 years ago
Other questions:
  • What process describes using technology as a basis for controlling the access and usage of sensitive data?
    7·1 answer
  • As you're helping a user configure her e-mail over the phone, she remarks that the IP address is different than it was when she
    6·1 answer
  • Write a program C statement to declare and initialize an array named afTest1 type float to store
    11·1 answer
  • It is important to verify internet source because-------- choose that apply. A.the source should be written by real author. B.an
    6·2 answers
  • A USB device used to transfer photos from the memory card to a hard drive is called a _____.
    5·2 answers
  • Gn guys have an Amazing day!
    12·2 answers
  • Which of the following is ture?
    11·1 answer
  • Which excel feature makes it easy to copy and paste formulas in multiple cells?.
    7·1 answer
  • Colours can be contrasting if<br>​
    9·1 answer
  • A malicious actor is preparing a script to run with an excel spreadsheet as soon as the target opens the file. the script includ
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!