answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lord [1]
1 year ago
6

Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10 factorials (from 0 to 9) w

ith the corresponding number. Remember that the factorial of a number is defined as the product of an integer and all integers before it. For example, the factorial of five (5!) is equal to 1*2*3*4*5

Computers and Technology
1 answer:
nadezda [96]1 year ago
3 0

Answer:

Following are code of factorial in python language

def factorial(n): # function

   result=1 #variable

   for x in range(2,n+1): #iterating the loop

       result=result*x  #storing result

   return result #return result

for n in range(10): #iterating loop

   print(n,factorial(n)) #print factorial

Output:

Following are the attachment of output

Explanation:

Missing information :

In the question the information is missing the code is missing which we have to correct it following are the code that are mention below.

def factorial(n): # function

   result=1 #variable

   for x in range(       ): #iterating the loop

       result=  #storing result

   return  #return result

for n in range(  ): #iterating loop

   print(n,factorial(n)) #print factorial

Following are the description of code

  • We have create a function factorial  in this we have pass the one parameter i.e "n".
  • In the for loop we have pass 2,n+1 which has been used to iterating the loop calculating factorial and string the result in the result variable
  • In the main function we have pass the range on which we have to calculated the factorial
  • Finally the print function will print the factorial .

Following are the attachment snip of code in the python language

You might be interested in
Write an if statement that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.
aev [14]

Answer:

if(goodsSold>500000){

bonus = 10000;

}

Explanation:

A complete Java program that prompts user to enter value for goodsSold is given below:

<em>import java.util.Scanner;</em>

<em>public class num14 {</em>

<em>    public static void main(String[] args) {</em>

<em>        Scanner in = new Scanner(System.in);</em>

<em>        System.out.println("Enter goods Sold: ");</em>

<em>        int goodsSold = in.nextInt();</em>

<em>        int bonus =0;</em>

<em>        if(goodsSold>500000){</em>

<em>            bonus=10000;</em>

<em>        }</em>

<em>        System.out.println("You bonus for "+goodsSold+" is "+bonus);</em>

<em>    }</em>

<em>}</em>

3 0
2 years ago
Validate that the user age field is at least 21 and at most 35. If valid, set the background of the field to LightGreen and assi
madam [21]

Answer:

Explanation:

The code provided had many errors. I fixed the errors and changed the userAgeCheck function as requested. Checking the age of that the user has passed as an input and changing the variables as needed depending on the age. The background color that was changed was for the form field as the question was not very specific on which field needed to be changed. The piece of the code that was created can be seen in the attached image below.

var validColor = "LightGreen";

var invalidColor = "Orange";

var userAgeInput = document.getElementById("userAge");

var formWidget = document.getElementById("userForm");

var userAgeValid = false;

function userAgeCheck(event) {

   if ((userAgeInput >= 25) && (userAgeInput <= 35)) {

       document.getElementById("userForm").style.backgroundColor = validColor;

       userAgeValid = true;

   } else {

       document.getElementById("userForm").style.backgroundColor = invalidColor;

       userAgeValid = false;

   }

};

function formCheck(event) {};

if (!userAgeValid) {

   userAgeInput.addEventListener("input", userAgeCheck);

   formWidget.addEventListener('submit', formCheck);  

   event.preventDefault();

}

6 0
1 year ago
Kathy is a senior teacher in her school. She is conducting a group discussion between parents and teachers. Her role is to ensur
Fynjy0 [20]
She is the leader of the discussion
3 0
1 year ago
Read 2 more answers
What is the only true way to wipe out every possibility of the virus?
const2013 [10]

Answer: Wipe it completely clean.

Explanation: The only true way to wipe out a possible virus is to wipe a computer completely clean. When you wipe the computer clean, you are starting from scratch and have a better chance of not receiving another virus moving forward.

3 0
2 years ago
Need help with this C++ question
sertanlavr [38]

Answer:

Here is the improvement of the program:

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

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

int main()  {   //start of main function

  string pet;         // "cat" or "dog"  

  char spayed;       // 'y' or 'n'      

  // Get pet type and spaying information  

cout << "Enter the pet type (cat or dog): ";   //prompts user to enter pet type

  cin  >> pet;   //reads input pet type

  if(pet=="cat"|| pet=="dog")     {   //use OR operator to check the type

  cout << "Has the pet been spayed or neutered (y/n)? ";   //prompts user to input if pet been spayed or neutered

  cin  >> spayed;}   //reads input spayed value

  else   // display the message below

  cout<<"only cats and dogs need pet tags";        

  // Determine the pet tag fee  

if (pet == "cat")   //if type of pet is cat

  {  if (spayed == 'y' || spayed == 'Y')  //lowercase or upper case y is accepted  

        cout << "Fee is $4.00 \n";   //if spayed is y or Y

     else   //if spayed is not y or Y

        cout << "Fee is $8.00 \n";   }  

  else if (pet == "dog")   //if type is dog

  {  if (spayed == 'y' || spayed=='Y')   //if spayed is y or Y

        cout << "Fee is $6.00 \n";  

     else   //if spayed is not y or Y

        cout << "Fee is $12.00 \n";    }        

  return 0;   }

 

Explanation:

Step 1:

Here is the copy of original source code:

#include <iostream>

using namespace std;

int main() {

string pet;

char spayed;

cout <<"Enter the pet type (cat or dog): ";

cin >> pet;

cout <<"Has the pet been spayed or neutered (y/n)?" ;

cin >>spayed;

if (pet=="cat") {

if (spayed=='y')

cout<< "Fee is $4.00 \n";

else

cout<< "Fee is $8.00 \n"; }

else if (pet== "dog") {

if (spayed=='y')

cout<<"Fee is $6.00 \n";

else

cout<<"Fee is $12.00 \n";}

else  

cout<<"Only cats and dogs need pet tags";

return 0; }

Step 2:

Compile the program and then run it 7 times

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $8.00                                           No

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $12.00                                         No

 7              hamster n        Only cats and dogs need pet tags       Yes                

Step 3:            

See the Answer section

OR logical operator is used so that either a lowercase 'y' or an uppercase 'Y is accepted:

if (spayed == 'y' || spayed == 'Y')

program only execute the spay/neuter prompt and input when the pet type is cat or dog:

if(pet=="cat"|| pet=="dog")  

 {     cout << "Has the pet been spayed or neutered (y/n)? ";    

cin  >> spayed; }    

else    

cout<<"only cats and dogs need pet tags";      

Step 4:

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $4.00                                           Yes

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $6.00                                           Yes

 7              hamster         Only cats and dogs need pet tags          Yes  

In the last input hamster the program does not ask for spayed information. It only asks to Enter the pet type. When the user enters hamster the program displays the message: Only cats and dogs need pet tags.

4 0
2 years ago
Other questions:
  • What are the two most important network-layer functions in a datagram network? what are the three most important network-layer f
    7·1 answer
  • Monica needs to work on a document where she has to highlight topics in bold and add emphasis to some words in a paragraph using
    9·1 answer
  • You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips
    10·2 answers
  • Which of the following are examples of algorithms? (Select all that apply, if any do.)
    15·2 answers
  • Print "userNum1 is negative." if userNum1 is less than O. End with newline Convert userNum2 to 0 if userNum2 is greater than 8.
    10·1 answer
  • How many times does the following loop execute?int upperCaseLetters = 0;String str = "abcdEfghI";boolean found = false;for (int
    5·1 answer
  • Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
    11·1 answer
  • given the numerical value 1010101.11, which of the following number systems is most likely represented.
    11·1 answer
  • Given the dictionary, d, find the largest key in the dictionary and associate the corresponding value with the variable val_of_m
    9·1 answer
  • How does Accenture help companies harness the power of data to achieve optimal business outcomes?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!