Danh sách mua hàng trong Bài tập Python

Tài nguyên cho phiên bản thứ hai có tại đây. Tôi muốn biết suy nghĩ của bạn về Python Crash Course; . Nếu bạn muốn biết khi nào có thêm tài nguyên, bạn có thể đăng ký nhận thông báo qua email tại đây

Quay lại giải pháp

Ghi chú. Sublime Text không chạy các chương trình nhắc người dùng nhập liệu. Bạn có thể sử dụng Sublime Text để viết chương trình nhắc nhập liệu, nhưng bạn sẽ cần chạy các chương trình này từ thiết bị đầu cuối. Xem “Chạy chương trình Python từ thiết bị đầu cuối” ở trang 16

7-1. Ôtô cho thuê

Viết chương trình hỏi người dùng muốn thuê loại xe nào. In một tin nhắn về chiếc xe đó, chẳng hạn như “Để tôi xem liệu tôi có thể tìm cho bạn một chiếc Subaru không”

car = input["What kind of car would you like? "]

print["Let me see if I can find you a " + car.title[] + "."]

đầu ra

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.

đứng đầu

7-2. Chỗ ngồi nhà hàng

Viết chương trình hỏi người dùng có bao nhiêu người trong nhóm ăn tối của họ. Nếu câu trả lời nhiều hơn tám, hãy in một thông báo nói rằng họ sẽ phải chờ bàn. Nếu không, báo cáo rằng bàn của họ đã sẵn sàng

party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]

đầu ra

How many people are in your dinner party tonight? 12
I'm sorry, you'll have to wait for a table.

hoặc là

How many people are in your dinner party tonight? 6
Your table is ready.

đứng đầu

7-3. bội số của mười

Yêu cầu người dùng cung cấp một số, sau đó báo cáo xem số đó có phải là bội số của 10 hay không

number = input["Give me a number, please: "]
number = int[number]

if number % 10 == 0:
    print[str[number] + " is a multiple of 10."]
else:
    print[str[number] + " is not a multiple of 10."]

đầu ra

Give me a number, please: 23
23 is not a multiple of 10.

hoặc là

Give me a number, please: 90
90 is a multiple of 10.

đứng đầu

7-4. bánh pizza

Viết một vòng lặp nhắc người dùng nhập một loạt lớp phủ bánh pizza cho đến khi họ nhập giá trị

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
8. Khi họ nhập từng topping, hãy in một thông báo nói rằng bạn sẽ thêm topping đó vào bánh pizza của họ

prompt = "\nWhat topping would you like on your pizza?"
prompt += "\nEnter 'quit' when you are finished: "

while True:
    topping = input[prompt]
    if topping != 'quit':
        print["  I'll add " + topping + " to your pizza."]
    else:
        break

đầu ra

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
0

đứng đầu

7-5. Vé xem phim

Một rạp chiếu phim tính giá vé khác nhau tùy thuộc vào độ tuổi của một người. Nếu là người dưới 3 tuổi thì miễn phí vé; . Viết một vòng lặp trong đó bạn hỏi tuổi của người dùng, sau đó cho họ biết giá vé xem phim của họ

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
0

đầu ra

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
1

đứng đầu

7-8. đồ nguội

Tạo một danh sách có tên là

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
9 và điền vào đó tên của các loại bánh mì khác nhau. Sau đó, tạo một danh sách trống có tên là
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
0. Lặp lại danh sách các đơn đặt hàng bánh sandwich và in một thông báo cho mỗi đơn hàng, chẳng hạn như
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
1 Khi mỗi chiếc bánh mì được làm xong, hãy di chuyển nó vào danh sách các bánh mì đã hoàn thành. Sau khi tất cả các bánh mì đã được làm xong, hãy in một thông báo liệt kê từng bánh mì đã được làm

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
2

đầu ra

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
3

đứng đầu

7-9. Không Pastrami

Sử dụng danh sách

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
9 từ Bài tập 7-8, đảm bảo bánh sandwich
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
3 xuất hiện trong danh sách ít nhất ba lần. Thêm mã gần đầu chương trình của bạn để in thông báo cho biết cửa hàng bán đồ nguội đã hết món pastrami, sau đó sử dụng vòng lặp
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
4 để loại bỏ tất cả các lần xuất hiện của
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
3 khỏi
What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
9. Đảm bảo không có bánh mì pastrami nào kết thúc ở
party_size = input["How many people are in your dinner party tonight? "]
party_size = int[party_size]

if party_size > 8:
    print["I'm sorry, you'll have to wait for a table."]
else:
    print["Your table is ready."]
7

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
4

đầu ra

What kind of car would you like? Toyota Tacoma
Let me see if I can find you a Toyota Tacoma.
5

đứng đầu

Viết chương trình thăm dò ý kiến ​​người dùng về kỳ nghỉ mơ ước của họ. Viết một lời nhắc tương tự như Nếu bạn có thể đến thăm một nơi trên thế giới, bạn sẽ đi đâu?

Chủ Đề