Skip to main content
Contents Index
Search Book
Search Results:
No results.
Read aloud
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 6.14 Write Code Questions Orig
Activity 6.14.1 .
The code below is supposed to print an estimate of the square root of a number (target). You are given an initial guess of 2. However, the indention is wrong on 4 lines. Fix these errors to find the estimate.
Activity 6.14.2 .
Create code to print an estimate of the square root of a number (target). You are given an initial guess of 2.
target = 6
guess = 2
---
guessSquared = guess * guess
---
while abs(target-guessSquared) > 0.01:
---
closer = target / guess
---
guess = (guess + closer) / 2.0
---
guessSquared = guess * guess
---
print("Square root of", target, "is", guess)
Activity 6.14.3 .
Rewrite the following code to use a while loop instead of a for loop to calculate the value of ten factorial.
Activity 6.14.4 .
Using the blocks below, create code to calculate the value of ten factorial.
product = 1
number = 1
---
while number < 11:
---
product = product * number
---
product = number * number #paired
---
number = number + 1
---
print(product)
You have attempted
of
activities on this page.