Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program: shirt order
#4
since available is True, while available in this case evaluates to while True.
But since it's a variable, the same holds for available = False, i.e. 'while False'

This gives you control over how the while loop interprets the condition.
Change the variable, you have changed the condition.

Quote: while not available" in this case means True since we have "available = False", right
That is correct! so the condition 'while not available' means I want to continue this loop while 'not available' is True.

Quote:When adding some third color I first receive Choose size input. Is there any way to avoid this? To get "Please choose the correct color!" immediately if I, for example, type in green colour?

Yes, you're in control, you can do whatever you wish!

In this case you want to use a function:
example:

def choose_item():
    color = size = None
    color = input("Choose color between white and blue: ")
    if color != 'quit':
        size = input("Choose size: ")
    return color, size


def check_if_available(color, size):
    if  ((color == 'white' and
        (size == 'M' or size == 'L')) or
        (color == 'blue' and
        (size == 'M' or size == 'S'))):
        return True
    else:
        return False

def myControl():
    while True:
        color, size = choose_item()
        if color == 'quit':
            break
        if check_if_available(color, size):
            print('Available')
        else:
            print('Not available')

if __name__ == '__main__':
    myControl()
Reply


Messages In This Thread
Program: shirt order - by Truman - Jan-17-2018, 11:22 PM
RE: Program: shirt order - by Larz60+ - Jan-18-2018, 02:02 AM
RE: Program: shirt order - by Truman - Jan-18-2018, 10:18 PM
RE: Program: shirt order - by Larz60+ - Jan-18-2018, 10:47 PM
RE: Program: shirt order - by Truman - Jan-18-2018, 11:13 PM
RE: Program: shirt order - by Larz60+ - Jan-19-2018, 12:00 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020