In this section we learn about the python if condition with using not. It is also called python if not. Mostly not condition use in while loop and for loop. In some case not condition is also use with if condition. If you dont know about while Loop and for Loop then visit our loop section. Mostly programmer use < ,> and == condition with if in python. For some case need to use in ,not, is in this case lots of beginner python programmer has been confused. Remember than the is not in always print boolen value means if true than print true iof false than print false.Â
python if not |
python is not in.
is not in is a condition mustly use in whhile loop for some case use in if condition. IS is define as (a = 5 or a is 5) difference in a = 5 that is gives 5 value to a and a is 5 is the value of a is 5. a has is own value 5.
In is define as the a = 2, a==2 and a in 2 difference in the 2 value is asssign to a and a==2 is a is equal to 2 or not here a is 2 and a and 2 is equal al last. a in 2 is the value of 2 is exist or not in a if a = 2 than true than a = 3 than false. in here a = 2 than a in 2 is true
Not is define as the the condition that use as is not or not in . Example a = 10 if a is not 10 her a is 10 and print false and if a is not 11 than print true because a = 10 not a 11. Now define the not in if a = 3, 4,5 than a not in 7 than print true if a not in 3,4 than print false.
This python is not in case is confusing problem for beginner. IN this section we will see the example of not in and is not, other is and in other section.
is notÂ
#codebugfree.com
print("Welcome to join the codebugfree societ ")
print("You will be first verify your age and name")
joining_age = 22 #only joining the group age 22
your_name = input("Enter your name: ") # input a club joining client name
your_age = int(input(f"{your_name} please enter your age: "))# input his age
if your_age is not joining_age: # user input age is greater than 22 or smaller than client doesnot jon
print("you cannot join the codebugfree club ")#if not join than print this message
else:
print("Thanks for joining the code bug free club")#if join than print this message
It is a club joining basic project. we input client user name and age . If client age is 22 than client join our club if not jon our club. At first we fix the joining age of client 22. Input a client user name and its age. Checking with if is not condition user input age is 22 than print else statement other wise print you cannot join the codebugfree club.
INOUTPUT With ifÂ
Welcome to join the codebugfree club
You will be first verify your age and name
Enter your name: codebugfree
codebugfree please enter your age: 20
you cannot join the codebugfree club
INOUTPUT with else
Welcome to join the codebugfree club
You will be first verify your age and name
Enter your name: programmer
programmer please enter your age: 22
Thanks for joining the code bug free club
not in
print("welcome to code bug free GYM center it is the most popular gym center")
print("privacy policy of code bug free gym center")
print('''you should have own towel
you didnot fight other gym friends
you always eat diet our menu other wise you kik out from our gym''')
gym_member = ["samir","rahul","shyam","rupak","roshan"]#this is our gym memeber
checking_member = input("you are old or new if new press n old than o: ")#checking for new user
if checking_member == "n":
new_client = input("Enter your name: ")#new client name
print(f"{new_client} is now sucesfully join member")#client join sucessfully
gym_member.append(new_client)#adding the new client information to list
print(f"now we have member {gym_member}")
else:
print("your are old members")#old memebers
gym_diet_plan = ["rice","dal","milk","curd","ghee","paneer","butter","salad","green vegetable","fruits","fresh juice"]
#gym diet plan
user_name = input("Enter a name: ")#enter a name
if user_name not in gym_member:
print("you are ling us")
else:
checking_user_diet = input("Enter your diet plan: ")#diet palan input
if checking_user_diet not in gym_diet_plan:#checking diet plan
print(f"sorry {user_name} you is now kick out from gym because you not follow our privacy policy")
gym_member.remove(user_name)
print(f"our member is decrease {gym_member}")
else:
print(f" thanks {user_name} for submiting your diet plan")
Here in this project we list our gym member in list data type. checking the member with input n and o n means new and o means o. using if user is n than register his name and adding new member name to gym member. Define the gym diet plan input user name if gym member name is not present in user name than program print you is ling us. if name exist han user input his sied if user input diet is not match to gym diet plan than gym member kick out from gym. gym died plan match user diet plant than member greet with thanks message.
INOUTPUT
welcome to code bug free GYM center it is the most popular gym center
privacy policy of code bug free gym center
you should have own towel
you didnot fight other gym friends
you always eat diet our menu other wise you kik out from our gym
you are old or new if new press n old than o: & C:/Users/newstar/AppData/Local/Programs/Python/Python39/python.exe "c:/Users/newstar/Desktop/python practice/mypyprac/pythonifnot.py"
your are old members
Enter a name: samir
Enter your diet plan: pizza
sorry samir you is now kick out from gym because you not follow our privacy policy
our member is decrease ['rahul', 'shyam', 'rupak', 'roshan']
INOUTPUT 2nd condition
welcome to code bug free GYM center it is the most popular gym center
privacy policy of code bug free gym center
you should have own towel
you didnot fight other gym friends
you always eat diet our menu other wise you kik out from our gym
you are old or new if new press n old than o: n
Enter your name: code bug free
code bug free is now sucesfully join member
now we have member ['samir', 'rahul', 'shyam', 'rupak', 'roshan', 'code bug free']
Enter a name: code bug free
Enter your diet plan: dal
thanks code bug free for submiting your diet plan
0 Comments
Don't comment a spam message