Skip to content

skim9142/Math480hw2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Math480hw2

Homework 2

""" def myfactorial(x): n = 1 if x%1 == 0: while (x > 0): n = n * x x = x - 1 return n print n else: print "Input must be an integer" """

I created a simple factorial algorithm called myfactorial that takes in any integer. It first creates an n varible equal to 1. Then it goes into an if statement to test whether the input varible is an integer. If x is an integer, the code goes through a while loop only while the input x is greater than 0. If x is greater than 0, the code multiplies n by x to get a new n value and decreases the value of x by 1. The while loop continues until x is equal to 0. After the while loop finishes, the code returns the value n and prints it as well. If x is not an integer, the code simple prints "Input must be an integer".

myfactorial(3) = 6 myfactorial(3.1) = Input must be an integer

About

Homework2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages