• Home
  • Textbooks
  • Python Programming: An Introduction to Computer Science
  • Computers and Programs

Python Programming: An Introduction to Computer Science

John M. Zelle

Chapter 1

Computers and Programs - all with Video Answers

Educators

RO

Chapter Questions

07:48

Problem 1

Start up an interactive Python session and try typing in each of the following commands. Write down the results you see.
a) print("Hello, world!")
b) print("Hello", "world!")
c) print (3)
d) print (3.0)
e) print $(2+3)$
f) print $(2.0+3.0)$
g) print("2" $+$ "3")
h) print $(" 2+3=", 2+3)$
i) print $(2 * 3)$
j) print $(2 * * 3)$
k) print $(7 / 3)$
1) print(7 // 3)

Willis James
Willis James
Numerade Educator
02:08

Problem 2

Enter and run the chaos program from Section 1.6. Try it out with various values of input to see that it functions as described in the chapter.

Akash M
Akash M
Numerade Educator
02:08

Problem 3

Modify the chaos program using 2.0 in place of 3.9 as the multiplier in the logistic function. Your modified line of code should look like this:
\[
x=2.0 * x *(1-x)
\]
Run the program for various input values and compare the results to those obtained from the original program. Write a short paragraph describing any differences that you notice in the behavior of the two versions.

Akash M
Akash M
Numerade Educator
07:19

Problem 4

Modify the chaos program so that it prints out 20 values instead of 10 .

RO
Reynald Oliveria
Numerade Educator
07:19

Problem 5

Modify the chaos program so that the number of values to print is determined by the user. You will have to add a line near the top of the program to get another value from the user:
$\mathrm{n}=$ eval (input ("How many numbers should I print? "))
Then you will need to change the loop to use n instead of a specific number.

RO
Reynald Oliveria
Numerade Educator
02:08

Problem 6

The calculation performed in the chaos program can be written in a number of ways that are algebraically equivalent. Write a version of the program for each of the following ways of doing the computation. Have your modified programs print out 100 iterations of the calculation and compare the results when run on the same input.
a) $3.9 * x *(1-x)$
b) $3.9 *(x-x * x)$
c) $3.9 * x-3.9 * x * x$
Explain the results of this experiment. Hint: See discussion question number $4,$ above.

Akash M
Akash M
Numerade Educator
07:19

Problem 7

(Advanced) Modify the chaos program so that it accepts two inputs and then prints a table with two columns similar to the one shown in Section 1.8. (Note: You will probably not be able to get the columns to line up as nicely as those in the example. Chapter 5 discusses how to print numbers with a fixed number of decimal places.)

RO
Reynald Oliveria
Numerade Educator