Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to coding
#1
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')
Reply
#2
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')
Reply
#3
Thank you, I am reading up on how to do that now.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020