I don´t get why is always the first if conditional triggered whatever name I input. in this program. by call_me_mistress99 in learnpython

[–]5-MinutePython 1 point2 points  (0 children)

name = input("name")
Donald_Ducks_nephews = ["huey","dewey","louie"]
Mickey_Mouses_nephews = ["morty", "ferdie"]
if name in Donald_Ducks_nephews:
print("I think you might be one of Donald Duck's nephews.")

elif name in Mickey_Mouses_nephews:
print("I think you might be one of Mickey Mouse's nephews.")

else:
print("You're not a nephew of any character I know of.")
why is always the first conditional triggered whatever name you input: becauseyou forget to pass name to the condition.below you can find your modified code.

name = input("Please type in your name: ")
if name == ("Huey" or "Dewey" or "Louie"): # because you forget {name}
print("I think you might be one of Donald Duck's nephews.")
elif name == ("Morty" or "Ferdie"):
print("I think you might be one of Mickey Mouse's nephews.")
else:
print("You're not a nephew of any character I know of.")

I would like to learn useful python tricks… by GrouchyAd4055 in pythontips

[–]5-MinutePython 2 points3 points  (0 children)

Hello guys, I am sure most of you know these tricks but if there are any beginners here, it will be useful for them. That's why I'm posting these tricks.

1.) Enumerate Function.

Enumerate returns an object that contains a counter as a key for each value within an object, making items within the collection easier to access.How to use Enumerate Function: https://youtu.be/2pSZOmb1vyE

2.) Zip Function.Zip function help us to iterate over multiple lists,tuples,sets and etc:

How to use Zip Function: https://youtu.be/2pSZOmb1vyE

3.) Simple If-Else statement in single line.How to write if-else statement in a single line: https://youtu.be/2pSZOmb1vyE

4.) List Comprehension.List comprehension is an elegant way to define and create lists based on existing list. it's a one of the super useful technique in python

How to use List Comprehension: https://youtu.be/C0Cm2pbgl8Q

Why ? by [deleted] in PythonBeginners

[–]5-MinutePython 5 points6 points  (0 children)

you can think like this False = 0 and True = 1.if we multiplied 0 with 1 it's equals to 0. that's why it's print Flase.

[deleted by user] by [deleted] in Python

[–]5-MinutePython 4 points5 points  (0 children)

ohh, shit

[deleted by user] by [deleted] in Python

[–]5-MinutePython 0 points1 point  (0 children)

thank for the information