Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.) ARGUMENT OF CORRECTNESS FOR CODE 2.) RUNTIME ANALYSIS FOR CODE CODE: '''returns the largest integer x such that x^k does not exceed n, assuming

1.) ARGUMENT OF CORRECTNESS FOR CODE

2.) RUNTIME ANALYSIS FOR CODE

CODE:

'''returns the largest integer x such that x^k does not exceed n,

assuming k and n are both positive integers'''

def iroot(k, n):

num=1

#looping until num^k is greater than n

while True:

#checking if current number ^ k is greater than n

if pow(num,k)>n:

#returning previous number

return num-1

#moving to next number

num+=1

#testing various cases

print(iroot(3,125)) #5

print(iroot(3,126)) #5

print(iroot(3,124)) #4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

4. What will the team agreement contain?

Answered: 1 week ago