Using 'if' with 'in'
Q1. Get this program working in Python:
super_users = ['David', 'Mary', 'Patrick', 'Majid']
username = input("What is your login? : ")
# Control who can access the system ....
if username in super_users:
print ("You are authorised to continue.")
print ("Access denied")
Q2. Describe how the above program works.
Q3. What would happen if you entered 'david' rather than 'David'? Try it out.
Q4. How could you overcome the problem identified in Q3 above.
Q5. Create the following new list and add it to the program:
normal_users = ['Jack', Jill', 'John', 'Jo', ''Jenny']
Q6. Modify the program using elif to check if someone is in this list as well. Display a suitable message if they are.
Q7. Create a third list and add it to your program.
Q8. Modify the program to check if someone is in this list as well. Display a suitable message if they are.
Q9. Write a new program that asks a user what they would like to eat. If their choice is available, then display a suitable message. If it is not available, display a suitable message and ask them to try again, until they enter something in the list. (HINT: You don't need an if construction here. Try using a while construction.)
Q10. Do some research. Find some examples of programs that use Boolean operators (and, or and not) in the if constructions. Write down at least six examples e.g.
if (temp>40) and (x < 10)