r/learnpython • u/Good_Unit7202 • Sep 23 '26
Hi guys, im pretty new to programming and i am looking for feedback..
So as i said in the title, im new to python (Literally installed it today) and i have written this program:
print("WELCOME TO THE GRAND SALE")
name = input("Please enter name: ")
mem_code = input("Enter Membership Code: ")
while True:
a = input("Enter amount spent: ")
try:
amt = float(a)
break
except ValueError:
print("Enter a valid amount")
while True:
b = input("What is your subscription level (Bronze/Silver/Gold/Platinum/Diamond)? ").strip().lower()
if b not in ["bronze","silver","gold","platinum","diamond"]:
print("Enter a valid subscription")
elif b in ["bronze"]:
d = 0.05
break
elif b in ["silver"]:
d = 0.10
break
elif b in ["gold"]:
d = 0.15
break
elif b in ["platinum"]:
d = 0.20
break
elif b in ["diamond"]:
d = 0.25
break
total = amt - amt*d
gst = total * 0.18
print(f"Welcome {name}")
print(f"Membership code: {mem_code}")
print(f"Amount: ${amt:.2f}")
print(f"Discount: {(int)(d*100)} %")
print(f"Taxable total: {total:.2f}")
print(f"GST (18%): ${gst:.2f}")
print(f"To pay: {(total + gst):.2f}")
It's basically a very simple discount calculator.. Any feedback and tips would be greatly appreciated.
Thanks!
0
Upvotes
3
u/Riegel_Haribo Sep 23 '26
You ask questions that have no point.
You can use a data object called a dict, where you can look up the value that is indexed by a string.
Then use one of a string's built-in methods to remove any extra spaces around the text.
1
u/TheRNGuy Sep 24 '26
Why do many empty lines?
Last 2 lines would be Syntax error.
Use dict instead of many if's / elif's.
1
u/el_farmerino Sep 23 '26
Good start, I would recommend as a next step looking into how you can use a dictionary to store the subscription levels and their respective discount values.
1
u/Puppydog04 Sep 23 '26
Variables should have descriptive names.
1
u/Jazzlike_Platypus430 Sep 23 '26
First off, I would organize subscriptions and d's (discounts?) in a dictionary, to avoid the if/elif...elif ladder hell.
Both loops should allow for some user's exit, in a nicer way than pressing Ctrl-C. Checking if amt > 0 seems sensible.
Also, name the variables with what they mean, amt -> amount, d -> discount.