0

I am attempting to get a correct input but whilst the input is false I want it to continually ask again until the output is correct, how do I correctly do this?

x = input("Enter your string")
if set(x).issubset({'m', 'u', 'i'}):
    print("true")
else:
    print("false")
    x = input("Enter your string")

2 Answers 2

5
while not set(input("Enter your string")).issubset({'m', 'u', 'i'}):
    print("false")
else:
    print("true")
Sign up to request clarification or add additional context in comments.

3 Comments

"just use the not operator and a while loop" might be worth adding to this answer since it is not immediately obvious.
Of course, that makes complete sense, is it common to create the true section in the else part of the statement?
I don't think it is uncommon, really. Thinking of it, it is just a condition. You can negate it to invert True or False. In fact, the not is not needed here, you could have the print("true") in the if and the other branch in the else. It is just a matter of readability / preference.
1

This should do also:

while not set(input("Enter your string")).issubset({'m', 'u', 'i'}):
    print("false")
print("true")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.