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
#2
This should work. The count variable is used to check if the program is on the first item. If so, it sets total_weight equal to that item. Then count is increased by one so the program now multiplies the rest. After, it is multiplied by seven for the end result.
amount_of_plastic = [5, 2, 2, 20]
total_weight = 0
count = 0
for item in amount_of_plastic:
    if count != 0:
        total_weight *= item
    else:
        total_weight = item
        count = 1
total_weight *= 7
Reply


Messages In This Thread
RE: What am I doing wrong? New to Python - by SheeppOSU - Jul-02-2019, 04:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,719 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,073 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