SHOW:
|
|
- or go back to the newest paste.
1 | def frac_add(): | |
2 | fraction_1=input('Please enter a fraction:\n') | |
3 | fraction_1="".join(fraction_1.split()) | |
4 | fraction_1=fraction_1.replace('/',' ') | |
5 | fraction_1=fraction_1.split() | |
6 | fraction_2=input('Please enter another fraction:\n') | |
7 | fraction_2="".join(fraction_2.split()) | |
8 | fraction_2=fraction_2.replace('/',' ') | |
9 | fraction_2=fraction_2.split() | |
10 | letters = set('abcdefghijklmnopqrstuvqxyz') | |
11 | print(fraction_1) | |
12 | print(fraction_2) | |
13 | if letters in set(fraction_1): | |
14 | print(str(fraction_1).strip("['']"), 'is not a valid fraction. Ending program.') | |
15 | elif letters in set(fraction_2): | |
16 | print(str(fraction_2).strip("['']"), 'is not a valid fraction. Ending program.') | |
17 | elif fraction_1[1]==fraction_2[1]: | |
18 | same_denominator=(int(fraction_1[0])+int(fraction_2[0])) | |
19 | same_denominator=str(same_denominator) | |
20 | print(fraction_1[0]+"/"+fraction_1[1]+" + "+fraction_2[0]+"/"+fraction_2[1]+" = "+same_denominator+"/"+fraction_1[1]) | |
21 | elif fraction_1[1]!=fraction_2[1]: | |
22 | numerator=((int(fraction_1[0])*int(fraction_2[1]))+(int(fraction_2[0])*int(fraction_1[1]))) | |
23 | numerator=str(numerator) | |
24 | denominator=int(fraction_2[1])*int(fraction_1[1]) | |
25 | denominator=str(denominator) | |
26 | print(fraction_1[0]+"/"+fraction_1[1]+" + "+fraction_2[0]+"/"+fraction_2[1]+" = "+numerator+"/"+denominator) | |
27 | - | |
27 | + | |
28 | - | |
28 | + | try: |
29 | - | |
29 | + | frac_add() |
30 | - | |
30 | + | except NameError,e: |
31 | - | |
31 | + | print 'bad input' |