## Wednesday, September 23, 2020

Solution Exercise 108: python algorithm to create a dictionary which contains some integers and their factorials

#### Exercise 108

Write a python program that asks the user to enter an integer n and return a dictionary whose keys are integers 1, 2, 3, ... n and whose values ​​are 1! , 2! , 3! , ... , n!

#### Solution

``````# create a function which calculates the factorial of an integer n
def fact(n):
facto = 1
for i in range(1, n + 1):
facto = facto*i
return facto

# create an empty dictionary which will contains the values of the typed integers
d = dict({})
n = int(input("Enter value of integer n"))
for i in range(1, n):
d[i] = fact(i)

# display obtained  dictionary d
print("The obtained dictionary is d = " , d)
# The output is :
#The obtained dictionary is d =  {1: 1, 2: 2, 3: 6, 4: 24, 5: 120, 6: 720, 7: 5040, 8: 40320, 9: 362880, 10: 3628800}``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 