Python Decimal places

Description

Python program to get a fractional number from user and display the same in two digit precision
Sample Input 1:
56.3426
Output:
56.34

Solution

num=float(input("Enter a Number:"))
print("{:.2f}".format(num))

Explanation

In python format specifiers are mentioned inside {} and value for the specifiers are passed through the format() method. Here :.2f specifies float value with 2 decimal point.



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution