Help with a task PLEASE!

I need help with a solution for a SNAP task for my son. He is at his wits end trying to figure it out but his teacher does not help him. I have no clue what I am doing and tried using AI but that didn't help. The task is :

Create a script that allows a user to input a series of names and store them in a variable list L . The list should allow the user to continue entering names until they enter the value "End", "END", or "end".
In addition, the array should only accept names that have 8 characters (individual letters or symbols) or less, and return an error for the input attempt if the name is too long. So if they entered "Leonardo" it would be fine, but "Alexander" would display an error before returning to a name entry.

I've tried so many ways with help from AI but I keep getting error messages or it just doesn't work. Is there anyone that can help me, I'd really appreciate it. Remember, I know very little of SNAP!

Please and thank you!

sorry.....the last bit of the instructions is "The final list should be printed to the stage.".....whatever that means.

you can edit your posts.

Welcome to Snap! Forum!

Here are a few code snippets that will help:

set [L V] to (list @addInput)

Makes sure L is a list, else errors will occur later in the script.

repeat until <(answer) = [end]> {

}

Until the answer is "end", "End", or "END" (well, the capitalization doesn't matter), runs the script inside.

ask [] and wait

ask [Input a name:] and wait

I suggest using two of the ask blocks, one empty and one with a prompt. The one with a prompt asks the user for an input as expected, while the empty one clears the answer so that the script doesn't mess up when enterring "end".

if (([length V] of text (answer))>[8]::operators) then {
say [Name is too long! Must be 8 characters or less]
} else {
add (answer) to (L)
}

Checks if the name length is longer than 8 characters, and if it is, shows a message. If it is 8 characters or shorter, adds to the list.

I hope this helps! If you have more questions, ask us!

We can't do your son's homework for him, but if you share the project with what you've tried, we can suggest what's getting in the way.

To share a project: After saving it, go to the File menu (:page_facing_up: symbol), choose Open, type the project name in the top text slot, then click the Share button. Then copy the URL bar from your browser, and paste it in a post here.

image

You need to take into consideration that only \textsf{basic users} can edit their own posts.

Good morning everyone!

Thank you for all of your suggestions. I will make another attempt with my son when he gets home from school. I wasn't trying to get anyone to do the homework for us but we've been working on this since September. My son's teacher rarely helps the students if they are stuck on something. If he does help, he expects you to pick it up immediately or he will walk away. He has no patience. He spends the majority of the class playing video games or watching television shows. Unbelievable but true. Even though it is an introductory course, assignments are given and students, for the most part, are expected to figure it out on their own. We have tried the task in so many different ways and it never works. Unfortunately, we don't have an example to share as we have deleted them all because the cut off date for assignments is tomorrow (Tuesday) and my son was just going to take the loss on it. Asking for help here was a last ditch effort. Of the many, many attempts we made, we mostly got error messages saying "was expecting a list and got a number" or something similar to that. We will make one last attempt tonight to see if we can do it. Thanks again everyone for responding. I appreciate it!

I feel so bad for you both.

Here is something that might help:

Variables start with their value being zero:


However for the common list blocks you need the variable to be a list: you can't add anything to a list that doesn't exist. It is important to understand that while Snap! isn't a strongly typed language, zero is not in any way shape or form a list. So, if you try to add something to your variable, you will get an error:
untitled script pic (13)
So, to fix this, we need to make sure that the variable is a list first. To do this, we can set the variable to an empty list:

Now, when we try a list operation on the variable (e.g. adding to the list), it works!

There is another reason why you will want to initialize your variable as an empty list:
Let's say someone runs your project, and the variable "a" becomes a list of 10 items:

Then, the next time they run your project, your list will still have those ten items. So, if they do the same names again, your list will look like this:

So that is yet another reason why you want to set your variable to an empty list at the start of your project.

.

.

For getting user input, you could use the "ask" block (already mentioned in this thread):
untitled script pic (18)
To determine whether to display an error or add to a list, an if-else block is in order:


For your error, you could do something like this:
untitled script pic (20)

Basically, your result should be visible. You could either use
untitled script pic (21)
which will show the variable's value on the stage, or you could do:
untitled script pic (22)
Which will have a similar result, only in a speech bubble.

.

I hope this helps!

.

PS: You don't need to use the block script variables ((a)) @> to create your variable - instead use the image button. I just used it for simplicity to create the pictures.

PPS: The difference between these methods for creating variables is that the block creates a variable only available to the script that it was created in and this variable is not saved with the project.
(I know that you are already confused with some things in Snap, so only look at this [by clicking on the blurred text] if you're sure that it won't make you even more confused. Maybe just forget that the script variables block exists for now.)

Snap home page https://snap.berkeley.edu/ with links to the resources
i.e. Beauty and Joy of Computing

Your son's teacher is bad

Good evening everyone!

My son took all of your suggestions and guidance, and finally managed to complete the task. It might not look pretty but at least it works according to the instructions. My son and I just wanted to thank you all again for the help, with just hours to go until the task is due to be submitted. All I can say is that you all provided more help than my son's teacher did all semester long. Thanks again! Have a great week!

Congratulations!

I'm sorry your son had such a terrible experience in his class! Programming is meant to be fun, not stressful. Next time, if there's a next time, ask for help earlier. :~)

I hope you'll file an official complaint about this teacher with the school. (Maybe not until after the grades are filed.) Perhaps you can help next year's students have a better experience.

How the hell was my answer inappropriate it was literally a script pic :man_facepalming:

It's because you're not supposed to just give a script to do someone else's homework (which this clearly is). If you're going to do something like that, explain what the script is doing.

Better yet, just don't do it!