(Chapter 2, Text book page 153) Solved

$24.99 $18.99

Write a program that prompts for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Here is a sample session: Input an integer: abc Error: try again. Input an integer: 4a Error: try again. Input an integer: 2.5 Error: try again. Input…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Write a program that prompts for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Here is a sample session:

Input an integer: abc

Error: try again. Input an integer: 4a

Error: try again. Input an integer: 2.5

Error: try again. Input an integer: 123

The integer is: 123

29. (Chapter 2, text book page 156)

Create a program that prompts for a positive number greater than 2 (check this condition), then keeps taking the square root of this number until the square root is less than 2. Print the value each time the square root is taken, along with the number of times the operation has been completed. For example:

Enter an integer greater than 2: 20

  1. 4.472

  2. 2.115

  3. 1.454

Extra: Look ahead to string formatting (Section 4.4) to print the values to only 3 decimal places as shown.

(Chapter 2, Text book page 153) Solved
$24.99 $18.99