Python 编码问题的条件逻辑?

Python 编码问题的条件逻辑?,python,Python,如果用户输入“N”表示“否”,您将如何避免额外的50美元费用,而不要求计算表面积的高度和宽度,并继续执行代码的其余部分?请记住,我没有在代码后面写问题;如果用户键入“Y”表示“是”,则将添加50美元,程序将询问房间中每面墙的宽度和高度 total_surface_area = 0 number = int(input("Number of rooms to paint") print("\n***ROOM DETAILS***") for room in range(number): r

如果用户输入“N”表示“否”,您将如何避免额外的50美元费用,而不要求计算表面积的高度和宽度,并继续执行代码的其余部分?请记住,我没有在代码后面写问题;如果用户键入“Y”表示“是”,则将添加50美元,程序将询问房间中每面墙的宽度和高度

total_surface_area = 0
number = int(input("Number of rooms to paint")
print("\n***ROOM DETAILS***")
for room in range(number):
    room_name = input("\n\nPlease enter the name of the room:")
    wall_number = int(input("Number of walls in the room:"))
    wallpaper = input("\nWould you like to remove the paint? (Y for Yes/N for No). If yes, $50 will be charged per room:")

您可能太模糊了,我们无法确定您的问题最优雅的解决方案是什么,但我怀疑您在寻找
continue
break
语句。你可以找到一个解释

这可能说明了如何使用这两种语句:

total_surface_area = 0
# You were missing a parenthesis in the following line.
number = int(input("Number of rooms to paint"))
print("\n***ROOM DETAILS***")
for room in range(number):
    print('=== details of room number '+str(room)+' ===')
    room_name = input("\n\nPlease enter the name of the room:")
    wall_number = int(input("Number of walls in the room:"))

    print("\nWould you like to remove the paint? (Y for Yes/N for No). If yes, $50 will be charged per room:")
    while True:
        buffer = input()
        if buffer == 'Y':
            wallpaper = True
            break
        elif buffer == 'N':
            wallpaper = False
            break
        else:
            print('please anser "Y" or "N"')

    if wallpaper:
        print('I will now ask many more questions.......')
        # continue asking questions ...
    else:
        # move to the next room
        continue

这可能就是您正在寻找的:

from distutils.util import strtobool
total_surface_area = 0
extra_cost = 0
number = int(input("Number of rooms to paint")
print("\n***ROOM DETAILS***")
for room in range(number):
    room_name = input("\n\nPlease enter the name of the room:")
    wall_number = int(input("Number of walls in the room:"))
    wallpaper = input("\nWould you like to remove the paint? (Y for Yes/N for No). If yes, $50 will be charged per room:")
    if strtobool(wallpaper):
        extra_cost += 50
        dimensions = []
        for wall in range(wall_number):
            dimensions.append(input("Please input wall dimensions..."))

    ...

如果墙纸=='N'
是一个好的开始,那么在条件语句中输出它们<代码>如果墙纸='N':。。。elif墙纸=='Y':…??