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
JulijaS [17]
3 years ago
13

Assume the availability of a function called fact. The function receives an argument containing an integer value and returns an

integer value. The function should return the factorial of the argument. That is, if the argument is one or zero, the function should return 1. Otherwise, it should return the product of all the integers from 1 to the argument. So the value of fact(4) is 1*2*3*4 and the value of fact(10) is 1*2*3*4*5*6*7*8*9*10. Additionally, assume that the variable k has been initialized with a positive integer value. Write a statement that assigns the value of fact(k) to a variable x. The solution must include multiplying the return value of fact by k.
Computers and Technology
1 answer:
anyanavicka [17]3 years ago
8 0

Answer:

Following are the code to the given question:

def fact(k):#defining a method fact that holds a parameter

   o=1#defining a variable o that holds a value that is 1

   if(k==0):#defining if block that checks k equal to 0

       o=1#using o variable that holds a value 1

   else:#defining else block

       for i in range(k):#defining for loop to calculates Factorial

           o=o*(i+1)#calculating Factorial value

       return(o)#return Factorial value

k=10#defining a variable k that holds a value 10

print("Factorial value:", fact(k))#use print method tom print Factorial value

Output:

Factorial value: 3628800

Explanation:

  • In this code, a method, "fact" is declared that accepts one parameter "k", in the method if block is used, in the if the block it checks k-value that is equal to 0 if the condition is true it will return a value that is "1".
  • Otherwise, it will go to the else block. This section, uses the for loop to calculates its factorial value and adds its value into the "o", and returns its value.
  • Outside the method, k is declared that holds its value and passes into the fact method parameter, and uses the print method to print its return value.  
You might be interested in
6.12 Nested Increments Write a program for spiritual lumberjacks who want to show their appreciation for each tree they 'kill' b
Nina [5.8K]

Answer:

trees_to_cut = int(input("How many trees do you wants to cut? "))

print(str(trees_to_cut) + " tree(s) will be cut.")

for i in range(trees_to_cut):

   print("Tree #" + str(i))

   

   rings = int(input("How many rings in tree " + str(i) + "? "))

   print("There are " + str(rings) + " ring(s) in this tree.")

   for j in range(rings):

       print("Celebrating tree #" + str(i) + "'s " + str(j+1) + ". birthday.")

Explanation:

*The code is in Python.

Ask the user to enter the number of trees to cut

Print this number

Create a for loop that iterates for each tree

Inside the loop:

Print the tree number. Ask the user to enter the number of rings. Print the number of rings. Create another for loop that iterates for each ring. Inside the inner loop, print the celebrating message for each birthday of the tree

7 0
4 years ago
What is the build in libary function to compare two strings?​
worty [1.4K]

Answer:

strcmp() is a built-in library function and is declared in <string. h> header file. This function takes two strings as arguments and compare these two strings lexicographically.

Explanation:

Hope it helps

3 0
4 years ago
BRAINLIEST You have a small company and want to keep your costs low, but it is important your employees share data. Which networ
solmaris [256]

Answer:Peer-to-peer

Explanation: I hope this helps

5 0
3 years ago
Read 2 more answers
You can change the ____ or position of text within a document's margins.
ahrayia [7]

Answer:

Alignment

Explanation:

That should be correct

7 0
3 years ago
In Python write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs
Lilit [14]

Answer:

ansList =input().split() #get input and split it by space

ansList = [int(i) for i in ansList if int(i)>0] #turn string to integer,and get all positive integers

print(ansList)

Explanation: I think this would work for you. I leace comments in the answer.

3 0
2 years ago
Other questions:
  • Write a complete main method that does the following: 1. Takes any number, but at least two, command line arguments which are nu
    8·1 answer
  • The ___________ process transforms new memories from a fragile state, in which they can be disrupted, to a more permanent state,
    10·1 answer
  • Text messaging is an example of nonverbal communication. Please select the best answer from the choices provided. T F
    7·2 answers
  • Why is outfitting a workplace with video games in a technology development company consiered a strategic use of money
    14·1 answer
  • A virus enters a computer or network _____.
    13·1 answer
  • Which of these is an aggregator?
    5·2 answers
  • Select three advantages of cloud computing.
    12·1 answer
  • Which function in Ecels tells how many numeric entries are there​
    7·2 answers
  • Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should NOT
    10·1 answer
  • Why do we create user accounts to customize our preferences​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!