# I need help with my computer science hw

Watch
Announcements
#1
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)
Last edited by learner38; 1 year ago
0
1 year ago
#2
(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.
1
#3
(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
0
1 year ago
#4
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
0
1 year ago
#5
(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.
Last edited by winterscoming; 1 year ago
0
#6
(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
0
X

new posts
Back
to top
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

see more

### See more of what you like onThe Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

### Poll

Join the discussion

#### Are you travelling in the Uni student travel window (3-9 Dec) to go home for Christmas?

Yes (136)
28.33%
No - I have already returned home (65)
13.54%
No - I plan on travelling outside these dates (93)
19.38%
No - I'm staying at my term time address over Christmas (45)
9.38%
No - I live at home during term anyway (141)
29.38%