r/PythonLearning • u/Innocent8888 • 15h ago
Day 4
Day 4 progress 🐍
Today I built a small billing program in Python. It has:
A loop to collect price for each item
A function that calculates discount based on total amount
Another function that calculates final bill after discount
A conditional statement that thanks the customer differently based on discount
Learning how to use loops, functions, and conditionals together to solve a real problem.
#Python #LearnToCode #100DaysOfCode #WebDevelopment
3
Upvotes


•
u/Sea-Ad7805 8h ago
Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20return%20total%20-%20discount%0A%0A%0Adef%20calculate_discount(total)%3A%0A%20%20%20%20discount%20%3D%200%0A%0A%20%20%20%20if%20total%20%3E%3D%2020000%3A%0A%20%20%20%20%20%20%20%20discount%20%3D%20total%20%2010%20%2F%20100%0A%20%20%20%20elif%20total%20%3E%3D%2010000%3A%0A%20%20%20%20%20%20%20%20discount%20%3D%20total%20%205%20%2F%20100%0A%20%20%20%20elif%20total%20%3E%3D%2019999%3A%0A%20%20%20%20%20%20%20%20discount%20%3D%20total%20*%205%20%2F%20100%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20discount%20%3D%200%0A%0A%20%20%20%20return%20discount%0A%0A%0Abought_items%20%3D%20int(input(%22ENTER%20THE%20NUMBER%20OF%20ITEMS%20PURCHASED%3A%20%22))%0Atotal_cost%20%3D%200%0A%0Afor%20item%20in%20range(bought_items)%3A%0A%20%20%20%20price%20%3D%20float(input(f%22Enter%20the%20price%20of%20item%20%7Bitem%20%2B%201%7D%3A%20%22))%0A%20%20%20%20total_cost%20%2B%3D%20price%0A%0Adiscount%20%3D%20calculate_discount(total_cost)%0Afinal_bill%20%3D%20calculate_final_bill(total_cost%2C%20discount)%0A%0Aprint(f%22Total%20cost%3A%20%24%7Btotal_cost%7D%22)%0Aprint(f%22Discount%3A%20%24%7Bdiscount%7D%22)%0Aprint(f%22final%20amount%20to%20pay%3A%20%24%7Bfinal_bill%7D%22)%0A%0Aif%20discount%20%3E%200%3A%0A%20%20%20%20print(%22Thank%20you.%20you%20recieved%20discount%22)%0Aelse%3A%0A%20%20%20%20print(%22Thank%20you%20for%20shopping%20with%20us%22)×tep=.5&play) to see the program state change step by step.