- 2nd Jul 2024
- 17:54 pm
Revise and apply core Python programming principles with practical exercises on string manipulation, dictionary operations, and password validation. Our experts provide comprehensive guidance to ensure you grasp each concept and complete the assignment effectively.
Task 1– Enhancing the Password Checker
There are a number of ways that the “checkPassword()” function could be improved. Let’s focus on making it more efficient. Try implementing the following changes:
- Immediately return False if the password is too long or too short.
- Only check for a certain piece of criteria if it has not already been met: Change
- “if char.isupper()” to “if not hasUpper and char.isupper()” so that the code can simply move on to the next check if the variable is already set to True.
- Stop checking characters if all criteria has been met: Move the line of code that checks if all of the boolean variables are True into the end of the loop body and return True right away if they are. After the loop, return False without checking the variables – the only way to get that far in the function is if the criteria was not met.
Task 2 – Username Generator
Create a new file in the Python Editor and copy-paste. This simply creates a dictionary named “students” which contains 6 items. The keys are student numbers, and the values are their names. Your task is to write a program that will generate usernames from the student names / numbers provided, implementing the following rules:
- All characters in a username should be in lowercase.
- Dashes (“-”) in a student’s name should not appear their username.
- Usernames consist of the first letter of the student’s first name, followed by the first 4 letters of their surname (e.g. “John Smith” would become “jsmit”). We will assume that a student’s name only consists of a first name and surname.
- Usernames must have a minimum length of 5 characters. If a student’s surname is less than 4 characters long, include add 0s (zeroes) to the end (e.g. “Sun Po” becomes “spo0”).
Your program should create a dictionary named “usernames”, with an item for each student.
Programming Principles Workshop - CSP1150 - Get Assignment Solution
Please note that this is a sample Programming Principles Workshop - CSP1150 assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Programming Principles Workshop - CSP1150
Task 1 Solution:
def checkPassword(pword):
shortEnough = False
longEnough = False
hasUpper = False
hasLower = False
hasNumber = False
hasSpecial = False
specialChars = '\'~!#$%^*()_+-={}|[]\\:<>?,./'
if len(pword) <= 16:
shortEnough = True
else:
return False
if len(pword) >= 8:
longEnough = True
else:
return False
for i in pword:
if not hasUpper and i.isupper():
hasUpper = True
if not hasLower and i.islower():
hasLower = True
if not hasNumber and i.isdigit():
hasNumber = True
if not hasSpecial and i in specialChars:
hasSpecial = True
if shortEnough == True and longEnough == True and hasUpper ==True and hasLower ==True and hasNumber == True and hasSpecial==True:
return True
return False
password = input('Enter your password: ')
if checkPassword(password):
print('Your password is valid.')
else:
print('Your password is not valid.')
Task 2 Solution
students = {60254: 'John Smith', 60255: 'Gert Du-Cart', 60256: 'Sun Po',
60257: 'Bort Woods', 60258: 'Andrew Butters', 60259: 'Betty Ho'}
usernames = {}
for i in students:
name = students[i]
name = name.replace("-","")
name = name.lower()
name = name.split(" ")
name = name[0][0] + name[1][:4]
name= name.ljust(5,'0')
usernames[i] = name
for i in usernames:
print(str(i) + " : " + usernames[i] )
Get the best Programming Principles Workshop - CSP1150 assignment help and tutoring services from our experts now!
About The Author - Dr. Emma Harper
Dr. Emma Harper is a seasoned educator and Python programming expert with extensive experience in developing practical and engaging coding exercises. Dr. Harper focuses on enhancing students' understanding of programming principles through real-world applications and efficient coding techniques.