Private: Code with Blockly
About Lesson

Activity 1:Create a list with 10 entries, composed of random numbers from 1-10000. Then find the largest number in this list.

Step 1: Let us generate a list with 10 entries. We will first create an empty list. Use the following block to do so.

Step 2: Now create a loop for 10 numbers. The following loop will run 10 times.

Step 3: The following function will help you to create the list. Read along with the explanation for each block used.
By joining the 3 steps, you will be able to generate the list. You can also see the list by using a print command.
Step4: now we will sort the list in descending order. It will shuffle the list so that the largest number comes up first in the list.

Step5: now that the list is shuffled, we know the position of the largest number. All we have to do is to use a block that will return the number stored at the first position.

And there you have it. By combining all these blocks, you will be able to generate a list with 10 numbers varying between 1-10000 and then retrieve the largest number
For self-practice, you can also modify this list to find the smallest number, second largest, third largest, and so on.

This concludes our session on lists. Next time we will learn about functions. But until then, keep practicing.

error:
Fill in the form for S’O’A Fablab Orientation 2021.
Open chat
Hello! Welcome to Activity » Karkhana!