The Student Room Group

National 5 computing coursework/assignemt

Does anyone know how to do the code? I have initialised the mystery fruit variables and I think I know how to do the input validation for the fruit length, but past that point i'm so confused can someone please help

Scroll to see replies

Reply 1

Original post
by explodinghead
Does anyone know how to do the code? I have initialised the mystery fruit variables and I think I know how to do the input validation for the fruit length, but past that point i'm so confused can someone please help
Pretty sure you need to (inside the loop) add 1 to the counter and append the users input into the array. outside the loop, you need an If statement and the conditions are the exact same as in the flow chart (if counter == 3 or counter...etc.). The rest is just printing the messages. I forgot most of it but that's what I remember :smile:

Reply 2

Original post
by ryzo12484
Do you remember how to implement the decision & is input validation required for the number of fruits? Am I supposed to ask them to input an individual fruit then ask if they would like to add another fruit until the counter reaches 6 or until they say no, or am I supposed to ask for the number of fruits then ask for all the fruits? The flowchart makes it seem like the 1st, but that seems so inefficient and I'm not sure how I'm supposed to code the program to stop asking when "no" is answered, or when the counter reaches 6. I'm rather confused - help would be greatly appreciated. πŸ™‚

This might not be 100% correct but it was smth like this.

1) in the flow chart it says "initialise variables", that includes the counter and the decision variables.

2) You need to make a loop that runs while the counter is <6 AND the decision is "no". (I just gave a big clue what type of loop it is :3)

β€’

After initialising the loop, you ask for an input e.g. fruits= input("enter the name the of the fruit...")

β€’

you then need an input validation. the fruit LENGTH (number of characters) needs to be at least 4 (i think, it says it on the sheet).

β€’

you then add 1 to counter (counter += 1)

β€’

then ask for a decision (decision= ("....")


the decision will save into the variable we made first thing at the top.
the loop will not run if the decision is no.


-Good luck, hope that helped!!!-

Reply 3

Original post
by Paper:3
This might not be 100% correct but it was smth like this.
1) in the flow chart it says "initialise variables", that includes the counter and the decision variables.
2) You need to make a loop that runs while the counter is <6 AND the decision is "no". (I just gave a big clue what type of loop it is :3)

β€’

After initialising the loop, you ask for an input e.g. fruits= input("enter the name the of the fruit...")

β€’

you then need an input validation. the fruit LENGTH (number of characters) needs to be at least 4 (i think, it says it on the sheet).

β€’

you then add 1 to counter (counter += 1)

β€’

then ask for a decision (decision= ("....")


the decision will save into the variable we made first thing at the top.
the loop will not run if the decision is no.
-Good luck, hope that helped!!!-

Omg can u pls help me see after u Dim all the variables and initialise the mystery fruits whats the next thing you do? Like before the While loop part, and also how do you display everything at the end??

Reply 4

Original post
by explodinghead
Omg can u pls help me see after u Dim all the variables and initialise the mystery fruits whats the next thing you do? Like before the While loop part, and also how do you display everything at the end??
After the mystery fruits u just have to initialise the user inputed fruits so..

fruit is the variable name im choosing (or whatever variable name you want)

fruit= [ ]

*empty brakcets *

Reply 5

Original post
by explodinghead
Omg can u pls help me see after u Dim all the variables and initialise the mystery fruits whats the next thing you do? Like before the While loop part, and also how do you display everything at the end??

to display at the end you just say..

print(" the fruits you entered were.")
print(fruits variable)
print("the mystery fruit was.")
print(mysteryfruit variable)
print(shake-shake recommends this to be a (drink type).)

it's not all meant to be printed at once, check the flow chart to see when each should be printed bcs your code should follow the flow chart.

Reply 6

Original post
by Paper:3
After the mystery fruits u just have to initialise the user inputed fruits so..
fruit is the variable name im choosing (or whatever variable name you want)
fruit= [ ]
*empty brakcets *

Wait im so stupid could u explain it clearer pls 😭😭😭mine is like:
fruits(6)=inputbox("What fruits would you like?")
Nooffruits=1
Decision=inputbox("Would you like to add another fruit?")

Then I go into the while loop, ik this is wrong because it just asks the questions an infinite number of times so how do I fix it

Reply 7

Original post
by explodinghead
Wait im so stupid could u explain it clearer pls 😭😭😭mine is like:
fruits(6)=inputbox("What fruits would you like?")
Nooffruits=1
Decision=inputbox("Would you like to add another fruit?")
Then I go into the while loop, ik this is wrong because it just asks the questions an infinite number of times so how do I fix it

I just realised we might be using different softwares 😭
which one do you use? I use thonny.

Reply 8

Original post
by Paper:3
I just realised we might be using different softwares 😭
which one do you use? I use thonny.

Visual Basic and its so bad πŸ’”πŸ’”

Reply 9

Original post
by explodinghead
Visual Basic and its so bad πŸ’”πŸ’”

Are you doing it in a school bcs if you can change to thonny its really good, I would defo recommend it.

Reply 10

Original post
by Paper:3
what I did was..
counter= 0
decision= ( )
mystery fruits= ["orange", "mango".... etc]
fruits= [ ]
(^array for user inputed fruits, empty bracket.)
While decision !"no" and counter <6:
fruit= input ("enter fruit name")
letters= len(fruit)
if letters >4:
print("invalid input")
fruit= input("enter fruit name")
counter +=1
decision= ("would you like to add another fruit?")
(end of while loop)
I'm not entirely sure this is now I ended the loop but I think it would work.
let me know if you need me to explain it more :3

Thank you that helps actually xx

Reply 11

Original post
by explodinghead
Thank you that helps actually xx

npp, dont forget to generate a random number for the mystery fruits as well.

good luck :3

Reply 12

Original post
by Paper:3
npp, dont forget to generate a random number for the mystery fruits as well.
good luck :3

Thanks man. One more question, how did u answer the last question about efficiency, robustness and readability?

Reply 13

Original post
by ryzo12484
Hi - thanks so much. Just clarifying that the input validation is required twice?
e.g
fruit = input(Enter fruit name)
while len(fruit) < 4
print(Invalid…etc)
decision = input(would you like to add another fruit?)
while answer = yes and counter < 6
fruit = input(Enter…..)
while len(fruit) < 4
print (……)

I put the second input validation as my loop starter. I think it deleted by accident but you should be able to see how I wrote it when you look at the message someone replied to it (explodinghead replied to the message and you can see it from there).

Reply 14

Original post
by explodinghead
Thanks man. One more question, how did u answer the last question about efficiency, robustness and readability?

I actually have no idea how to word those 😭.
-For efficieny you can say you used an array instead of separate variables for users fruits.
-Robustness is, if you input text instead of a number would the program crash or withstand it and send a message to the user. (no idea how to word it)
-for Readability you can say , use of white space helps separate code and internal commentary was used to help explain what the code was doing which makes the code easier to read and understand.

*these comments have to be related to YOUR code and what you used in it (not the functional requirements)*

(I'm gonna be doing this section tomorrow so I'll update on what I put down for each) :3

Reply 15

Original post
by Paper:3
This might not be 100% correct but it was smth like this.
1) in the flow chart it says "initialise variables", that includes the counter and the decision variables.
2) You need to make a loop that runs while the counter is <6 AND the decision is "no". (I just gave a big clue what type of loop it is :3)

β€’

After initialising the loop, you ask for an input e.g. fruits= input("enter the name the of the fruit...")

β€’

you then need an input validation. the fruit LENGTH (number of characters) needs to be at least 4 (i think, it says it on the sheet).

β€’

you then add 1 to counter (counter += 1)

β€’

then ask for a decision (decision= ("....")


the decision will save into the variable we made first thing at the top.
the loop will not run if the decision is no.
-Good luck, hope that helped!!!-

Hiya, so yk how you are meant to use a while loop for the repeats, I used a for loop instead. It works but I'm not sure if that is following the design?

Reply 16

Original post
by ra099
Hiya, so yk how you are meant to use a while loop for the repeats, I used a for loop instead. It works but I'm not sure if that is following the design?


I don't remember the exact words of the flow chart but if it does specify a while loop then you should prob use it too.

I used a for loop at first but I couldn't get the decision bit to work out. How did you do it? :3

Reply 17

Original post
by Paper:3
I don't remember the exact words of the flow chart but if it does specify a while loop then you should prob use it too.
I used a for loop at first but I couldn't get the decision bit to work out. How did you do it? :3

I did for counter in range(9) then did all my code like the input validation then I did if counter>6 and user input = no break. Also how do I know if the flowcharts asks for a while loop or a for loop?

Reply 18

Original post
by ra099
I did for counter in range(9) then did all my code like the input validation then I did if counter>6 and user input = no break. Also how do I know if the flowcharts asks for a while loop or a for loop?


Yk how it says: "decision==yes and counter>6" then it loops back up.

if it says "while decision..." or "if decision.." then that's what it's asking but I can't remember if it does. πŸ˜…

Reply 19

Original post
by ra099
I did for counter in range(9) then did all my code like the input validation then I did if counter>6 and user input = no break. Also how do I know if the flowcharts asks for a while loop or a for loop?


Yeah I did the same thing with the If when I tried it first but I didn't know how to forcefully stop the loop (the break command) so I changed it to a while loop 😭

Quick Reply

How The Student Room is moderated

To keep The Student Room safe for everyone, we moderate posts that are added to the site.