This is a programming exercise. You must write a Python script that solves Project Euler Problem #20. If you do not want to sign up for Project Euler, you may ask the instructor for the correct answer. ## RequirementsProject Euler Problem #20 reads as follows:
Create a Python script named ## BackgroundThe factorial of a number
You can calculate the factorial of a number in Python using the `import math` `print math.factorial(10)`
The sum of the digits in the number
Double check your program using the answer provided above, then solve for the case where ## HintsThere are two hints that will help significantly with this problem. I recommend you break this into two subproblems: (a) how to get the last digit in a number, and (b) how to strip the last digit off a number. First, notice what happens when you take a number modulo 10: `print 123 % 10 # Prints 3` `print 12 % 10 # Prints 2` Now, notice what happens when you use integer division (using the double slash `print 123 // 10 # Prints 12` `print 12 // 10 # Prints 1` `print 1 // 10 # Prints 0` Combine both of these properly in a loop and you'll get your answer! ## SubmissionWhen complete, show your script to the instructor for credit. If you do not finish by the end of the class, you may email the script to the instructor. Please include the following subject line for your email:
Make sure you include your full name in the email body. |

Assignments > Lab Assignments > Day 1 – Python Programming, Part 1 > Unit B – Conditionals and Iteration >