In: Computer Science
X=5,Y=7,Z=10
A. if(X<Y):
print "LESS"
else:
print "OTHER"
B.
if (x == 1): print "ONE"
elif (x == 2): print "TWO"
elif (x == 3): print "THREE"
elif (x == 4): print "FOUR"
elif (x == 5): print "FIVE"
elif (x == 6): print "SIX"
else: print "OTHER"
C.
if (X<Z):
print X
X = X + 1
D.
while (X<Z):
print X
X = X + 1
Q11. What is the final value of X in D
Q12. Is it legal to have an if with no else?
Q13. Is it legal to have an if with no elif?
Q14. Is the expression Y = X == 1 legal?
Q15. Is the expression IF (X<Z): legal?
Program:
X=5,Y=7,Z=10
A. if(X<Y):
print "LESS"
else:
print "OTHER"
B.
if (x == 1): print "ONE"
elif (x == 2): print "TWO"
elif (x == 3): print "THREE"
elif (x == 4): print "FOUR"
elif (x == 5): print "FIVE"
elif (x == 6): print "SIX"
else: print "OTHER"
C.
if (X<Z):
print X
X = X + 1
D.
while (X<Z):
print X
X = X + 1
Q11. What is the final value of X in D
Program:
import java.io.*;
class Segment
{
public static void main(String args[])throws IOException
{
int x=5,y=7,z=10;
if(x<y)
{
System.out.println("LESS");
}
if (x<z)
System.out.println("In C x= " +x);
x = x + 1;
while (x<z){
System.out.println("In D x= " +x);
x = x + 1;
}
}
}
Output:
Q11.
Answer: the final value of X in D is 9
Q12. Is it legal to have an if with no else?
Answer: legal
Q13. Is it legal to have an if with no elif?
Answer: legal
Q14. Is the expression Y = X == 1 legal?
Answer: It is not legal
Explanation:
Program:
import java.io.*;
class Segment
{
public static void main(String args[])throws IOException
{
int x,y;
y = x == 1;
System.out.println("In D y= " +y);
}
}
Output:
Q15. Is the expression IF (X<Z):
legal?
Answer: Legal