Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Stuck on this all day please help
Old
LebronJames
Junior Member
 
Status: Offline
Posts: 3
Join Date: Nov 2015
Default Stuck on this all day please help - 11-05-2015, 05:23 PM

I even woke up before class to speak with my professor during his office hours which he was busy with registering students for next semester so I completed what I could but became very lost from there. I will Highlight what I have completed so far in my Alice world. The info that is Bold are the Questions I need help with but I attached my world work I have so far for you to inspect.

1) Place a chicken in the world. Create a method named chickenSquare that takes a parameter named size to indicate the size of the square. Using a loop, have the chicken move in a square where all movement is ‘forward’ (so the chicken will need to turn). Next create a method named chickenManySquares that takes a numeric parameters count and size. It then uses chickenSquare to make the chicken move in count number of squares of the given size. If the count isn’t valid (because it is negative) then the method should do nothing.

2) Write a method named findRem5. It asks the user for two numbers start and end. End must be > start and if it isn’t, the program should continue asking the user for a value until end is > start. It then counts up starting from start to end by ones printing each value. In addition to printing the number, if that number is divisible by 5 it should print an * beside it. For example, if start was 3 and end was 12 the output would be:
3.0
4.0
5.0*
6.0
7.0
8.0
9.0
10.0*
11.0
12.0
Attached Files
File Type: a2w LOOPS.a2w (247.8 KB, 2 views)
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 11-09-2015, 02:52 PM

When does this need to be done?


(')>
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 210
Join Date: Dec 2012
Location: Frosno, Ca
Default 11-18-2015, 03:26 PM

Quote:
Originally Posted by LebronJames View Post
I even woke up before class to speak with my professor during his office hours which he was busy with registering students for next semester so I completed what I could but became very lost from there. I will Highlight what I have completed so far in my Alice world. The info that is Bold are the Questions I need help with but I attached my world work I have so far for you to inspect.

1) Place a chicken in the world. Create a method named chickenSquare that takes a parameter named size to indicate the size of the square. Using a loop, have the chicken move in a square where all movement is ‘forward’ (so the chicken will need to turn). Next create a method named chickenManySquares that takes a numeric parameters count and size. It then uses chickenSquare to make the chicken move in count number of squares of the given size. If the count isn’t valid (because it is negative) then the method should do nothing.

2) Write a method named findRem5. It asks the user for two numbers start and end. End must be > start and if it isn’t, the program should continue asking the user for a value until end is > start. It then counts up starting from start to end by ones printing each value. In addition to printing the number, if that number is divisible by 5 it should print an * beside it. For example, if start was 3 and end was 12 the output would be:
3.0
4.0
5.0*
6.0
7.0
8.0
9.0
10.0*
11.0
12.0
Lets Start with findRem5.
The big problem here is the while loop you included in the for loop. It says while True do nothing. The result is as follows:
  1. The first number is printed.
  2. The while statement evaluates True to determine if it is true. Question when will True be False??
  3. Since True is True perform the instructions within the while loop. In this case nothing is done.
  4. Evaluate the while condition and if true return to step 3, otherwise continue with the next instruction after the while loop.
The upshot is that the program is stuck in a while loop that can never end.

Other things to look at are the condition used to accept the end value. Your problem description says that end must be greater than start. Can you see why the use of end < start could be a problem?

You have not done the asterisk for values divisible by 5. The easiest way to check for this, since Alice does not have a Mod function, is to compare X/5 to Int(X/5). If they are equal then X is divisible by 5.

Mark


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote
Chicken Square
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 210
Join Date: Dec 2012
Location: Frosno, Ca
Default Chicken Square - 11-18-2015, 03:48 PM

Quote:
Originally Posted by LebronJames View Post
I even woke up before class to speak with my professor during his office hours which he was busy with registering students for next semester so I completed what I could but became very lost from there. I will Highlight what I have completed so far in my Alice world. The info that is Bold are the Questions I need help with but I attached my world work I have so far for you to inspect.

1) Place a chicken in the world. Create a method named chickenSquare that takes a parameter named size to indicate the size of the square. Using a loop, have the chicken move in a square where all movement is ‘forward’ (so the chicken will need to turn). Next create a method named chickenManySquares that takes a numeric parameters count and size. It then uses chickenSquare to make the chicken move in count number of squares of the given size. If the count isn’t valid (because it is negative) then the method should do nothing.

2) Write a method named findRem5. It asks the user for two numbers start and end. End must be > start and if it isn’t, the program should continue asking the user for a value until end is > start. It then counts up starting from start to end by ones printing each value. In addition to printing the number, if that number is divisible by 5 it should print an * beside it. For example, if start was 3 and end was 12 the output would be:
3.0
4.0
5.0*
6.0
7.0
8.0
9.0
10.0*
11.0
12.0
The chickenSquare method is close to being correct. I think the problem here is that you are not thinking your way through code you have written. In chickenSquare how many times should the the chicken walk forward and turn to make a square? The easiest way to see this is to do it yourself, walk in a square and you will walk forward and turn a set number of times.
Now, when you created the chickenSquare method you added a parameter. That parameter was suppose to determine the length of each side of the square. So now the question becomes, if you want to use sizeSquare to determine the size of each side of the square, where would sizeSquare be placed in the method? Currently it is used to determine how many sides the chicken walks. The chicken could stay where it is (sizeSquare=0) or it could walk one meter, turn and stop or it could move 1 meter and turn thousands of times before stopping. I should note that the chicken will not necessarily complete the last square. In other words the chicken could end up at a different place and facing a different direction then when it started.

I hope this puts you on the right track.
Mark


Mark Henwood
mhenwood@ieee.org

Last edited by chickentree; 11-18-2015 at 03:53 PM.
   
Reply With Quote
Reply

Tags
loops, parameters, questions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2017, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.