Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Python Institute Exam PCEP-30-02 Topic 2 Question 23 Discussion

Actual exam question for Python Institute's PCEP-30-02 exam
Question #: 23
Topic #: 2
[All PCEP-30-02 Questions]

Assuming that the following assignment has been successfully executed:

My_list -- [1, 1, 2, 3]

Select the expressions which will not raise any exception.

(Select two expressions.)

Show Suggested Answer Hide Answer
Suggested Answer: C

The code snippet that you have sent is a loop that checks if a variable ''floor'' is less than or equal to 0 and prints a string accordingly. The code is as follows:

floor = 5 while floor > 0: print(''+'') floor = floor - 1

The code starts with assigning the value 5 to the variable ''floor''. Then, it enters a while loop that repeats as long as the condition ''floor > 0'' is true. Inside the loop, the code prints a ''+'' symbol to the screen, and then subtracts 1 from the value of ''floor''. The loop ends when ''floor'' becomes 0 or negative, and the code exits.

The code outputs five ''+'' symbols to the screen, one for each iteration of the loop. Therefore, the correct answer is C. five.


Contribute your Thoughts:

Odette
13 days ago
Wait, what's a 'my_Li1st'? Is that some kind of new Python data structure I haven't heard about yet?
upvoted 0 times
...
Melynda
14 days ago
C) my list [6] is a bit tricky. Since the variable is named 'my_list' and not 'my list', this one will raise a NameError. Gotta be careful with variable names!
upvoted 0 times
...
Leota
15 days ago
D) my_List- [0:1] looks promising. Slicing a list is a safe operation, and it won't raise any exceptions.
upvoted 0 times
...
Gail
17 days ago
B) my_list|my_Li1st | 3| I is a complete mess. It's not even a valid Python expression, so this one is out too.
upvoted 0 times
Corazon
2 days ago
A) my_list[-10]
upvoted 0 times
...
...
Burma
18 days ago
A) my_list[-10] will raise an IndexError, as the index is out of range for the list. It's definitely not a safe option.
upvoted 0 times
Felicitas
3 days ago
B) my_list|my_Li1st | 3| I is not a valid expression, it will raise a NameError.
upvoted 0 times
...
...
Wenona
2 months ago
I believe option D will not raise an exception because it's slicing the list.
upvoted 0 times
...
Iola
2 months ago
I agree, accessing an index that doesn't exist will raise an exception.
upvoted 0 times
...
Margo
2 months ago
I think option A will raise an exception.
upvoted 0 times
...

Save Cancel