I’m new to python and following a book to learn it. However there are some exercises without any solution, so i thought I ask it here, see if you can help me out.
First I need to make a list of names:
sailors = [“Jan”, “Piet”, “Joris”, “Korneel”]
Then I need to ask the user to input his/her name:
name = input (“Type your name please”.)
Then, and HERE is my problem, I need to use a for loop to check if the name is in the list.
If so, I need to print an answer like ("Hi, welcome’)
So far I came up with this:
sailors = [“Jan”, “Piet”, “Joris”, “Korneel”]
name = input (“What is your name?”)
for name in sailors:
if (name == “Jan” ):
print (“Well you must be a sailor!”)
else:
print (“You are not a sailor”)
But if I run it and I type in “Jan”, the output is:
well you must be a sailor
you are not a sailor
So, with just this basic commands, hope you can help me out to understand how this works.