SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.loops
Exercise:
Programming Excercises
Question:14 | ISBN:978013274719 | Edition: 6

Question

(Find the smallest n such that n^2>12,000) Use a while loop to find the smallest integer n such that n^2 is greater than  12,000.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program code:

# Initialize the counter and n
counter = 1
n = 1

# Use a while loop to find the smallest n 
#such that n^2 is greater than 12,000
while n**2 <= 12000:
    n += 1
    counter += 1

# Display the result
print("The smallest integer n such that n^2 is greater than 12,000 is:", n)
print("n^2 =", n**2)
print("Number of iterations:", counter)

Executed Output:

The smallest integer n such that n^2 is greater than 12,000 is: 110
n^2 = 12100
Number of iterations: 110

 

0 0

Discussions

Post the discussion to improve the above solution.