📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    What will be the value of `x` after the following

    pseudo-code execution?  ```     x = 0     data = [10, 20, 30]     for item in data:         if item > 15:             x = x + item         else:             x = x - item     ```
    A 40 Correct Answer Incorrect Answer
    B 20 Correct Answer Incorrect Answer
    D 60 Correct Answer Incorrect Answer

    Solution

     Dry Run:            `x = 0`            `item = 10`: `10 > 15` is false. `x = 0 - 10 = -10`            `item = 20`: `20 > 15` is true. `x = -10 + 20 = 10`            `item = 30`: `30 > 15` is true. `x = 10 + 30 = 40`            Final `x = 40`

    Practice Next
    More IT DBMS Questions
    ask-question