Mar-25-2018, 01:54 PM
Hi all.
My daugther has Python proggraming task for homework. It might be simple, but since she was ill at time when they learned about that , she obviously missed alot. To cut story short here is the task (ill do my best at translating to English):
Task 3. Robot (solution via for loop)
Robot puts apples to boxes. Average mass of one box loaded with apples must be less or equal to 1000 grams. Mass of every Apple is different and on track came n apples which must be put into boxes.
Write program in which will be written mass of n apples. Program must calculate and print how many boxes is needed that robot put n apples in them wich came to track.
Input data:
· in variable n needs to be input integer number of apples, broj jabuka
· in variable x needs to be input mass of every single Apple jabuka (in grams)
Output data:
· Print of how many boxes is needed to put apples into them.
I Know only a bit of very old basic (C-64 XD) and Python syntax and way of working is totaly unknown to me so keep in mind when you respond lol. main thing is that For loop must be used in this code.
Thank you very much:
Here is what we tried to do so far (unfinished):
Tommy
My daugther has Python proggraming task for homework. It might be simple, but since she was ill at time when they learned about that , she obviously missed alot. To cut story short here is the task (ill do my best at translating to English):
Task 3. Robot (solution via for loop)
Robot puts apples to boxes. Average mass of one box loaded with apples must be less or equal to 1000 grams. Mass of every Apple is different and on track came n apples which must be put into boxes.
Write program in which will be written mass of n apples. Program must calculate and print how many boxes is needed that robot put n apples in them wich came to track.
Input data:
· in variable n needs to be input integer number of apples, broj jabuka
· in variable x needs to be input mass of every single Apple jabuka (in grams)
Output data:
· Print of how many boxes is needed to put apples into them.
I Know only a bit of very old basic (C-64 XD) and Python syntax and way of working is totaly unknown to me so keep in mind when you respond lol. main thing is that For loop must be used in this code.
Thank you very much:
Here is what we tried to do so far (unfinished):
n = 0 #number of appples sum = 0.0 # total mass of apples x = 1 # mass of single apple b = 0 # variable for division while x != 0: # attempt of counting Apple masses up to when oyu enter 0 for end of input x = int(input("")) sum = sum + x n += 1 if n == 0: #part where we tried to make calculations and checks for b=sum//1000: for c=sum % 1000 if c>=1 then c=1 d=b+c print ('Total number of boxes:', d) else c=0 d=b+c print ('Total number of boxes:', d)my daugther also did try some ideas but as I Know code is not working. Main idea is to use For loop and to be beginner and simple code. Anyway thank you all in advance.
Tommy