forked from astoned/Guttag-2013-Finger-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Finger_3.1.py
34 lines (28 loc) · 899 Bytes
/
Finger_3.1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 8 21:32:17 2019
@author: astoned
"""
# Finger exercise: 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 pair of integers exists, it should
# print a message to that effect.
x = int(input('Number? '))
root = 0
for pwr in range(1,6):
if x > 0:
while root <= x:
root += 1
if root**pwr == x:
print('root = ', root, ' and pwr = ', pwr)
root = 0
elif x < 0:
while root >= x:
root -= 1
if root**pwr == x:
print('root = ', root, ' and pwr = ', pwr)
root = 0
elif x == 0:
print('There is no such pair')
break