Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Help with my coding
#1
material = input("What material is it? ")
length = float(input("What is its length in cm? "))
# Plastic goes into recycling bin. 
if material == "plastic" == length < 7.5:
    waste_type = "trash"
if material == "plastic" == length > 7.5:
    waste_type = "recycling" 
# Anything else goes into trash can.
if material != "plastic":
    waste_type = "trash"
# Result. 
print("Please deposit your item in the " + waste_type + " bin.")

So in this code, I need to classify all plastic with a length of less than 7.5cm as trash. How do I do that? Sorry for bothering y'all but I'm a noob lol. Wall
Larz60+ write Oct-08-2024, 10:32 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Tags have been added this time. Please use BBCode tags on future posts.
Reply
#2
Your problem is with the if statements. You are thinking they are testing something they are not. Given that this looks suspiciously like homework not giving the complete solution.

And, of course, what if the length is exactly 7.5?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Is there some coding that will do the following in 3 separate events? bensan 23 9,761 Jul-27-2021, 03:48 PM
Last Post: jefsummers
  [split] Very basic coding issue aary 4 3,478 Jun-03-2020, 11:59 AM
Last Post: buran

Forum Jump:

User Panel Messages

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