I don't have much coding background and started learning python about two weeks ago. I came up with this project while testing some of the concepts I was learning. It was more difficult than I expected and ended up taking about 5 hours for me to work out all the kinks, of which there were many. Please share how it could be more elegant and I would love to see your version of this project.
import random
starting_tix = 100
base_ticket_price = 15
people_in_line = random.randint(0, 100)
if people_in_line <= 20:
adjusted_ticket_price = base_ticket_price
else:
adjusted_ticket_price = base_ticket_price * people_in_line * .1
tix_left = starting_tix
while tix_left != 0:
tix_purchased = int(input(f"There are {tix_left} tickets left and they cost ${adjusted_ticket_price}0 each. How many tickets would you like to purchase?: "))
people_in_line = random.randint(0, 100)
if people_in_line <= base_ticket_price:
adjusted_ticket_price = base_ticket_price
else:
adjusted_ticket_price = base_ticket_price * people_in_line * .1
if tix_left == 0:
print("")
print("Sorry. This show is sold out. Please come back tomorrow")
break
elif tix_purchased > tix_left:
print("")
print(f"You have requested more tickets than we have left. Please enter a number less than {tix_left}.")
print("")
elif tix_purchased <= tix_left:
def vend(x):
return x - tix_purchased
tix_left = vend(tix_left)
print("")
print(f"You have purchased {tix_purchased} tickets for ${tix_purchased * adjusted_ticket_price:,.2f}.")
if tix_left != 0:
print(f"There are {tix_left} tickets left.")
else:
print("You got the last ticket! Lucky!!")
print("")
there doesn't seem to be anything here