Posted: Sat Nov 22, 2014 7:27 pm Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!
I'll work on, but most important is you know my Rock, Paper, Scissors game! Is it possible if you could delete three of the first comments because what happen is I was publishing my work and then, all my data went missing so I was re-editing it to fix that problem, but then, somebody responded to my missing data message.
Sponsor Sponsor
master-awesome
Posted: Sun Nov 23, 2014 2:21 pm Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!
I think I finally figured it out, but could you double check just to be sure!
Your method actually helped! I was getting really pissed when you brought up a deck of cards because it wasn't making sense. It would have helped though, if you showed this!
Quote:
if num1 < num2 and num2 < num3 and answer = "A" then
cls
put "Numbers Ascending!"
put num1
put num2
put num3
Then, I would have gotten it. I would have said more along the lines that "Oh so it is mathematical! Okay let me try!" Instead I was getting really confused and asked a classmate to show me an example of the code. After that, I just wrote it down here the example on this site to triple check that this is the method I use and after it was verified. I spent a lot of time today, trying to make the code agree with the output of the computer using your method of working 1 number at a time.
WARNING: Next time, show an example or something instead of saying, put a deck of cards. Maybe, it helps some people, but when somebody doesn't get it, use another method like showing an example.
Posted: Sun Nov 23, 2014 7:16 pm Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!
Your solution probably works. At the very least it has all the possible orders. It might have problems if some of the numbers are the same (e.g., the input is "5,5,5")
re: "show me an example of the code" -- in this case an example is effectively a solution. It would certainly be easier to just copy/paste your way to an answer, but then you would have a similarly difficult time with the next new question.
I think a challenge with your code is in understanding some of the more complicated cases. E.g.
code:
if num1 > num2 and num1 < num3 and num2 < num1 and num3 > num1 and num2 < num3 and answer = "A" then
That is a lot of conditions to keep in mind at the same time. This is very easy for computers, but difficult for humans. A good strategy might be nested if statements (if statements inside of other if statements).
Now that you have some working code, it's appropriate to share examples
code:
if num1 <= num2 and num1 <= num3 then
% we know that num1 is the smallest value
put num1
% now we only have num2 and num3 left
if num2 <= num3 then
% num2 is smaller
put num2
put num3
else
% otherwise it must be the case that num3 is smaller
put num3
put num2
end if
% num1 was not the smallest, see if it's num2
elsif num2 <= ...
Here we use IFs inside IFs to build out this decision tree. If you do much gaming, you can think of tech tree or skill tree as reference. We make simple decisions at first (what is the smallest number of the 3? (note that this was the hint question we've asked you to solve before)) and that leaves us with smaller problems (given that we already know what the smallest number is, how do we arrange the other 2?).
Posted: Sun Nov 23, 2014 7:54 pm Post subject: Re: RE:I NEED HELP WITH 4.2 Practice Question 11!
Quote:
[quote="Tony @ Sun Nov 23, 2014 7:16 pm"]Your solution probably works. At the very least it has all the possible orders. It might have problems if some of the numbers are the same (e.g., the input is "5,5,5")
You are completely right about this!
I'm actually struggling with getting the 5,5,5 thing and all other same number and I'm getting confused! The teacher actually wants it with no elsif statement in the program, so I don't have a choice here!
Tony
Posted: Sun Nov 23, 2014 9:32 pm Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!
Consider the example above with the use of <= (less then or equals). Basically if you are sorting two 5s, then it doesn't really matter which which of the 5s is "smaller", so you are free to take whichever is more convenient.
elsif requirement is rather arbitrary, but it's not needed to make the same approach works. E.g.
code:
if num = 1 then
...
elsif num = 2 then
...
end
is exactly the same* as
code:
if num1 = 1 then
...
end if
if num1 = 2 then
...
end if
* as long as the value of num1 doesn't change in between.
The advantage of the if-elsif-else (especially else) is that you'll end up in some decision. Any program can be implemented just the same without the elsif, but you have to make sure that your checks cover every possible scenario.