saravana kumar
saravana kumar

Reputation: 1

I'm not getting expected result , I want to know what's wrong with the code

I want to know whether I can use Input function under for loops and Lists?

I'm using the latest version of python 3.7.4.

List=['apple','Pomegranate','orange']
K=print(input('Enter the Value:'))
if (K in List):
    print("yes it's in the list")
else:
    print("It's not in the list")

If I entered apple I'm getting the result as it's not on the list. I want to know whether we can use Input function under for loops and lists with if-else conditions.

Upvotes: 0

Views: 39

Answers (2)

lazyalways
lazyalways

Reputation: 9

Here you can check your error with print function.

List=['apple','Pomegranate','orange']

K=print(input('Enter the Value:'))

print(K)

.....

K is None in this case.

Upvotes: 0

jamesfranco
jamesfranco

Reputation: 520

Your issue is with the line

K=print(input('Enter the Value:'))

You do not need print here. Print is a function that takes a value, prints it to your screen and returns None. You passed the input to print, but you want to store the value in K, not print it to the screen (the user is entering the value so they probably do not need to see it again). So change this to:

K=input('Enter the Value:')

Upvotes: 2

Related Questions