Question: Answer the following questions about the given code fragments. For each question assume that variables have already been assigned as X=5 , Y=7 , and

Answer the following questions about the given code fragments. For each question assume that variables have already been assigned as X=5, Y=7, and Z=10 (that is, the result of one question does not affect the result of any other question):

  1.  if (X < Y): print ("LESS") else: print ("OTHER") 
  2.  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") 
  3.  if (X < Z): print (X) X = X + 1 
  4.  while (X < Z): print (X) X = X + 1
  5. In #1, what is printed?
    2. In #2, what is printed?
    3. In #3, what is printed?
    4. How many lines are printed in #3?
    5. How many lines are printed in #4?
    6. What is the final value of X in #1?
    7. What is the final value of X in #2?
    8. What is the final value of X in #3?
    9. What is the final value of X in #4?
    10. What is the final value of Z in #3?
    11. What is the final value of Z in #4?
    12. Is it legal to have an if with no else?
    13. Is it legal to have an if with no elif?
    14. Is the expression Y = X == 1 legal?
    15. Is the expression IF (X < Z): legal?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!