Topic 6: Problem solving with programming
PART 4- 6.4 INPUT/OUTPUT
On this page is:
-
Activities
-
What You Need To Know
Bootcamp 1- Login and Date and Time System
Clive has created the shell of a program but needs some help finishing it. Basically he wants a system that will check that both username and password are in the list before logging them in and then offering them a choice of date or time.
Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler
import time
unameset=["admin","adminuser","useradmin"]
pwordset=["password","adminpassword"]
????????? ("What is your username?: ")
?????????("What is your password?: ")
if ??????????????:
print ("Login error, please try again")
if ??????????????:
choice= input ("Press 1 for time, 2 for date, 3 to exit")
if ????=="????":
print (time.strftime("%I:%M:%S"))
elif ????=="????":
print (time.strftime("%d/%m/%Y"))
elif choice=="????":
print ("Now log out")
else:
print ("Goodbye!")
DONE? Prove you have done it by showing your teacher or loading it to Edmodo
Bootcamp 2- Spy System Login]
M (James Bond Quartermaster) has created the shell of a program but needs some help finishing it. Basically he wants a system that generates a random number between 1 and 10 and if the user guesses correctly is logged in. If they guess incorrect it loops until they get it right.
Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler
import ?????
compGuesses = ??????? (1,10)
print ("Mi6 Computer System. Enter The Code To Access Spy Records? Number is between 1 and 10. Enter a number now!")
userGuesses = input()
???????? userGuesses != compGuesses:
print ("Access Denied! Security Called. Enter A New Number")
userGuesses = input()
????????????????????????????
print ("ACCESS GRANTED TO Mi6 Spy Records. Hello James Bond 007. Security Not Coming Now")
print ("Would you like to contact M regarding your next mission? Type 'yes' or 'no'")
yes = '1'
no = '2'
answer = input()
if answer == '1':
print ("Your next mission is to leave now and catch a flight to Moscow")
if answer == '2':
print ("Miss Moneypenny will be along soon with a cup of tea!")
print ("Do you require a firearm or a poison pen? Type 'gun' or 'pen'")
gun = '1'
pen = '2'
answer = input()
?????????????????
print ("Walther PPK Issued James. Good luck!")
?????????????????
print ("You will have to use just your charm!")
DONE? Prove you have done it by showing your teacher or loading it to Edmodo
Bootcamp 3- Valid Email Check
Claire works in IT security at ABC Ltd and needs a program written that checks whether the email address contains an @ sign or a . (dot). If the email entered does not contain a an @ sign or a . (dot) it will loop until they enter the correct format of email address. Here is the code to get you started:
Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler
status="False"
print ("Welcome to ABC Ltd New User Set Up")
while status=="False":
emailadd=input("Please enter a valid email address")
DONE? Prove you have done it by showing your teacher or loading it to Edmodo
Bootcamp 4- Valid Email Check- Special Symbol and Number
Mary needs a robust password checking sytem that ony allows symbols and number together. FInish her code
Copy the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler
print("Password checking system. All passwords must have a special symbol and number in it")
print ("The system will score your password. Get 5 points for a symbol and number. Pass score is 10")
pword=input("Enter password: ")
??????????? = "~`!@#$%^&*()_-+={}[]:>;',</?*-+"
pscore=0
for i in pword:
if i in symbol:
print ("You have a symbol. This is important. 5 points")
pscore=pscore+5
break
num = "0 1 2 3 4 5 6 7 8 9"
???????????
???????????
print ("You have a number. This is important. 5 points")
pscore=pscore+5
break
???????????:
print("Your password has been accepted")
???????????:
print("Your password has not been accepted. Check that you have a symbol and a number together")
DONE? Prove you have done it by showing your teacher or loading it to Edmodo
Bootcamp 5- Add On Length Check
Mary loves what you did in Bootcamp 4.
Can you now add in a length check of the password so that ithe password must be no more than 8 characters long. Use the string function len()
Enter the code into Python or the online version here: https://www.onlinegdb.com/online_python_compiler
DONE? Prove you have done it by showing your teacher or loading it to Edmodo
KEY LEARNING AREAS
In the following area you will:
6.4.1 be able to write programs that accept and respond appropriately to user input
6.4.2 be able to write programs that read from and write to comma separated value text files
File operations include open, close, read, write and append.
<fileid> = open(<filename>, "r") Opens file for reading
for <line> in <fileid>: Reads every line, one at a time
<alist> = <fileid>.readlines() Returns a list where each item is a line from the file
<aline> = <fileid>.readline() Returns a line from a file. Returns an empty string on the end of the file
<fileid> = open(<filename>, "w") Opens file for writing
<fileid> = open(<filename>, "a") Opens file for appending
<fileid>.writelines(<structure>) Writes <structure> to a file. <structure> is a list of strings
<fileid>.write(<aString>) Writes a single string to a file
<fileid>.close() Closes file
6.4.3 understand the need for and be able to write programs that implement validation (length check, presence check, range check, pattern check)
6.4.4 understand the need for and be able to write programs that implement authentication (ID and password, lookup)