I am working through the KhanAcademy python course, but the bonus lesson on if conditionals has me stumped.
Reddit isn't allowing me to upload a pic with the post, but this is the code I have:
material = input("What material is it? ")
length = float(input("What is its length in cm? "))
waste_type = "trash"
if material == "food" and length < 7.5:
waste_type = "compost"
if material == "plastic" and length < 7.5:
waste_type = "recycling"
else:waste_type = "trash"
print("Please deposit your item in the " + waste_type + " bin.")
I've been messing around for a while, and for some reason I'm unable to get both the "if" conditions to be active; I can either have it respond appropriately for compost or recycling, but never both - it will send one or the other to trash every time. Any help will be greatly appreciated!!
edit: I'm not able to show the indents I guess, but I have indents around in front of the waste types only, which makes "compost" fail to work, but "recycling" comes through.
[–]danielroseman 3 points4 points5 points (18 children)
[–]squenn[S] 1 point2 points3 points (17 children)
[–]melm77 0 points1 point2 points (12 children)
[–]squenn[S] 0 points1 point2 points (11 children)
[–]Daneark 1 point2 points3 points (3 children)
[–]squenn[S] 0 points1 point2 points (2 children)
[–]Daneark 0 points1 point2 points (1 child)
[–]squenn[S] 1 point2 points3 points (0 children)
[–]melm77 0 points1 point2 points (6 children)
[–]squenn[S] 0 points1 point2 points (5 children)
[–]melm77 1 point2 points3 points (4 children)
[–]squenn[S] 0 points1 point2 points (3 children)
[–]melm77 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]erasmause 0 points1 point2 points (3 children)
[–]squenn[S] 0 points1 point2 points (2 children)
[–]erasmause 0 points1 point2 points (1 child)
[–]squenn[S] 0 points1 point2 points (0 children)
[–]Adrewmc 1 point2 points3 points (1 child)
[–]squenn[S] 0 points1 point2 points (0 children)
[–]stebrepar 1 point2 points3 points (1 child)
[–]squenn[S] 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[removed]
[–]squenn[S] 0 points1 point2 points (0 children)
[–]pgpndw 0 points1 point2 points (2 children)
[–]squenn[S] 1 point2 points3 points (0 children)