19.04.2017 Views

Learn to Program with Small Basic

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TRY IT OUT 18-10<br />

Use the techniques you learned in the House That Jack Built example <strong>to</strong> write a<br />

program that tells your favorite s<strong>to</strong>ry. Don’t have one? Make one about an alien<br />

rat trapped in a <strong>to</strong>wer <strong>with</strong> nothing but JELL-O, a slingshot, and an advanced<br />

chemistry set. Explain how the rat got there and how it escapes!<br />

<strong>Program</strong>ming Challenges<br />

If you get stuck, check out http://nostarch.com/smallbasic/ for the solutions<br />

and for more resources and review questions for teachers and students.<br />

1. Open the file Shoot_Incomplete.sb from this chapter’s folder. Run the program<br />

<strong>to</strong> see the following interface.<br />

The goal of this game is <strong>to</strong> estimate the turn angle and moving<br />

distance between the turtle and the target. When a player enters their<br />

input, it is saved in a variable named strIn. Your task is <strong>to</strong> split strIn in<strong>to</strong><br />

two parts: assign the substring before the comma <strong>to</strong> angle, and assign<br />

the substring after the comma <strong>to</strong> dist. The comments in the file tell you<br />

where <strong>to</strong> add your code. If you get stuck, see the file Shoot.sb, which contains<br />

the completed program.<br />

2. Open the file BinaryToDecimal_Incomplete.sb from this chapter’s folder.<br />

This program converts binary numbers <strong>to</strong> decimal numbers and then<br />

asks the user <strong>to</strong> input an 8-bit binary number. It then shows the input<br />

number in the graphics window, computes its decimal number, and displays<br />

the result of the conversion, as shown in the following figure.<br />

284 Chapter 18

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

Saved successfully!

Ooh no, something went wrong!