"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Analyzing a line of text\n\n\n\ndef scan_line(line,pv,pc,pd,pw,po):\n\n for c in line:\n\n if c=='A' or c=='E' or c=='I' or c=='O' or c=='U':\n pv[0]+=1\n elif c>='A' and c<='Z':\n pc[0]+=1\n elif c>='0' and c<='9':\n pd[0]+=1\n elif c==' ' or c=='\\t':\n pw[0]+=1\n else:\n po[0]+=1\n\n return\n\n\nvowel,consonants,digits,whitespc,other=[0],[0],[0],[0],[0]\nline=\"Personal computers with memories in excess of 4096 KB are now quite common.\"\nline=line.upper()\nscan_line(line,vowel,consonants,digits,whitespc,other)\nprint \"\\n\\n\"\nprint \"No. of vowels : \",vowel[0]\nprint \"No. of consonants : \",consonants[0]\nprint \"No. of digits : \",digits[0]\nprint \"No. of whitespace characters : \",whitespc[0]\nprint \"No. of other characters : \",other[0]",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n\nNo. of vowels : 23\nNo. of consonants : 35\nNo. of digits : 4\nNo. of whitespace characters : 12\nNo. of other characters : 1\n"
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Reoedering a list of numbers\n\n\ndef reorder(x):\n n=len(x)\n for item in range(0,n-1):\n for i in range(item+1,n):\n if x[i]Example 11.17, Page number: 11.21