diff --git a/5/5.12/5.12.1/main.py b/5/5.12/5.12.1/main.py new file mode 100644 index 0000000..f55733f --- /dev/null +++ b/5/5.12/5.12.1/main.py @@ -0,0 +1,9 @@ + +def swap(list): + m_list = list[0], list[-1] = list[-1], list[0] + return m_list + +values_list = input().split(',') # Program receives comma-separated values like 5,4,12,19 +swap(values_list) + +print(values_list) diff --git a/5/5.17/5.17.1/main.py b/5/5.17/5.17.1/main.py new file mode 100644 index 0000000..f033cf5 --- /dev/null +++ b/5/5.17/5.17.1/main.py @@ -0,0 +1,12 @@ +gas_const = 8.3144621 + +def compute_gas_volume(pressure, temperature, moles): + return (moles * gas_const * temperature) / pressure + +gas_pressure = float(input()) +gas_moles = float(input()) +gas_temperature = float(input()) +gas_volume = 0.0 + +gas_volume = compute_gas_volume(gas_pressure, gas_temperature, gas_moles) +print('Gas volume:', gas_volume, 'm^3') diff --git a/5/5.18 LAB/main.py b/5/5.18 LAB/main.py new file mode 100644 index 0000000..4af0071 --- /dev/null +++ b/5/5.18 LAB/main.py @@ -0,0 +1,6 @@ +def swap_values(user_val1, user_val2): + return user_val2, user_val1 + +if __name__ == '__main__': + val1, val2 = swap_values(input(), input()) + print('{0} {1}'.format(val1, val2)) diff --git a/5/5.19 LAB/main.py b/5/5.19 LAB/main.py new file mode 100644 index 0000000..b27f4fb --- /dev/null +++ b/5/5.19 LAB/main.py @@ -0,0 +1,46 @@ +coins = [ + ['Dollars', 'Dollar'], + ['Quarters', 'Quarter'], + ['Dimes', 'Dime'], + ['Nickels', 'Nickel'], + ['Pennies', 'Penny']] + +def coin_enumeration(change): + if len(change) != 0: + for coin in coins: + num_coins = change.count(coin) + if num_coins != 0: + if num_coins > 1: + print('{0} {1}'.format(num_coins, coin[0].lower())) + else: + print('{0} {1}'.format(num_coins, coin[1].lower())) + else: + print('no change') + +def fit_coin(to_make, coin_val): + num_coin = to_make // coin_val + remainder = to_make - (num_coin * coin_val) + + return num_coin, remainder + +def exact_change(input_val): + nd, input_val = fit_coin(input_val, 100) + nq, input_val = fit_coin(input_val, 25) + ndime, input_val = fit_coin(input_val, 10) + nn, input_val = fit_coin(input_val, 5) + np, input_val = fit_coin(input_val, 1) + + return nd, nq, ndime, nn, np + +if __name__ == '__main__': + change = [] + input_val = int(input()) + num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val) + + change.extend([coins[0] for i in range(num_dollars)]) + change.extend([coins[1] for i in range(num_quarters)]) + change.extend([coins[2] for i in range(num_dimes)]) + change.extend([coins[3] for i in range(num_nickels)]) + change.extend([coins[4] for i in range(num_pennies)]) + + coin_enumeration(change) diff --git a/5/5.3/5.3.2/main.py b/5/5.3/5.3.2/main.py new file mode 100644 index 0000000..23f68f6 --- /dev/null +++ b/5/5.3/5.3.2/main.py @@ -0,0 +1,19 @@ +def find_max(num_1, num_2): + max_val = 0.0 + + if (num_1 > num_2): # if num1 is greater than num2, + max_val = num_1 # then num1 is the maxVal. + else: # Otherwise, + max_val = num_2 # num2 is the maxVal + return max_val + +max_sum = 0.0 + +num_a = float(input()) +num_b = float(input()) +num_y = float(input()) +num_z = float(input()) + +max_sum = sum([max([num_a, num_b]), max([num_y, num_z])]) + +print('max_sum is:', max_sum) diff --git a/5/5.3/5.3.3/main.py b/5/5.3/5.3.3/main.py new file mode 100644 index 0000000..5898043 --- /dev/null +++ b/5/5.3/5.3.3/main.py @@ -0,0 +1,9 @@ + +def pyramid_volume(base_length, base_width, pyramid_height): + return(((base_length * base_width) * pyramid_height) * (1/3)) + + +length = float(input()) +width = float(input()) +height = float(input()) +print('Volume for 4.5, 2.1, 3.0 is:', pyramid_volume(length, width, height)) diff --git a/5/5.5/5.5.1/main.py b/5/5.5/5.5.1/main.py new file mode 100644 index 0000000..da6cd17 --- /dev/null +++ b/5/5.5/5.5.1/main.py @@ -0,0 +1,8 @@ + +def mph_and_minutes_to_miles(mph, dt): + return (dt / 60) * mph + +miles_per_hour = float(input()) +minutes_traveled = float(input()) + +print('Miles: {:f}'.format(mph_and_minutes_to_miles(miles_per_hour, minutes_traveled))) diff --git a/5/5.6/5.6.1/main.py b/5/5.6/5.6.1/main.py new file mode 100644 index 0000000..c066bca --- /dev/null +++ b/5/5.6/5.6.1/main.py @@ -0,0 +1,22 @@ + +def get_user_num(): + # This is bad practice, you should use python ABC or raise NotImplementedError instead. + print('FIXME: Finish get_user_num()') + return -1 + #raise NotImplementedError + +def compute_avg(user_num1, user_num2): + # This is bad practice, you should use python ABC or raise NotImplementedError instead. + print('FIXME: Finish compute_avg()') + return -1 + #raise NotImplementedError + +user_num1 = 0 +user_num2 = 0 +avg_result = 0 + +user_num1 = get_user_num() +user_num2 = get_user_num() +avg_result = compute_avg(user_num1, user_num2) + +print('Avg:', avg_result) diff --git a/5/5.7/5.7.1/main.py b/5/5.7/5.7.1/main.py new file mode 100644 index 0000000..98e578f --- /dev/null +++ b/5/5.7/5.7.1/main.py @@ -0,0 +1,12 @@ + +def print_popcorn_time(bag_ounces): + if bag_ounces < 3: + print('Too small') # This should be returned instead. + elif bag_ounces > 10: + print('Too large') # This should be returned instead. + else: + print('{0} seconds'.format(6 * bag_ounces)) # This should be returned instead. + + +user_ounces = int(input()) +print_popcorn_time(user_ounces) diff --git a/5/5.7/5.7.2/main.py b/5/5.7/5.7.2/main.py new file mode 100644 index 0000000..fbc4acb --- /dev/null +++ b/5/5.7/5.7.2/main.py @@ -0,0 +1,13 @@ + +def shampoo_instructions(num_cycles): + if num_cycles < 1: + print('Too few.') + elif num_cycles > 4: + print('Too many.') + else: + for i in range(num_cycles): + print('{0} : Lather and rinse.'.format(i + 1)) + print('Done.') + +user_cycles = int(input()) +shampoo_instructions(user_cycles)