I need to take a given amount of teaspoons and convert it to statements in which the bigger units fill first and the smaller units fill second. For example,
this is what it's supposed to look like:
total_teaspoons = 57
19 tablespoons, 0 teaspoons
9 ounces, 1 tablespoon, 0 teaspoons
1 cup, 1 ounce, 1 tablespoon, 0 teaspoons
0 pints, 1 cup, 1 ounce, 1 tablespoon, 0 teaspoons
I've been stuck on this for a while and I don't know how to work it out.
total_teaspoons = 57
pints = (total_teaspoons // 96)
cups = (total_teaspoons // 48)
ounces = (total_teaspoons) // 6
tbsps = total_teaspoons // 3
tsps = total_teaspoons % total_teaspoons
print(tbsps, tsps)
print(ounces, tbsps, tsps)
print(cups, ounces, tbsps, tsps)
print(pints, cups, ounces, tbsps, tsps)
The thing I don't get is how to change the value of tablespoon or ounces depending on whether you are including the other bigger measurements like cups or pints?
This solution will work, it is not the most elegant solution, but you can get the idea on how it should work and you can play with it to improve it.
The idea is that using
%you get the rest of the division and so you get the remaing teaspoons to convert in the next unit.For printing in a smaller number of units you just need to convert the unit that you won't print in the largest unit you want to print and you can do that by dividing the conversion factor of each unit you will not use by the conversion factor of the biggest unit you will use.