The Student Room Group

What will this code output

This is in one of my homeworks, where do left and right come from?

notice = "Please do not walk on the grass" stringLength = notice.length
sub1 = notice.substring(0,5)
sub2 = notice.substring(10, 8)
print(stringLength)
print(left)
print(right)
Reply 1
Original post by joeheap
This is in one of my homeworks, where do left and right come from?

notice = "Please do not walk on the grass" stringLength = notice.length
sub1 = notice.substring(0,5)
sub2 = notice.substring(10, 8)
print(stringLength)
print(left)
print(right)

looks like a mistake - if that's the complete code then left and right have never been assigned values
Original post by joeheap
This is in one of my homeworks, where do left and right come from?

notice = "Please do not walk on the grass" stringLength = notice.length
sub1 = notice.substring(0,5)
sub2 = notice.substring(10, 8)
print(stringLength)
print(left)
print(right)

It seems plausible that left is supposed to be sub1, given that sub1 contains the left-most characters from notice. On that same basis, perhaps right is supposed to be sub2.

Alternatively, perhaps your task is to identify that the code will print nothing, given that left and right are undeclared. If this is a compiled language, it's unlikely to even compile.

Is this supposed to be an actual language, or pseudo-code? Are you sure this is exactly what the code says?

Quick Reply

Latest

Trending

Trending