|
| 1 | +''' |
| 2 | +Lab 1 |
| 3 | +Unit Converter |
| 4 | +''' |
| 5 | +# def for version 1 -3 !!!!!!!!! <--------- |
| 6 | + |
| 7 | +# def meters_to_feet(x): |
| 8 | +# converted_ft = x * .3048 #### all function names are backwards meters_to_feet is feet_to_meters.. ect |
| 9 | +# return converted_ft |
| 10 | + |
| 11 | +# # print(meters_to_feet(10)) |
| 12 | + |
| 13 | +# def meters_to_mile(x): |
| 14 | +# converted_mi = x * 1609.34 |
| 15 | +# return converted_mi |
| 16 | + |
| 17 | +# def meters_to_km(x): |
| 18 | +# converted_km = x * 1000 |
| 19 | +# return converted_km |
| 20 | + |
| 21 | +# def meters_to_yard(x): |
| 22 | +# converted_yd = x * .9144 |
| 23 | +# return converted_yd |
| 24 | + |
| 25 | +# def meters_to_inch(x): |
| 26 | +# converted_in = x * .0254 |
| 27 | +# return converted_in |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +# print(meters_to_feet(10)) # 3.048 |
| 32 | + |
| 33 | +# --- Version 1 |
| 34 | +''' |
| 35 | +
|
| 36 | +feet = int(input("enter the distance you wish to convert to meters: ")) |
| 37 | +print(f'\n {feet}ft is {meters_to_feet(feet)}m') # 10ft is [3.048]m # need to remove brackets |
| 38 | +''' |
| 39 | +# --- Version 2 |
| 40 | + |
| 41 | +''' |
| 42 | +
|
| 43 | +distance = int(input('Enter the total distance: ')) |
| 44 | +units = input('Enter the units you wish to convert to meters (mi, km, ft) ') |
| 45 | +converted_output = [] |
| 46 | +
|
| 47 | +if units.lower() == 'mi': |
| 48 | + converted_output = meters_to_mile(distance) |
| 49 | + print(f'\n {distance}mi is {converted_output}m') |
| 50 | +elif units.lower() == 'km': |
| 51 | + converted_output = meters_to_km(distance) |
| 52 | + print(f'\n {distance}km is {converted_output}m') |
| 53 | +elif units.lower() == 'ft': |
| 54 | + converted_output = meters_to_feet(distance) |
| 55 | + print(f'\n {distance}ft is {converted_output}m') |
| 56 | +else: |
| 57 | + print('Did not reconize input') |
| 58 | +
|
| 59 | +''' |
| 60 | + |
| 61 | +# --- Version 3 |
| 62 | + |
| 63 | +''' |
| 64 | +
|
| 65 | +# distance = int(input('Enter the total distance: ')) |
| 66 | +# units = input('Enter the units you wish to convert to meters (mi, km, ft, in or yd) ') |
| 67 | +# converted_output = [] |
| 68 | +
|
| 69 | +# if units.lower() == 'mi': |
| 70 | +# converted_output = meters_to_mile(distance) |
| 71 | +# print(f'\n {distance}mi is {converted_output}m') |
| 72 | +# elif units.lower() == 'km': |
| 73 | +# converted_output = meters_to_km(distance) |
| 74 | +# print(f'\n {distance}km is {converted_output}m') |
| 75 | +# elif units.lower() == 'ft': |
| 76 | +# converted_output = meters_to_feet(distance) |
| 77 | +# print(f'\n {distance}ft is {converted_output}m') |
| 78 | +# elif units.lower() == 'in': |
| 79 | +# converted_output = meters_to_inch(distance) |
| 80 | +# print(f'\n {distance}in is {converted_output}m') |
| 81 | +# elif units.lower() == 'yd': |
| 82 | +# converted_output = meters_to_yard(distance) |
| 83 | +# print(f'\n {distance}yd is {converted_output}m') |
| 84 | +
|
| 85 | +''' |
| 86 | + |
| 87 | +# --- Version 4 |
| 88 | + |
| 89 | +# !!!!!!!!!!!!!!!!!!!!!! functions only for version 4 !!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 90 | +def feet_to_meters(x): |
| 91 | + converted_ft = x * .3048 |
| 92 | + return converted_ft |
| 93 | + |
| 94 | +def mile_to_meters(x): |
| 95 | + converted_mi = x * 1609.34 |
| 96 | + return converted_mi |
| 97 | + |
| 98 | +def km_to_meters(x): |
| 99 | + converted_km = x * 1000 |
| 100 | + return converted_km |
| 101 | + |
| 102 | +def meters_to_feet(x): |
| 103 | + converted_ft = x * 3.28084 |
| 104 | + return converted_ft |
| 105 | + |
| 106 | +def meters_to_mile(x): |
| 107 | + converted_mi = x * .000621371 |
| 108 | + return converted_mi |
| 109 | + |
| 110 | +def meters_to_km(x): |
| 111 | + converted_km = x * .001 |
| 112 | + return converted_km |
| 113 | + |
| 114 | + |
| 115 | +distance = int(input('Enter the total distance: ')) |
| 116 | +units = input('Enter the units you are using (mi, km, ft, m) ') |
| 117 | +units_to_convert = input('Enter the units you wish to convert to (mi, km, ft, m) ') |
| 118 | + |
| 119 | +if units.lower() == 'mi'and units_to_convert.lower() == 'km': |
| 120 | + converted_output = meters_to_km(mile_to_meters(distance)) |
| 121 | + print(f'\n {distance}mi is {converted_output}km') |
| 122 | + |
| 123 | +elif units.lower() == 'mi'and units_to_convert.lower() == 'm': |
| 124 | + converted_output = mile_to_meters(distance) |
| 125 | + print(f'\n {distance}mi is {converted_output}m') |
| 126 | + |
| 127 | +elif units.lower() == 'mi'and units_to_convert.lower() == 'ft': |
| 128 | + converted_output = meters_to_feet(mile_to_meters(distance)) |
| 129 | + print(f'\n {distance}mi is {converted_output}ft') |
| 130 | + |
| 131 | +elif units.lower() == 'km'and units_to_convert.lower() == 'mi': |
| 132 | + converted_output = meters_to_mile(km_to_meters(distance)) |
| 133 | + print(f'\n {distance}km is {converted_output}mi') |
| 134 | + |
| 135 | +elif units.lower() == 'km'and units_to_convert.lower() == 'm': |
| 136 | + converted_output = km_to_meters(distance) |
| 137 | + print(f'\n {distance}km is {converted_output}m') |
| 138 | + |
| 139 | +elif units.lower() == 'km'and units_to_convert.lower() == 'ft': |
| 140 | + converted_output = meters_to_feet(km_to_meters(distance)) |
| 141 | + print(f'\n {distance}km is {converted_output}ft') |
| 142 | + |
| 143 | +elif units.lower() == 'ft'and units_to_convert.lower() == 'mi': |
| 144 | + converted_output = mile_to_meters(feet_to_meters(distance)) |
| 145 | + print(f'\n {distance}ft is {converted_output}mi') |
| 146 | + |
| 147 | +elif units.lower() == 'ft'and units_to_convert.lower() == 'm': |
| 148 | + converted_output = feet_to_meters(distance) |
| 149 | + print(f'\n {distance}ft is {converted_output}m') |
| 150 | + |
| 151 | +elif units.lower() == 'ft'and units_to_convert.lower() == 'km': |
| 152 | + converted_output = meters_to_km(feet_to_meters(distance)) |
| 153 | + print(f'\n {distance}mi is {converted_output}ft') |
| 154 | + |
| 155 | +elif units.lower() == 'm'and units_to_convert.lower() == 'ft': |
| 156 | + converted_output = meters_to_feet(distance) |
| 157 | + print(f'\n {distance}km is {converted_output}ft') |
| 158 | + |
| 159 | +elif units.lower() == 'm'and units_to_convert.lower() == 'mi': |
| 160 | + converted_output = meters_to_mile(distance) |
| 161 | + print(f'\n {distance}ft is {converted_output}mi') |
| 162 | + |
| 163 | +elif units.lower() == 'm'and units_to_convert.lower() == 'km': |
| 164 | + converted_output = meters_to_km |
| 165 | + print(f'\n {distance}mi is {converted_output}ft') |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
0 commit comments