My professor is very strict about coding style and making sure everything looks nice and readable. The homework he gave us was to make a script taking multiple inputs from the user for like an item_description, price_per_unit, and Tax_rate. My question is, is okay to put the main function at the bottom of the script or does it not matter, and if someone could just check my code and let me know if there are things i could do better.
def get_retail_item_description(): return input("Enter retail item description: ") def get_num_of_items_purchased(): return int(input("Enter Quantity purchased: ")) def get_price_usd_per_unit(): return float(input("Enter price per unit is USD: ")) def get_tax_rate(): tax = int(input("Enter Tax rate in percentage: ")) tax/=100 return tax def calculate_subtotal_usd(price_per_unit, quantity): return price_per_unit * quantity def calculate_tax_usd(subtotal, tax_rate): return subtotal * tax_rate def calculate_total_usd(subtotal, tax_amount): return subtotal + tax_amount def main(): item_desc = get_retail_item_description() quantity = get_num_of_items_purchased() price_per_unit = get_price_usd_per_unit() tax_rate = get_tax_rate() subtotal = calculate_subtotal_usd(price_per_unit, quantity) tax_amount = calculate_tax_usd(subtotal, tax_rate) total = calculate_total_usd(subtotal, tax_amount) print("Sales Receipt:") print(item_desc) print(quantity) print(price_per_unit) print(tax_rate) print(subtotal) print(tax_amount) print(total) if __name__ == "__main__": main()
submitted by /u/Killjoy092
[link] [comments]
r/learnpython My professor is very strict about coding style and making sure everything looks nice and readable. The homework he gave us was to make a script taking multiple inputs from the user for like an item_description, price_per_unit, and Tax_rate. My question is, is okay to put the main function at the bottom of the script or does it not matter, and if someone could just check my code and let me know if there are things i could do better. def get_retail_item_description(): return input(“Enter retail item description: “) def get_num_of_items_purchased(): return int(input(“Enter Quantity purchased: “)) def get_price_usd_per_unit(): return float(input(“Enter price per unit is USD: “)) def get_tax_rate(): tax = int(input(“Enter Tax rate in percentage: “)) tax/=100 return tax def calculate_subtotal_usd(price_per_unit, quantity): return price_per_unit * quantity def calculate_tax_usd(subtotal, tax_rate): return subtotal * tax_rate def calculate_total_usd(subtotal, tax_amount): return subtotal + tax_amount def main(): item_desc = get_retail_item_description() quantity = get_num_of_items_purchased() price_per_unit = get_price_usd_per_unit() tax_rate = get_tax_rate() subtotal = calculate_subtotal_usd(price_per_unit, quantity) tax_amount = calculate_tax_usd(subtotal, tax_rate) total = calculate_total_usd(subtotal, tax_amount) print(“Sales Receipt:”) print(item_desc) print(quantity) print(price_per_unit) print(tax_rate) print(subtotal) print(tax_amount) print(total) if __name__ == “__main__”: main() submitted by /u/Killjoy092 [link] [comments]
My professor is very strict about coding style and making sure everything looks nice and readable. The homework he gave us was to make a script taking multiple inputs from the user for like an item_description, price_per_unit, and Tax_rate. My question is, is okay to put the main function at the bottom of the script or does it not matter, and if someone could just check my code and let me know if there are things i could do better.
def get_retail_item_description(): return input("Enter retail item description: ") def get_num_of_items_purchased(): return int(input("Enter Quantity purchased: ")) def get_price_usd_per_unit(): return float(input("Enter price per unit is USD: ")) def get_tax_rate(): tax = int(input("Enter Tax rate in percentage: ")) tax/=100 return tax def calculate_subtotal_usd(price_per_unit, quantity): return price_per_unit * quantity def calculate_tax_usd(subtotal, tax_rate): return subtotal * tax_rate def calculate_total_usd(subtotal, tax_amount): return subtotal + tax_amount def main(): item_desc = get_retail_item_description() quantity = get_num_of_items_purchased() price_per_unit = get_price_usd_per_unit() tax_rate = get_tax_rate() subtotal = calculate_subtotal_usd(price_per_unit, quantity) tax_amount = calculate_tax_usd(subtotal, tax_rate) total = calculate_total_usd(subtotal, tax_amount) print("Sales Receipt:") print(item_desc) print(quantity) print(price_per_unit) print(tax_rate) print(subtotal) print(tax_amount) print(total) if __name__ == "__main__": main()
submitted by /u/Killjoy092
[link] [comments]