That brings me to my question at hand. There were and still are many instances when I needed to add, subtract, multiply etc. fractions and was too lazy or forgetful to do the calculations on paper. I work in the construction trade (mostly plumbing and electrical) and frequently I deal with fractions regarding measured distances. I have successfully written a very verbose and basic fraction calculator in Python.

The current program just consists of inputting the first fraction, selecting add or subtract, inputting the second fraction and finally it returns the calculation. Pretty simple, right? I recently implemented the Android UI menus to select what the first fraction would be.

- Code: Select all
`title = 'First Frac Denominator Range'`

droid.dialogCreateAlert(title)

droid.dialogSetSingleChoiceItems(['1/2', 'Thirds', 'Fourths', 'Eighths', 'Sixteenths'])

droid.dialogSetPositiveButtonText('Ok')

droid.dialogShow()

result = droid.dialogGetResponse().result

ffdr = droid.dialogGetSelectedItems().result

for num1 in ffdr:

if num1 == 0:

showfrac = str('1/2')

frts() #frts() is a function that just displays the showfrac str

firstot = float(.50)

elif num1 == 1:

title = 'Thirds'

droid.dialogCreateAlert(title)

droid.dialogSetSingleChoiceItems(['1/3', '2/3'])

droid.dialogSetPositiveButtonText('Ok')

droid.dialogShow()

result = droid.dialogGetResponse().result

thirds = droid.dialogGetSelectedItems().result

for tnum1 in thirds:

if tnum1 == 0:

showfrac = str('1/3')

frts()

firstot = float(.33)

elif tnum1 == 1:

showfrac = str('2/3')

frts()

firstot = float(.66)

That is a brief incomplete example of what I have. It coverts whatever fraction into a float. I won't show the entire script because it is long. Then it asks if you want to add or subtract. After that it asks for the second fraction in the same manner but it only deals with 1/2, 3rds, 4ths, 8ths and 16ths. It will either add or subtract the two float values and with a long series of if and elif statements convert the result back to a str.

Example:

- Code: Select all
`if total_of_two == 0.125:`

answer = str('1/8')

elif total_of_two == .50:

answer = str('1/2')

Pretty inefficient way of doing it but it works. Ok FINALLY on to my REAL question. How could I incorporate whole numbers to accompany the fraction and calculation? I have read the Python Docs regarding the "fractions" module and I couldn't gather any answer from that. BTW, I'm currently using Python 2.6.2. I tried an if statement that would give me the left over numbers if the total was > 1 but I'm lost when it comes to trying to work with values > 1.

I appreciate any help and I'm not afraid to ask. I was not born with the knowledge of Python in my head lol. Before learning Python I had some experience with BASIC which helped me understand a little about programming but after learning that 13 years ago in high school my brain is rusty. Thanks for reading!