Practise formatting integers
Study the following examples, all of which use the format method:
print("6015 with the sign is {:+d}".format(6015)) results in +6015 being displayed.
print("-6015 with the sign is {:+d}".format(-6015)) results in -6015 being displayed.
print("25 in a field 10 characters wide, padded with zeros from the left is {:0>10d}".format(25)) results in 0000000025 being displayed.
print("25 in a field 5 characters wide, padded with H from the left is {:H>5d}".format(25)) results in HHH25 being displayed.
print("25 in a field 7 digits wide, padded with X from the right is {:X<7d}".format(25)) results in 25XXXXX being displayed.
print("33 in a field 10 digits wide, righthand justified, is {:10d}".format(33)) results in 33 being displayed. (Note: right hand justified is the default).
print("33 in a field 10 digits wide, lefthand justified, is {:<10d}".format(33)) results in 33 being displayed.
print("33 in a field 10 digits wide, center justified, is {:^10d}".format(33)) results in 33 being displayed.
print("5000000000 with comma separators is {:,}".format(5000000000)) results in 5,000,000,000 being displayed.
Q1. Display 324 with a plus sign.
Q2. Display -4255 with its sign.
Q3. Display 453 as 000453.
Q4. Display 453 as PPPPP453.
Q5. Display 453 as 453BB.
Q6. Display 93 in field 10 characters wide, right hand justified.
Q7. Display 93 in field 8 characters wide, lefthand justified.
Q8. Display 93 in field 12 characters wide, center justified.
Q9. Display 69030203007 as a number separated using a comma.
Q10. Test each other. Write a problem, and a solution, and then give it to a neighbour for them to do.