book question is :
write a program that asks the user to enter an integer and prints two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. if no such pairing exists state a message to that effect.
so far i have :
number = int(raw_input('Enter an integer: '))
while root**pwr <= number and pwr<6:
##need to check if different roots will work before
increasing pwr again##
if root**pwr = number:
print 'No pair of numbers relate exponentially to the given input"
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
I've never seen the double pound sign after a comment. AFAIK, a single pound sign before the comment, tells the interpreter that the rest of the line is a comment.
The if statement on the following line is probably not what you want. A single '=' is assignment. Comparison is "==".
root is never changed from 0.
I would guess that you want to have a nested ( one inside the other ) loop for this.
Also, there will always be a solution as root^1 will equal input number when root equals number.
good point breet .. but how disappointing a program it would be if it just returned the number you put in and power of one XD
Not the answer you are looking for? Search for more explanations.
this will also print 'No pair of numbers relate exponentially to the given input" many times
I'm not sure if you are still looking for this or not. I learned a lesson here: look at the book example! I really only looked at the examples to see the loop structures, mostly ignoring the content. When I got to the exercise, I spent a LOT of time trying to decide whether to use integers, how to handle remainders, or whether to use floats and how to convert back to integers at the end, etc. Finally I found an easier way. Then I realized my easier way is the way the author showed in his example!
I won't be getting those hours of my life back. LOL!
Anyway, here is how I did it if you still care.
P.S. I updated this slightly because the old code was ugly. I'm not totally satisfied with this, but it is better: