Python Forum
School python program task help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
School python program task help
#1
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):
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
Reply
#2
Do you still need help with this?

either way this is the solution I got based on the information given to me
total_n = int(input('Enter number of apples: ')) #Number of apples
n = total_n
t_mass = 0 #total mass of apples
number_of_boxes = 0

while n > 0:
    for x in range(0,n):
        mass = int(input('Enter the mass of an apple: ')) #The mass of one apple since its variable you enter it every time
        n = n-1 #reducing 1 apple as its been put in a box
        t_mass = t_mass + mass #Calculating total
        if t_mass >= 1000: #Checking if the total mass of the box is 1000g
            break
        number_of_boxes +=1 # this is adding 1 to the number of boxes variable
print('{} of apples fit in {} boxes'.format(total_n, number_of_boxes)) #Printing the mass of n apples
Don't doubt always question. There's a difference.
Reply
#3
Thank you very much .

This has been big help and she can have nice insight into code work thank to hashtags.

Tommy
Reply
#4
(Apr-03-2018, 12:06 PM)TommyLee Wrote: Thank you very much . This has been big help and she can have nice insight into code work thank to hashtags. Tommy

You are welcome. :)
Don't doubt always question. There's a difference.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my python project for school vavervirus 2 634 Oct-12-2023, 03:28 AM
Last Post: buran
  simple task in python Rapito 4 2,158 Nov-22-2021, 10:09 PM
Last Post: jefsummers
  Python School Project andreas30298 2 2,134 Nov-12-2020, 09:58 AM
Last Post: Axel_Erfurt
  small newbie task to python intoxicated_dk 2 2,348 Jun-17-2019, 01:57 PM
Last Post: intoxicated_dk
  Fun Task: Python 3.7.2 CozyDarkness 1 2,030 May-10-2019, 07:12 AM
Last Post: buran
  file python task, need help ! rayabv 7 3,474 Apr-15-2019, 10:07 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020