Python Forum
trying an online challenge
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying an online challenge
#6
I finally figured out how the website works and the code that passed the challenge is:
def FirstFactorial(num): 
   n = num - 1
   while n>0:
       num = num+n
       n = n-1
   return num

print (FirstFactorial(raw_input()))
Why am I posting the answer? Because this challenge is about 10% your ability to write some code, and 90% figuring out test parameters that are not provided. This is important to note because it's a good life metaphor. You can be really good at something, but you have to be able to adapt your skills to the situation for it to matter. And NO ONE is going to tell you what you need to know to adapt your skill set to the situation, and sometimes they will lie to you. You need to be able to pick up the clues or you will fail. So, by looking at what the challenge says it wants and what the correct setup is, we can figure what the actual parameters of the challenge are:
First, WTF is raw_input()? I'm sure someone who knows more about python than I do currently can explain it in general(I haven't checked the docs yet); specifically, it is the test values the page will be injecting into your code. If raw_input() is replaced by anything, the code will fail because the site is no longer able to inject what is wants, even though when you run the code you get the expected output.
Secondly, the range they mention isn't a range. The site runs the code once for each raw_input() it injects. In this case, it runs the code 10 times, once for each value between 1 and 11. If it gets the expected output, you pass the challenge for that run. Each successful run is worth .5 points. This means if you use a range, it will fail every time because you are running the code for the range of all values instead of once for each value.

Actual test parameters: Get an output that is a factorial of a value injected into the code to replace raw_input()

Once I configured my code around the actual test parameters instead of the reported parameters, it passed the challenge. Now that I know it's only testing if raw_input() is included where the site wants it to be, and it gets the expected output each time it runs, I've been able to pass a couple of other challenges without problem.

Other things I learned:  1) Don't use "while" when you already running "for" in a range. It's redundant and can cause problems. 2) Same thing with redefining a variable that was defined by the range. It will break your range. 3) Don't make things harder than you have to.
num = raw_input()
n=num-1
while n>0:
   num=num*n
   n=n-1

print(num)
works better, because you are using fewer lines of code, and removing a few possibilities for mistakes. The second one passed the challenge too, BTW.
Reply


Messages In This Thread
trying an online challenge - by tozqo - Jun-12-2017, 11:38 AM
RE: trying an online challenge - by Ofnuts - Jun-12-2017, 12:22 PM
RE: trying an online challenge - by tozqo - Jun-13-2017, 07:32 AM
RE: trying an online challenge - by sparkz_alot - Jun-13-2017, 02:01 PM
RE: trying an online challenge - by tozqo - Jun-14-2017, 07:04 AM
RE: trying an online challenge - by tozqo - Jun-18-2017, 03:34 AM
RE: trying an online challenge - by Ofnuts - Jun-18-2017, 10:19 AM
RE: trying an online challenge - by tozqo - Jun-20-2017, 10:01 AM
RE: trying an online challenge - by Kebap - Jun-21-2017, 07:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Team Chooser Challenge kanchiongspider 3 2,503 Jun-02-2020, 04:02 AM
Last Post: kanchiongspider
  Meal cost challenge Emekadavid 3 3,013 Jun-01-2020, 02:01 PM
Last Post: Emekadavid
  Appending To Files Challenge erfanakbari1 3 3,092 Mar-27-2019, 07:55 AM
Last Post: perfringo
  Problem with a basic if challenge erfanakbari1 2 2,089 Oct-12-2018, 08:04 AM
Last Post: erfanakbari1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020