Reputation: 13
I am new to python programming. I have some implementation problem with local and global variable concept. I have read some answers about the global and local variables. I tried to use this concept, however, in the code below, I did not get proper output. When I press 'y' it shows the number of the persons in the room 0.
my code:
sw1 = 0
sw2 = 0
d1sen1 = 1
d1sen2 = 0
d2sen1 = 1
d2sen2 = 0
chk = 0
d = 0
count = 0
def dgopenig_operation(x):
d1sen1 = 0
d1sen2 = 0
d2sen1 = 0
d2sen2 = 0
print ("the door is going to open")
def doppened_operation():
d1sen1 = 0
d1sen2 = 1
d2sen1 = 0
d2sen2 = 1
print ("the door is oppened u can pass now")
def dgclose_operation(x):
d1sen1 = 0
d1sen2 = 0
d2sen1 = 0
d2sen2 = 0
print ("the door is going to closed")
def close_operation():
d1sen1 = 0
d1sen2 = 0
d2sen1 = 0
d2sen2 = 0
print ("the door is going to closed")
sw1 = input("enter 1 for enteringing the room")
dgopenig_operation(sw1)
doppened_operation()
chk = input("are u passed or not? y/n")
if (chk == 'y' and sw1 == 1):
dgclose_operation(1)
global count
count = count +1
else:
print ('the door is still oppening')
print( 'the no of person in the room is ',count)
Upvotes: 0
Views: 76
Reputation: 479
you have almost done. But there is a small mistake in if condition. Your required condition should be like below:
if (chk == 'y' and sw1 == '1'):
That means you should keep 1 in single quotes '1' because it's a string
Upvotes: 2