I recently started learning Python. I have watched several YouTube vids, read some documentation, and experimented on my own. I'm currently trying to complete the first challenge for a website(not able to find in TOS if posting links or URL's is approved). The paraphrased challenge is:
Have a function take the num parameter and return the factorial. The range is between 1 and 18, and input is always an integer.
Here's the first sequence I tried:
Have a function take the num parameter and return the factorial. The range is between 1 and 18, and input is always an integer.
Here's the first sequence I tried:
def factorial(): num = int(input("Pick a number between 1 and 18 ")) n = num - 1 while n>0: num = num*n n = n-1 return num print(factorial())When I submitted, it hung for a few minutes, said I was wrong, and the results indicated it was supposed to test all values from 1 to 10. I figured out there was no actual input because I told it to run code, and it's still running 20 minutes later. I assume it's waiting for input to define num. I reread the challenge, saw "range," and thought "Oh, I need a range type." So then I try this:
def FirstFactorial(num): n = num - 1 while n>0: num = num*n n = n-1 return num for x in range (1,20,1): while x != 19: num = x print(FirstFactorial(num)) x = x+1All I get back is an endless list of "1." Obviously, I'm missing something with the way ranges work, so I just simplify the loop and try this:
def FirstFactorial(num): n = num - 1 while n>0: num = num*n n = n-1 return num x = 1 while x != 19: num = x print(FirstFactorial(num)) x = x+1I get the expected output, submit it, and it still says all outputs are wrong. The site allows looking at other submissions, but requires a premium account to do so. I thought I should put this in coding help, but it seemed to fit here better with the restrictions on the challenge. Any advice on what I might be missing? I've read through range type on docs.python.org a few times and I'm not seeing anything for how to actually use the range for managing loops.