# computer science help plz

Watch
Announcements
#1
1. (a) How many lines of output will the following pseudocode algorithm produce?
for a = 8 to 19 step 4
for b = 1 to 3
if a mod b >= b/3 then
if a/4 <= b+1 then
print (“Homer”)
else
print (“Marge”)
endif
else
print (“Bart”)
endif
next b
next a

(b) Trace through the pseudocode and write down what is output. 

thanks
0
1 month ago
#2
I show you beginning you continue
a=8 b=1 , 8 mod 1 =0 1/3 =0 0==0
a/4 = 2 b+1 =2 print Marge... it continues.. the solution is too long you need to understand logic and try it using a programming language
0
#3
(Original post by cvgk)
I show you beginning you continue
a=8 b=1 , 8 mod 1 =0 1/3 =0 0==0
a/4 = 2 b+1 =2 print Marge... it continues.. the solution is too long you need to understand logic and try it using a programming language
thanks i will try and figure it out when i convert this into python.

btw do you know how you can get the answer for part b.
0
1 month ago
#4
(Original post by peteryoungy)
1. (a) How many lines of output will the following pseudocode algorithm produce?
for a = 8 to 19 step 4
for b = 1 to 3
if a mod b >= b/3 then
if a/4 <= b+1 then
print (“Homer”)
else
print (“Marge”)
endif
else
print (“Bart”)
endif
next b
next a

(b) Trace through the pseudocode and write down what is output. 

thanks
homer
homer
homer
homer
homer
homer
Marge
homer
homer
Marge
Marge
homer
0
1 month ago
#5
(Original post by peteryoungy)
thanks i will try and figure it out when i convert this into python.

btw do you know how you can get the answer for part b.
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
Last edited by cvgk; 1 month ago
0
1 month ago
#6
(Original post by cvgk)
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
yo can do it using while loop as well.
0
#7
(Original post by cvgk)
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
Thanks do you know how to do it in python language. I havn't learnt java. This will be very strange for my teacher.
0
1 month ago
#8
(Original post by peteryoungy)
Thanks do you know how to do it in python language. I havn't learnt java. This will be very strange for my teacher.
Sorry I don't know python if you don't mind are you going to university or high school , is this from algorithm lecture ?
0
1 month ago
#9
but don't be scared loops are similar just you need to change instead of System.out.println() use print in python.that is it.
0
#10
i am 6 form and only know python.
1
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

Yes (124)
87.32%
No (18)
12.68%