Write a recursive function sumSquares(num) that given an integer num, returns the sum of squares of numbers from 1 to num. For example: sumSquares(3) should return 1^2 2^2 3^2

Answers

Answer 1

Answer:

Here is the recursive function sumSquares(num) that takes an integer num as parameter and returns the sum of squares of numbers from 1 to num.

def sumSquares(num):

   if(num >= 0):  # checks if the value of num is less than or equal to 0

       if (num==0):  #if value of num is 0

           return 0  #returns 0 if value of num is 0

       else:  #if value of num is greater than 0

           return sumSquares(num - 1)+ num * num  #recursively calls the sumSquares method to return the sum of squares of numbers from 1 to num

   else:  # if a user enters a negative num

       (print("The number if not positive"))  #prints this message

       exit()  # exits after displaying that number if not positive message

#below print statement is used in order to check the working of the function        

print(sumSquares(3)) #calls function and passes value 3 for num

Explanation:

The program works as follows:

The function sumSquares(num) that takes an integer num as parameter and returns the sum of squares of numbers from 1 to num

The first if condition checks if value of num is positive. If this condition evaluates to true then the another if statement inside this if statement is executed which checks if the value of num is 0. If this condition evaluates to true then the program returns 0. However if this condition evaluates to false then the else part executes which has the following statement:

return sumSquares(num - 1) + num * num

For example num = 3

so the above recursive statement works as follows:

sumSquares(3-1) + 3 * 3

sumSquares(2) + 9

Note that the sumSquares() method is called again and the value 2 is passed as num. As 2 is greater than 0. So again the recursive statement executes:

sumSquares(2 - 1) + 2 * 2 + 9

sumSquares(1) + 4 + 9

sumSquares(1) + 13

sumSquare() method is called again and the value 1 is passed as num. As 1 is greater than 0. So again the recursive statement executes:

sumSquares(1 - 1) + 1 * 1 + 13

sumSquares(0) + 1 + 13

sumSquares(0) + 14

sumSquare() method is called again and the value 0 is passed as num

As the value of num=0 So the if (num == 0):  condition evaluates to true and the statement returns 0 executes which returns 0:

sumSquares(0) + 14

0 + 14

Hence the output is:

14

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

Write A Recursive Function SumSquares(num) That Given An Integer Num, Returns The Sum Of Squares Of Numbers

Related Questions

Giving Brainliest IFFF CORRECT

Jonathan needs to create a chart that shows the change in weight he can lift in weightlifting class. Which chart or graph should he use?

Bar graph

Column chart

Line graph

Pie chart

Answers

Answer:

line graph

Explanation:

the change in weight is linear

Answer:

Line Graph

Explanation:

Linear Weight change

In what way does a hash provide a better message integrity check than a checksum (such as the Internet checksum)?

Answers

Answer:

Hash function have less collision than a internet checksum because of computational infeasibility.

Explanation:

A collision means there is more then one way to produce the same sum. It is nearly difficult to developed two messages with same hash however, in checksum, it is more easier to develop or modify two messages to have same sum, thereby enabling attackers to have access to the message or the information arising to less message integrity.

________type of website is an interactive website kept constantly updated and relevant to the needs of its customers using a database.

Answers

Answer:

Data-driven Website

Explanation:

A Data-driven website is a type of website that is continually updated by its administrators so as to meet users' needs. It is opposed to a static website whose information remains the same and is never changed once uploaded.

The data-driven website is used in a platform where information has to be continually updated. An example is an online platform where people place orders for goods and services. There are usually changing prices and new goods continually uploaded. So, to keep the consumers updated, the administrators of such platforms would use a data-driven platform.

You suspect that a hacker has compromised a computer using one of its open ports. Which command would allow you to view the open ports on the computer

Answers

Answer:

[tex]netstat[/tex]

Explanation:

The netstat command displays network connections for TCP and can help to view the open ports on the computer.

Hope this helped!

In Antivirus Software, Heuristic detection looks for things like anomalies, Signature based detection uses content matches.a. Trueb. False

Answers

Answer:

true

Explanation:

Given a number N, write a code to print all psoitive numbers less than N in which all adjacent digits differ by 1

Answers

Answer:

def lesser_adjacent_num ( N ):

     N = int( N )

     while N == True:

            next = N - 1

            print if  next >= 0 ? next : break

Explanation:

The python function above called "lesser_adjacent_num" accepts an argument called "N" which is an integer. The function print the number "next" which is a number less than the N integer for every loop for the condition where N is not zero.

Giving BRANLIEST IFFF CORRECT

Which type of chart or graph shows the contribution of each item in a total of 100%?

Bar graph

Column chart

Line graph

Pie chart

Answers

Answer:

pie chart

Explanation:

pie chart shows percentage per item

Answer:

pie chart

Explanation:

Scams where people receive fraudulent emails that ask them to supply account information are called ________.

Answers

Answer:

"Phishing" will be the correct approach.

Explanation:

This aspect of cyber attacks or fraud is called phishing, whereby clients or users are questioned for personally identifiable information about them.Attackers could very well-currently the most frequently use phishing emails to exchange malicious programs that could operate effectively in what seems like several different ways. Others would get victims to steal user credentials including payment details.

Reasons why operating system is pivotal in teaching and learning

Answers

Answer:

Explanation: The operating system simply acts as the communication interface between the user and the components if a computer including it's hardware. The reasons why an operating system is pivotal in leaching and learning includes :

In most cases, teaching and learning requires the use of application programs or softwares which could be the program to be learnt or that which is used to aid learning. Irrespective of the type of application program, it's installation and usage depends and is made possible with the help of an operating system. Programs used for video sessions during teaching, writing programs and document editors all require an operating system in other to aid installation and ultimately function.

Suppose there are 4 nodes sharing a broadcast channel using TDMA protocol. Suppose at time t=0: • Node 1 has 6 frames to transmit, • Node 2 has 4 frames to transmit, • Node 3 has 8 frames to transmit, • Node 4 has 3 frames to transmit. Maximum number of frames which can be transmitted by a node in a time slot = 3 The time required to transmit one frame = 1 Second Explain how TDMA protocol works to complete this task? How much time will it take to transmit all frames?

Answers

Answer:

Following are the description of the given nodes:

Explanation:

The Multiple Access frequency - division facilitates control by granting every node a fixed time slot. Also, every slot seems to be identical in width. Its whole channel bandwidth is often used in every channel node. Compared to FDMA it takes more time.  

Time slot=3 frames for all the above scenario

In the first point, It is reserved the node 1, and as well as 3 frames were also transmitted 1.  In the second point, It is reserved the node 2, and as well as 3 frames are transmitted. In the third point, It is reserved 3 nodes, and as well as 3 frames were transmitted.  In the fourth point, It is reserved 4 slots and the transmit 3 frames.  In the fifth point, It stores the slot 1 and the transmit 3 frames.  In the sixth point, It stores the slot 2 and the transmit 1 frame.  In the seventh point, It stores the slot 3  and the transmit 3 frames.  In the Eight points, It stores the slot 3 and the transmit 2 frames.  

Time interval = number of frames in first slot Time to send 1 frame number of images  

                      [tex]= 8 \times 3 \times 1 \\\\ = 8 \times 3 \\\\= 24 \ seconds[/tex]

Your task is to write and test a function which takes one argument (a year) and returns True if the year is a leap year, or False otherwise. The seed of the function is already sown in the skeleton code in the editor. Note: we've also prepared a short testing code, which you can use to test your function. The code uses two lists - one with the test data, and the other containing the expected results. The code will tell you if any of your results are invalid.

Answers

Answer:

function isLeapYear( aYear ){

   var confirmYear=  year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);

   return confirmYear ? True : False;

}

Explanation:

The javascript function above requires an argument which is the year when it is passed, it is analyzed, counting the number of days in that year and a boolean value of true or false is dynamically assigned to the variable 'confirmYear'.

The ternary operator would logically select the right value, which is outputted to the user. To test the function, use the console to call the function with an argument.

console.log( isLeapYear( 1999 ) );

Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python methods that works like the following: a. count b. in: return True if the item is in the list c. reverse d. index: return -1 if the item is not in the list e. insert

Answers

Answer:

Here are the methods:

a) count

def count(object, list):  

   counter = 0

   for i in list:

       if i == object:

           counter = counter + 1

   return counter

b) in : return True if the item is in the list

def include(object, list):  

   for i in list:

       if i == object:

           return True

   return False

c)  reverse

def reverse(list):

   first = 0            

   last = len(list)-1    

   while first<last:

       list[first] , list[last] = list[last] , list[first]

       first = first + 1

       last = last - 1

   return list

d) index: return -1 if the item is not in the list  

def index(object, list):

   for x in range(len(list)):

       if list[x] == object:

           return x

   return -1

e)  insert

def insert(object, index, list):

   return list[:index] + [object] + list[index:]

Explanation:

a)

The method count takes object and a list as parameters and returns the number of times that object appears in the list.

counter variable is used to count the number of times object appears in list.

Suppose

list = [1,1,2,1,3,4,4,5,6]

object = 1

The for loop i.e. for i in list iterates through each item in the list

if condition if i == object inside for loop checks if the item of list at i-th position is equal to the object.  So for the above example, this condition checks if 1 is present in the list. If this condition evaluates to true then the value of counter is incremented to 1 otherwise the loop keeps iterating through the list searching for the occurrence of object (1) in the list.

After the complete list is moved through, the return counter statement returns the number of times object (i.e. 1 in the example) occurred in the list ( i.e. [1,1,2,1,3,4,4,5,6]  ) As 1 appears thrice in the list so the output is 3.

b)  

The method include takes two parameters i.e. object and list as parameters and returns True if the object is present in the list otherwise returns False. Here i have not named the function as in because in is a reserved keyword in Python so i used include as method name.

For example if list = [1,2,3,4] and object = 3

for loop for i in list iterates through each item of the list and the if condition if i == object checks if the item at i-th position of the list is equal to the specified object. This means for the above example the loop iterates through each number in the list and checks if the number at i-th position in the list is equal to 3 (object). When this if condition evaluates to true, the method returns True as output otherwise returns False in output ( if 3 is not found in the list). As object 3 is present in the list so the output is True.

c) reverse method takes a list as parameter and returns the list in reverse order.

Suppose list = [1,2,3,4,5,6]

The function has two variables i.e. first that is the first item of the list and last which is the last item of the list. Value of first is initialized to 0 and value of last is initialized to len(list)-1 where len(list) = 6 and 6-1=5 so last=5 for the above example. These are basically used as index variables to point to the first and last items of list.

The while loop executes until the value of first exceeds that of last.

Inside the while loop the statement list[first] , list[last] = list[last] , list[first]  interchanges the values of elements of the list which are positioned at first and last. After each interchange the first is incremented to 1 and last is decremented to 1.

For example at first iteration:

first = 0

last = 5

list[0] , list[5] = list[5] , list[0]

This means in the list [1,2,3,4,5,6] The first element 1 is interchanged with last element 6. Then the value of first is incremented and first = 1, last = 4 to point at the elements 2 and 5 of the list and then exchanges them too.

This process goes on until while condition evaluates to false. When the loop breaks  statement return list returns the reversed list.

d) The method index takes object and list as parameters and returns the index of the object/item if it is found in the list otherwise returns -1

For example list = [1,2,4,5,6] and object = 3

for loop i.e.  for x in range(len(list)):  moves through each item of the list until the end of the list is reached. if statement  if list[x] == object:  checks if the x-th index of the list is equal to the object. If it is true returns the index position of the list where the object is found otherwise returns -1. For the above examples 3 is not in the list so the output is -1  

e) insert

The insert function takes as argument the object to be inserted, the index where the object is to be inserted and the list in which the object is to be inserted.

For example list = [0, 1, 2, 4, 5, 6] and object = 3 and index = 3

3 is to be inserted in list  [1,2,4,5] at index position 3 of the list. The statement:

return list[:index] + [object] + list[index:]

list[:index] is a sub list that contains items from start to the index position. For above example:

list[:index] = [0, 1, 2]

list[index:] is a sub list that contains items from index position to end of the list.

list[index:] = [4, 5, 6]

[object] = [3]

So above statement becomes:

[0, 1, 2] + [3] + [4, 5, 6]

So the output is:

[0, 1, 2, 3, 4, 5, 6]    

Will the Python code below print something? And will it terminate?
def print_n(s, n):
if n > 0:
print(s)
print_n(s, n-1)
return n
n = 3
while print_n("hi", n):
print_n("there!", n)
n = 0
a. no and no
b. yes and no
c. no and yes
d. yes and yes
e. syntax error

Answers

Answer:

Yes and Yes

Explanation:

When programs are written without indentation; it becomes a problem to read;

I'll rewrite your program as follows:

def print_n(s, n):  

   if n > 0:  

       print(s)  

       print_n(s, n-1)  

   return n  

n = 3  

while print_n("hi", n):  

   print_n("there!", n)  

   n = 0

Using the above as a point of reference,

Yes, the program will run and Yes, it'll terminate;

Because n is initialized to 3 at line 6 (where the main starts);

The following is passed to the function; s = "hi" and n=3

This prints "hi", three times

s = "there" and n=3 is then passed to the function print_n, afterwards;

The function then prints "there" three times

Then, the program terminates

The intention of this problem is to analyze a user input word, and display the letter that it starts with (book → B).

a. Create a function prototype for a function that accepts a word less than 25 characters long, and return a character.
b. Write the function definition for this function that evaluates the input word and returns the letter that the word starts with in capital letter (if it’s in small letters).
c. Create a function call in the main function, and use the function output to print the following message based on the input from the user. (Remember to have a command prompt in the main function requesting the user to enter any word.)

Computer starts with the letter C.
Summer starts with the letter S.

d. Make sure to consider the case where a naughty user enters characters other than the alphabet to form a word and display a relevant message.

%sb$ is not a word.
$500 is not a word.

e. Have the program process words until it encounters a word beginning with the character

Answers

Answer:

Here is the C++ program:

#include<iostream>  // to use input output functions

using namespace std;     //to identify objects like cin cout

void StartChar(string str)  {  // function that takes a word string as parameter and returns the first letter of that word in capital

   int i;  

   char c;

   do  //start of do while loop

   {

   for (int i = 0; i < str.length(); i++) {  //iterates through each character of the word str

       if(str.length()>25){  //checks if the length of input word is greater than 25

           cout<<"limit exceeded"; }  //displays this message if a word is more than 25 characters long

      c = str.at(i);   // returns the character at position i

       if (! ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ) ) {  //checks if the input word is contains characters other than the alphabet

            cout<<str<<" is not a word!"<<endl; break;}  //displays this message if user enters characters other than the alphabet

        if (i == 0) {  //check the first character of the input word

           str[i]=toupper(str[i]);  //converts the first character of the input word to uppercase

           cout<<str<<" starts with letter "<<str[i]<<endl;  }  // prints the letter that the word starts with in capital letter

   }   cout<<"Enter a word: ";  //prompts user to enter a word

      cin>>str;   //reads input word from user

}while(str!="#");   }    //keeps prompting user to enter a word until the user enters #

int main()   //start of the main() function body

{ string str;  //declares a variable to hold a word

cout<<"Enter a word: "; //prompts user to enter a word

cin>>str; //reads input word from user

   StartChar(str); }  //calls function passing the word to it

     

Explanation:

The program prompts the user to enter a word and then calls StartChar(str) method by passing the word to the function.

The function StartChar() takes that word string as argument.

do while loop starts. The for loop inside do while loop iterates through each character of the word string.

First if condition checks if the length of the input word is greater than 25 using length() method which returns the length of the str. For example user inputs "aaaaaaaaaaaaaaaaaaaaaaaaaaa". Then the message limit exceeded is printed on the screen if this if condition evaluates to true.

second if condition checks if the user enters anything except the alphabet character to form a  word. For example user $500. If this condition evaluates to true then the message $500 is not a word! is printed on the screen.

Third if condition checks if the first character of input word, convert that character to capital using toupper() method and prints the first letter of the str word in capital. For example if input word is "Computer" then this prints the message: Computer starts with the letter C in the output screen.

The program keeps prompting the user to enter the word until the user enters a hash # to end the program.

The output of the program is attached.

PROGRAM 8: Grade Converter! For this program, I would like you to create a function which returns a character value based on a floating point value as

Answers

Answer:

This function will return a character grade for every floating-point grade for every student in the class.

function grade( floatPoint ){

      let text;

      switch ( floatPoint ) {

        case floatPoint < 40.0 :

             text= " F ";

             break;

        case floatPoint == 40.0 :

             text= " P ";

             break;

        case floatPoint > 40.0 && floatPoint <= 50.0 :

             text=  " C ";

             break;

        case floatPoint > 50.0 && floatPoint < 70.0 :

             text=  " B ";

             break;

        case floatPoint >=70.0 && floatPoint <= 100.0 :

             text= " C ";

             break;

        default :

            text= "Floating point must be between 0.0 to 100.0"

      }

     return text;

}

Explanation:

This javascript function would return a character grade for floating-point numbers within the range of 0.0 to 100.0.

Bharath has made a table of content for his document in Open Office, in which he wants to make few changes, but he is unable to make the changes. Give reason. Explain how he can make the necessary changes

Answers

Answer:

H cannot update it because it is probably protected.

If you cannot click in the table of contents, it is probably because it is protected. To disable this protection, choose Tools > Options > OpenOffice.org Writer > Formatting Aids, and then select Enable in the Cursor in protected areas section. If you wish to edit the table of contents without enabling the cursor, you can access it from the Navigator.

Explanation:

. To update a table of contents when changes are made to the document:

Right-click anywhere in the TOC.

From the pop-up menu, choose Update Index/Table. Writer updates the table of contents to reflect the changes in the document.

You can also update the index from the Navigator by right-clicking on Indexes > Table of Contents1 and choosing Index > Update from the pop-up menu.

The penalties for ignoring the requirements for protecting classified information when using social networking services are _________________ when using other media and methods of dissemination.

Answers

The penalties for ignoring the requirements for protecting classified information when using social networking services are the same when using other media and methods of dissemination.

The penalties are the same because it does not matter what the medium used, the effect is that classified information and confidential details have been left unguarded and exposed.

When in hold of such information, it is not okay to leave it unguarded or exposed. A person who is found guilty of disclosure of classified materials would face sanctions such as:

They would be given criminal sanctionsThey would face administrative sanctionsThey would also face civil litigations

Read more on https://brainly.com/question/17207229?referrer=searchResults

You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should save the data back to the same data file when the program exits.

Answers

Answer:

C++ PROGRAM

Explanation:

b. Does “refactoring” mean that you modify the entire design iteratively? If not, what does it mean?

Answers

Explanation:

Refactoring consists of improving the internal structure of an existing program's source code, while preserving its external behavior. 

list 2 forms of computer output​

Answers

Audio, visual, and hard copy media

Answer:

Soft copy like audio

Hard copy e.g printouts

Explanation:

CHALLENGE ACTIVITY 3.7.2: Type casting: Reading and adding values.
Assign totalowls with the sum of num_owls A and num_owls_B.
Sample output with inputs: 34
Number of owls: 7
1. total_owls -
2.
3. num_owls A - input
4. num_owls_B - input
5.
6. " Your solution goes here
7.
8. print("Number of owls:', total_owls)

Answers

Answer:

total_owls = 0

num_owls_A = int(input())

num_owls_B = int(input())

total_owls = num_owls_A + num_owls_B

print("Number of owls:", total_owls)

Explanation:

Initialize the  total_owls as 0

Ask the user to enter num_owls_A and num_owls_B, convert the input to int

Sum the num_owls_A and num_owls_B and set it to the total_owls

Print the total_owls

avg_owls=0.0

num_owls_zooA = int(input())

num_owls_zooB = int(input())

num_owls_zooC = int(input())

num_zoos = 3

avg_owls = (num_owls_zooA + num_owls_zooB + num_owls_zooC) / num_zoos

print('Average owls per zoo:', int(avg_owls))

There is a problem while you are trying the calculate the average owls per zoo.

As you may know, in order to calculate the average, you need to get the total number of owls in all the zoos, then divide it to the number of zoos. That is why you need to sum num_owls_zooA + num_owls_zooB + num_owls_zooC and divide the result by num_zoos

Be aware that the average is printed as integer value. That is why you need to cast the avg_owls to an int as int(avg_owls)

Learn more about integer value on:

https://brainly.com/question/31945383

#SPJ6

What caused the substantial schedule delay of software development for the Jaguar project? (b) How did the software problem impact the project? (c) If you were the project manager, what would you have done differently to prevent the software problem from happening?

Answers

Answer:

ES LA  B

Explanation:

Define Proportional spacing fornt.​

Answers

Answer:

Alphabetic character spacing based on the width of each letter in a font. ... Proportional spacing is commonly used for almost all text. In this encyclopedia, the default text is a proportional typeface, and tables are "monospaced," in which all characters have the same fixed width.

hope this answer helps u

pls mark me as brainlitest .-.

Design a class named Rectangle to represent a rectangle. The class contains:

Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height.
A no-arg constructor that creates a default rectangle.
A constructor that creates a rectangle with the specified width and height.
A method named getArea() that returns the area of this rectangle.
A method named getPerimeter() that returns the perimeter.

Draw the UML diagram for the class then implement the class. Write a test program that create two Rectangle objects - one with width 4 and height 40, and the other with width 3.5 and height 35.9.
Display the width, heigth, area, and perimeter of each rectangle in this order.

Answers

Answer:

function Rectangle(width=1, height= 1 ) {

    this.width= width;

    this.height= height;

    this.getArea= ( ) = > {return width * height};

    this.getPerimeter= ( ) = >{ return 2( height + width)};

}

var rectangleOne= new Rectangle(4, 40)

var rectangleTwo= new Rectangle(3.5, 35.9)

console.log(rectangleOne.width, rectangleOne.height, rectangleOne.getArea( ), rectangleOne.getPerimeter( ) )

console.log(rectangleTwo.width, rectangleTwo.height, rectangleTwo.getArea( ), rectangleTwo.getPerimeter( ) )

Explanation:

This is a Javascript class definition with a constructor specifying arguments with default values of one for both width and height, and the getArea and getPerimeter methods.

Write a method named coinFlip that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of whitespace-separated tokens. Assume that the input file data represents results of sets of coin flips. A coin flip is either the letter H or T, or the word Heads or Tails, in either upper or lower case, separated by at least one space. You should read the sequence of coin flips and output to the console the number of heads and the percentage of heads in that line, rounded to the nearest whole number. If this percentage is 50% or greater, you should print a "You win!" message; otherwise, print "You lose!". For example, consider the following input file: H T H H T Tails taIlS tAILs TailS heads HEAds hEadS For the input above, your method should produce the following output: 6 heads (50%) You win!

Answers

Answer:

Here is the JAVA program:

import java.io.*;

import java.util.*;

public class Main {

public static void main(String[] args) throws FileNotFoundException{ //the start of main() function body, it throws an exception that indicates a failed  attempt to open the file

Scanner input = new Scanner(new File("file.txt")); //creates a Scanner object and a File object to open and scan through the file.txt    

coinFlip(input);    } //calls coinFlip method

public static void coinFlip(Scanner input) { //coinFlip method that accepts as its parameter a string input holding a file name

while(input.hasNextLine()) { //iterates through the input file checking if there is another line in the input file

Scanner scan = new Scanner(input.nextLine()); //creates a Scanner object

int head = 0; // stores count of number of heads

int count = 0; //stores count of  total number of tokens

while(scan.hasNext()) { //iterates through the sequence checking if there is another sequence in the input file

String token= scan.next(); // checks and returns the next token

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads")) { //compares H or Heads with the tokens in file ignoring lower case and upper case differences

           head++;                } //if a token i.e. any form of heads in file matches with the H or Heads then add 1 to the number of heads

           count++;            } //increment to 1 to compute total number of counts

double result = Percentage(head, count); //calls Percentage method passing number of heads and total counts to compute the percentage of heads

System.out.println(head + " heads " + "(" + result +"%)"); // prints the number of heads

if(result >= 50.00) { //if the percentage is greater or equal to 50

System.out.println("You win!");} //displays this message if above if condition is true

else //if the percentage is less than 50

{System.out.println("You lose!");}  }    } //displays this message if above if condition is false

public static double Percentage(int h, int total) { //method to compute the percentage of heads

double p = (double)h/total* 100; // divide number of heads with the total count and multiply the result by 100 to compute percentage

return p;    } } //returns result

Explanation:

The program is well explained in the comments mentioned with each line of the above code. I will explain how the method coinFlip  works.

Method coinFlip accepts a string holding a file name as its parameter. It opens that file and reads its contents as a sequence of tokens. Then it reads and scans through each token and the if condition statement:

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads"))

checks if the each token in the sequence stored in the file is equal to the H or Heads regardless of the case of the token. For example if the first token in the sequence is H then this if condition evaluates to true. Then the head++ statement increments the count of head by 1. After scanning each token in the sequence the variable count is also increased to 1.

If the token of the sequence is HeAds then this if condition evaluates to true because the lower or upper case difference is ignored due to equalsIgnoreCase method. Each time a head is found in the sequence the variable head is incremented to 1.

However if the token in the sequence is Tails then this if condition evaluates to false. Then the value of head variable is not incremented to 1. Next the count variable is incremented to 1 because this variable value is always incremented to 1 each time a token is scanned because count returns the total number of tokens and head returns total number of heads in the tokens.

Percentage method is used to return the percentage of the number of heads in the sequence. It takes head and count as parameters (h and total). Computes the percentage by this formula h/total* 100. If the result of this is greater than or equal to 50 then the message  You win is displayed otherwise message You lose! is displayed in output.

#Write a function called fancy_find. fancy_find should have #two parameters: search_within and search_for. # #fancy_find should check if search_for is found within the #string search_within. If it is, it should print the message #"[search_for] found at index [index]!", with [search_for] #and [index] replaced by the value of search_for and the #index at which it is found. If search_for is not found #within search_within, it should print, "[search_for] was #not found within [search_within]!", again with the values #of search_for and search_within. # #For example: # # fancy_find("ABCDEF", "DEF") -> "DEF found at index 3!" # fancy_find("ABCDEF", "GHI") -> "GHI was not found within ABCDEF!"

Answers

Answer:

Here is the Python program:

def fancy_find(search_within , search_for):  # function definition of fancy_find function that takes two parameters

   index = 0  #to store the index of search_within where the search_for string is found

   if search_for in search_within:  #checks if the string search_for is present in string search_within

       sf = search_for[0]  #points to the first character of the search_for

       for sw in search_within:  #iterates through search_within

           if sw == sf:  #if the first character of search_for is equal to the character at sw index of search_within

               if search_within[index:index+len(search_for)] == search_for:  #checks if the value of search_for is found in search_within

                   print(search_for,"found at index",index,"!")  #if above condition is true prints the message "[search_for] found at index [index]!", with [search_for] and [index] replaced by the value of search_for and the index at which it is found

                   return ""  

           index += 1  #increments value of index at each iteration

   print(search_for,"is not found within", search_within)  #if search_for is not found within search_within, prints message "[search_for] was not found within [search_within]!" with the values of search_for and search_within.

   return ""    

#following two statements are used to test the working of above function

print(fancy_find("ABCDEF", "DEF"))  #calls fancy_find() passing "ABCDEF" as search_within and "DEF" as search_for

print(fancy_find("ABCDEF", "GHI")) #calls fancy_find() passing "ABCDEF" as search_within and "GHI" as search_for

Explanation:

The program is well explained in the comments. I will explain the working of the function with the help of an example:

Suppose

search_within = "ABCDEF"

search_for = "DEF"

We have to find if search_for i.e. DEF is present in search_within i.e. ABCDEF

if search_for in search_within statement checks using in operator that if DEF is included in ABCDEF. Here this condition evaluates to true so the next statement sf = search_for[0]  executes which sets the first element of search_for i.e. D to sf. So sf = 'D'

for sw in search_within this statement has a for loop that iterates through ABCDEF and works as following:

At first iteration:

sw contains the first character of search_within  i.e. A

if sw == sf: condition checks if the first character of the search_for i.e. D is equal to sw i.e. A. Its not true so the program control moves to this statement:

index += 1 This increases the value of index by 1. index was initialized to 0 so now it becomes 1. Hence index=1

At second iteration:

sw contains the second character of search_within  i.e. B

if sw == sf: condition checks if the first character of the search_for i.e. D is equal to sw i.e. B Its not true so the program control moves to this statement:

index += 1 This increases the value of index by 1. index was initialized to 0 so now it becomes  2. Hence index=2

At third iteration:

sw contains the third character of search_within  i.e. C

if sw == sf: condition checks if the first character of the search_for i.e. D is equal to sw i.e. C Its not true so the program control moves to this statement:

index += 1 This increases the value of index by 1. index was initialized to 0 so now it becomes  3. Hence index=3

At fourth iteration:

sw contains the third character of search_within  i.e. D

if sw == sf: condition checks if the first character of the search_for i.e. D is equal to sw i.e. D. Its true so so the program control moves to this statement:

  if search_within[index:index+len(search_for)] == search_for:

current value of index=3

len(search_for) returns the length of DEF i.e. 3

So the if condition checks for the search_for in search_within. The statement becomes:

if search_within[3:3+3] == search_for:

search_within[3:3+3]  means from 3rd index position of search_within to 6-th index position of the search_within. This means from 4th element of search_within i.e. D to the last. Hence search_within[3:3+3] is equal to DEF.

search_for = DEF so

if search_within[3:3+3] == search_for: checks if

search_within[3:3+3] = DEF is equals to search_for = DEF

Yes it is true so

print(search_for,"found at index",index,"!") statement is executef which prints the following message:

DEF found at index 3!

This output is because search_for = "DEF" and index=3

EAPOL operates at the network layers and makes use of an IEEE 802 LAN, such as Ethernet or Wi-Fi, at the link level.
A. True
B. False

Answers

B. False ....................

Write the program to compute how many gallons of paint are needed to cover the given square feet of walls. Assume 1 gallon can cover 350.0 square feet. So gallons =the square feet divided by 350.0. If the input is 250.0, the output should be: 0.714285714286

Answers

Answer:

Here is the Python and C++ program.

Python program:

gallons_paint=0.0  #declare and initialize gallons_paint  

wall_area = float(input())  #prompts user to enter wall area

gallons_paint = wall_area / 350  #formula to compute gallons of paint needed to cover the given square feet of walls

print(gallons_paint) #display the result

C++ program:

#include <iostream> //to use input output functions

using namespace std; //to identify objects like cin cout

int main(){ //start of main() function body

   float wall_area,gallons_paint=0; //declare variables

   cin>>wall_area; //reads input wall area from user

   gallons_paint=wall_area/350; //formula to compute gallons of paint needed to cover the given square feet of walls

   cout<<gallons_paint;} //print the result

Explanation:

The program prompts the user to enter the area of wall and stores the input value in wall_area

Suppose the user enters 250 as wall area

The the formula gallons_paint=wall_area/350; works as follows:

gallons_paint = wall_area/350;

                         = 250/350

                         = 0.71428

gallons_paint  = 0.71428

So the output is:

0.71428

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

Suppose that the tuition for a university is $10,000 this year and increases 4% every year. In one year, the tuition will be $10,400. Write a program using for loop that computes the tuition in ten years and the total cost of four years’ worth of tuition after the tenth year.

Answers

Answer:

The programming language is not stated; however, I'll answer using Python programming language (See attachment for proper format)

tuition = 10000

rate = 0.04

for i in range(1,15):

tuition = tuition + tuition * rate

if i <= 10:

print("Year "+str(i)+" tuition:",end=" ")

print(round(tuition,2))

if i == 14:

print("Tuition 4th year after:",end=" ")

print(round(tuition,2))

Explanation:

The first 2 lines initializes tuition and rate to 10000 and 0.04 respectively

tuition = 10000

rate = 0.04

The next line iterates from year 1 to year 14

for i in range(1,15):

This line calculates the tuition for each year

tuition = tuition + tuition * rate

The next 3 lines prints the tuition for year 1 to year 10

if i <= 10:

print("Year "+str(i)+" tuition:",end=" ")

print(round(tuition,2))

The next 3 lines prints the tuition at the 4th year after year 10 (i.e. year 14)

if i == 14:

print("Tuition 4th year after:",end=" ")

print(round(tuition,2))

11. Which of the following is word processing
software?

Answers

WordPerfectWordpadMS Word

Hope this is correct

HAVE A GOOD DAY!

Other Questions
the/to/company/dubai/goods/exports the anti federalists believed in a loose construction of the constitution Which statement accurately describes the European American population in the United States? A. European immigration declined as a result of the exclusion laws. B. European immigrants adjusted easily to American life because they all spoke the same language. C. European Americans enjoy the same kinds of food, clothing, and music. D. European Americans make up the largest segment of the population today You and your mom enter a drawing with 3 different prizes a total of 9 people enter cual es el area de un rectangulo multiplying polinomiyal(5x+2)(3x+4) find the positive square root of 26.77 a pizza shop offers 30% of the price of a large pizza every tuesday night. if the regular price is 25, what is the discount price? What point is Robin failing to understand as he gets angry at the men? A. By pointing the gun at them, he was the first to act with hostility. B. The men are the people that the military has said they are there to protect and free from Saddam Hussein. C. By getting angry at the men, he is proving that he does care. D. All of the choices are correct. A triangular pyramid has a base shaped like an equilateral triangle. The legs of the equilateral triangle are all 4 centimeters long, and the height of the equilateral triangle is 3.5 centimeters. The pyramid's slant height is 8 centimeters. What is its surface area? Which area of study involves microeconomWhich area of study involves microeconomics? A. a nation's ability to meet consumer demand B. rates of unemployment and inflation C. consumer behavior and preferences D. national income and its sourcesics? This force governs atomic decay. Lee y escoge la frase que corresponde a la imagen. Read and choose the sentence that matches the image. Waitress talking to male customer who listens to her l escucha a la mesera. T lees en el restaurante. l lee en el restaurante. T escucho a la mesera. Sorry cant put picture don't know how Given an array of integers check if it is possible to partition the array into some number of subsequences of length k each, such that:Each element in the array occurs in exactly one subsequence For each subsequence, all numbers are distinct Elements in the array having the same value must be in different subsequences If it is possible to partition the array into subsequences while satisfying the above conditions, return "Yes", else return "No". A subsequence is formed by removing 0 or more elements from the array without changing the order of the elements that remain. For example, the subsequences of [1, 2, 3] are D. [1], [2], [3]. [1, 2], [2, 3], [1, 3], [1, 2, 3]Example k = 2. numbers [1, 2, 3, 4] The array can be partitioned with elements (1, 2) as the first subsequence, and elements [3, 4] as the next subsequence. Therefore return "Yes" Example 2 k 3 numbers [1, 2, 2, 3] There is no way to partition the array into subsequences such that all subsequences are of length 3 and each element in the array occurs in exactly one subsequence. Therefore return "No".Function Description Complete the function partitionArray in the editor below. The function has to return one string denoting the answer. partitionArray has the following parameters: int k an integer int numbers[n]: an array of integers Constraints 1 sns 105 1 s ks n 1 s numbers[] 105 class Result *Complete the 'partitionArray' function below. The function is expected to return a STRING The function accepts following parameters: 1. INTEGER k 2. INTEGER ARRAY numbers public static String partitionArray (int k, Listpublic class Solution In the figure below MNOP is a parallelogram. Which of the following statements can be used toexplain why the shaded triangles are congruent? When a boy pulls his sled with a rope, the rope makes an angle of 70 with the horizontal. If a pull of 20 pounds on the rope is needed to move the sled, what is the horizontal component force?7 lb19 lb20 lb24 lb Question 16Which of the following may not be used when securing a wireless connection? (select multiple answers where appropriate)WEPVPN tunnellingOpen Access PointWPA2WPA2Nahan nah Verify the identity. cos quanity x plus pi divided by two = -sin x Is a non judicial settlement of a case in which the defendant exchanges a guilty plea for judicial concessions and reduced sentences When astronauts are on spacewalks outside of the International Space Station, they must use a communication system with radio waves to be able to talk to each other. Explain why focusing on the difference between sound and light waves