19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2. Although the pizza in the previous exercise is very yummy, it’s not<br />

grammatically correct, because the program outputs 1 slices of pizza.<br />

Fix the program so that its output is grammatically correct (and you<br />

won’t embarrass your English teacher). (Hint: use an If statement<br />

inside the For loop.)<br />

3. We built a game for you <strong>to</strong> quiz Alice on her multiplication so she’ll<br />

be ready for the queen’s questions. The program generates 10 random<br />

multiplication questions and asks Alice <strong>to</strong> enter the answer for each<br />

question. Alice earns one point for each correct answer. If she enters a<br />

wrong answer, show her the correct answer. The program ends by showing<br />

her <strong>to</strong>tal score. Re-create the program, run it, and explain how it<br />

works:<br />

score = 0<br />

For N = 1 To 10 ' Asks 10 questions<br />

n1 = Math.GetRandomNumber(10)<br />

n2 = Math.GetRandomNumber(10)<br />

TextWindow.Write(n1 + " x " + n2 + "? ")<br />

ans = TextWindow.ReadNumber()<br />

If (ans = n1 * n2) Then ' Increases the score<br />

score = score + 1<br />

Else<br />

' Shows the correct answer<br />

TextWindow.WriteLine("Incorrect --> " + (n1 * n2))<br />

EndIf<br />

EndFor<br />

TextWindow.WriteLine("Your score is: " + score + "/10")<br />

4. Write a program that draws the following image. (Hint: use a For loop<br />

<strong>to</strong> draw the line pattern for each of the four corners.)<br />

Repeating For Loops 193

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!