These are solutions to the Practice Problems in this chapter. You should only consult these answers after you have tried each of them for yourself first. Practice Problems are meant to help reinforce the material you have just read so make use of them.

1.20.1 Solution to Practice Problem 1.1

The decimal equivalent of the binary number 010101012 is 85.

1.20.2 Solution to Practice Problem 1.2

58/2 = 29 remainder 0

29/2 = 14 remainder 1

14/2 = 7 remainder 0

7/2 = 3 remainder 1

3/2 = 1 remainder 1

1/2 = 0 remainder 1

So the answer is 001110102.

1.20.3 Solution to Practice Problem 1.3

−8310 = 101011012

1.20.4 Solution to Practice Problem 1.4

The ASCII code for space is 32. 3210 = 001000002

1.20.5 Solution to Practice Problem 1.5

We, as programmers, determine how bytes in memory are interpreted by the statements that we write. If we want to interpret the bits 01010011 as a character we write 'S' in our program. If we want the same bits to represent an integer, we write 83 in our program.

1.20.6 Solution to Practice Problem 1.6

There is no solution needed for this exercise. Try it out and if you have problems, talk to your instructor or someone who can help to make sure you get this working before proceeding.

1.20.7 Solution to Practice Problem 1.7

1. An assignment statement is written as

< variable > = < expression >

where a variable is assigned the value of an expression.

2. To retrieve a value from memory we write the name of the variable that refers to that value.

3. If we use a variable before it has been assigned a value Python will complain of a name error, meaning the variable has not been assigned a value yet.

1.20.8 Solution to Practice Problem 1.8

The binary representation of 58 is 00111010. The number is 3 A16 and 728. In Python syntax that would be 0x 3 A and 0o72.

1.20.9 Solution to Practice Problem 1.9

There is no solution needed for this since it is in the text. However, you should make sure you try this so you understand the mechanics of writing a program using the IDE. If you can't get it to work you should ask someone that did get it to work for help or ask your instructor.

1.20.10 Solution to Practice Problem 1.10

sideA = 6

sideB = 8

sideC = ( sideA * sideA + sideB **2) ** 0 . 5

print ( sideC )

1.20.11 Solution to Practice Problem 1.11

Here is one program that you might get as a result.

name = ' Sophus Lie '

print (" The name is " , name )

word = name [ 3 ] + name [ 1 ] + name [ 4 ] + name [ 5 ] + name [ 9 ]

print ( word )

1.20.12 Solution to Practice Problem 1.12

Here is one version of the program. Do you understand why + was used at the end of the print statement?

x = chr (83)

print (" The ASCII character equivalent of " , ord (x)," is " , x+".")

1.20.13 Solution to Practice Problem 1.13

You cannot use input to implement this because the input function waits for the enter key to be pressed, not just any key. You could prompt the user though with “Press Enter to continue.. .”.

1.20.14 Solution to Practice Problem 1.14

Here is a version of the program. It must have variables to 1 and 100 to be correct according to the directions.

start = 1

end = 100

sumOfNums = end * ( end + 1) // 2

print (" sum ("+ s t r ( start )+ " .. "+ s t r ( end )+")="+ s t r ( sumOfNums ))

1.20.15 Solution to Practice Problem 1.15

start = 1

end = 100

sumOfNums = end * ( end + 1) // 2

print (" sum (% d ..% d )=% d" %( start , end , sumOfNums ))

Found a mistake? Please highlight the word and press Shift + Enter