0

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)
2
  • What does this have to do with Java or the Oracle 11g Database? Tag soup = down-voted. Commented Nov 3, 2017 at 6:54
  • I removed the redundant tags. Please take care to tag appropriately, in order to get your question in front of the right people. Commented Nov 3, 2017 at 7:22

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

first thanks for solution. i used global key word in my code. it gives an warning that SyntaxWarning: name 'count' is assigned to before global declaration
can you please paste code as a comment ? By that I can understand ur exact problem.

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.