Question

In: Computer Science

On Python a) Use format() method to print an integer value entered by the user and...

On Python

a) Use format() method to print an integer value entered by the user and its cube root with two decimal places.

b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr)

c) Switch the order of keyword arguments and show that this has no effect on the output.

Solutions

Expert Solution

Answer for the above question:

code:


#Input from user
n=int(input("Enter Number :"))
#Calculating cube Root
cr = pow(n,1/3)

#a Answer
#using format function to print number and cube root
print("Cube Root of {} is {:.2f}".format(n,cr))

#b Answer
#Keyword arguments and labels
print("Cube Root of {number} is {cubeRoot:.2f}".format(number=n,cubeRoot=cr))

#c Answer
#Switcing keyword arguments
print("Cube Root of {number} is {cubeRoot:.2f}".format(cubeRoot=cr,number=n))

OUTPUT:

PS: If you have any doubt please mention in the comment section. I will solve it as soon as possible.


Related Solutions

PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
1. Use the get() method to print the value of the "name" key and the value...
1. Use the get() method to print the value of the "name" key and the value of the "age" key of the stuInfo dictionary. Use the variable given below: stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20} 2. Use the dict() function to make a copy of the NY dictionary to NewYorkState dictionary. 3. Change the "name" value from "John Smith" to "James Bond" of the stuInfo dictionary. Use the variable given below: stuInfo = {'name': 'John Smith', "gpa":...
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as: n! = n·(n-1)·(n-2)·.……·3·2·1. The factorial of 0 is 1. If a number is negative, factorial does not exist and this program should display error message. Sample output dialogues should look like these:  Enter an integer: -5 ERROR!!! Tactorial of a negative number doesn't exist  Enter an integer: 10  Factorial = 3628800
in python This is the animal speaking game. Print the following menu for your user: ------------------------------------...
in python This is the animal speaking game. Print the following menu for your user: ------------------------------------ 1) Dog 2) Cat 3) Lion 4) Sheep 5) Exit Please enter a selection. ------------------------------------ If the user enters 1, print("Bark") If the user enters 2, print("Meow") If the user enters 3, print("Roar") If the user enters 4, print("Baah") If the user enters 5, exit the program. define functions for each animal. For example: def dog() : def cat() : and so forth ......
Playing with encryption: Write a program that will read a four-digit integer entered by the user...
Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original...
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Create a python program that will ask the user for his job title and print out...
Create a python program that will ask the user for his job title and print out the first letter, the last letter and the total number of letters in his job
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT