Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

Problem: The New York City marathon uses a lottery system to determine whether an applicant is permitted to participate. An applicant is accepted for the current year's marathon if the applicant is drawn in this year's lottery or if the applicant has unsuccessfully applied in each of the previous three years. The first parameter indicates whether a person won the lottery this year and the second parameter is the number of times this applicant has been turned down in this and the preceding three years. Return True iff this person gains entry to the NYC marathon.

OpenStudy (anonymous):

My code: def nyc_entry (lottery, applied): """(bool, int) -> bool Return True iff person gains entry to NYC marathon # Entry is gained by either winning the lottery with the lotto number # Or/And if the applicant has applied three or more times. nyc_entry(1, 1) True nyc_entry(2, 2) False nyc_entry(1, 4) True """ if (lottery == 1): return True if (applied < 3): return False else: return True Teachers comment: The following test cases failed: | | test_nyc_entry_not_drawn_in_lottery_previously_successful - | | IncorrectReturnValue | | Incorrect result when participant has failed to win the lottery a few | | times

OpenStudy (anonymous):

same issue, what do i need to fix in order for the test not to have failed

OpenStudy (konradzuse):

Your code is hard to understand. What you need to do is set up a case for each. So basically if(user.ticket == lottery ticket && failed lotteries >= 3) { true } Else { false}

OpenStudy (konradzuse):

so the real Q is how do we know who won the lottery or not.

OpenStudy (konradzuse):

What does the lottery represent? I would assume more info should be given, or does your professor want you to make something up?

OpenStudy (anonymous):

he wants us to makes something up and teh code at the top is required to have the two variables ( lottery, applied)

OpenStudy (anonymous):

would your code be able to track with the two variable thing

OpenStudy (anonymous):

consider if I didn't get picked this year, last year or the year before but 3 years ago i did. Your function call would look like this nyc_entry(false, 3) by which id hit the last condition, saying this year I get to go. That's incorrect because in the 3 previous years I was only turned down twice. Next year I get to go either way because if I don't get picked, I'll have missed 3 years in a row. The second argument to your function includes the current year, which needs to be subtracted off to test the previous 3 years.

OpenStudy (anonymous):

alright ye that makes sense and i was thinking along those lines too but my confusion is how would i display that through the coding in a way it worked?

OpenStudy (anonymous):

if(lottery == 1) return true; if((applied-1) == 3) return true; return false; (Syntax may not be correct I've never used Python)

OpenStudy (anonymous):

thank you, i fixed the code to do that

OpenStudy (anonymous):

that should fix the issues right?

OpenStudy (anonymous):

Yep

OpenStudy (anonymous):

much appreciated

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!