Python Forum
What am I doing wrong? New to Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong? New to Python
#1
Hi everyone I have recently been introduced to Python and I am attempting some activities for beginners but I have become stuck on one part.
Basically my task is to create a function that takes a list of four input values and from that an output value is formed. Each number in the list should be multiplied by the next number in the list e.g. [5,4,3,2] would be 5 * 4 * 3 * 2 then the total of this sum is then multiplied by 7 and that is the final answer. (This program should work for any combination in the list) Below I have shown my attempt. I could be so far off but it'll be good to learn from;

def amount_of_plastic(width_brick, height_brick, length_brick, number_of_bricks):
    """Given the dimensions of a brick (width, height, length in cm) and the number of bricks ordered, calculate how much plastic, in grams, is required (if a cubic centimetre weighs 7 grams)."""

    # INSERT YOUR CODE BELOW THIS LINE FOR CALCULATING THE 
    # AMOUNT OF PLASTIC AND RETURNING THE RESULT (DO NOT CHANGE
    # THE HEADER OF THE FUNCTION WHICH HAS BEEN PROVIDED FOR YOU
    # ABOVE)

    total_weight = 0

    amount_of_plastic = [5, 2, 2, 20]

    for item in amount_of_plastic:
        total_weight = item * item
        total_weight = item * 7
        
    return(total_weight)
Any help is greatly appreciated.
Reply


Messages In This Thread
What am I doing wrong? New to Python - by Stthmc_1995 - Jul-02-2019, 03:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,653 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,056 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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