1answer.
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
ElenaW [278]
2 years ago
11

Write a Python function that takes a positive integer N and returns the factorial of N, i.e., N! The factorial of N, denoted N!,

is the product of the integers from 1 to N. (1 Point)
Computers and Technology
1 answer:
sesenic [268]2 years ago
6 0

Answer:

The python function is as follows:

def fact(N):

   factorial = 1

   for i in range(1,N+1):

       factorial = factorial * i

   return(factorial)

Explanation:

This line defines the function

def fact(N):

This line initializes the product of 1 to N to 1

   factorial = 1

This line iterates through 1 to N

   for i in range(1,N+1):

This line calculates the product of 1 to N i.e. factorial

       factorial = factorial * i

This line returns the factorial

   return(factorial)

You might be interested in
Given an array as follows
slava [35]

Answer:

1) Method calcTotal:

  1. public static long calcTotal(long [][] arr2D){
  2.        long total = 0;
  3.        
  4.        for(int i = 0; i < arr2D.length; i++ )
  5.        {
  6.            for(int j = 0; j < arr2D[i].length; j++)
  7.            {
  8.                total = total + arr2D[i][j];
  9.            }
  10.        }
  11.        
  12.        return total;
  13.    }

Explanation:

Line 1: Define a public method <em>calcTotal</em> and this method accept a two-dimensional array

Line 2: Declare a variable, total, and initialize it with zero.

Line 4: An outer for-loop to iterate through every rows of the two-dimensional array

Line 6: An inner  for-loop to iterate though every columns within a particular row.

Line 8: Within the inner for-loop, use current row and column index, i and j, to repeatedly extract the value of each element in the array and add it to the variable total.

Line 12: Return the final total of all the element values as an output

Answer:

2) Method calcAverage:

  1. public static double calcAverage(long [][] arr2D){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            for(int j = 0; j < arr2D[i].length; j++)
  8.            {
  9.                total = total + arr2D[i][j];
  10.                count++;
  11.            }
  12.            
  13.        }
  14.        
  15.        double average = total / count;
  16.        
  17.        return average;
  18.    }

Explanation:

The code in method <em>calcAverage</em> is quite similar to method <em>calcTotal</em>. We just need to add a counter and use that counter as a divisor of total values to obtain an average.

Line 4: Declare a variable, count, as an counter and initialize it to zero.

Line 11: Whenever an element of the 2D array is added to the total, the count is incremented by one. By doing so, we can get the total number of elements that exist in the array.

Line 16: Use the count as a divisor to the total to get average

Line 18: Return the average of all the values in the array as an output.

Answer:

3) calcRowAverage:

  1. public static double calcRowAverage(long [][] arr2D, int row){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            if(i == row)
  8.            {
  9.                for(int j = 0; j < arr2D[i].length; j++)
  10.                {
  11.                    total = total + arr2D[i][j];
  12.                    count++;
  13.                }
  14.            }
  15.            
  16.        }
  17.        
  18.        double average = total / count;
  19.        
  20.        return average;
  21.    }

Explanation:

By using method <em>calcAverage </em>as a foundation, add one more parameter, row, in the method <em>calcRowAverage</em>. The row number is used as an conditional checking criteria to ensure only that particular row of elements will be summed up and divided by the counter to get an average of that row.

Line 1: Add one more parameter, row,

Line 8-15: Check if current row index, i, is equal to the target row number, proceed to sum up the array element in that particular row and increment the counter.

5 0
3 years ago
Globalization is based on <br>​
Blababa [14]

Answer:

the growing interdependence of the world's economies.

Explanation:

it's of all the cultures and populations that crossed the border by trading

5 0
2 years ago
How many inputs are included in the following requirement? REQUIREMENT: Write a program that asks the employee for their age. Th
wolverine [178]

Answer:

The correct answer for the given question is 1

Explanation:

Following are the program in c language  

#include<stdio.h> // header file

#include<conio.h>  //header file

void main()  // main method

{

int age,retiredAge;  // variable

clrscr();  // clear screen

printf("Enter Age : ");

scanf("%d",&age);  // input age

printf("************************");

retiredAge = (65-age);  // calculating retired age

printf("\nYour Age is %d",age);

if(retiredAge<0)  // checking condition

{

printf("\nYou are already cross the retired age. Or Enter Invalid Age.");

}

else

{

printf("\nNo of Years Left to retired is %d",retiredAge);  // dsiplay age

}

getch();

}

Output:

Enter Age : 50

************************

Your Age is 50

No of Years Left to retired is 15

Here Age is the only required input to calculate the retirement age of employee. if entered age is greater than 65 then a message is printed " You are already cross the retired age. Or Enter Invalid Age. " if entered age is valid then retiredAge is calculated with the formula retiredAge = (65-age). and finally display the age,followed by the number of years left to retirement.

Therefore  1 input are required for the above program.

4 0
3 years ago
Which of the following modes of replication requires a very low latency network connection and ensures data remains in synch wit
Snowcat [4.5K]

Answer:

b. Synchronous replication

Explanation:

Replication of data in storage partitions or in a number redundant array of independent disk drives helps to promote redundancy, as implied, and faulty tolerance to reduce loss of data.

There are two categories of replication and they are synchronous and asynchronous replication.

Synchronous replication requires low latency network site to mirror data, while asynchronous replication mirrors data in large metropolitan area in high latency networks.

4 0
2 years ago
Recently, a serious security breach occurred in your organization. An attacker was able to log in to the internal network and st
natulia [17]

Answer: Geotagging was enabled on her smartphone

Explanation:

The security weakness that is the most likely cause of the security breach is that geotagging was enabled on the vice president's smartphone.

Geotagging, occurs when geographical identification metadata are added to websites, photograph, video, etc. Geotagging can be used to get the location of particular place.

In this case, since geotagging was enabled on her smartphone, it was easy for the attacker to locate her house.

8 0
3 years ago
Other questions:
  • Hard drives are usually self-contained, sealed devices. Why must the case for the hard drive remain sealed closed?
    8·1 answer
  • The computers that run the DBMS and all devices that store database data should reside in locked, controlled-access facilities.
    15·1 answer
  • The sequence of folders to a file or folder is called a(n) ________
    8·1 answer
  • Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program mus
    8·1 answer
  • Write a program that takes the radius of a sphere (a floating-point number) as input and then outputs the sphere’s: Diameter (2
    7·1 answer
  • Boardman College maintains two files—one for Sociology majors and another for Anthropology majors. Each file contains students'
    5·1 answer
  • What is the first priority when building or using vex robots
    10·2 answers
  • Do you think it’s better for a young designer to use free, open-source art programs or to pay for commercial programs? Explain y
    14·1 answer
  • What is string literal in Java?
    5·1 answer
  • The ____ file is typically saved with a prefix of inc_.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!