Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test pull request #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 117 additions & 84 deletions Labs/module-1_labs/01_python/12_project-challenge/your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,110 +16,143 @@
"There needs to be at least 1 number.\n",
"The password needs to be at least 8 characters long.\n",
"\n",
"*You are permitted to use any methods to validate the password.*"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge B: Credit Card Validator\n",
"\n",
"#### Description\n",
"\n",
"Your task is to write a program which reads credit card number prints the validation result ‘Valid’ or ‘Invalid’.\n",
"\n",
"A valid credit card has following features:\n",
"\n",
"- It should start with 4, 5 or 6\n",
"- It should have exactly 16 digits\n",
"- It should only consist of digits (0-9)\n",
"- It may have digits in groups of 4 and separated by one hyphen \"-\"\n",
"- It should NOT use any other separator like ‘ ’,‘_’, etc.\n",
"- It should NOT have 4 or more consecutive repeated digits\n",
"\n",
"Valid Credit Card Numbers:\n",
"1. 4263525778615786\n",
"2. 5535535535559555\n",
"3. 6344-2389-7542-9163\n",
"\n",
"Invalid Credit Card Numbers:\n",
"1. 42536258796157867 \n",
"2. 66266666626662666 \n",
"3. 5122-2368-7954 -3214 \n",
"4. 44244x4424442444 \n",
"5. 0525362587961578"
"*You are permitted to use any methods to validate the password.*"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# your code here \n"
]
},
{
"cell_type": "markdown",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter here your new password :\n",
" amandine8\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The password needs at least 1 uppercase letter.\n",
"Your password is not valid, please restart !\n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter here your new password :\n",
" Amandine8523*\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your password is valid\n",
"\n"
]
}
],
"source": [
"## Challenge C: Multiplication Table\n",
"\n",
"#### Description\n",
"import re\n",
"\n",
"\n",
"#Texte de bienvenue, création et conditions du mot de passe par l'utilisateur\n",
"print(\"*** Welcome on our site ! ***\\n\\n\"\n",
" \"Now to finalize your inscription, we need to record your new password :)\\n\\n\"\n",
" \"Please, to create a secure password, you have to respect these conditions : \\n\"\n",
" \"- at least 1 uppercase letter. \\n\"\n",
" \"- at least 1 lowercase letter. \\n\"\n",
" \"- at least 1 number. \\n\"\n",
" \"- The password needs to be at least 8 characters long. \\n\"\n",
" )\n",
"\n",
"\n",
"#Fonction pour tester si au moins 1 majuscule\n",
"def test_uppercase(str1):\n",
" if len(re.findall('[A-Z]', str1)) >= 1:\n",
" return 0\n",
" else:\n",
" print(\"The password needs at least 1 uppercase letter.\")\n",
" return 1\n",
" \n",
"Your task, is to create a function which returns a **NxN multiplication table**, of size N provided as a function argument.\n",
"\n",
"for example, when given size is 3:\n",
"\n",
"1 2 3\n",
" \n",
"#Fonction pour tester si au moins 1 minuscule\n",
"def test_lowercase(str2):\n",
" if len(re.findall('[a-z]', str2)) >= 1:\n",
" return 0\n",
" else:\n",
" print(\"The password needs at least 1 lowercase letter.\")\n",
" return 1\n",
"\n",
"2 4 6\n",
" \n",
"#Fonction pour tester si au moins 1 chiffre\n",
"def test_number(str3):\n",
" if len(re.findall('\\d', str3)) >= 1:\n",
" return 0\n",
" else:\n",
" print(\"The password needs at least 1 number.\")\n",
" return 1\n",
" \n",
"\n",
"3 6 9\n",
"#Fonction pour tester si caractère espace dans le mot de passe, caractère interdit\n",
"def test_space(str5):\n",
" if len(re.findall('\\s', str5)) >= 1:\n",
" print(\"The space is not allowed\")\n",
" return 1\n",
" else:\n",
" return 0\n",
" \n",
" \n",
"#Fonction pour tester si au moins 8 caractères\n",
"def test_len_characters(str4):\n",
" total_characters = len(str4)\n",
" if total_characters < 8:\n",
" print(\"The password needs to be at least 8 characters long.\")\n",
" return 1\n",
" else:\n",
" return 0\n",
" \n",
" \n",
"#Fonction pour vérifier la validité du mot de passe\n",
"def test_all(int1, int2, int3, int4, int5):\n",
" if int1 + int2 + int3 + int4 + int5 > 0:\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"So for the given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]]"
" \n",
"#Boucle de création de mot de passe valide, si non, l'utilisateur doit recommencer\n",
"while True:\n",
" ask_password = input('Enter here your new password :\\n')\n",
" if test_all(test_len_characters(ask_password), test_uppercase(ask_password), \n",
" test_lowercase(ask_password), test_number(ask_password), test_space(ask_password)):\n",
" print('Your password is not valid, please restart !\\n')\n",
" else:\n",
" print('Your password is valid\\n')\n",
" break\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge D: ID Assignment\n",
"\n",
"#### Description\n",
"\n",
"a) You work in a company with 100 people - to start, please create a list of people ranging from Person 1 to Person 100. For company purposes, each of these people is identified with a Personal ID, which is a combination of 2 uppercase letters and a random number of 5 digits. For each person, generate a random ID, and store it in a dictionary alongside their name (for example ('Person 5': 'AB73648')). Then sort the dictionary according to the values of their Personal IDs.\n",
"\n",
"b) One month later, your company changes the ID format for every employee - from now on, every person will have an ID that consists of only letters. In order to convert them, every number in the employee ID should be replaced by the corresponding uppercase letter in the alphabeth. Please write a function that accomplishes this change and apply it to the dictionary."
]
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
]
"source": []
}
],
"metadata": {
Expand All @@ -138,9 +171,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}