DS4PS / cpp-527-fall-2020

http://ds4ps.org/cpp-527-fall-2020/
0 stars 1 forks source link

Lab 01 - Step 5 #5

Open MeghanPaquette opened 4 years ago

MeghanPaquette commented 4 years ago

Hi Professor Lecy, For Step 5, I listed my code below. When I run the test code, I am getting an odd note and sometimes it is quite working. The bolded part is the message. Also, I noticed that the opened goat door was my initial selection. I am working on that part as well.

[1] "GAME SETUP" [1] "goat" "goat" "car" [1] "My initial selection: 1" [1] "The opened goat door: 1" [1] "My final selection: 2" "My final selection: 3" [1] "GAME OUTCOME:" the condition has length > 1 and only the first element will be usedthe condition has length > 1 and only the first element will be used[1] "LOSE"

Step 5: DETERMINE IF CONTENSTANT HAS WON

determine_winner <- function(final.pick, game)
{
  if(game[ final.pick ] == "car")
   return("WIN")
  if(game[ final.pick ] == "goat")
   return("LOSE")
}
ecking commented 4 years ago

I'm so glad you asked!

I'm getting the same thing as well.

I've tried all sorts of variations here and I'm kind of stuck

MeghanPaquette commented 4 years ago

I think part of it is the bug in part 3 for me, but also, I am not sure my Step 5 is even right. Glad someone else is getting that same error.

lecy commented 4 years ago

Step 5 looks fine. I would encourage you to always use brackets to separate code that belongs to the IF statement to avoid any ambiguity of what code is being run and what code is being skipped.

> determine_winner <- function( final.pick, game )
+ {
+   if( game[ final.pick ] == "car" )
+   { 
+     return( "WIN" )  
+   }
+ 
+   if( game[ final.pick ] == "goat" )
+   {  
+     return( "LOSE" )
+   }
+ }
> 
> determine_winner( final.pick=1, game=c("car","goat","goat")  )
[1] "WIN"
> determine_winner( final.pick=2, game=c("car","goat","goat")  )
[1] "LOSE"
> determine_winner( final.pick=3, game=c("car","goat","goat")  )
[1] "LOSE"

The issue is in fact in Step 03. It's a subtle error that has to do with an edge case.

If you can identify it, great!

It's fine if your functions are mostly working and Step 03 is the part causing issues. You will get full credit for proper logic and code that executes as expected. I'll go over the bug in the solutions.

It's not at all obvious, but good if you at least identified it in the unit testing!

ecking commented 4 years ago

Ahhh ok. I see it now. I thought I was going crazy.

lecy commented 4 years ago

@ecking it was updated this morning. Please note the new instructions - attempt all of them but only post the solution to one question.