The Student Room Group

I need help with my computer science hw

What is output by the following algorithm?
notice = "Please do not walk on the grass"
start=pos (r notice," ")
end = pos (notice, "t")
x = substring (0,start, notice)
stringLength=len(notice)
y = substring (end 2, stringLength - 1 , notice)
print ("x = "x)
print (“y= , y)
print (x y)
(edited 4 years ago)
Original post by learner38
What is output by the following algorithm?
notice = "Please do not walk on the grass"
start=pos (r notice," ")
end = pos (notice, "t")
x = substring (0,start, notice)
stringLength=len(notice)
y = substring (end 2, stringLength - 1 , notice)
print ("x = "x)
print (“y= , y)
print (x y)


What language is this? It looks somewhat similar to Python, but with syntax errors. If you have some valid Python code then you should just run it inside your Python interpreter and see what the output is.
Reply 2
Original post by winterscoming
What language is this? It looks somewhat similar to Python, but with syntax errors. If you have some valid Python code then you should just run it inside your Python interpreter and see what the output is.


It’s an algorithm idk what the language is I just want to know what the output would be
It looks like a form of pseudo code. I think you may have some typos in lines 2, 6, 7 and 9.
If the r wasn't there in line 2, that line gets the position of the first space within the notice.
Line 4 gets the part of notice between position 0 and start.
Line 5 gets the length.
Line 6 does similar to 4 but with different positions.

The output is the value of each of X and y, then the 2 joined together I think, although the + or , is missing in the final line
Original post by learner38
It’s an algorithm idk what the language is I just want to know what the output would be

It's probably pseudocode in that case.

Trace it through line-by-line and write down the values of each of the variables as you step through.

For example:
The first line sets a variable notice containing a string value which is "Please do not walk on the grass".
The second line sets a variable start which is the position of the first space character in that string, which would be 6 (strings and arrays are 'zero based', so the first character 'P' is position zero)

etc.
(edited 4 years ago)
Reply 5
Original post by CCauston113
It looks like a form of pseudo code. I think you may have some typos in lines 2, 6, 7 and 9.
If the r wasn't there in line 2, that line gets the position of the first space within the notice.
Line 4 gets the part of notice between position 0 and start.
Line 5 gets the length.
Line 6 does similar to 4 but with different positions.

The output is the value of each of X and y, then the 2 joined together I think, although the + or , is missing in the final line


The r was a mistake but everything I got was from my homework sheet

Quick Reply

Latest

Trending

Trending