r/pythonhelp • • Oct 22 '20

Simple assignment, don't know where I went wrong.

Post image
7 Upvotes

5 comments sorted by

11

u/socal_nerdtastic Oct 22 '20

You need in, not ==.

if x in [a,b,c,d,e]:

Also, it's a lot easier to help if you post code as text, not as an image.

1

u/eGUIBNFG Oct 22 '20

Heres what i'm trying to do: Write a function named isYes that takes no parameters. The function should ask the user to enter yes or no. If the user types in y, Y, yes, or YES the function should return true. Otherwise, the function should return false.

1

u/robohobo- Oct 23 '20

try removing the "" from the True and False and see what it prints.

use in not == otherwise you're checking if a string is equivalent to a list which will always be false.

To make it a function

def isYes():

then insert your code tabbed over

Use return instead of print (you can print and then return also if you want)

return True

Then you need to call your function

isYes()

if you want to see whats returned you can do

result = isYes()

print(result)

or you can do

print(isYes())

you should also look at string.upper() and str.lower()

if you convert the users input to uppercase you only need to compare characters

so yes, Yes, yEs,YES,yeS.... will all be changed to YES so you dont need to create a variable for every combination.

x = str(input("Enter value")).upper()

another short way to do this would be check if the first character of the input is a Y

if x[0].upper() == "Y":

1

u/dakingofmeme Oct 23 '20

I think what you want is If (x==a) or (x==b) or ...