Question

In: Computer Science

a). Write a program that asks the user to enter an integer N and prints two...

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".

Solutions

Expert Solution

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.


Related Solutions

Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT