Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reduce a while-loop condition – python

I’m trying to create a constraint so that the "lettera" input variable is a letter of the alphabet between a and h on this code *1 but I think there’s a better way to write the condition for the loop.

Thanks if someone could help me figuring out how re-write it smaller.

*1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

while (lettera != 'a' and lettera != 'b' and lettera != 'c' and lettera != 'd' and lettera != 'e' and lettera != 'f' and lettera != 'g' and lettera != 'h'):
    lettera= input('Inserisci un valore lettera a-h ')

>Solution :

while lettera not in 'abcdefgh':
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading