This time we have to do factorials. This means n! = (n)(n-1)(n-2)…(1). Multiply n times the previous number until it reaches 1.
For this I used a for i in range (1, x + 1) . When x is the value that the user inputs. The, y = y*i so it keeps repeating itself until it becomes 1. Secondly I used conditionals to predict the parameters when x is 0 or when x is a negative, so the program gives the obvious.
Finally, I took a peek at my classmates’s blog to learn what to do in order to let the user try again or exit the program. Thanks to Pxthon Progrxmmer I learned that you can use a while True to make the whole conditionals and the factorial formula work and when it ends let the user try again by typing ‘a’ or exit by typing a different letter.
Today’s song is ‘Short Change Hero’ by The Heavy. A song that is used at the intro of Borderlands 2 when introducing the main characters. It is an epic way to show the players what they will meet in the world of Pandora because Pandora “ain’t no place for no hero”.
WSQ09 Factorials! by rhcpalmarichie is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.