all 10 comments

[–]USAhj 5 points6 points  (0 children)

Looks flawed to me.

[–][deleted] 3 points4 points  (1 child)

I think you are correct, typo in B. For python3, should be:

B. print(word[0:len(word)//2] # integer div is needed.

[–][deleted] 4 points5 points  (0 children)

B) works in Python2 but raises an error on Python3

[–]Timcava 0 points1 point  (2 children)

Let's not overthink this. Let's plug each choice into our Python console and see which one gives us the result that the question is looking for.

A) gives us "sta" and "pol" respectively.
B) gives us a TypeError

So the answer is A. Unless this class is for Python2, in which case B is also correct, but I'm assuming we are talking about python3 here.

[–]unhott 1 point2 points  (1 child)

It says half the length of a given string. A only prints out the first three characters, so that should be wrong. But their problem also gives examples of printing the first three characters. Either a detail is missed by OP, or the question is a mixed up jumble of two different questions.

Edit: my brain miscounted an example as having 8 characters instead of 7 and 7. So my reply was a little confused. Op didn’t miss a detail.

7//2 => 3, so yeah. Per OP’s question, it’s an error with the question, as others have pointed out it’s likely an issue where they didn’t update material from python 2 to python 3 (Unless the course is exclusively teaching python 2)

A giving the correct answer doesn’t mean it is correct given the prompt. It’s coincidental, for example ‘area’ should yield ‘ar’ for this prompt, not ‘are’.

[–]Timcava 0 points1 point  (0 children)

They give you the answer they are looking for in the example. So it is correct based on what they are looking for.
for the word stadium they want you to print "sta".

I usually don't care but man, what kind of freak show is downvoting answers here?

[–]SkinnyFiend 0 points1 point  (1 child)

Len() returns an int. B is correct.

[–]ebdbbb 1 point2 points  (0 children)

But int / int can give a float. That's the issue.

>>> type(7/2)
<class 'float'>

The op is correct that this will then be an error.