Back

Practise formatting floating point numbers - Answers

Q1. Display 5.673046 to 1 decimal place. Display the answer in a sentence, as in the above examples.

print("5.673046 with one decimal place is {:.1f}".format(5.673046))

Q2. Display 5.673046 to 2 decimal places. Display the answer in a sentence, as in the above examples.

print("5.673046 with two decimal places is {:.2f}".format(5.673046))

Q3. Display 5.673046 to 3 decimal places. Display the answer in a sentence, as in the above examples.]

print("5.673046 with three decimal places is {:.2f}".format(5.673046))

Q4. Display 5.673046 to 4 decimal places. Display the answer in a sentence, as in the above examples.

print("5.673046 with four decimal places is {:.4f}".format(5.673046))

Q5. Display 5.673046 to 5 decimal places. Display the answer in a sentence, as in the above examples.

print("5.673046 with five decimal places is {:.5f}".format(5.673046))

Q6. Display 5.673046 to 6 decimal places. Display the answer in a sentence, as in the above examples.

print("5.673046 with six decimal places is {:.6f}".format(5.673046))

Q7. Display 5.673046 to 0 decimal places. Display the answer in a sentence, as in the above examples.

print("5.673046 with no decimal places is {:.0f}".format(5.673046))

Q8. Display 5.673046 to 3 decimal places and with its sign. Display the answer in a sentence, as in the above examples.

print("5.673046 with three decimal places and the sign is {:+.3f}".format(5.673046))

Q9. Display -5.673046 to 2 decimal places and with its sign. Display the answer in a sentence, as in the above examples.

print("-5.673046 with two decimal places and the sign is {:+.2f}".format(-5.673046))

Q10. Select some numbers and write some formatting questions like the examples above. Challenge someone sitting next to you, to see if they can format the numbers in the way that you want.

Back