Computer Science, asked by thakurpalak1982, 1 month ago

int(input("enter first number"))
y=int(input(enter second number"))
if not(x==10 or y<=x):
x=x+20
y=x-y
else:
x=x-20
y=x+y
print("x=",x,"y=",y)

predict/find output if the values of x and y input by the user are:
1. x=5 and y=15
2. x=15 and y=5
3. x=10 and y=10​

Answers

Answered by allysia
3

Languages:

Python

Correcting program:

x=int(input("enter first number"))

y=int(input("enter second number"))

if not(x==10 or y<=x):

x=x+20

y=x-y

else:

x=x-20

y=x+y

print("x=",x,"y=",y)

What it does?

  • Takes input for x and y
  • a==b in python checks if a is equal to b or not. y<=x checks if y is smaller than or equal to x or not.
  • or returns True if either of the given conditons is true
  • not gate retuns complement of input if the input was True it will return False and vice versa
  • So basically if returns x increased by 20 and new y as x-y if either x is not equal to 10 or y is smaller than or equal to x or both of them is true.
  • If not the other statements under else are run.

Output:

#using the conditions above

  • x=5,y=15

Since x isnt equal to 10, and y is not smaller than 15 both integrated conditions are False.

Now, we have to check not(F or F) which is T therefore,

x= 25 y= 10

  • x=15,y=5

Again not(F or T) which is F therefore else statements run,

x= -5 y= 0

  • x=10,y=10

Once again test for not(T or T) which is F therefore,

x= -10 y= 0

Note: T = True and F= False here.

Similar questions