Password Validation

Code in Python Programming Language, Code for Password Validation

The given assignment has a number of subparts. In each part, a specific code has to be written in Python Programming language.

  1. In the first two sub-parts, skeleton code is given. Students have to predict the output of the given code.
  1. In this part, a program has to be written to check the validity of a password entered by the user. User name and passwords are entered as part of logging in to the website. The constraints for password validation are given in the question.
  1. Here, a code is to be written to read the elements from a set of digits in which elements are separated by commas. The position of elements in the set has to emerge as output.
  1. In this part, a code has to be written in python. The input from the console is in the form of a string. In the output, characters would be printed that have even indexes.
  1. In this part of the question, a program has to be written in python. Here the input is a string from console. The output would be the string with characters in reverse order.
  1. In this part, a code has to be written; such that it accepts input from the console. As output, it prints the characters and the total number of times the character appears in the input string.
  1. In this part of the question, two programs are to be written. In the first program, two sets of digits are given. An output displaying the intersection of digits in two sets has to be printed.

In the second program, a list of numbers is given. Output has to be printed by excluding one particular number from the list.

  1. In the final part programs are to be written as stated below: –
  1. A list of numbers is given, output has to be printed by eliminating certain numbers from the list. The position of numbers that have to be eliminated in the list is given.
  2. A list of numbers is given. The output has to be printed by eliminating the numbers in the list which are divisible by 5 or 7.
  3. A special numeric series is given in the question. The series is: –

1/2+2/3+3/4+…+n/n+1. A program has to be written which accepts the value of ‘n’ as input. The program would print the output after computing the value of the summation of series.

SOLUTION: –

{

“cells”: [

{

“cell_type”: “code”,

“execution_count”: 1,

“metadata”: {},

“outputs”: [],

“source”: [

“from __future__ import print_function”

]

},

{

“cell_type”: “code”,

“execution_count”: 2,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“4\n”

]

}

],

“source”: [

“nums = set([1,1,2,3,3,3,4,4])\n”,

“print(len(nums)) ”

]

},

{

“cell_type”: “code”,

“execution_count”: 3,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“[‘john’, ‘peter’]\n”

]

}

],

“source”: [

“d = {\”john\”:40, \”peter\”:45} \n”,

“print(list(d.keys()))”

]

},

{

“cell_type”: “code”,

“execution_count”: 4,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“Enter the Password – [email protected]\n”,

“Valid Password\n”

]

}

],

“source”: [

“password = raw_input(\”Enter the Password – \”)\n”,

“\n”,

“if len(password)>=6 and len(password)<=12:\n”,

”    c1 = False\n”,

”    c2 = False\n”,

”    c3 = False\n”,

”    c4 = False\n”,

”    for i in password:\n”,

”        if i.isalpha():\n”,

”            if i>’a’ and i<‘z’:\n”,

”                c1 = True\n”,

”            elif i>’A’ and i<‘Z’:\n”,

”                c2 = True\n”,

”        elif i.isdigit():\n”,

”            if int(i)>=0 and int(i)<=9:\n”,

”                c3 = True\n”,

”        elif i==’$’ or i==’#’ or i==’@’:\n”,

”            c4 = True\n”,

”        else: pass\n”,

”    if c1 and c2 and c3 and c4 :\n”,

”        print (\”Valid Password\”)\n”,

”    else:\n”,

”        print (\”Invalid Password\”)\n”,

“else:\n”,

”    print (\”Invalid Password\”)”

]

},

{

“cell_type”: “code”,

“execution_count”: 5,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“4 is at position 1\n”,

“7 is at position 2\n”,

“3 is at position 3\n”,

“2 is at position 4\n”,

“5 is at position 5\n”,

“9 is at position 6\n”

]

}

],

“source”: [

“a = [4, 7, 3, 2, 5, 9]\n”,

“i = 1\n”,

“for x in a:\n”,

”    print (str(x)+’ is at position ‘+str(i))\n”,

”    i = i+1″

]

},

{

“cell_type”: “code”,

“execution_count”: 7,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“Enter a String -H1e2l3l4o5w6o7r8l9d\n”,

“Helloworld”

]

}

],

“source”: [

“word = raw_input(\”Enter a String -\”)\n”,

“for x in range(0,len(word),2):\n”,

”    print (word[x],end=\”\”,sep=”)”

]

},

{

“cell_type”: “code”,

“execution_count”: 8,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“Enter a String -rise to vote sir\n”,

“ris etov ot esir\n”

]

}

],

“source”: [

“word = raw_input(\”Enter a String -\”)\n”,

“print (word[::-1])”

]

},

{

“cell_type”: “code”,

“execution_count”: 9,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“Enter a String -abcdefgabc\n”,

“a,2\n”,

“c,2\n”,

“b,2\n”,

“e,1\n”,

“d,1\n”,

“g,1\n”,

“f,1\n”

]

}

],

“source”: [

“word = raw_input(\”Enter a String -\”)\n”,

“all_freq = {} \n”,

”  \n”,

“for i in word: \n”,

”    if i in all_freq: \n”,

”        all_freq[i] += 1\n”,

”    else: \n”,

”        all_freq[i] = 1\n”,

“\n”,

“for key, value in all_freq.iteritems() :\n”,

”    print (key,’,’,value,sep=”)”

]

},

{

“cell_type”: “code”,

“execution_count”: 10,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“[1, 3, 6, 12, 78, 88, 35, 55, 24, 120, 155]\n”

]

}

],

“source”: [

“l1 = [1,3,6,78,35,55]\n”,

“l2 = [12,24,35,24,88,120,155]\n”,

“l = list(set(l1+l2))\n”,

“print (l)”

]

},

{

“cell_type”: “code”,

“execution_count”: 11,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“[12, 35, 88, 120, 155]\n”

]

}

],

“source”: [

“l = [x for x in [12,24,35,24,88,120,155] if x!=24]\n”,

“print(l)”

]

},

{

“cell_type”: “code”,

“execution_count”: 43,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“[24, 35, 70, 155]\n”

]

}

],

“source”: [

“l = [12,24,35,70,88,120,155]\n”,

“l = [x for x in l if not(l.index(x)==0 or l.index(x)==4 or l.index(x)==5)]\n”,

“print(l)”

]

},

{

“cell_type”: “code”,

“execution_count”: 37,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“[12, 24, 88]\n”

]

}

],

“source”: [

“l = [12,24,35,70,88,120,155]\n”,

“l = [x for x in l if not(x%7==0 or x%5==0)]\n”,

“print(l)”

]

},

{

“cell_type”: “code”,

“execution_count”: 17,

“metadata”: {},

“outputs”: [

{

“name”: “stdout”,

“output_type”: “stream”,

“text”: [

“Enter an integer greater than 0 – 5\n”,

“3.55\n”

]

}

],

“source”: [

“n = input(‘Enter an integer greater than 0 – ‘)\n”,

“sum = 0\n”,

“for i in range(n+1):\n”,

”    sum += (float(i)/(i+1))\n”,

“print(sum)”

]

}

],

“metadata”: {

“kernelspec”: {

“display_name”: “Python 2”,

“language”: “python”,

“name”: “python2”

},

“language_info”: {

“codemirror_mode”: {

“name”: “ipython”,

“version”: 2

},

“file_extension”: “.py”,

“mimetype”: “text/x-python”,

“name”: “python”,

“nbconvert_exporter”: “python”,

“pygments_lexer”: “ipython2”,

“version”: “2.7.16”

}

},

“nbformat”: 4,

“nbformat_minor”: 2

}