Click HEREto view my Problem #1.
In this lab, we learned about how to use lsists, and variables within lists. I chose to do the Even or Odd Problem. In this problem, we needed to have the user enter numbers into a list. Once they were finished entering numbers, the sprite needed to say whether each item was even or odd, using modular arithmetic. This also needed to be performed within only one conditional. Then, if the number of even numbers was greater than the number off odd numbers in the list, the sprite would change costumes.
This problem took a lot of thinking at first. The first thing I needed to do was create a conditional statement including the modular arithmetic to figure out if a number was even or odd. I created a block for this. I made a list called "numbers", which the user enters numbvers into. The user enters numbers until they type stop. I made a variable called "continue" for this, and the sprite will continue to ask for numbers until "continue=stop". I then made another variable called count. Count simply allowed the sprite to go from one number to the next within the list, since the length is unknown before the program. Then, my final two variables were "even" and "odd". Iff a number was one of these, the variable would increase by 1. At the end off the list, if even was greater than odd, the sprite switched to costume 2.
1) The length of an empty list is 0.
2) Lists are more powerful than variables because they can store multiple items at once.3) Lists can store anything. Lists can hold whatever the user wants in some programs.
Click HERE to return to homepage.