Answer:
a. 118.20.210.254
Explanation:
Here are the few characteristics of Class A:
First bit of the first octet of class A is 0.
This class has 8 bits for network and 24 bits for hosts.
The default sub-net mask for class A IP address is 255.0.0.0
Lets see if the first bit of first octet of 118.20.210.254 address is 0.
118 in binary (8 bits) can be represented as : 1110110
To complete 8 bits add a 0 to the left.
01110110
First bit of the first octet of class A is 0 So this is class A address.
For option b the first octet is : 183 in the form of bits = 10110111 So it is not class A address
For option c the first octet is 215 in the form of bits = 11010111 So it is not class A address
For option d the first octet is 255 in the form of bits = 11111111. The first bit of first octet is not 0 so it is also not class A address.
A variable that can have values only in the range 0 to 65535 is a :
a. Two-byte unsigned int.
b. Four-byte int.
c. Two-byte int.
d. Four-byte unsigned int.
Answer:
a.
Explanation:
Two bytes have 2 times 8 bits is 16 bits.
Max value that can be expressed is 2¹⁶-1 = 65535
Which of these statements are true about managing through Active Directory? Check all that apply.
Answer:
ADAC uses powershell
Domain Local, Global, and Universal are examples of group scenes
Explanation:
Active directory software is suitable for directory which is installed exclusively on Windows network. These directories have data which is shared volumes, servers, and computer accounts. The main function of active directory is that it centralizes the management of users.
It should be noted thst statements are true about managing through Active Directory are;
ADAC uses powershellDomain Local, Global, and Universal are examples of group scenes.Active Directory can be regarded as directory service that is been put in place by Microsoft and it serves a crucial purpose for Windows domain networks.
It should be noted that in managing through Active, ADAC uses powershell.
Therefore, in active directory Domain Local, Global, and Universal are examples of group scenes .
Learn more about Active Directory at:
https://brainly.com/question/14364696
You are a project manager for Laredo Pioneer's Traveling Rodeo Show. You're heading up a project to promote a new line of souvenirs to be sold at the shows. You are getting ready to write the project management plan and know you need to consider elements such as policies, rules, systems, relationships, and norms in the organization. Which of the following is not true? A These describe the authority level of workers, fair payment practices, communication channels, and the like. B This describes organizational governance framework. C This describes management elements. D This is part of the EEF input to this process.
Answer:
A. These describe the authority level of workers, fair payment practices, communication channels, and the like.
Explanation:
As seen in the question above, you have been asked to write the project management plan and know that you need to consider elements such as policies, rules, systems, relationships and standards in the organization. These elements are part of EEF's entry into this process, in addition they are fundamental and indispensable for the description not only of the organizational governance structure, but also describe the management elements that will be adopted and used.
However, there is no way to use them to describe the level of authority of workers, fair payment practices, communication channels and the like, as this is not the function of this.
A cashier distributes change using the maximum number of five-dollar bills, followed by one-dollar bills. Write a single statement that assigns num_ones with the number of distributed one-dollar bills given amount_to_change. Hint: Use %. Sample output with input: 19 Change for $ 19 3 five dollar bill(s) and 4 one dollar bill(s)
Answer:
num_ones = amount_to_change % 5
Explanation:
It is given that the cashier has to change the money in the maximum number of 5 dollar bills and remaining as $1 bills.
We have to write a single statement of code to assign the value to variable num_ones to find the value of $1 bills given amount_to_change.
Let us solve this by taking example:
If amount_to_change = $19
Then total number of $5 bills that can be given is 3. And amount that can be given as $5 bills is [tex]\bold{3 \times 5 = \$15}[/tex]
So, the remaining amount i.e. $19 - $15 = $4 will be given as one dollar bills.
Out of these $19, 4 bills of $1 can be found using the Modulus (%) operator.
Modulus operator leaves the remainder i.e.
Output of p % q is the remainder when a number 'p' is divided by 'q'.
19 % 5 = 4
4 is the number of one dollar bills to be given.
So, single line of code for the number of one dollar bills can be written as:
num_ones = amount_to_change % 5
Let us try it for amount_to_change = $30
We know that 6 number of $5 bills can be used to change the amount of $30 and no one dollar bill required.
num_ones = 30 % 5 = 0 (because 30 is completely divisible by 5 so remainder is 0)
So, the correct statement is:
num_ones = amount_to_change % 5
Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what is the number of page faults for the given reference string?
Answer:
223 8s an order of algorithm faults refrénce fifio 14 suppose in 14 and 123 no need to take other numbers
Use the get_seconds function to work out the amount of seconds in 2 hours and 30 minutes, then add this number to the amount of seconds in 45 minutes and 15 seconds. Then print the result.
Answer:
Since the get_seconds function is not given, I'll implement it myself;
The full program (get_seconds and main) written in python is as follows:
def get_seconds(hour,minute,seconds):
seconds = hour * 3600 + minute * 60 + seconds
return seconds
time1 = get_seconds(2,30,0)
time2 = get_seconds(0,45,15)
result = time1 + time2
print(result)
Explanation:
The get_seconds defines hour, minute and seconds as its arguments
This line defines the get_seconds function
def get_seconds(hour,minute,seconds):
This line calculates the second equivalent of the time passed to the function
seconds = hour * 3600 + minute * 60 + seconds
This line returns the the calculated seconds equivalent of time
return seconds
The main starts here
This line calculates the number of seconds in 2 hours and 30 minutes
time1 = get_seconds(2,30,0)
This line calculates the number of seconds in 45 minutes and 15 seconds
time2 = get_seconds(0,45,15)
This line adds both together
result = time1 + time2
This line prints the result
print(result)
7. When using find command in word we can search?
a. Characters
b. Formats
c. Symbols
d. All of the above
Answer:
When using find command in word we can search all of the above
Write a program that asks for the weight of a package and the distance it is to be shipped. This information should be passed to a calculateCharge function that computes and returns the shipping charge to be displayed . The main function should loop to handle multiple packages until a weight of 0 is entered.
Answer:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int WEIGHT_MIN = 0,
WEIGHT_MAX = 20,
DISTANCE_MIN = 10,
DISTANCE_MAX = 3000;
float package_weight,
distance,
total_charges;
cout << "\nWhat is the weight (kg) of the package? ";
cin >> package_weight;
if (package_weight <= WEIGHT_MIN ||
package_weight > WEIGHT_MAX)
{
cout << "\nWe're sorry, package weight must be\n"
<< " more than 0kg and less than 20kg.\n"
<< "Rerun the program and try again.\n"
<< endl;
}
else
{
cout << "\nDistance? ";
cin >> distance;
if (distance < DISTANCE_MIN ||
distance > DISTANCE_MAX)
{
cout << "\nWe're sorry, the distance must be\n" << "within 10 and 3000 miles.\n"
<< "Rerun the program and try again.\n"
<< endl;
}
else
{
if (package_weight <= 2)
total_charges = (distance / 500) * 1.10;
else if (package_weight > 2 &&
package_weight <= 6)
total_charges = (distance / 500) * 2.20;
else if (package_weight > 6 &&
package_weight <= 10)
total_charges = (distance / 500) * 3.70;
else if (package_weight > 10 &&
package_weight <= 20)
total_charges = (distance / 500) * 4.80;
cout << setprecision(2) << fixed
<< "Total charges are $"
<< total_charges
<< "\nFor a distance of "
<< distance
<< " miles\nand a total weight of "
<< package_weight
<< "kg.\n"
<< endl;
}
}
Explanation:
CHALLENGE ACTIVITY 2.1.3: Multiplying the current value of a variable. Write a statement that assigns cell_count with cell_count multiplied by 10. * performs multiplication. If the input is 10, the output should be: 100
Answer:
cell_count = int(input("Enter the value: "))
cell_count *= 10
print(cell_count)
Explanation:
Ask the user to enter a value and set it to the cell_count variable
Multiply the cell_count by 10 and assign it to the cell_count (It can also be written as cell_count = cell_count * 10)
Print the cell_count
K-Map is a method used for : 1 Solving number system 2 To apply De-morgan’s Law 3 To simplify Logic Diagram 4 Above all
Answer:
The answer is to simplify the logic diagrams.
Explanation:
With the help of K-map, we can find the Boolean expression with the minimum number of the variables. To solve the K-map, there is no need of theorems of the Boolean algebra. There are 2 forms of the K-map - POS (Product of Sum) and SOP (Sum of Product), these forms are used according to the requirement. From these forms, the expression can be found.
What is displayed by the alert dialog box after the following code executes? var name = "Donny,Duck"; var index = name.indexOf(","); var lastName = name.substr(index + 1, name.length - 1);; alert("Last name: " + lastName);
Answer:
Last name: Duck
Explanation:
explanation is provided in the attached document.
What is the main advantage of using DHCP? A. Allows you to manually set IP addresses B. Allows usage of static IP addresses C. Leases IP addresses, removing the need to manually assign addresses D. Maps IP addresses to human readable URLs
Answer: DHCP (dynamic host configuration protocol) is a protocol which automatically processes the configuring devices on IP networks.It allows them to to use network services like: NTP and any communication proto cal based on UDP or TCP. DHCP assigns an IP adress and other network configuration parameters to each device on a network so they can communicate with other IP networks. it is a part of DDI solution.
Explanation:
Programming Challenge: Test Average CalculatorUsing a variable length array, write a C program that asks the user to enter test scores.Then, the program should calculate the average, determine the lowest test score, determine the letter grade, and display all three.
Answer:
well you could use variables in C and display them
Explanation:
Write Album's PrintSongsShorterThan() to print all the songs from the album shorter than the value of the parameter songDuration. Use Song's PrintSong() to print the songs.
#include
#include
#include
using namespace std;
class Song {
public:
void SetNameAndDuration(string songName, int songDuration) {
name = songName;
duration = songDuration;
}
void PrintSong() const {
cout << name << " - " << duration << endl;
}
string GetName() const { return name; }
int GetDuration() const { return duration; }
private:
string name;
int duration;
};
class Album {
public:
void SetName(string albumName) { name = albumName; }
void InputSongs();
void PrintName() const { cout << name << endl; }
void PrintSongsShorterThan(int songDuration) const;
private:
string name;
vector albumSongs;
};
void Album::InputSongs() {
Song currSong;
string currName;
int currDuration;
cin >> currName;
while (currName != "quit") {
cin >> currDuration;
currSong.SetNameAndDuration(currName, currDuration);
albumSongs.push_back(currSong);
cin >> currName;
}
}
void Album::PrintSongsShorterThan(int songDuration) const {
unsigned int i;
Song currSong;
cout << "Songs shorter than " << songDuration << " seconds:" << endl;
/* Your code goes here */
}
int main() {
Album musicAlbum;
string albumName;
getline(cin, albumName);
musicAlbum.SetName(albumName);
musicAlbum.InputSongs();
musicAlbum.PrintName();
musicAlbum.PrintSongsShorterThan(210);
return 0;
}
Answer:
Here is the function PrintSongsShorterThan() which prints all the songs from the album shorter than the value of the parameter songDuration.
void Album::PrintSongsShorterThan(int songDuration) const {
unsigned int i;
Song currSong;
cout << "Songs shorter than " << songDuration << " seconds:" << endl;
for(int i=0; i<albumSongs.size(); i++){
currSong = albumSongs.at(i);
if(currSong.GetDuration()<songDuration){
currSong.PrintSong(); } } }
Explanation:
I will explain the working of the for loop in the above function.
The loop has a variable i that is initialized to 0. The loop continues to execute until the value of i exceeds the albumSongs vector size. The albumSongs is a Song type vector and vector works just like a dynamic array to store sequences.
At each iteration the for loop checks if the value of i is less than the size of albumSongs. If it is true then the statement inside the loop body execute. The at() is a vector function that is used to return a reference to the element at i-th position in the albumSongs. So the album song at the i-th index of albumSongs is assigned to the currSong. This currSong works as an instance. Next the if condition checks if that album song's duration is less than the specified value of songDuration. Here the method GetDuration() is used to return the value of duration of the song. If this condition evaluates to true then the printSong method is called using currSong object. The printSong() method has a statement cout << name << " - " << duration << endl; which prints/displays the name of the song with its duration.
If you see the main() function statement: musicAlbum.PrintSongsShorterThan(210);
The musicAlbum is the Album object to access the PrintSongsShorterThan(210) The value passed to this method is 210 which means this is the value of the songDuration.
As we know that the parameter of PrintSongsShorterThan method is songDuration. So the duration of each song in albumSongs vector is checked by this function and if the song duration is less than 210 then the name of the song along with its duration is displayed on the output screen.
For example if the album name is Anonymous and the songs name along with their duration are:
ABC 400
XYZ 123
CDE 300
GHI 200
KLM 100
Then the above program displays the following output when the user types "quit" after entering the above information.
Anonymous
Songs shorter than 210 seconds:
XYZ - 123
GHI - 200
KLM - 100
Notice that the song name ABC and CDE are not displayed because they exceed the songDuration i.e. 210.
The output is attached.
What is a what if analysis in Excel example?
Answer:
What-If Analysis in Excel allows you to try out different values (scenarios) for formulas. The following example helps you master what-if analysis quickly and easily.
Assume you own a book store and have 100 books in storage. You sell a certain % for the highest price of $50 and a certain % for the lower price of $20.
(i really hope this is what u needed)
Availability is an essential part of ________ security, and user behavior analysis and application analysis provide the data needed to ensure that systems are available. baseline infrastructure applications network
Answer:
Network.
Explanation:
Availability is an essential part of network security, and user behavior analysis and application analysis provide the data needed to ensure that systems are available.
Availability in computer technology ensures that systems, applications, network connectivity and data are freely available to all authorized users when they need them to perform their daily routines or tasks. In order to make network systems available regularly, it is very essential and important to ensure that all software and hardware technical conflicts are always resolved as well as regular maintenance of the systems.
A network administrator can monitor the network traffics and unusual or unknown activities on the network through the user behavior analysis and data gathered from the application analysis to ensure the effective and efficient availability of systems.
Hashing algorithms are used on evidence files to uphold the chain of custody in an investigation. Which of the following is NOT a hashing algorithm?
A. SHA-256
B. MD5
C. DAT-1
D. SHA-1
Answer:
C. DAT-1
Explanation:
Chain of custody is applied when examining digital evidence and checking for proof that no alterations have been made to the document. It ensures that the original piece of digital evidence which could be in text, image, video, or other electronic formats, is preserved and protected from alterations. Hashing algorithms which are mathematical computations that help to condense files are applied during this procedure.
Common hashing algorithms applied, include; the message digest 4, secure hashing algorithms 1, 2, 256, 224, 512, etc. The message digest 4 is used to evaluate why a particular piece of evidence was handled by an individual. This is further authenticated by examining the fingerprint.
Write a program segment that simulates flipping a coin 25 times by generating and displaying 25 random integers, each of which is either 1 or 2
Answer:
//import the Random class
import java.util.Random;
//Begin class definition
public class CoinFlipper {
//The main method
public static void main(String []args){
//Create an object of the Random class
Random ran = new Random();
System.out.println("Result");
//Use the object and the number of times for simulation
//to call the flipCoin method
flipCoin(ran, 25);
} //End of main method
//Method to flip coin
public static void flipCoin(Random ran, int nooftimes){
//Create a loop to run as many times as specified in variable nooftimes
for(int i=1; i<=nooftimes; i++)
System.out.println(ran.nextInt(2) + 1);
}
} //End of class definition
====================================================
Sample Output:
Result
1
1
1
2
1
2
2
1
2
1
1
2
1
2
1
1
1
2
1
1
1
2
2
1
2
========================================================
Explanation:
The above code has been written in Java. It contains comments explaining every part of the code. Please go through the comments.
The sample output from the execution of the code is also given above.
The code is re-written as follows without comments.
import java.util.Random;
public class CoinFlipper {
public static void main(String []args){
Random ran = new Random();
System.out.println("Result");
flipCoin(ran, 25);
}
public static void flipCoin(Random ran, int nooftimes){
for(int i=1; i<=nooftimes; i++)
System.out.println(ran.nextInt(2) + 1);
}
}
Would you expect all the devices listed in BIOS/UEFI setup to also be listed in Device Manager? Would you expect all devices listed in Device Manager to also be listed in BIOS/UEFI setup?
Answer:
1. Yes
2. No
Explanation:
1 Note that the term BIOS (Basic input and Output System) refers to instructions that controls a computer device operations. Thus, devices that shows up in BIOS should be in device manager.
2. Not all devices listed in devcie manager of a computer system will be listed in BIOS.
Alcatel-Lucent’s High Leverage Network (HLN) increases bandwidth and network capabilities while reducing the negative impact on the environment. HLN can handle large amounts of traffic more efficiently because __________.
Answer:
The networks are intelligent and send packets at the highest speed and most efficiently.
Explanation:
Alcatel-Lucent was founded in 1919, it was a French global telecommunications equipment manufacturing company with its headquarter in Paris, France. Alcatel-Lucent provide services such as telecommunications and hybrid networking solutions deployed both in the cloud and on properties.
Alcatel-Lucent’s High Leverage Network (HLN) increases bandwidth and network capabilities while reducing the negative impact on the environment. This high leverage network can handle large amounts of traffic more efficiently because the networks are intelligent and send packets at the highest speed and most efficiently. HLN are intelligent such that it delivers increased bandwidth using fewer devices and energy.
Generally, when the High Leverage Network (HLN) is successfully implemented, it helps telecommunications companies to improve their maintenance costs, operational efficiency, enhance network performance and capacity to meet the bandwidth demands of their end users.
You turn on your Windows computer and see the system display POST messages. Then the screen goes blank with no text. Which of the following items could be the source of the problem?
1. The video card
2. The monitor
3. Windows
4. Microsoft word software installed on the system.
1 #Write a function called phonebook that takes two lists as
2 #input:
3 #
4 # - names, a list of names as strings
5 # - numbers, a list of phone numbers as strings
6 #
7 #phonebook() should take these two lists and create a
8 #dictionary that maps each name to its phone number. For
9 #example, the first name in names should become a key in
10 #the dictionary, and the first number in numbers should
11 #become the value corresponding to the first name. Then, it
12 #should return the dictionary that results.
13 #
14 #Hint: Because you're mapping the first name with the first
15 #number, the second name with the second number, etc., you do
16#not need two loops. For a similar exercise, check back on
17 #Coding Problem 4.3.3, the Scantron grading problem.
18 #
19 #You may assume that the two lists have the same number of #items: there will be no names without numbers or numbers
20 #without names.
21 #Write your function here!
25
26
27
28 #Below are some lines of code that will test your function
29 #You can change the value of the variable(s) to test your
30 #function wit h different inputs 2 If your function works correctly, this ill originally
31
32 #print (although the order of the keys may vary):
33| #('Jackie': '404-555-1234., 'Joshua': .678-555-5678., "Marguerite': '778-555-9012
35
36 name_list ['Jackie', Joshua', 'Marguerite']
37 number list-['484-555-1234, 678-555-5678 770-555-9812']
38 print (phonebook (name list, numberlist))
39
40
41
Answer:
I am writing a Python program.
def phonebook(names, numbers): #method phonebook that takes two parameters i.e a list of names and a list of phone numbers
dict={} #creates a dictionary
for x in range(len(names)): # loop through the names
dict[names[x]]=numbers[x] #maps each name to its phone number
return dict #return dictionary in key:value form i.e. name:number
#in order to check the working of this function, provide the names and numbers list and call the function as following:
names = ['Jackie', 'Joshua', 'Marguerite']
numbers = ['404-555-1234', '678-555-5678', '770-555-9012']
print(phonebook(names, numbers))
Explanation:
The program has a function phonebook() that takes two parameters, name which is a list of names and numbers that is a list of phone numbers.
It then creates a dictionary. An empty dictionary is created using curly brackets. A dictionary A dictionary is used here to maps a names (keys) phone numbers (values) in order to create an unordered list of names and corresponding numbers.
for x in range(len(names)):
The above statement has a for loop and two methods i.e. range() and len()
len method is used to return the length of the names and range method returns sequence of numbers just to iterate as an index and this loops keeps iterating until x exceeds the length of names.
dict[names[x]]=numbers[x]
The above statement maps each name to its phone number by mapping the first name with the first umber, the second name with the second number and so on. This mapping is done using x which acts like an index here to map first name to first number and so on. For example dict[names[1]]=numbers[1] will map the name (element) at 1st index of the list to the number (element) at 1st index.
return dict retursn the dictionary and the format of dictionary is key:value where key is the name and value is the corresponding number.
The screenshot of the program and its output is attached.
How many times does the following loop execute? double d; Random generator = new Random(); double x = generator.nextDouble() * 100; do { d = Math.sqrt(x) * Math.sqrt(x) - x; System.out.println(d); x = generator.nextDouble() * 10001; } while (d != 0); exactly once exactly twice can't be determined always infinite loop
Answer:
The number of execution can't always be determines
Explanation:
The following points should be noted
Variable d relies on variable x (both of double data type) for its value
d is calculated as
[tex]d = \sqrt{x}^2 - x[/tex]
Mere looking at the above expression, the value of d should be 0;
However, it doesn't work that way.
The variable x can assume two categories of values
Small Floating Point ValuesLarge Floating Point ValuesThe range of the above values depend on the system running the application;
When variable x assumes a small value,
[tex]d = \sqrt{x}^2 - x[/tex] will definitely result in 0 and the loop will terminate immediately because [tex]\sqrt{x}^2 = x[/tex]
When variable x assumes a large value,
[tex]d = \sqrt{x}^2 - x[/tex] will not result in 0 because their will be [tex]\sqrt{x}^2 \neq x[/tex]
The reason for this that, the compiler will approximate the value of [tex]\sqrt{x}^2[/tex] and this approximation will not be equal to [tex]x[/tex]
Hence, the loop will be executed again.
Since, the range of values variable x can assume can not be predetermined, then we can conclude that the number of times the loop will be executed can't be determined.
In Network Address and Port Translation (NAPT), which best describes the information used in an attempt to identify the local destination address?
Answer:
Hello your question lacks the required options here are the options
source IP and destination IPsource IP and destination portsource IP and source portsource port and destination IPsource port and destination portanswer : source IP and destination port
Explanation:
The information that is used in an attempt to identify the local destination address is the source IP and destination port
source IP is simply the internet protocol address of a device from which an IP packet is sent to another device while destination port are the ports found in a destination device that receives IP packets from source ports they are found in many internet applications
1. Railroad tracks present no problems for a motorcyclist.
A. O TRUE
B. O FALSE
2. Which of the following is considered to be a vulnerable road user?
A. Bicyclists
B. Motorcyclists
C. Pedestrians
D. all of the above
Answer: 1 is A
2 is D
Explanation:
A program is considered portable if it . . . can be rewritten in a different programming language without losing its meaning. can be quickly copied from conventional RAM into high-speed RAM. can be executed on multiple platforms. none of the above
Answer:
Can be executed on multiple platforms.
Explanation:
A program is portable if it is not platform dependent. In other words, if the program is not tightly coupled to a particular platform, then it is said to be portable. Portable programs can run on multiple platforms without having to do much work. By platform, we essentially mean the operating system and hardware configuration of the machine's CPU.
Examples of portable programs are those written in;
i. Java
ii. C++
iii. C
Without data compression, and focusing only on the data itself without any overhead, what transmission rate is required to send 30 frames per second of gray-scale images with resolution 1280 x 1024?
Answer:
315 Mbps
Explanation:
Given data :
30 frames per second
resolution = 1280 * 1024
what transmission rate is required can be calculated as
frames per second = rendered frames / number of seconds passed
30 = 30 / 1
Transmission rate = the rate at which the images are transmitted from source to destination =315 Mbps without data compression
What is a real-life example of a Microsoft Access Query?
Explanation:
Microsoft Access is an information management tool that helps you store information for reference, reporting, and analysis. Microsoft Access helps you analyze large amounts of information, and manage related data more efficiently than Microsoft Excel or other spreadsheet applications.
A real-life example of a Microsoft Access Query is a table that stores the names of new customers at a supermarket.
What is Microsoft Access?Microsoft Access is a database management software application designed and developed by Microsoft Inc., in order to avail its end users an ability to create, store and add data to a relational database.
In Microsoft Access, the options that are available on the File tab include the following:
Opening a database.
Selecting a template.
Creating a new database.
In conclusion, a database is an element in Microsoft Access which is an ideal data source and a query would always obtain, generate, or pick information from it.
Read more on Microsoft Access here: brainly.com/question/11933613
#SPJ2
5- The Menu key or Application key is
A. is the placements and keys of a keyboard.
B. a telecommunications technology used to transfer copies of documents
c. a key found on Windows-oriented computer keyboards.
Answer:
c. a key found on Windows-oriented computer keyboards.
Explanation:
Hope it helps.
The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case and 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
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.
Following are the modified program to the given question:
Program Explanation:
Import package.Defining a method "compare_strings" that takes two parameters "string1, string2".Inside the method, parameter variables have been used that convert and hold string values into lower case.In the next step, a variable "punctuation" is defined that holds value.After this, a parameter variable is used that calls the sub-method that checks parameter value with punctuation variable value, and at the return keyword is used that check string1 value equal to string2.Outside the method, multiple print method is used calls the method, and prints its value.Program:
import re #import package
def compare_strings(string1, string2):#defining a method compare_strings that takes two parameters
string1 = string1.lower().strip()#defining a variable string1 that converts and holds string value into lower case
string2 = string2.lower().strip()#defining a variable string1 that converts and holds string value into lower case
punctuation = r'[^\w\s]'#defining a variable that holds value
string1 = re.sub(punctuation, '', string1)#using the variable that calls the sub method that checks parameter value with punctuation variable value
string2 = re.sub(punctuation, '', string2)#using the variable that calls the sub method that checks parameter value with punctuation variable value
return string1 == string2#using return keyword that check string1 value equal to string2
print(compare_strings("Have a Great Day!", "Have a great day?")) # calling method that prints the return value
print(compare_strings("It's raining again.", "its raining, again")) # calling method that prints the return value
print(compare_strings("Learn to count: 1, 2, 3.", "Learn to count: one, two, three.")) # calling method that prints the return value
print(compare_strings("They found some body.", "They found somebody.")) # calling method that prints the return value
Output:
Please find the attached file.
Learn more:
brainly.com/question/21579839