A community for students.
Here's the question you clicked on:
 0 viewing
suirsuss
 2 years ago
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"
suirsuss
 2 years ago
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"

This Question is Closed

rsmith6559
 2 years ago
Best ResponseYou've already chosen the best response.0I'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.

breet
 2 years ago
Best ResponseYou've already chosen the best response.0Also, there will always be a solution as root^1 will equal input number when root equals number.

suirsuss
 2 years ago
Best ResponseYou've already chosen the best response.0good point breet .. but how disappointing a program it would be if it just returned the number you put in and power of one XD

harsimran_hs4
 2 years ago
Best ResponseYou've already chosen the best response.0this will also print 'No pair of numbers relate exponentially to the given input" many times

RCMorea
 2 years ago
Best ResponseYou've already chosen the best response.0I'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
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.