Here's the question you clicked on:
suirsuss
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: ')) root=0 pwr=0 while root**pwr <= number and pwr<6: pwr +=1 ##need to check if different roots will work before increasing pwr again## if root**pwr = number: print root,',',power else: print 'No pair of numbers relate exponentially to the given input"
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
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: http://pastebin.com/DHPMnmJ5