Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

calculator - i got set this coding task from my school and am having trouble doing the python code

https://www.101computing.net/entry-fees-calculator-using-a-flowchart/

I was trying to do the coding challenge my school sent me (link attached above) and I got quite stuck so I was hoping if someone could help. I was stuck when trying to add the discount calculating part because I had to see if the price was more than 50 and if it was, apply a 5% discount to it

def ThemePark():
    age = int(input('Enter age: '))
    if age <= 15:
        print("Your entry price is £11")
    if age >= 15:
        print("Your entry price is £13.50")
    if age >= 18:
        print("Your entry price is £15 ")
    discount = get_discount(price1 + price2 + price3)
    print_discount_message(discount)
    price > 50
    price1 = 11
    price2 = 13.50
    price3 = 15
    price > 50
    discountprice = calculate_discount_price(price, discount)
    print(f'  Your price: {discd} (original price: {price})')

def Discount(price):
    if price > 50:
        discount = 0.95
    else:
        discount = 0.0

    return discount

def print_discount_message(discount):
    if discount == 0.0:
        print('  Not qualified for family discount.')
    else:
        print('  Qualified for discount: {}%'.format(int(discount * 100)))

def calculate_discount_price(original_price, discount):
    return round(original_price - original_price * discount, 2)

if __name__ == '__main__':
    while True:
        ThemePark()
        more = input('Buy more? (Yes/No): ')
        if more != 'Yes':
            break
question from:https://stackoverflow.com/questions/65918600/i-got-set-this-coding-task-from-my-school-and-am-having-trouble-doing-the-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

def print_discount_message(discount): if discount == 0.0: print(' Not qualified for family discount.') else: print(' Qualified for discount: {}%'.format(int(discount * 100)))

To output the print(' Qualified for discount: {}%'.format(int(discount * 100))) you should have: print(' Qualified for discount: {}%'.format(int((1 - discount) * 100)))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...