Question
May I please know how to program this question in python? Thank you. V = ? ? r 2? h You are tasked with writing
May I please know how to program this question in python? Thank you.
V = ? ? r2?h
You are tasked with writing a program to calculate the area of the base of the cylinder and the volume of the cylinder using the radius and height specified in the command line by the user.
Your program should take two command line arguments. The first argument is the radius of the base of the cylinder. The second one is the height of the cylinder.
Since command line arguments are stored as strings, you will need to use convert it to a float value.
If the number of command line arguments is smaller than two, your program should output:
Not enough arguments.
If the number of command line arguments is greater than two, your program should output:
Too many arguments.
If the radius is negative, your program should output (without checking the value of the height):
Radius cannot be negative.
If the radius is non-negative but the height is negative, your program should output:
Height cannot be negative.
For all situations listed above, the program should terminate immediately after the message has been printed.
The value for PI will should be set as a constant with the value 3.141592. (You should declare a global variable)
You can assume that the values for radius and height will always be decimal numbers.
The volume of the cylinder can be calculated using the formula:
V=??r2?h
Your program should display the volume up to 2 decimal places. (print and use a formatted string.)
For Example:
if r = 4 and h = 10
The volume of the cylinder is 502.65.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started