การใช้ if elif while python ค่ะ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

Mind Mild
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 03/11/2019 8:13 am

การใช้ if elif while python ค่ะ

โพสต์ที่ยังไม่ได้อ่าน โดย Mind Mild »

โค้ด: เลือกทั้งหมด

print("Welcome to Ticketing System")
name = (input("Enter your name : "))

height = (input("Enter your height (cm) : "))

age = int(input("Enter your age : "))

if age == 0:
    print("Please enter your age again")
    age = int(input("Enter your age : "))
if age >= 100:
    print("Please enter your age again")
    age = int(input("Enter your age : "))
if age <= 12:
    print("Your ticket price : 60 Baht")
elif age >= 13:
    print("Your ticket price : 120 Baht")

pay = int(input("Payment amount : "))

if pay < 60:
    print("Please enter your payment again")
    cost = int(input("Payment amount : "))

change = int(pay) - 60
print("Your change : " + str(change) + " Baht")

while (change > 0):
    if change // 1000 >= 1:
        print("Change 1000 Baht : " + str(change // 1000),"Cash")
        change %= 1000
    elif change // 500 >= 1:
        print("Change 500 Baht : " + str(change // 500),"Cash")
        change %= 500
    elif change // 100 >= 1:
        print("Change 100 Baht : " + str(change // 100),"Cash")
        change %= 100
    elif change // 50 >= 1:
        print("Change 50 Baht : " + str(change // 50),"Cash")
        change %= 50
    elif change // 20 >= 1:
        print("Change 20 Baht : " + str(change // 20),"Cash")
        change %= 20
    elif change // 10 >= 1:
        print("Change 10 Baht : " + str(change // 10),"Coin")
        change %= 10
    elif change // 5 >= 1:
        print("Change 5 Baht : " + str(change // 5),"Coin")
        change %= 5
    elif change // 2 >= 1:
        print("Change 2 Baht : " + str(change // 2),"Cash")
        change %= 2
    elif change // 1 >= 1:
        print("Change 1 Baht : " + str(change // 1),"Cash")
        change %= 1
        break
    pay = int(input("Payment amount : "))
เป็นโปรแกรมขายตั๋ว โดยมี 2 ราคา แยกจากอายุค่ะ 1-12 = 60 บาท , 13-99 = 120 บาท แล้วก็มีเงินทอนค่ะ

คือว่าพอลองรัน แล้วใส่ค่าอายุเป็น >= 13 มันจะไปคิดตรงเงินทอนของราคาเด็ก 60 บาทอะค่ะ (ควรจะคิดราคา 120 บาท ลองใช้ break ใน while
แล้วใส่คำสั่งเพิ่มเข้าไปก็ไม่ได้ค่ะ)

รบกวนช่วยดูให้หน่อยนะคะ ขอบคุณค่ะ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41363
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: การใช้ if elif while python ค่ะ

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

มีสมาชิกมาแนะนำให้แล้วในนี้
viewtopic.php?f=16&t=61708
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 99