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:15 | ISBN:978013274719 | Edition: 6

Question

(Find the largest n such that n^3< 12,000) Use a while loop to find the largest integer n such that n^3 is less than 12,000.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program code: 

# Initialize variables
n = 0  # Start with n = 0
cubed = 0  # Store the cube of n

# Use a while loop to find the largest n such that n^3 < 12,000
while cubed < 12000:
    n += 1  # Increment n by 1
    cubed = n ** 3  # Calculate the cube of n

# After the loop, n will be the largest integer such that n^3 < 12,000
# But since we incremented n before checking the condition, we need to decrement it by 1
n -= 1

# Print the result
print("The largest integer n such that n^3 is less than 12,000 is:", n)

Executed Output:

The largest integer n such that n^3 is less than 12,000 is: 22

 

0 0

Discussions

Post the discussion to improve the above solution.