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

How to check if a user inputted string meets requirements

I’m extremely new to coding/python and I need to check if the user of the program is a member of an organization. This is part of a bigger program but this is what I have so far:

member = str(input("Enter your membership status, y or n: "))
elif member == y:
    print ("You are a member")
elif member == n:
    print("You need a membership")

How do I just check if the user is a member and not print anything and if they’re not a member print that they need a membership?

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

>Solution :

Use this code:

member = str(input("Enter your membership status, y or n: "))
if member == 'y':
    print ("You are a member")
elif member == 'n':
    print("You need a membership")
  1. since your member variable is having string content, you need to put the values of string in quotes in your if condition member == 'y'.
  2. when checking the condition, first you need to start with if instead of elif.
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