0
flag=False
if color1=="blue":
    color2=input("Do you want to mix red or yellow with blue?")
    color2=color2.lower()
    while flag==False:
        if color2=="red" or color2=="yellow":
            flag = True
        else:
            color2=input("That is not a valid choice. Enter either red or yellow to mix\ with", color1)
    if color2=="red":
        print("The color you made is purple")
    else:
        print("The color you made is green")
flag=False
elif color1=="red":
    color2=input("Do you want to mix blue or yellow with red?")
    color2=color2.lower()
    while flag==False:
        if color2=="blue" or color2=="yellow":
            flag = True
        else:
            color2=input("That is not a valid choice. Enter either blue or yellow to\ mix with", color1)

我在“elif color1=="red":”那行中间的一个 elif 语句出现问题。只是为了获得一些上下文,这是一个简单的程序,它将混合三种原色。

4

1 回答 1

3

假设您的程序中的缩进与您的问题中出现的缩进相同,那么flag=False紧接在前面的行elif需要缩进,否则解析器会认为您已经离开了该if块,而实际上您没有。

于 2013-10-28T03:19:32.487 回答