w3resource

Python: Print the following floating numbers with no decimal places


Print numbers without decimal places.

Write a Python program to print the following positive and negative numbers with no decimal places.

Python String Exercises: Print the following floating numbers with no decimal places

Sample Solution:

Python Code:

# Define a variable 'x' and assign it the value 3.1415926 (a positive floating-point number).
x = 3.1415926

# Define a variable 'y' and assign it the value -12.9999 (a negative floating-point number).
y = -12.9999

# Print an empty line for spacing.
print()

# Print the original value of 'x' with a label.
print("Original Number: ", x)

# Format the value of 'x' with no decimal places and print it.
print("Formatted Number with no decimal places: "+"{:.0f}".format(x))

# Print the original value of 'y' with a label.
print("Original Number: ", y)

# Format the value of 'y' with no decimal places and print it.
print("Formatted Number with no decimal places: "+"{:.0f}".format(y))

# Print an empty line for spacing.
print() 

Sample Output:

Original Number:  3.1415926                                                                                   
Formatted Number with no decimal places: 3                                                                    
Original Number:  -12.9999                                                                                    
Formatted Number with no decimal places: -13 

Flowchart:

Flowchart: Print the following floating numbers with no decimal places

For more Practice: Solve these Related Problems:

  • Write a Python program to round a list of floats to the nearest integer and print them without decimals.
  • Write a Python program to convert floating-point numbers to integers and print the results without any decimal part.
  • Write a Python program to use int() conversion to display numbers as whole numbers, preserving the sign.
  • Write a Python program to iterate over a list of numbers and format them as integers with no decimal places.

Python Code Editor:

Previous: Write a Python program to print the following floating numbers upto 2 decimal places with a sign.
Next: Write a Python program to print the following integers with zeros on the left of specified width.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.