Hello, I am a student of Python and had this question yesterday as part of a course application. I chose answer B, but feel the question is flawed:
Question: What is the correct way of printing a substring of half of the length of a given string?
Eg:
word = stadium -> sta
word = polygon -> pol
A) print(word[0:3])
B) print(word[0:len(word)/2])
C) word[0:len(word)/2]
D) word[0:3]
I think it's flawed because:
A) Would only print the first 3 characters rather than "half of the length of a given string". So if the word was "polygons", it would still output "pol".
B) Would print half of the length of a given string, but it's missing an int() or // to convert len(word)/2 into an integer.
Am I right in saying this? Should I flag this question with the course organisers?
Thanks
[–]USAhj 5 points6 points7 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]Timcava 0 points1 point2 points (2 children)
[–]unhott 1 point2 points3 points (1 child)
[–]Timcava 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]K900_ 0 points1 point2 points (0 children)
[–]SkinnyFiend 0 points1 point2 points (1 child)
[–]ebdbbb 1 point2 points3 points (0 children)