1. Write a fuction called 'fac' that takes an input of number N and output N!.Print the result as N! is result. For example, N = 5, N! = 5 * 4 * 3 * 2 * 1 = 120. Print '5! is 120' Make a plot for y =...

1 answer below »
1.

  1. Write a fuction called 'fac' that takes an input of number N and output N!.Print the result as N! is result. For example, N = 5, N! = 5 * 4 * 3 * 2 * 1 = 120. Print '5! is 120'

  2. Make a plot for y = log(x), x is between 1 and 100.

  3. Write a function called "operate" that takes as input two numbers, and a string that can be either "add" or "multiply". The output should be either the sum or product of the two numbers, depending on the string entered.

  4. Write a function called "describe" that takes as input a list of numbers, and prints the number of elements in the list, and the mean, variance, and standard deviation. The printed quantities should be labeled. The output should look something like: number of elements: 12 mean: 0.5 variance: 0.04 standard deviation: 0.2

  5. A simple substitution code codes 'a' as 1, 'b' as 2, ..., 'z' as 26. Write a function called "encode" that takes in a string, and prints the coded text. The output should be a string, with letters separated by ".". Use "999" for punctuation and spaces. For example, encode("Hello!") should print out "8.5.12.12.15.999".

Answered Same DaySep 03, 2021

Answer To: 1. Write a fuction called 'fac' that takes an input of number N and output N!.Print the result as N!...

J Anitha answered on Sep 04 2021
144 Votes
Write a fuction called 'fac' that takes an input of number N and output N!.Print the result as N! is result. For example, N = 5, N! = 5 * 4 * 3 * 2 * 1 = 120. Print '5! is 120'
Program
def fac(N):
fact = 1
if N < 0:
print("Factorial doesn't exist for negative numbers")
elif N == 0:
print("The factorial of 0 is 1")
else:
for i in range(1, N + 1):
fact = fact * i
print(" The factorial of " + str(N) + "is " + str(fact))
N = int(input("Enter a number"))
fac(N)
Output
>python fact.py
Enter a number4
The factorial of 4is 24
>python fact.py
Enter a number-8
Factorial doesn't exist for negative numbers
>python fact.py
Enter a number5
The factorial of 5is 120
Make a plot for y = log(x), x is between 1 and 100.
Program
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 100)
y = np.log(x)
plt.plot(x,y)
plt.show()
Output
Write a function called "operate" that takes as input two numbers, and a string that can be either "add" or "multiply". The output should be either the sum or product of the two numbers, depending on the string entered.
Program
def Operate(a,b,c):
if c=="add":
sum = a + b
print("The sum of two numbers" + str(a) + "and" + str(b) + "is" +...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here