Python

Find the sum of the digits in the number 100! (Python)

Sponsored
Sponsored
Sponsored
Sponsored

Python code to demonstrate a method to compute the factorial digists sum, i.e. 100 factorial (100!).

This test exercise I’ve recieved when I was looking for a Trainee Python Developer position.

n = 100
fact = 1
  
for i in range(1, n+1): 
    fact = fact * i

# Convert number to string
text_fact = str(fact)

# Initialize empty list for every letter of factorial string 
summ = []

for letter in text_fact:
    summ.append(int(letter))
print(sum(summ))
648
Share
Published by
Serhii Kupriienko

Recent Posts

Як стати  Software Engineer: моя історія

Для кого ця стаття? Для таких як я сам, хто в часи пандемії та суттєвої…

3 роки ago

Useful Git commands

Git is a free and open source distributed version control system designed to handle everything from small…

4 роки ago

Useful ASCII tables

ASCII Tables ASCII abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication.…

4 роки ago

Conda cheatsheet

Conda Managing Conda and Anaconda, Environments, Python, Configuration, Packages. Removing Packages or Environments Читати далі…

4 роки ago

TOP-10 questions about Python

Читати далі TOP-10 questions about Python

4 роки ago

TOP-10 questions about Django

Читати далі TOP-10 questions about Django

4 роки ago

This website uses cookies.