Python Forum
New to coding - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code Review (https://python-forum.io/forum-46.html)
+--- Thread: New to coding (/thread-29155.html)



New to coding - gallatin721 - Aug-20-2020

Sorry very basic just starting out. is there a way to improve this. I was able to get it to work, but is there a better way to code it? Thanks.

x = 4
y = 5

if x != 4 and y != 5:
    print('x != 4, y != 5')
elif x == 4 and y == 5:
    print('x = 4  y = 5')

elif x != 4 and y == 5:
    print('x != 4, y = 5')

elif x == 4 and y != 5:
         print('x = 4, y != 5')



RE: New to coding - Larz60+ - Aug-20-2020

Here's another way, there are probably even better ways, but end of day and I'm not clever now:
if x == 4:
    if y == 5:
        print('x = 4  y = 5')
    else:
        print('x = 4, y != 5')
else:
    if y == 5:
        print('x != 4, y = 5')
    else:
        print('x != 4, y != 5')



RE: New to coding - gallatin721 - Aug-21-2020

Thank you, I am reading up on how to do that now.