What is the value of the num_colors variable? var colors = ["red","blue","orange","yellow","green","brown","purple"]; num_colors = colors.length
Answer:
Hello the options to your question is missing here are the options
6 7 8 NaNanswer : 7
Explanation:
The value of the num_colors variable is 7 and this because you have to neglect the fact that there is no termination symbol at the end of the assignment operation in the code.
But when we consider the none existence of a termination symbol at the end of the assignment operation in the code, the code will generate a syntax error instead of a value.
What is the output of the following Python statements? def recurse(a): if (a == 0): print(a) else: recurse(a) recurse(0)
Answer:
d) 0 1 1 2
The above piece of code prints the Fibonacci series.
Explanation:
def a(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return a(n-1)+a(n-2)
for i in range(0,4):
print(a(i),end=" ")
Modify short_names by deleting the first element and changing the last element to Joe. Sample output with input: 'Gertrude Sam Ann Joseph'
Answer:
I am writing a Python program:
For taking input from user:
user_input = input() # takes input from user
short_names = user_input.split() #splits user_input into list of strings
short_names.pop(0) # removes the first element of the list i.e. Gertrude
short_names[-1] = "Joe" #sets the last element to Joe
print(short_names) #prints modified list of Sam Ann Joe
If you do not want to take input from user:
short_names=['Gertrude', 'Sam', 'Ann', 'Joseph'] #list of 4 elements
short_names=short_names[1:] # removes the first element Gertrude
short_names.pop() # removes last element i.e. Joseph from list
short_names.append('Joe') #adds Joe to the end of the list
print(short_names) #prints modified list Sam Ann Joe
If you do not want to use pop() and append() methods:
short_names = ['Gertrude', 'Sam', 'Ann', 'Joseph'] #creates list of 4 values
short_names = short_names[1:] # removes first value i.e. Gertrude from list
short_names[-1] = "Joe" #set the last element to Joe
print(short_names) #prints modified list Sam Ann Joe
Explanation:
The first program takes the names from the user, splits them into list of strings, then pop(0) has given index value 0 which means 1st value in the list. So it removes and returns first value from the list. Next statement sets the last value of list to Joe.
The second program has a hard coded list ['Gertrude', 'Sam', 'Ann', 'Joseph']
short_names = short_names[1:] removes the first value of the short_names list i.e. Gertrude. Next pop() removes and returns last value in the list i.e. Joseph from list. Last statement append('Joe') adds Joe to the end of the list.
The third program has a list of 4 elements. short_names = short_names[1:] removes first value i.e. Gertrude from list and short_names[-1] = "Joe" sets the last element to Joe.
The function was implemented using the JavaScript language, the shift, pop and push function was used to get the desired output
Array and String OperationsThe function bellow is written in JavaScript
function shortName (short_names){
short_names.shift() // The first element "Gertrude" was removed
short_names.pop() //The last element "Joseph" was removes
short_names.push("joe") //"Joe" is added to the new list
return short_names //The new list is returned as output
}
Learn more about array operation here:
https://brainly.com/question/26104158
The best way to avoid driving impaired is to...
A. avoid drinking.
B. stay under the legal BAC limit.
C. keep a taxi fare on hand.
Answer:
the answer is A avoid drinking 10 Tips to Avoid Driving Drunk
Explanation:
Give someone your keys. Find someone trustworthy who isn't drinking and hand over your keys for the night. ...
Don't drink on an empty stomach. ...
Know your body and pace yourself. ...
Take public transit. ...
Spend the night. ...
Wait an hour or two. ...
Stop drinking 90 minutes before you plan to leave. ...
Take the night off from drinking. hope this helps you :)
Write a method called listUpper() that takes in a list of strings, and returns a list of the same length containing the same strings but in all uppercase form. You can either modify the provided list or create a new one.
Answer:
public static List<String> listUpper(List<String> list){
List<String> upperList = new ArrayList<String>();
for(String s:list){
s = s.toUpperCase();
upperList.add(s);
}
return upperList;
}
Explanation:
Create a method named listUpper that takes list as a parameter
Inside the method, initialize a new list named upperList. Create a for-each loop that iterates through the list. Inside the loop, convert each string to uppercase, using toUpperCase method, and add it to the upperList.
When the loop is done, return the upperList
Identify and write the errors given in the flowchart (with steps and flowchart) : Start ↓ Input A,B ↓ Average = (A + B + C) / 3 ↓ Print Average ↓ Stop
Answer:
i will send you the answers in the next 10minute
what kind of company would hire an information support and service employee?
-software development
-computer repair
-website development
-network administration
Answer:
it's a
Explanation:
The UNIX operating system started the concept of socket which also came with a set of programming application programming interface (API) for 'socket level' programming. A socket was also uniquely identified:
a. as the combination of IP address and port number to allow an application within a computer to set up a connection with another application in another computer without ambiguity.
b. the port number to clearly identify which application is using TCP.
c. IP address to make sure the Internet device using the socket is delineated.
d. the access network, such as Ethernet or Wi-Fi so that multiple LAN devices could be installed on a single computer.
Answer:
(a). as the combination of IP address and port number to allow an application within a computer to set up a connection with another application in another computer without ambiguity.
Explanation:
The explanation is in the answer.
a. A hard disk has four surfaces (that's top and bottom of two platters). Each track has 2, 048 sectors and there are 131, 072 (2^17) tracks per surface. A block holds 512 bytes. The disk is not "zoned." What is the total capacity of this disk?
b. Given the disk in Part 1, how much data can be accessed without moving the disk heads. (That, is, what is the capacity of one cylinder?)
Answer:
Explanation:
Given that:
number of surfaces on a hard disk = 4
number of sectors = 2048 sectors
number of tracks per surface = 131, 072 (2^17)
a block holds 512 bytes.
Since, 'The disk is not "zoned.".....
then, Number of bytes / sector = 512
a) What is the total capacity of this disk?
The total capacity of the disk is:[tex]= 4 \ surfaces \times 131072 \dfrac{tracks}{surfaces} \times 2048 \dfrac{sector}{tracks} \times 512 \dfrac{bytes}{sector}[/tex]
[tex]= 5.49755814\times 10^{11} \ bytes[/tex]
= 549755814 KB ( kilobytes)
= 549755.814 MB (megabytes)
=549.755814 GB (gigabytes)
b. Given the disk in Part 1, how much data can be accessed without moving the disk heads. (i.e what is the capacity of one cylinder?)
The capacity of one cylinder can be estimated by determining the capacity of one surface and the capacity of one track.
The capacity of one surface = [tex]131072\dfrac{tracks}{surface} \times 2048 \dfrac{sector}{tracks} \times 512\dfrac{bytes}{sector}[/tex]
The capacity of one surface = [tex]1.37438953 \times 10^{11[/tex] byte = 137.44 GB
Capacity of one track = 2048 sectors/track × 512 bytes/sector
Capacity of one track = 1048576 Bytes/track
Capacity of one track =1048 KB/track
Capacity of one track ≅ 1 MB/track
Since the hard disk contains four surfaces
∴
capacity of one cylinder = 1 MB/track × 4 track/cylinder
capacity of one cylinder = 4 MB
Shovels and Shingles is a small construction company consisting of 12 computers that have Internet access. The company's biggest concern is that a wily competitor will send e-mail messages pretending to be from Shovels and Shingles in order to get confidential information. Write down an encryption solution that best prevents a competitor from receiving confidential information and justify the recommendation.
Answer:
The Encryption solution that best prevents a competitor from receiving confidential information is the SSL(secure Socket Layer) Or TLS(Transport Layer Security).
Explanation:
Solution:
From my own perspective the encryption solution that i will use that prevents s a competitor from receiving confidential information and justify the recommendation is the SSL(secure Socket Layer) Or TLS(Transport Layer Security).
This is because in this case we have to share data confidentially (information need to be hidden from Unauthorized security access. also these provides the Transport Layer security that we needed in above example above.
The purpose of these protocol is to provide server and client authentication, Data confidentiality,and Data integrity (protected from unauthorized change). Application Layer client/server program such as HTTP that uses the service of TCP can encapsulate their data in SSL Packets.
SSL (Secure Socket Layer): is defined as the normal technology for protecting an internet connection secure and defend any sensitive data that is being sent between two systems, and not allowing criminals from reading and changing any information sent, including potential personal details.
TLS (Transport Layer security): It is a procedure that allows data integrity and privacy over Internet communications.
The instruction format of a computer is given by one indirect bit, opcode bits, register address bits, immediate operand bits and memory address bits. It occupies one memory word of 64 bits.
a- How many memory addresses can be generated if the memory size is 1 Giga Bytes (Giga-2)? Number of addresbits Number of addresses
b- Complete the missing fields in the following instruction format, given that the number of opcodes is 128, the immediate operand field occupies 24 bits and the instruction occupies one memory word Opcode Register address Immediate operand Memory address
c- If the immediate value is increased by combining it with the address field in the above instruction. Find the largest positive and smallest negative immediate values that can be stored on the address field, before and after combining it with the address field. Range before combining (+ Range after combining-+
Answer:
Following are the answer to this question:
Explanation:
A)
The memory size is 1 Giga Bytes which is equal to [tex]2^{30}[/tex]
[tex]\texttt{Number of address bits \ \ \ \ \ \ \ \ \ \ \ \ \ \ Number of addresses}\\\\ \ \ \ \ 30 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2^{30}= 1073741824[/tex]
B) [tex]\texttt{I \ \ \ Opcode \ \ \ Register address \ \ \ Immediate operand \ \ \ Memory address}\\\\\\\textt{1 \ bit \ \ \ \ \ \ 128 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2 \ bits \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 24 \ bits \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 30 \ bits}\\\\\\[/tex] [tex]= 2^7 \\\\ = 7 \ bits[/tex]
calculating the register Bits:
[tex]= 64-(1+7+24+30)\\\\=64 -62\ \ bits\\\\= 2\ \ bits\\[/tex]
C)
Immediate value size while merging the additional benefit with the address field:
[tex]= 2^{24} + 2^{30}\\\\= 2^{54}\\\\[/tex][tex]\texttt{Range before combining(-,+) 24 bits \ \ \ \ \ \ Range after combining( -,+)54bits}\\\\[/tex] [tex]\textt{-2^{12} from + (2^{12}-1) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -2^{27} from + (2^{27}- 1)}[/tex]
[tex]= \frac{24}{2} = 12\\\\= \frac{54}{2} = 27[/tex]
The range is accomplished by dividing the bits by 2 into the two sides of the o and the number is one short to 0.
More than one component in a particular automotive electric circuit is not working. Technician A starts testing the circuit at the power source. Technician B starts testing the circuit at its load. Who is right?
Hi there! Hopefully this helps!
--------------------------------------------------------------------------------------------------
The answer is A, testing the circuit at the power source.
Jan has had a small business for three years or so, selling decorative art pieces. She works out of her home office. Jan has read about the Apple iPad and wants to get one for her art business. What kind of computer would the iPad probably replace
Answer:
In this sense, the different types of computers would range from Desktop to Laptops, to iPads, then Mobile Phones. Somewhere in-between the phone and the iPad is the phablet.
A phablet is a group of mobile devices with the combined functionality and size of a smartphone and a tablet.
On the balance of probabilities, Jan is trying to replace her laptop.
Cheers!
The score of a student in two subjects are inserted in the B2 and C2 cells and the passing score for each subject is 60. Which of these functions will you insert in the D2 cell so that it returns TRUE if at least one score is greater than or equal to 60, or else it returns FALSE
Answer:
=OR(B2>=60, C2>=60)
Explanation:
If you want to check if at least one of the scores is equal to or greater than 60, you should use the OR function. The OR function tests multiple conditions and returns TRUE if at least one is met. Therefore, the function in cell D2 would be:
= OR(B2>=60, C2>=60)
In other to obtain the boolean value True if one of two or more conditions are met, the OR operator is used. Hence, the appropriate function is =OR(B2>=60, C2>=60)
The OR opertor gives a True value if one of the two conditions is met., if the student scores 60 or above in one of the two subjects, the output will be True. Similarly, if the student score above 60 in both, the output will be true.Hence, the appropriate function is =OR(B2>=60, C2>=60).
Learn more : https://brainly.com/question/20702793
Define stubs for the functions get_user_num) and compute_avg). Each stub should print "FIXME: Finish function_name" followed by a newline, and should return -1. Each stub must also contain the function's parameters Sample output with two calls to get_user_num) and one call to compute_avg): FIXME: Finish get_user_num() FIXME: Finish get_user_num() FIXME: Finish compute_avg() Avg: -1 1 ' Your solution goes here '' 2 4 user_num1 = 0 5 user_num2 = 0 6 avg_result = 0 7 8 user_num1 = get_user_num 9 user_num2 = get_user_num ) 10 avg_result = compute_avg(user_num1, user_num2) 11 12 print'Avg:', avg_result)|
Answer:
Here are the stub functions get_user_num() and compute_avg()
def get_user_num():
print('FIXME: Finish get_user_num()')
return -1
def compute_avg(user_num1, user_num2):
print('FIXME: Finish compute_avg()')
return -1
Explanation:
A stub is a small function or a piece of code which is sometimes used in program to test a function before its fully implemented. It can also be used for a longer program that is to be loaded later. It is also used for a long function or program that is remotely located. It is used to test or simulate the functionality of the program.
The first stub for the function get_user_num() displays FIXME: Finish get_user_num() and then it returns -1.
The seconds stub for the function compute_avg() displays the FIXME: Finish compute_avg() and then it returns -1.
Here with each print statement, there is function name after this FIXME: Finish line. The first function name is get_user_num and the second is compute_avg().
Next the function get_user_num() is called twice and function compute_avg() followed by a print statement: print('Avg:', avg_result) which prints the result. So the program as a whole is given below:
def get_user_num():
print('FIXME: Finish get_user_num()')
return -1
def compute_avg(user_num1, user_num2):
print('FIXME: Finish compute_avg()')
return -1
user_num1 = 0 # the variables are initialized to 0
user_num2 = 0
avg_result = 0
user_num1 = get_user_num() #calls get_user_num method
user_num2 = get_user_num()
avg_result = compute_avg(user_num1, user_num2)
print('Avg:', avg_result)
The method get_user_num() is called twice so the line FIXME: Finish get_user_num() is printed twice on the output screen. The method compute_avg() is called once in this statement avg_result = compute_avg(user_num1, user_num2) so the line FIXME: Finish compute_avg() is printed once on the output screen. Next the statement print('Avg:', avg_result) displays Avg: -1. You can see in the above program that avg_result = compute_avg(user_num1, user_num2) and compute_avg function returns -1 so Avg= -1. The program along with the produced outcome is attached.
#Write a function called 'string_type' which accepts one #string argument and determines what type of string it is. # # - If the string is empty, return "empty". # - If the string is a single character, return "character". # - If the string represents a single word, return "word". # The string is a single word if it has no spaces. # - If the string is a whole sentence, return "sentence". # The string is a sentence if it contains spaces, but # at most one period. # - If the string is a paragraph, return "paragraph". The # string is a paragraph if it contains both spaces and # multiple periods (we won't worry about other # punctuation marks). # - If the string is multiple paragraphs, return "page". # The string is a paragraph if it contains any newline # characters ("\n"). # #Hint: think carefully about what order you should check #these conditions in. # #Hint 2: remember, there exists a count() method that #counts the number of times a string appears in another #string. For example, "blah blah blah".count("blah") #would return 3.
Answer:
I am writing a Python program:
def string_type(string):
if string=="": //if the string is empty
return "empty"
elif string.count(".")>1: #if the period sign occurs more than once in string
if string.count("\n"): #checks if the new line occurs in the string
return "page" #if both the above cases are true then its a page
return "paragraph" # if the period sign condition is true then its a para
elif string.count(" ")>=1: #if no of spaces in string occur more than once
return "sentence" #returns sentence
elif len(string)==1: # if length of the string is 1 this
return "character" #returns character
else: #if none of the above conditions is true then its a word
return "word" #returns word
Explanation:
def string_type(string): this is the definition of method string_type which takes a string as argument and determines whether the type of string is a word, paragraph, page, sentence or empty.
if string=="" this if condition checks if the string is empty. If this condition is true then the method returns "empty"
elif string.count(".")>1 This condition checks if the string type is a paragragh
string.count(".")>1 and if string.count("\n") both statements check if the string type is a page.
Here the count() method is used which is used to return the number of times a specified string or character appears in the given string.
Suppose the string is "Paragraphs need to have multiple sentences. It's true.\n However, two is enough. Yes, two sentences can make a paragraph."
The if condition first checks if count(".")>1 which means it counts the occurrence of period i.e. "." in the string. If the period occurs more than once this means it could be a page. But it could also be a paragraph so in order to determine the correct string type another if statement if string.count("\n") inside elif statement determines if the string is a page or not. This statement checks the number of times a new line appears in the string. So this distinguishes the string type paragraph from string type page.
elif string.count(" ")>=1: statement determines if the string is a sentence. For example if the string is "i love to eat apples." count() method counts the number of times " " space appears in the string. If the space appears more than once this means this cannot be a single word or a character and it has more than one words. So this means its a sentence.
elif len(string)==1: this else if condition checks the length of the string. If the length of the string is 1 this means the string only has a single character. Suppose string is "!" Then the len (string) = 1 as it only contains exclamation mark character. So the method returns "character" . If none of the above if and elif conditions evaluates to true then this means the string type is a word.
Answer:
def string_type(string):
if string=="": //if the string is empty
return "empty"
elif string.count(".")>1: #if the period sign occurs more than once in string
if string.count("\n"): #checks if the new line occurs in the string
return "page" #if both the above cases are true then its a page
return "paragraph" # if the period sign condition is true then its a para
elif string.count(" ")>=1: #if no of spaces in string occur more than once
return "sentence" #returns sentence
Explanation:
Implement the function is_maxheap which takes a list of integers and returns True if the list represents a valid max-heap, and False otherwise. Assume that the list represents the contents of a complete binary tree, following the parent/child indexing conventions established in class. E.g., is_maxheap should return True for the following inputs: a) [] b) [10] c) [10, 7, 8] E.g., is_maxheap should return False for the following inputs: a) [1, 2] b) [5, 6, 3] You should not define or use any external data structures in your implementation besides the list passed in.
Answer:
I am writing a Python function:
def is_maxheap(list):
#finds the length of the list
size=len(list)
#loop has a variable i which starts traversing from root til end of last #internal node
for i in range(int((size - 2) / 2) + 1):
if list[2 * i + 1] > list[i]: #If left child is greater than its parent then return #false
return False
if (2 * i + 2 < size and
list[2 * i + 2] > list[i]): #checks if right child is greater, if yes then #returns false
return False
return True
Explanation:
The function is_maxheap() traverses through all the internal nodes of the list iteratively. While traversing it checks if the node is greater than its children or not. To check the working of this function you can write a main() function to check the working on a given list. The main() function has a list of integers. It then calls is_maxheap() method by passing that list to the function. The program displays a message: "valid max heap" if the list represents valid max-heap otherwise it returns invalid max heap.
def main():
list = [10,7,8]
size = len(list)
if is_maxheap(list):
print("Valid Max Heap")
else:
print("Invalid Max Heap")
main()
The program along with its output is attached in a screenshot.
When a higher-priority thread enters the ready state, the operating system generally preempts the currently running thread (an operation known as preemptive scheduling). Depending on the operating system, a steady influx of higher-priority threads could postponeâ possibly indefinitelyâ the execution of lower-priority threads. such indefinite postponement is sometimes referred to more colorfully as________.
Answer:
starvation
Explanation:
An indefinite postponement is sometimes make reference to as more colorfully as starvation when a stable influx of preferential or higher-priority threads could postponeâ possibly indefinitelyâ the execution of lower-priority threads though depending on operation system
Operating systems employ a technique called aging to curb against or avoid starvation, when a thread waits in the ready state, the operating system moderately grow the thread’s priority to ensure that the thread will eventually run.
Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand.
Answer:
I am writing a function using C++ programming language. Let me know if you want the program in some other programming language.
void PrintFeetInchShort(int numFeet , int numInches){
cout<<numFeet<<"\' "<<numInches<<"\"";
The above function takes two integer variables numFeet and numInches as its parameters. The cout statement is used to print the value of numFeet with a single quote at the end of that value and print the value of numInches with double quotes at the end of that value. Here \ backslash is used to use the double quotes. Backslash is used in order to include special characters in a string. Here i have used backslash with the single quote as well. However it is not mandatory to use backslash with single quote, you can simply use cout<<numFeet<<"' " to print a single quote. But to add double quotes with a string, backslash is compulsory.
Explanation:
This is the complete program to check the working of the above function.
#include <iostream> // to use input output functions
using namespace std; //to identify objects like cout and cin
void PrintFeetInchShort(int numFeet , int numInches){
//function to print ' and ' short hand
cout<<numFeet<<"\' "<<numInches<<"\""; }
int main() { //start of the main() function body
PrintFeetInchShort(5, 8); }
//calls PrintFeetInchShort() and passes values to the function i.e. 5 for //numFeet and 8 for numInches
If you want to take the values of numFeet and numInches from user then:
int main() {
int feet,inches; // declares two variables of integer type
cout<<"Enter the value for feet:"; //prompts user to enter feet
cin>>feet; //reads the value of feet from user
cout<<"Enter the value for inch:"; //prompts user to enter inches
cin>>inches; //reads the value of inches from user
PrintFeetInchShort(feet, inches); } //calls PrintFeetInchShort()
The screenshot of the program and its output is attached.
a reviewer is required to enter a reason in the comments field only when a candidate is recommended to be hired. which action can a developer take to enforce this requirement?
Answer:
Create a validation rule
Explanation:
Solution
The action a developer would take to enforce this requirement is by creating a validation rule.
Validation rule: A validation rules demonstrate that the data a user enters in a record meets the standards you identify before the user can save the record.
A validation rule can have a formula or expression that assesses the data in more than one fields and returns a value of either “True” or “False”.
It allow for values which are or are not allowed on a specific field.
A network technician is designing a network for a small company. The network technician needs to implement an email server and web server that will be accessed by both internal employees and external customers. Which of the following would best secure the internal network and allow access to the needed servers?
A. Implementing a site-to-site VPN for server access.B. Implementing a DMZ segment for the server.C. Implementing NAT addressing for the servers.D. Implementing a sandbox to contain the servers.
Answer:
Option A (Implementing a site-to-site VPN for server access) seems to be the correct choice.
Explanation:
A site-to-site configuration is something that a single Open VPN network links several more separate networks linked. Technologies through one network will access machines in all the other computer systems in that connection model, including conversely. Implementing this would be extremely straightforward, for as much further even though Access Server was indeed implicated.The much more challenging aspect happens when interacting regarding firewalls including privacy filtering methods, as well as modifying the forwarding table in internet gateways, as several of them from different manufacturers but instead prototypes which they may not be able to log many of these.This rather gateway device uses an Open VPN with a Linux VPN client, to create a connection between various channels. If someone's server hardware is also measured accurately then perhaps a site-to-site configuration could be accomplished which works straightforwardly throughout all systems in both cable systems.Other choices are not related to the given instance. So that Option A would be the right one.
(Displaying a Sentence with Its Words Reversed) Write an application that inputs a line of text, tokenizes the line with String method split and outputs the tokens in reverse order. Use space characters as delimiters.
Answer:
I am writing a JAVA and Python program. Let me know if you want the program in some other programming language.
import java.util.Scanner; // class for taking input from user
public class Reverse{ //class to reverse a sentence
public static void main(String[] args) { //start of main() function body
Scanner input = new Scanner(System.in); //create a Scanner class object
System.out.print("Enter a sentence: "); //prompts user to enter a sentence
String sentence = input.nextLine(); // scans and reads input sentence
String[] tokens = sentence.split(" "); // split the sentence into tokens using split() method and a space as delimiter
for (int i = tokens.length - 1; i >= 0; i--) { //loop that iterates through the tokens of the sentence in reverse order
System.out.println(tokens[i]); } } } // print the sentence tokens in reverse order
Explanation:
In JAVA program the user is asked to input a sentence. The sentence is then broken into tokens using split() method. split method returns an array of strings after splitting or breaking the sentence based on the delimiter. Here the delimiter used is space characters. So split() method splits the sentence into tokens based on the space as delimiter to separate the words in the sentence. Next the for loop is used to iterate through the tokens as following:
Suppose the input sentence is "How are you"
After split() method it becomes:
How
are
you
Next the loop has a variable i which initialized to the tokens.length-1. This loop will continue to execute till the value of i remains greater than or equals to 0.
for (int i = tokens.length - 1; i >= 0; i--)
The length of first token i.e you is 3 so the loop executes and prints the word you.
Then at next iteration the value of i is decremented by 1 and now it points at the token are and prints the word are
Next iteration the value of i is again decremented by i and it prints the word How.
This can be achieved in Python as:
def reverse(sentence):
rev_tokens = ' '.join(reversed(sentence.split(' ')))
return rev_tokens
line = input("enter a sentence: ")
print((reverse(line)))
The method reverse takes a sentence as parameter. Then rev_tokens = ' '.join(reversed(sentence.split(' '))) statement first splits the sentence into array of words/tokens using space as a delimiter. Next reversed() method returns the reversed sentence. Next the join() method join the reversed words of the sentence using a space separator ' '.join(). If you want to represent the reversed tokens each in a separate line then change the above statement as follows:
rev_tokens = '\n'.join(reversed(sentence.split(' ')))
Here the join method joins the reversed words separating them with a new line.
Simply input a line of text and call this reverse() method by passing the input line to it.
______is a technology that allows users to access databases that contain case law or statutory law governing a particular issue.
Explanation:
In my opinion this is computer assisted legal search
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to become a single conditional, and show the equivalent single conditional.
Answer:
One of the strategies to avoid nested conditional is to use logical expressions such as the use of AND & operator.
One strategy is to use an interface class with a method. That method can be created to be used for a common functionality or purpose. This is also called strategy design pattern. You can move the chunk of conditional statement to that method. Then each class can implement that interface class and use that shared method according to their own required task by creating objects of sub classes and call that common method for any such object. This is called polymorphism.
Explanation:
Nested conditionals refers to the use of if or else if statement inside another if or else if statement or you can simply say a condition inside another condition. For example:
if( condition1) {
//executes when condition1 evaluates to true
if(condition2) {
//executes when condition1 and condition2 evaluate to true
} else if(condition3) {
//when condition1 is true and condition3 is true
} else {
//condition1 is true but neither condition2 nor conditions3 are true
} }
The deeply nested conditionals make the program difficult to understand or read if the nested conditionals are not indented properly. Also the debugging gets difficult when the program has a lot of nested conditionals.
So in order to avoid nested conditionals some strategies are used such as using a switch statement.
Here i will give an example of the strategies i have mentioned in the answer.
Using Logical Expressions:
A strategy to avoid nested conditionals is to use logical expressions with logical operators such as AND operator. The above described example of nested conditionals can be written as:
if(condition1 && condition2){ //this executes only when both condition1 and condition2 are true
} else if(condition1 && condition3) {
this executes only when both condition1 and condition3 are true
} else if(condition1 ){
//condition1 is true but neither condtion2 nor condtion3 are true }
This can further be modified to one conditional as:
if(!condition3){
// when condition1 and condition2 are true
}
else
// condition3 is true
Now lets take a simple example of deciding to go to school or not based on some conditions.
if (temperature< 40)
{
if (busArrived=="yes")
{
if (!sick)
{
if (homework=="done")
{
printf("Go to school.");
}
}
}
}
This uses nested conditionals. This can be changed to a single conditional using AND logical operator.
if ((temperature <40) && (busArrived=="yes") &&
(!sick) && (homework=="done"))
{ cout<<"Eligible for promotion."; }
The second strategy is to use an interface. For example you can
abstract class Shape{
//declare a method common to all sub classes
abstract public int area();
// same method that varies by formula of area for different shapes
}
class Triangle extends Shape{
public int area() {
// version of area code for Triangle
return (width * height / 2);
}
}
class Rectangle extends Shape{
public int area() {
// version of area code for Rectangle
return (width * height)
}
}
// Now simply create Rectangle or Triangle objects and call area() for any such object and the relevant version will be executed.
An organization's IRP prioritizes containment over eradication. An incident has been discovered where an attacker outside of the organization has installed crypto-currency mining software on the organization's web servers. Given the organization's stated priorities, which of the following would be the NEXT step?
a. Remove the affected servers from the network.
b. Review firewall and IDS logs to identify possible source IPs.
c. Identify and apply any missing operating system and software patches
d. Delete the malicious software and determine if the servers must be reimaged
Answer:
a. Remove the affected servers from the network.
Explanation:
An organization's incident response process (IRP) can be defined as all of the process involved in the cleanup and recovery of data when they fall victim to an attack or cybersecurity breach. The incident response process comprises of six (6) important stages and these are;
1. Preparation.
2. Detection and analysis (identification).
3. Containment.
4. Eradication.
5. Recovery.
6. Review of incident activities.
When an organization's IRP prioritizes containment over eradication and an incident is discovered, where an attacker outside the organization installed a crypto-currency mining software on the organization's web servers. Given the organization's stated priorities, the cybersecurity engineer should remove the affected servers from the network.
A containment process is focused on taking steps to eliminate or contain the attack. It basically involves acting swiftly in response to the attack, so as to prevent it from spreading across board or in order to mitigate the damage already caused.
In this context, the cybersecurity engineer should remove the affected servers from the network in accordance with the organization's IRP priority (containment).
Furthermore, he could take a step further to contain the attack by installing a firewall and updating their policies in the Intrusion Prevention System (IPS) of the organization.
TO COMPUTING IN BUSINE
ANSWER ALL QUESTIONS IN BOTH SE
TIME ALLOWED: 2 hours 30 minutes
Which of the following is not a Business Software?
a Word processing
SECTION A (50 Marks)
b. Spreadsheet
c. Presentation
d. Personal Finance
uolatile memory and sto
Answer:
the correct answer is a. Word processing.
Explanation:
hope this works out!!!!!
Letm1, m2,···mnbe distinct numbers on the number line, in the increasing order. Your goalis to color all of them blue. You have magical blue pens with the following property: Whenyou place the pen at co-ordinate x, all the points in the range [x - 5, x + 5] turn blue. Apen can be used only once. Give an algorithm to color all the points using as few pens aspossible. Prove the correctness of the algorithm and derive the runtime.
Answer:
Following are the algorithm to this question:
y = 0 // initialize variable y that assigns the value 0
p = 1 // initialize value 1 in the variable p which also known as starting position
init num = 1//define variable num that assign value 1
for j = 1 to n: //defining loop
y = m[j] - m[p]
if (y > 10) //defining if block
num++; //increment num variable
p=i; //holding loop value in p variable
y= 0//assign value 0 in y variable
Explanation:
Following are the runtime analysis of the above-given algorithm:
The above-provided algorithm is greedy, but if it doesn't exceed the scope, it operates by greedily choosing its next object. Therefore the algorithm selects the fewest number of pens.
Running time:
This algorithm merely iterates once over all the points. The run-time is therefore O(n).
The following code uses a nested if statement.
if (employed == 'Y')
cout << "Employed!" << endl;
else if (employed == 'N')
cout << "Not Employed!" << endl;
else
cout << "Error!" << endl;
a. True
b. False
Answer:
true
Explanation:
else if used so I think it's true
Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10)
#include
/* Your solution goes here
*/ int main(void) {
const int SORT_ARR_SIZE = 4;
int sortArray[SORT_ARR_SIZE];
int i;
int userNum;
for (i = 0; i < SORT_ARR_SIZE; ++i) {
scanf("%d", &sortArray[i]);
}
SwapArrayEnds(sortArray, SORT_ARR_SIZE);
for (i = 0; i < SORT_ARR_SIZE; ++i) {
printf("%d ", sortArray[i]);
}
Answer:
Here is the SwapArrayEnds()
//function with two parameters; the array and array size
void SwapArrayEnds(int sortArray[],int SORT_ARR_SIZE){
int temp; //temporary variable to hold the first element of sortArray
if(SORT_ARR_SIZE > 1){ //if sortArray size is greater than 1
temp = sortArray[0]; // set value of temp to the first element of sortArrray
sortArray[0] = sortArray[SORT_ARR_SIZE-1]; // set the value of first element of sortArray to the last element of sortArray
sortArray[SORT_ARR_SIZE-1] = temp; } } // set last element value to temp
Explanation:
Lets understand the working of the above function with the help of an example. Suppose the sortArray has the following elements: {10,20,30,40}. So the size of this array is 4.
if(SORT_ARR_SIZE > 1) has an if statement which checks if the array size is greater than 1. This condition evaluates to true as 4 > 1. So the body of if condition executes.
Next the statement temp = sortArray[0]; sets the value of temp variable to the value of first element of sortArray. As sortArray[0] means the element at 0-th index position of the sortArray. So using the above example the first element of the array is 10. So temp = 10.
Next the statement sortArray[0] = sortArray[SORT_ARR_SIZE-1]; sets the last element of the sortArray to the position of first element of the sortArray.
SORT_ARR_SIZE-1 is the position of last element of the array. As the size of sortArray is 4, so 4-1 = 3 which points to the last element. Now this element is moved to the first position of the array. This means that the value of first element of array becomes 40 as the element at 3-th index of the sortArray is 40.
Next the statement sortArray[SORT_ARR_SIZE-1] = temp moves the value in temp variable to the last position of the sortArray. As we know that the value of temp= 10. So this element 10 of the sortArray is positioned at SORT_ARR_SIZE-1 position of sortArray which is 4-1 = 3-th index of sortArray. This simply means that 10 is moved to the last position of sortArray.
So now the final sortArray becomes: 40,20,30,10 as the first and last element of the array are swapped using above function SwapArrayEnds().
The program along with the output is attached in screenshot.
Functions are collection of codes or instructions merged together to act as one.
The function, where comments are used to explain each line is as follows:
//This defines the function
void SwapArrayEnds(int sortArray[],int SORT_ARR_SIZE){
//This increments the array element at index 0
sortArray[0] += sortArray[SORT_ARR_SIZE-1];
//This replaces the last element with the first
sortArray[SORT_ARR_SIZE-1]= sortArray[0]- sortArray[SORT_ARR_SIZE-1];
//This replaces the first element with the last
sortArray[0]= sortArray[0]- sortArray[SORT_ARR_SIZE-1];
}
At the end of the function, the first and the last elements of the array are swapped.
Read more about similar programs at:
https://brainly.com/question/15582117
Write a program that asks the user to input a positive integer and then calculates and displays the factorial of the number. The program should call a function named getN
Answer:
The program is written in python and it doesn't make use of any comment;
(See explanation section for line by line explanation)
def getN(num):
fact = 1
for i in range(1, 1 + num):
fact = fact * i
print("Factorial: ",fact)
num = int(input("Number: "))
if num < 0:
print("Invalid")
else:
getN(num)
Explanation:
The function getNum is defined here
def getN(num):
Initialize the result of the factorial to 1
fact = 1
Get an iteration from 1 to the user input number
for i in range(1, 1 + num):
Multiply each number that makes the iteration
fact = fact * i
Print result
print("Factorial: ",fact)
Ths line prompts user to input number
num = int(input("Number: "))
This line checks if user input is less than 0; If yes, the program prints "Invalid"
if num < 0:
print("Invalid")
If otherwise, the program calls the getN function
else:
getN(num)