Hey guys,
I'm new to Scratch and was wondering if anyone can help me out!
After talking to my teacher, I decided to take up his challenge of "making" a ticket vendor in Scratch. One of his challenges was for me to give "customers" a discount of minus $1 if they purchase a ticket on a weekend. I can't seem to figure this out. His hint was that I needed to use thr random operator.
Thanks guys
Offline
hmmm.... Random operator huh?
well, i am only guessing, but the first thing to do is to build your week, and then have the weekend day's send a message to the ticket dispenser that it's a weekday.
I think he may have been saying to use the random operator for determining the day.
If you want me to, i can try to make a program that does that... If you do then just post it, then if i am successful i will post it and put the link here. Then you can download it and i can delete it off my projects.
so just to clarify, you need to either make 7 sprites with text that represents each day, or make one sprite that has 7 costumes and then make it so that if a variable called "day_" is a certain number, then go to the corresponding costume or sprite.
I hope that helps,
CAA14
Offline
benSeath wrote:
Hey guys,
I'm new to Scratch and was wondering if anyone can help me out!
After talking to my teacher, I decided to take up his challenge of "making" a ticket vendor in Scratch. One of his challenges was for me to give "customers" a discount of minus $1 if they purchase a ticket on a weekend. I can't seem to figure this out. His hint was that I needed to use thr random operator.
Thanks guys
Here's the "algorithm" your teacher may have been talking about.
Create a list of Days, this will associate a day with a number.
set a variable daynumber with a range from 1 to the length of Days
Then test to see if Day is Saturday or Sunday and use an If/else block to assign a value to Discount.
add [Monday] to Days add [Tuesday] to Days add [Wednesday] to Days add [Thursday] to Days add [Friday] to Days add [Saturday] to Days add [Sunday] to Days set [daynumber v] to (pick random (1) to (length of [Days])) if < < ( daynumber ) = [6] > or < ( daynumber ) = [7] > > set [Discount v] to [1] else set [Discount v] to [0] end
Last edited by dechan (2013-01-28 18:42:10)
Offline
Hi,
Good algorithm,
I would of done it different because i don't yet know how to use lists.
Regards,
CAA14
Offline
random operator is
(pick random (#) to (#))because it falls under operators category and is random!
Offline
dechan wrote:
benSeath wrote:
Hey guys,
I'm new to Scratch and was wondering if anyone can help me out!
After talking to my teacher, I decided to take up his challenge of "making" a ticket vendor in Scratch. One of his challenges was for me to give "customers" a discount of minus $1 if they purchase a ticket on a weekend. I can't seem to figure this out. His hint was that I needed to use thr random operator.
Thanks guysHere's the "algorithm" your teacher may have been talking about.
Create a list of Days, this will associate a day with a number.
set a variable daynumber with a range from 1 to the length of Days
Then test to see if Day is Saturday or Sunday and use an If/else block to assign a value to Discount.add [Monday] to Days add [Tuesday] to Days add [Wednesday] to Days add [Thursday] to Days add [Friday] to Days add [Saturday] to Days add [Sunday] to Days set [daynumber v] to (pick random (1) to (length of [Days])) if < < ( daynumber ) = [6] > or < ( daynumber ) = [7] > > set [Discount v] to [1] else set [Discount v] to [0] end
Why create the list when it will never be used? If the list is static and you want to get the length, why not just specify the length?
Here, use this:
set [day v] to (pick random (1) to (7)) set [discount v] to [0] if <(day) > [5]> set [Discount v] to [1] end
Offline
Gravitation wrote:
dechan wrote:
benSeath wrote:
Hey guys,
I'm new to Scratch and was wondering if anyone can help me out!
After talking to my teacher, I decided to take up his challenge of "making" a ticket vendor in Scratch. One of his challenges was for me to give "customers" a discount of minus $1 if they purchase a ticket on a weekend. I can't seem to figure this out. His hint was that I needed to use thr random operator.
Thanks guysHere's the "algorithm" your teacher may have been talking about.
Create a list of Days, this will associate a day with a number.
set a variable daynumber with a range from 1 to the length of Days
Then test to see if Day is Saturday or Sunday and use an If/else block to assign a value to Discount.add [Monday] to Days add [Tuesday] to Days add [Wednesday] to Days add [Thursday] to Days add [Friday] to Days add [Saturday] to Days add [Sunday] to Days set [daynumber v] to (pick random (1) to (length of [Days])) if < < ( daynumber ) = [6] > or < ( daynumber ) = [7] > > set [Discount v] to [1] else set [Discount v] to [0] endWhy create the list when it will never be used? If the list is static and you want to get the length, why not just specify the length?
Here, use this:set [day v] to (pick random (1) to (7)) set [discount v] to [0] if <(day) > [5]> set [Discount v] to [1] end
Specifying a list of constants with a self-generated numerical index created by a list is good solid programming.
If someone is going to start using Lists in Scratch this is one of the better ways to get started.
If I was teaching the class and someone brought me a solution which used a list they would get a "+" because instead of creating some elaborate "if" blockset to display a value they could use
say <item [Day v] of [Days v]>which is much better than using a large set of if-blocks, and any time we can eliminate if blocks we're winning.
Offline
CAA14 wrote:
Hi,
Good algorithm,
I would of done it different because i don't yet know how to use lists.
Regards,
CAA14
I could teach you how to use lists if you would like.
Last edited by ImagineIt (2013-02-10 11:05:54)
Offline
dechan wrote:
benSeath wrote:
Hey guys,
I'm new to Scratch and was wondering if anyone can help me out!
After talking to my teacher, I decided to take up his challenge of "making" a ticket vendor in Scratch. One of his challenges was for me to give "customers" a discount of minus $1 if they purchase a ticket on a weekend. I can't seem to figure this out. His hint was that I needed to use thr random operator.
Thanks guysHere's the "algorithm" your teacher may have been talking about.
add [Monday] to [Days v] add [Tuesday] to [Days v] add [Wednesday] to [Days v] add [Thursday] to [Days v] add [Friday] to [Days v] add [Saturday] to [Days v] add [Sunday] to [Days v] set [daynumber v] to (pick random (1) to (length of [Days])) if < < ( daynumber ) = [6] > or < ( daynumber ) = [7] > > set [Discount v] to [1] else set [Discount v] to [0] end
Fixed.
Offline
dechan wrote:
Gravitation wrote:
dechan wrote:
Here's the "algorithm" your teacher may have been talking about.
Create a list of Days, this will associate a day with a number.
set a variable daynumber with a range from 1 to the length of Days
Then test to see if Day is Saturday or Sunday and use an If/else block to assign a value to Discount.add [Monday] to Days add [Tuesday] to Days add [Wednesday] to Days add [Thursday] to Days add [Friday] to Days add [Saturday] to Days add [Sunday] to Days set [daynumber v] to (pick random (1) to (length of [Days])) if < < ( daynumber ) = [6] > or < ( daynumber ) = [7] > > set [Discount v] to [1] else set [Discount v] to [0] endWhy create the list when it will never be used? If the list is static and you want to get the length, why not just specify the length?
Here, use this:set [day v] to (pick random (1) to (7)) set [discount v] to [0] if <(day) > [5]> set [Discount v] to [1] endSpecifying a list of constants with a self-generated numerical index created by a list is good solid programming.
If someone is going to start using Lists in Scratch this is one of the better ways to get started.
If I was teaching the class and someone brought me a solution which used a list they would get a "+" because instead of creating some elaborate "if" blockset to display a value they could usesay <item [Day v] of [Days v]>which is much better than using a large set of if-blocks, and any time we can eliminate if blocks we're winning.
However, it's not good to create needless arrays that take up memory, later in programming.
He never said to use lists/arrays. I always try to use the simplest solution possible. Not using the list is the simplest solution.
Personally, what I would do, not looking at any other solution, in pseudocode, is this:
Set Day to random from 1 to 7
Set price to 10
if Day = 6 or Day = 7 (weekends)
change price by -1
That's how I would do it. Only 4 lines of code.
Offline
"For every problem there is a solution which is simple, clean and wrong.” Henry Louis Mencken
Anyone can make a case for using the simplest solution possible.
I provided an elegant easy to understand and easily extensible solution.
If someone finds what I did too complex please understand that I'm not a judgmental person, but people who read weak excuses for not using good programming practices may not be as enlightened as I am.
Offline
dechan wrote:
"For every problem there is a solution which is simple, clean and wrong.” Henry Louis Mencken
Anyone can make a case for using the simplest solution possible.
I provided an elegant easy to understand and easily extensible solution.
If someone finds what I did too complex please understand that I'm not a judgmental person, but people who read weak excuses for not using good programming practices may not be as enlightened as I am.
But your algorithm isn't extremely good either. There's no point in making a list/array that will never be used. It will just take up space.
Offline
ImagineIt wrote:
dechan wrote:
"For every problem there is a solution which is simple, clean and wrong.” Henry Louis Mencken
Anyone can make a case for using the simplest solution possible.
I provided an elegant easy to understand and easily extensible solution.
If someone finds what I did too complex please understand that I'm not a judgmental person, but people who read weak excuses for not using good programming practices may not be as enlightened as I am.But your algorithm isn't extremely good either. There's no point in making a list/array that will never be used. It will just take up space.
I just want to say that although you both have good points, please don't turn this into a flame war.
Offline