Sep-07-2020, 02:51 PM
Hello
I want to print number as whole if there is no decimal point and if there is decimal point, then print with decimal point.
For example,
Thanks
I want to print number as whole if there is no decimal point and if there is decimal point, then print with decimal point.
For example,
length = float(input("Enter length: ")) width = float(input("Enter width: ")) total = length * width print(f"The area of {length}x{width} is {total}")The o/p be like
Output:Enter length: 30
Enter width: 50
The area of 30.0x50.0 is 1500.0
OROutput:Enter length: 25
Enter width: 35.5
The area of 25.0x35.5 is 887.5
I want the output to be in whole number if there are no decimal points and in float if there are decimal points, like the followingOutput:The area of 30x50 is 1500
The area of 25x35.5 is 887.5
How do I format my print statement? Is that even possible?Thanks