In: Computer Science
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than N = 4 ** 3. That is, order the loops so that the lowest power is found.
b). order the loops so that the lowest root is found. For the example given in a) , where N = 64, your program will find N = 4 ** 3, rather than 8 ** 2.
c) read an integer N from the user, and read a phrase from the user. Print the phrase N times, each time on a different line.
d) Ask the user to input 10 integers, and then the program prints the largest odd number that was entered. For example of the integers were: 10, 9, 7, 12, 2, 5, 15, 100, 90, 60, then the program would print 15 as the largest odd number. If there is no odd number, then the program should print a message to that effect.
it should be Python, and the question was asked to be solved by "Finger exercise".
a) b)
from math import *
n=int(input("Enter a integer"))#raed a number
f=0
for i in range(2,n//2):
for j in range(6):
if pow(i,j)==n:#check if power is equal to n
print(i,j,sep=" ")
f=1
break
if f==1:
break
else:
print("No such pair exist")#If loop ietartion completes there is no
such pair
c)
n=int(input("Enter a integer"))
p=input("Enter a phrase")#read inputs
for i in range(n):
print(p)#iterate n times and print phrase
d)
l=list(map(int,input("Enter 10 numbers").split(",")))#read
numbers to list
res=[]
for i in l:
if i%2!=0:
res.append(i)#append number to list if i is odd number
print(max(res))#print max number from res list
Screenshots:
The screenshots are attached below for reference.
Please follow them for output and proper indentation.
Please upvote my answer. Thank you.