2 Replies - 1008 Views - Last Post: 11 October 2012 - 08:47 AM Rate Topic: -----

#1 Errk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-October 12

python gives 2 different numbers instead of just 1

Posted 11 October 2012 - 08:06 AM

x=raw_input(">");
y=raw_input(">");
z=raw_input(">");

x=int(x);
y=int(y);
z=int(z);

if (x!=y!=z):
  a=int(x)+int(y)+int(z);
  printNow(a);

if (x==y and x!=z and y!=z):
  b=int(x)+int(z)
  printNow(B)/>;
   
if (x==z and x!=y and y!=z):
  c=int(y)+int(x);
  printNow(c);


so my assignment is to make a program that you enter 3 numbers and they have to be added together, but the none of the 3 numbers can be the same as each other. i was expecting for the bottom section
if (x==z and x!=y and y!=z):
  c=int(y)+int(x);
  printNow(c);
to give me a 3 if x=1 y=2 and z=1, which it does but it gives me a 4 then a line below a 3. why is this? i dont know where the 4 comes from and i dont want it there. help would be appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: python gives 2 different numbers instead of just 1

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2100
  • View blog
  • Posts: 3,197
  • Joined: 21-June 11

Re: python gives 2 different numbers instead of just 1

Posted 11 October 2012 - 08:22 AM

x != y != z means the same thing as x != y and y != z - it does not require that x != z.

So your problem is that it executes the first as well as the last if when x and z are equal.
Was This Post Helpful? 1
  • +
  • -

#3 Errk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-October 12

Re: python gives 2 different numbers instead of just 1

Posted 11 October 2012 - 08:47 AM

oh wow thank u so much, i was completely overlooking that, i fixed it to work perfect. you've been a lot of help thanks a ton :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1