Answer:
Given Loop Variant P = a[0], a[1] ... a[i]
It is product of n terms in array
Explanation:
The Basic Step: i = 0, loop invariant p=a[0], it is true because of 'p' initialized as a[0].
Induction Step: Assume that for i = n - 3, loop invariant p is product of a[0], a[1], a[2] .... a[n - 3].
So, after that multiply a[n - 2] with p, i.e P = a[0], a[1], a[2] .... a[n - 3].a[n - 2].
After execution of while loop, loop variant p becomes: P = a[0], a[1], a[2] .... a[n -3].a[n -2].
for the case i = n-2, invariant p is product of a[0], a[1], a[2] .... a[n-3].a[n-2]. It is the product of (n-1) terms. In while loop, incrementing the value of i, so i=n-1
And multiply a[n-1] with p, i.e P = a[0].a[1].a[2].... a[n-2].
a[n-1]. i.e. P=P.a[n-1]
By the assumption for i=n-3 loop invariant is true, therefore for i=n-2 also it is true.
By induction method proved that for all n > = 1 Code will return product of n array elements.
While loop check the condition i < n - 1. therefore the conditional statement is n - i > 1
If i = n , n - i = 0 , it will violate condition of while loop, so, the while loop will terminate at i = n at this time loop invariant P = a[0].a[1].a[2]....a[n-2].a[n-1]
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:
Discuss the differences between dimensionality reduction based on aggregation and dimensionality reduction based on techniques such as PCA and SVD.
Answer:
Following are the difference to this question can be defined as follows:
Explanation:
In terms of projections of information into a reduced dimension group, we can consider the dimension structure of PCA and SVD technologies. In cases of a change in the length, based on consolidation, there's also a unit with dimensions. When we consider that the days have been aggregated by days or the trade of a commodity can be aggregated to both the area of the dimension, accumulation can be seen with a variance of dimension.Dimensionality reduction based on aggregation involves selection of important character and variable from a large variable and dimensionality reduction based on techniques with the use of PCA and SVD.
What is dimensionality?Dimensionality involves reducing features that have been written or identified or constructing less features from a pool of important features.
Principal components analysis(PCA) and Single value decomposition(SVD) is a form or analysis that can be used to reduce some character that are not important to an information and can also help to select important variables from among many variables.
Therefore, dimensionality reduction based on aggregation involves selection of important character and variable from a large variable and dimensionality reduction based on techniques with PCA and SVD.
Learn more on dimensional analysis here,
https://brainly.com/question/24514347
ntify five key technologies/innovations and discuss their advantages and
disadvantages to developing countries like Ghana
Answer:
1. Blockchain Technology: Blockchain is a distributed ledger technology that lets data to be stored globally on its servers and it is based on a P2P topology which makes it difficult for someone to tamper with the network.
It can be used as a cryptocurrency wallet that supports BitCoin, Ethereum, etc.
An advantage of it is that it is distributed among several users and stable.
A disadvantage for a developing country like Ghana is that once a blockchain is sent, it cannot go back which brings up the question of security.
2.Artificial Intelligence: This technology is simply the simulation of human intelligence in machines. AI can be used for problem-solving and learning. An advantage of AI is that it reduces human error and is fast in solving problems. A disadvantage of AI is that its expensive to maintain and also it does not improve with experience.
3. Global Positioning System: GPS is a satellite-based positioning system that is used to pinpoint and track location. It has the advantage of being available worldwide and information is provided to users in real-time. One disadvantage of the GPS for a developing country like Ghana is that electromagnetic interference can affect the accuracy of the GPS.
4. 5G Network: This is the 5th generation of mobile internet connectivity that gives super fast download and upload speeds when compared to its predecessors 4G, 3G, 2G, and Edge networks.
One major disadvantage of 5G for a developing country like Ghana is that it is expensive and quite unknown and its security and privacy issues are yet to be resolved.
5. Lasers: This isn't a new technology as it has been in use for some time already but its importance cannot possibly be over-emphasized. LASER is an acronym that means Light Amplification by the Stimulated Emission of Radiation.
It is precise and accurate in cutting when compared to thermal and other conventional cutting methods. It is being used in surgeries that require the highest levels of accuracy with great success.
A disadvantage of Laser technology is that it is expensive to use and maintain.
Teachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching experience. For example, a beginning teacher in the Lexington School District might be paid $30,000 the first year. For each year of experience after this first year, up to 10 years, the teacher receives a 2% increase over the preceding value. Write a program that displays a salary schedule, in tabular format, for teachers in a school district. The inputs are:
Answer:
Here is the python code:
StartingSal = int(input("Enter the starting salary: "))
AnnualIncrease = (int(input("Enter the annual % increase: ")) / 100)
Years = int(input("Enter the number of years: "))
for count in range(1,Years+1):
print("Year ", count, " Salary: ", StartingSal*((1+AnnualIncrease)**(count-1)))
Explanation:
This program prompts the user to enter starting salary, percentage increase in salary per year and number of years.
The for loop has range function which is used to specify how many times the salaries are going to be calculated for the number of years entered. It starts from 1 and ends after Years+1 means one value more than the year to display 10 too when user inputs 10 days.
The year and corresponding salary is displayed in output. At every iteration the starting salary is multiplied by annual percentage increase input by user. Here count is used to count the number of salaries per year, count-1 means it will start from 30000.
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)
Below is some info for some internet transactions. We want to sort it by time and by location. Which sorting algorithm is appropriate for this particular problem?
a. radix sort.
b. heap sort.
c. selection sort.
d. shell sort.
Answer:
c. selection sort
Explanation:
The best way to sort the internet transactions data based on time and location is selection sort. The algorithms sorting technique is used to sort the complex data in computer programs. Shell sort is the technique which sorts the data apart from each other and reduces interval between them. Heap sort is sorting technique based on binary heap data structure. Radix sort is an integer sorting technique in algorithms.
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.
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
An app developer is shopping for a cloud service that will allow him to build code, store information in a database and serve his application from a single place. What type of cloud service is he looking for?
Answer:
Platform as a Service (PaaS).
Explanation:
In this scenario, an app developer is shopping for a cloud service that will allow him to build code, store information in a database and serve his application from a single place. The type of cloud service he is looking for is a platform as a service (PaaS).
In Computer science, Platform as a Service (PaaS) refers to a type of cloud computing model in which a service provider makes available a platform that allow users (software developers) to build code (develop), run, store information in a database and manage applications over the internet.
The main purpose of a Platform as a Service (PaaS) is to provide an enabling environment for software developers to code without having to build and maintain complex infrastructure needed for the development, storage and launching of their software applications.
Simply stated, PaaS makes provision for all of the software and hardware tools required for all the stages associated with application development over the internet (web browser).
Hence, the advantage of the Platform as a Service (PaaS) is that, it avails software developers with enough convenience as well as simplicity, service availability, ease of licensing and reduced costs for the development of software applications.
These are the different types of Platform as a Service;
1. Private PaaS.
2. Public PaaS.
3. Hybrid PaaS.
4. Mobile PaaS.
5. Communications PaaS.
6. Open PaaS.
The software developers can choose any of the aforementioned types of PaaS that is suitable, effective and efficient for their applications development. Some examples of PaaS providers are Google, Microsoft, IBM, Oracle etc.
Implement function easyCrypto() that takes as input a string and prints its encryption
defined as follows: Every character at an odd position i in the alphabet will be
encrypted with the character at position i+1, and every character at an even position i
will be encrypted with the character at position i 1. In other words, ‘a’ is encrypted with
‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’ with ‘c’, and so on. Lowercase characters should remain
lowercase, and uppercase characters should remain uppercase.
>>> easyCrypto('abc')
bad
>>> easyCrypto('Z00')
YPP
Answer:
The program written in python is as follows;
import string
def easyCrypto(inputstring):
for i in range(len(inputstring)):
try:
ind = string.ascii_lowercase.index(inputstring[i])
pos = ind+1
if pos%2 == 0:
print(string.ascii_lowercase[ind-1],end="")
else:
print(string.ascii_lowercase[ind+1],end="")
except:
ind = string.ascii_uppercase.index(inputstring[i])
pos = ind+1
if pos%2 == 0:
print(string.ascii_uppercase[ind-1],end="")
else:
print(string.ascii_uppercase[ind+1],end="")
anystring = input("Enter a string: ")
easyCrypto(anystring)
Explanation:
The first line imports the string module into the program
import string
The functipn easyCrypto() starts here
def easyCrypto(inputstring):
This line iterates through each character in the input string
for i in range(len(inputstring)):
The try except handles the error in the program
try:
This line gets the index of the current character (lower case)
ind = string.ascii_lowercase.index(inputstring[i])
This line adds 1 to the index
pos = ind+1
This line checks if the character is at even position
if pos%2 == 0:
If yes, it returns the alphabet before it
print(string.ascii_lowercase[ind-1],end="")
else:
It returns the alphabet after it, if otherwise
print(string.ascii_lowercase[ind+1],end="")
The except block does the same thing as the try block, but it handles uppercase letters
except:
ind = string.ascii_uppercase.index(inputstring[i])
pos = ind+1
if pos%2 == 0:
print(string.ascii_uppercase[ind-1],end="")
else:
print(string.ascii_uppercase[ind+1],end="")
The main starts here
This line prompts user for input
anystring = input("Enter a string: ")
This line calls the easyCrypto() function
easyCrypto(anystring)
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
What is industry 4.0 -automation revolution-, what is your opinion about the direction this revolution is taking the industry in, and discuss the fate of unskilled and semi-skilled workers affected by industry 4.0.
Answer:
Find the explanation below.
Explanation:
1. Industry 4.0 -automation revolution is a term first used in Germany in 2011 to describe the fourth generation of the industrial revolution. It is the incorporation of digitalized procedures that use smart technology that can work in real-time to industrial production. This means that the machines used in production can independently interact between themselves to accomplish tasks that would otherwise have needed human involvement.
2. My opinion regarding this industrial revolution is that it is a welcome development for businesses because it will help them execute projects at faster rates and limit some working expenses.
3. Unskilled and Semi-skilled workers will be badly affected by this revolution because tasks ordinarily performed by them would be mostly taken over by these machines. This means that companies would most likely lay off these workers whose jobs would now be performed by machines. Job regulation agencies would do well to seek ways to intervene for this group of workers. They may also have to improve their skills if they want to remain relevant to their jobs.
The revolution, however, would be favorable for high-skilled workers because they would be needed to perform jobs such as the maintenance and programming of these machines.
Identify five key technologies/innovations and discuss their advantages and disadvantages to developing countries like Ghana.
Answer:
The key technology/ innovation advantage and disadvantage can be defined as follows:
Explanation:
Following are the 5 innovations and technology, which promote the other development goals, like renewable energy, quality of jobs, and growth of economic with the good health and very well-being:
1) The use of crop monitoring drone technology promotes sustainable farming.
2) The production of plastic brick including highways, floors, and houses.
3) The new banking market or digital banking.
4) E-commerce site.
5) Renewable energy deployment such as solar panels.
Advantage:
It simple insect control, disease, fertilizer, etc. It helps in aid in environmental purification and job formation.It is also fast and easy, Funds are transferred extremely easily through one account to another. Minimal prices, quick customer developments, and competition in the industry. It saves them money in the medium-haul, less servicing.Disadvantage:
The drones are too expensive to use, so poor farmers can be cut off. Specialist technicians and gaining popularity are required. The financial services data can be distributed through many devices and therefore become more fragile. The personal contact loss, theft, security problems, etc. The higher operating costs, geographical limitations, and so on.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
in terms of computer what does mie mean
Answer:
Microsoft Internet explorer
Which best describes the purpose of LoJack on a computer
Answer:The purpose of the lo jack on a computer to the lock and delete files on the computer devices.
Explanation:The lo jack on a computer to locate all the lock and delete files.
lo jack can provides the computer on the passwords that contains different levels of the bios access.
lo jack perform on the computer operating system provides on the boot only the trusted by the computer operating system.
Lo jack computer on the function is used to the published the exam answers on the websites.
Lo jack insures to the data into hard drives to the correct computer password.
NMCI is the name used for a large-scale effort to link Navy and Marine Corps computer systems on bases, boats, and in offices around the world. When completed, this internal WAN will use Internet technology to link soldiers in the field with support personnel on bases, etc. NMCI is an example of a(n):
Answer:
The answer is "Intranet".
Explanation:
The intranet becomes an information exchange computer network, in which the resources collaborate with OS and other computing infrastructure within the organization. It is usually done without access from third parties and primarily uses for analysis of the data.
Here, the NMCI links the computer network of navy and maritime bodies on the bases of both the boats and the regional offices, that's why we can say that it is the example of the Internet.
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.
state five uses of building
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.
Assume a PHP document named hello.php has been saved in a folder named carla inside the htdocs folder on your computer. Which is the correct path to enter to view this page in a browser?
The available options are:
A. localhost/Carla/hello.php
B. localhost/htdocs/hello.php
C. localhost/htdocs/Carla/hello.php
D. carla/hello.php5
Answer:
C. localhost/htdocs/Carla/hello.php
Explanation:
A path in computer programming can be defined as the name of a file or directory, which specifies a unique location in a file system.
Therefore, to get the correct path to enter to view this page in a browser, one needs to follow the directory tree hierarchy, which is expressed in a string of characters in which path components, separated by a delimiting character, represent each directory.
Hence, correct path to enter to view this page in a browser is "localhost/htdocs/Carla/hello.php"
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.
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
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.
Can someone help me out with this one? I'm not sure why my code is not working
Now, let's improve our steps() function to take one parameter
that represents the number of 'steps' to print. It should
then return a string that, when printed, shows output like
the following:
print(steps(3))
111
222
333
print(steps(6))
111
222
333
444
555
666
Specifically, it should start with 1, and show three of each
number from 1 to the inputted value, each on a separate
line. The first line should have no tabs in front, but each
subsequent line should have one more tab than the line
before it. You may assume that we will not call steps() with
a value greater than 9.
Hint: You'll want to use a loop, and you'll want to create
the string you're building before the loop starts, then add
to it with every iteration.
Write your function here
def steps(number):
i = 1
while i < number + 1:
string = str(i) * 3
string1 = str(string)
if i != 0:
string1 = (i * 4*' ' + "\b" + "\b" + "\b" + "\b") + string
elif i == 1:
string1 = string
print(string1)
i = i + 1
#The following two lines will test your code, but are not
#required for grading, so feel free to modify them.
print(steps(3))
print(steps(6)
Answer:
Add this statement at the end of your steps() function
return ""
This statement will not print None at the end of steps.
Explanation:
Here is the complete function with return statement added at the end:
def steps(number): # function steps that takes number (number of steps to print) as parameter and prints the steps specified by number
i = 1 #assigns 1 to i
while i < number + 1:
string = str(i) * 3 #multiplies value of i by 3 after converting i to string
string1 = str(string) # stores the step pattern to string1
if i != 0: # if the value of i is not equal to 0
string1 = (i * 4*' ' + "\b" + "\b" + "\b" + "\b") + string #set the spaces between steps
elif i == 1: # if value of i is equal to 1
string1 = string #set the string to string1
print(string1) # print string1
i = i + 1 # increments i at each iteration
return "" #this will not print None at the end of the steps and just add a an empty line instead of None.
Screenshot of the corrected program along with its output is attached.
The code below takes the list of country, country, and searches to see if it is in the dictionary gold which shows some countries who won gold during the Olympics. However, this code currently does not work. Correctly add try/except clause in the code so that it will correctly populate the list, country_gold, with either the number of golds won or the string "Did not get gold".
1
2 gold = {"US":46, "Fiji":1, "Great Britain":27, "Cuba":5, "Thailand":2, "China":26, "France":10}
3 country = ["Fiji", "Chile", "Mexico", "France", "Norway", "US"]
4 country_gold = []
5
6 for x in country:
7 country_gold.append(gold[x])
8 country_gold.append("Did not get gold")
Answer:
Modify your program by replacing
for x in country:
country_gold.append(gold[x])
country_gold.append("Did not get gold")
with
for x in country:
try:
country_gold.append(gold[x])
except:
country_gold.append("Did not get gold")
Explanation:
The addition of try/except clause in the program is to let the program manage error;
In this case, the program checks for a country in the list country; This is implemented using the following line
for x in country:
If the country exists, the statement in the try block is executed
try:
country_gold.append(gold[x]) ->This appends the country name to the country_gold list
Otherwise, the statement in the except clause is executed
except:
country_gold.append("Did not get gold") -> This appends "Did not get gold" to the country_gold list
To confirm what you've done, you may add the following line of code at the end of the program: print(country_gold)
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
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
The IT department sets up a user account and software. Which stage of the hardware lifecycle does this situation belong to?
Answer:
"Development" would be the correct answer.
Explanation:
All that would be required to complete the plan is designed mostly during the development or planning process. The production process is finished whenever it's prepared to resume execution.Local participants and perhaps suppliers are helped to bring in, a timetable would be managed to make, parts and equipment are decided to order, employee training should be given and many more.Suppose that we want to multiply 500 matrices and we use the optimal parenthesization computed by the MATRIX-CHAIN-ORDER function discussed in class. After finding the optimal parenthesization, how many pairs of round brackets ( ) are printed by the procedure PRINT-OPTIMAL-PARENS(s, 1, 500)?
a. 249
b. 501
c. 251
d. 250
e. 499
f. 500
Answer:
síganme en las claves de ustedes pronto. Seré un buen día. He seguido un poco sobre el Is. He seguido un poco sobre el Is. He seguido un poco sobre el.
is (c)251? correct since i'm not really sure