Python Forum

Full Version: New to coding
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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')
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')
Thank you, I am reading up on how to do that now.