Amazon cover image
Image from Amazon.com
Image from Google Jackets

Problem Solving And Python Programming /

By: Material type: TextTextLanguage: English Publication details: Chennai : Yesdee, c2018.Edition: 2ndDescription: 655p.: illISBN:
  • 9789388005036
Subject(s): DDC classification:
  • 004 KUL
Contents:
4.9.5 Python logical operators 4.9.6 Python identity operators 4.9.7 Python membership operators 4.9.8 Type conversion in Python 4.9.9 Type promotion (coercion) in Python 4.10 Python Operator Precedence 4.10.1 Python expressions Exercises Chapter 5 Python Input and Output Statements 5.1 Input Statements in Python 5.1.1 input () function 5.2 Output Statements in Python 5.2.1 print() function 5.3 Python String Formatting Options 5.3.1 Write a program in Python to convert a given temperature in Celsius To Fahrenheit and a given temperature in Fahrenheit to Celsius 5.4 Python Math Library 5.5 Write a Python Program to Compute Simple Interest (SI) and Compound Interest (CI) for a Given Principal, Rate of Interest and Duration in Years 5.5.1 Theory 5.5.2 Algorithm 5.5.3 Flowchart 5.5.4 Python program: InterestCalc.py 5.6 Write a Python Program to Swap Two Variables without using a Third Variable 5.6.1 Theory 5.6.2 Algorithm 5.6.3 Flowchart 5.6.4 Python program: Swap direct.py 5.7 Write a Python Program to Print the Ones Place of any Given Integer Number 5.7.1 Theory 5.7.2 Algorithm 5.7.3 Flowchart 5.7.4 Python program: Unit.digit.py 5.8 Write a Python Program to Compute the Area of a Triangle when the Three Sides are Given 5.8.1 Theory 5.8.2 Algorithm 5.8.3 Flowchart 5.8.4 Python program: Area Triangle.py 5.9 Random Numbers 5.9.1 Pseudo random numbers 5.9.2 To generate random integer number within a range 5.9.3 To choose a random element from a sequence 5.9.4 To return a list of unique elements from a population of sequence 5.9.5 Write a python program to generate 100 random numbers from a given range of values 5.9.6 To shuffle a sequence randomly in place 5.9.7 To generate floating point random number 5.9.8 To generate a random number between a range 5.9.9 To generate floating point random number for any given range 5.9.10 Write a Python program to simulate a dice game between User 1 who is a computer and User 2 who is a human. The greatest dice value among the users determines the winner Exercises Chapter 6 Python Programs on Control Structures 6.1 Introduction 6.2 Conditional Statements 6.3 if Statement 6.4 Write a Python Program to Evaluate Body Mass of a Person to Determine His Weight Status 6.4.1 Theory 6.4.2 Algorithm 6.4.3 Flowchart 6.4.4 Python program: Weight Height.py 6.5 if-else Statement 6.6 Write a Python Program to Compute Whether a Given Year is a Leap Year or Not 6.6.1 Theory 6.6.2 Algorithm 6.6.3 Flowchart 6.6.4 Python program: LeapYear.py 6.7 Write a Python Program to Compute the Roots of Quadratic Equation 6.7.1 Theory 6.7.2 Algorithm 6.7.3 Flowchart 6.7.4 Python program: QuadRoot.py 6.8 Write a Python Program to Find the Largest Among Three Integer Numbers 6.8.1 Theory 6.8.2 Algorithm 6.8.3 Flowchart 6.8.4 Python program: BigOfThree.py 6.9 Nested Conditional Statements 6.10 Dangling Else Problem 6.11 if-elif-else Statement 6.12 Write a Python Program to Compute the Percentage and Class of Students Given the Average of Six Subject Marks. The Maximum Mark for Each Subject is100Marks 6.12.1 Theory 6.12.2 Algorithm 6.12.3 Flowchart 6.12.4 Python program: Ifelse.py 6.13 Repetition Statements 6.13.1 while loop 6.13.2 Infinite loop 6.13.3 while loop with else 6.14 Write a Program in Python to Compute the Factorial for a Given Number 6.14.1 Theory 6.14.2 Algorithm 6.14.3 Flowchart 6.14.4 Python program: Factorial.py 6.15 Write a Program in Python to Test Whether a Given Number is Prime or Not 6.15.1 Theory 6.15.2 Algorithm 6.15.3 Flowchart 6.15.4 Python program: Prime.py 6.16 Write a Program in Python to Generate Fibonacci Series for a Given Number 6.16.1 Theory 6.16.2 Algorithm 6.16.3 Flowchart 6.16.4 Python program: Fibonacci.py 6.17 Write a Program in Python to Compute Whether the Given Integer Number is A Palindrome 6.17.1 Theory 6.17.2 Algorithm 6.17.3 Flowchart 6.17.4 Python program: Palindrome.py 6.18 Write a Python Program to ComputeWhether a Given Number is an Armstrong Number 6.18.1 Theory 6.18.2 Algorithm 6.18.3 Flowchart 6.18.4 Python program: Armstrong.py 6.19 Write a Python Program to Convert a Given Decimal Number to its Corresponding Binary Number 6.19.1 Theory 6.19.2 Algorithm 6.19.3 Flowchart 6.19.4 Python program: DecToBin.py 6.20 Write a Python Program to Convert a Given Binary Number to its Equivalent Decimal Number 6.20.1 Theory 6.20.2 Algorithm 6.20.3 Flowchart 6.20.4 Python program: Bin to Dec.py 6.21 for loop 6.22 Write a Python Program to Compute cos(x) from the Given Series 6.22.1 Theory 6.22.2 Algorithm 6.22.3 Flowchart 6.22.4 Python program: Cos Series.py 6.23 Write a Python Program to Compute sin(x) from the Given Series 6.23.1 Theory 6.23.2 Algorithm 6.23.3 Flowchart 6.23.4 Python program: Sine series.py 6.24 Write a Python Program to Compute Pythagorean Triplets up to a Given Maximum Value 6.24.1 Theory 6.24.2 Algorithm 6.24.3 Flowchart 6.24.4 Python program: PythaTriplet.py 6.25 for loop with else Statement 6.26 Nesting of Loops 6.27 Write a Python Program to Build a Multiplication Table from 1 to 10 6.27.1 Theory 6.27.2 Algorithm 6.27.3 Flowchart 6.27.4 Python program: MultiTable.py 6.27.5 Output 6.28 Python break statement 6.29 Role of break Statement in while with else Statement 6.29.1 Role of break statement in for with else statement 6.30 Python continue Statement 6.31 Pass Statement in Python 6.32 Case Study: Prime Number Generation Exercises Chapter 7 User-defined Functions 7.1 Introduction 7.2 Syntax of User-defined Function 7.3 Flowchart 7.4 Local Variables and Global Variables 7.5 Return Statement 7.6 Function Arguments in Python 7.6.1 Positional arguments 7.6.2 Keyword arguments 7.6.3 Variable length arguments 7.7 Default Parameter 7.8 Call-by-value vs. Call-by-reference in Python 7.9 Nested Functions in Python 7.10 Closure Function in Python 7.11 Anonymous Function in Python 7.12 Function Composition in Python 7.13 Write a Python Program using Functions to Generate the Floyd’s Triangle for a Specified Number of Rows 7.13.1 Theory 7.13.2 Algorithm 7.13.3 Flowchart 7.13.4 Python program: Flyod.py 7.14 Write a Python Program using Functions to Compute the Least Common Multiple (LCM) of Two Given Integers 7.14.1 Theory 7.14.2 Algorithm 7.14.3 Flowchart 7.14.4 Python program: lcm.py 7.15 Recursive Function in Python 7.16 Case Study Exercises Chapter 8 Python Programs on Strings 8.1 Strings in Python 8.2 Reading Strings from Keyboard 8.3 Accessing Strings 8.4 Modifying Strings in Python 8.5 String Concatenation 8.6 String Updating 8.7 Finding the Length of a String 8.8 Iterating through a String 8.9 String Member ship Operations 8.10 Built-in String Functions 8.10.1 Converting strings in lowercase to uppercase, vice versa and swapping the case 8.10.2 Searching in a string 8.10.3 Splitting strings and removing whitespaces 8.10.4 String join, length, replace and miscellaneous string functions 8.11 Escape Sequences in Python 8.12 Write a Python Program to Check Whether an Entered String is a Palindrome or Not without using Built-in String Functions Available in Python 8.12.1 Theory 8.12.2 Algorithm 8.12.3 Flowchart 8.12.4 Python program: Palin.py 8.13 Write a Python Program to Count Separately the Vowels of a Given String 8.13.1 Theory 8.13.2 Algorithm 8.13.3 Flowchart 8.13.4 Python program: Vowel count.py 8.14 Write a Python Program to Compute the Length of an Input String without using the Built-in Python Function len() 8.14.1 Theory 8.14.2 Algorithm 8.14.3 Flowchart 8.14.4 Python program: String length.py 8.15 Write a Python Program to Count the Number of Characters in a Given Word 8.15.1 Theory 8.15.2 Algorithm 8.15.3 Flowchart 8.15.4 Python program: Char count.py 8.16 Write a Python Program to Check the Bigger of the Two Inputted Strings 8.16.1 Theory 8.16.2 Algorithm 8.16.3 Flowchart 8.16.4 Python program: Biggest String.py 8.17 Write a Python Program to Count the Common Characters in the Two Inputted Strings 8.17.1 Theory 8.17.2 Algorithm 8.17.3 Flowchart 8.17.4 Python program: Common char.py 8.18 Write a Python Program to Count the Occurrences of the Substring in a Given String 8.18.1 Theory 8.18.2 Algorithm 8.18.3 Flowchart 8.18.4 Python program: Substring.py 8.19 Write a Python Program to Check Whether the Characters of an Inputted String are in Alphabetical Order 8.19.1 Theory 8.19.2 Algorithm 8.19.3 Flowchart 8.19.4 Python program : Alpha String.py 8.20 Write a Python Program to Sort Words Entered by User in Alphabetical Order 8.20.1 Theory 8.20.2 Algorithm 8.20.3 Flowchart 8.20.4 Python program: Sort String.py 8.21 Write a Recursive Python Program to Find Permutation of all Characters in a String 8.21.1 Theory 8.21.2 Algorithm 8.21.3 Flowchart 8.21.4 Python program: String Permu.py 8.22 Case Study Exercises Chapter 9 Python Lists 9.1 Introduction 9.2 How to Read a List Type from a Keyboard 9.3 Accessing Elements of a List 9.4 Modifying Elements of a List 9.5 Deleting Elements of a List 9.6 Basic List Operations 9.7 Built-in List Functions 9.8 Python List Methods 9.9 Python List Duplication and Comparison of Two Lists 9.10 Write a Python Program to Compute the Sum of Odd and Even Numbers for a Given Range in a List 9.10.1 Theory 9.10.2 Algorithm 9.10.3 Flowchart 9.10.4 Python program: SumOddEven.py 9.11 Write a Python Program to Compute Mean, Variance and Standard Deviation of a List of Numbers 9.11.1 Theory 9.11.2 Algorithm 9.11.3 Flowchart 9.11.4 Python program: Standard Deviation.py 9.12 Write a Python Program to Compute Prime Numbers from 0 to Maximum Range using Sieve of Eratosthenes 9.12.1 Theory 9.12.2 Algorithm 9.12.3 Flowchart 9.12.4 Python program: Sieve Prime.py 9.13 Write a Python Program to Compute the Average of Best of Two of Three Assignment Tests. Maximum Marks for each Assignment is 25. Fractional Marks in Final Average are Rounded off to the Nearest and Highest Whole Number 9.13.1 Theory 9.13.2 Algorithm 9.13.3 Flowchart 9.13.4 Python program: Avg Best 2.py 9.14 Write a Python Program to Reverse the Members of a Given List 9.14.1 Theory 9.14.2 Algorithm 9.14.3 Flowchart 9.14.4 Python program: Reverse list.py xviii Contents 9.15 Write a Python Program to Compute the Value of a Given Polynomial of n degree through Horner’s Method 9.15.1 Theory 9.15.2 Algorithm 9.15.3 Flowchart 9.15.4 Python program: Poly.py 9.16 Write a Python Program to Search a Given Element in an Integer List using Binary Search Technique 9.16.1 Theory 9.16.2 Algorithm 9.16.3 Flowchart 9.16.4 Python program: Binary Search.py 9.17 Write a Python Program to Sort an Integer List using Bubble Sorting Technique 9.17.1 Theory 9.17.2 Algorithm 9.17.3 Flowchart 9.17.4 Python program: Bubble Sort.py 9.18 Write a Python Program to Sort an Integer List using Insertion Sorting Technique 9.18.1 Theory 9.18.2 Algorithm 9.18.3 Flowchart 9.18.4 Python program: Insertion.Sort.py 9.19 Write a Python Program to Add Two Given Matrices of Size m × n and p × q . 339 9.19.1 Theory 9.19.2 Algorithm 9.19.3 Flowchart 9.19.4 Python program: Matrix Addition.py 9.20 Write a Python Program to Compute Multiplication of Matrices of Order m × n and p ×q 9.20.1 Theory 9.20.2 Algorithm 9.20.3 Flowchart 9.20.4 Python program: Matrix Multiplication.py 9.21 Write a Python Program to Compute Transpose of a Given Matrix 9.21.1 Theory 9.21.2 Algorithm 9.21.3 Flowchart 9.21.4 Python program: Matrix Transpose.py 9.22 Write a Python Program to Add and Find the Sum of Principal Diagonal Elements of a Given Matrix 9.22.1 Theory 9.22.2 Algorithm 9.22.3 Flowchart 9.22.4 Python program: Matrix Add Principal.py 9.23 Write a Python Program to Add and Find the Sum of Secondary Diagonal Elements of a Given Matrix 9.23.1 Theory 9.23.2 Algorithm 9.23.3 Flowchart 9.23.4 Python program: Matrix Add Secondary.py 9.24 Write a Python Program to Compute the Norm of a Given Matrix 9.24.1 Theory 9.24.2 Algorithm 9.24.3 Flowchart 9.24.4 Python program: Matrix Norm.py 9.25 Write a Python Program to Compute Row Sum and Column Sum of a Given Matrix 9.25.1 Theory 9.25.2 Algorithm 9.25.3 Flowchart 9.25.4 Python program: Matrix Row Col Sum.py 9.26 Write a Python Program to Compute Whether the Given Square Matrix is a Magic Square 9.26.1 Theory 9.26.2 Algorithm 9.26.3 Flowchart 9.26.4 Python program: matrix magic.py 9.27 Case Study Exercises Chapter 10 Python Programs on Tuples 10.1 Introduction 10.2 How to Read a List Type from a Keyboard 10.3 Accessing Elements of a Tuple 10.4 Modifying Elements of a Tuple 10.5 Deleting Elements of a Tuple 10.6 Basic Tuple Operations 10.7 Tuple Built-in Functions 10.8 Write a Python Program using Tuples to Accept Individual Address Details And Display the Same 10.8.1 Theory 10.8.2 Algorithm 10.8.3 Flowchart 10.8.4 Python program: Address Display.py 10.9 Write a Python Program using Tuples to Accept Employee Salary Details and Calculate Final Salary Based on the Overtime Hours 10.9.1 Theory 10.9.2 Algorithm 10.9.3 Flowchart 10.9.4 Python program: Salary Calc.py 10.10 Write a Python Program using Tuples to Input Student Details. The Program Should Accept a Given Student’s Roll Number and Display His Specific Records 10.10.1 Theory 10.10.2 Algorithm 10.10.3 Flowchart 10.10.4 Python program: Student Info.py 10.11 Write a Python Program using Tuples to Input Student Details and Compute His Percentage and Class Based on His Average Marks for Five Subjects 10.11.1 Theory 10.11.2 Algorithm 10.11.3 Flowchart 10.11.4 Python program: Student Result.Analysis.py 10.12 Write a Python Program using Tuples to Guess the Number of Colors in a Traffic Signal and also to Guess which Color is used to say “Stop if Possible!”. The Program Should Evaluate Whether the Answers are Right or Wrong 10.12.1 Theory 10.12.2 Algorithm 10.12.3 Flowchart 10.12.4 Python program: Traffic Signal.py Exercises Chapter 11 Python Dictionary 11.1 Introduction 11.2 Creating a Dictionary and Printing a Dictionary 11.3 Accessing Dictionary Elements 11.4 Modifying a Dictionary 11.5 Delete Operations on a Dictionary 11.6 Dictionary Key Properties 11.7 Comparing Two Dictionaries 11.8 Python Dictionary Built-in Functions 11.9 How to Generate Keys, Values and Items for Python Dictionary 11.10 Copying and Updating a Dictionary 11.11 Write a Python Program using Dictionary to Generate a Small Dictionary of Synonyms. The Program Should then Accept a Word and Generate Synonyms for the Same 11.11.1 Theory 11.11.2 Algorithm 11.11.3 Flowchart 11.11.4 Python program: Synonym.py 11.12 Write a Python Program using Dictionary to Accept a Sentence and Generate The Frequency of Words for the Same 11.12.1 Theory 11.12.2 Algorithm 11.12.3 Flowchart 11.12.4 Python program: Word Freq.py 11.13 Write a Python Program to Create a Dictionary Consisting of State and Their Corresponding Dishes. The Program Should Accept a State Name from the user and Generate the Corresponding Dishes 11.13.1 Theory 11.13.2 Algorithm 11.13.3 Flowchart 11.13.4 Python program: State Dishes.py 11.14 Write a Python Program using Dictionary to Find the Maximum and Minimum Among the Given Values 11.14.1 Theory 11.14.2 Algorithm 11.14.3 Flowchart 11.14.4 Python program: Max Min Dict.py 11.15 Write a Python Program using Dictionary to Encrypt and Decrypt a Given Plain Text using Additive Cipher 11.15.1 Theory 11.15.2 Algorithm 11.15.3 Flowchart 11.15.4 Python program: Subs Cipher.py Exercises Chapter 12 Python Files 12.1 Introduction 12.2 Writing into Files 12.3 Reading from Files 12.4 Reading Lines from Files 12.5 Stripping Characters from Files 12.6 Filenames and Paths 12.7 Format Operator 12.8 Command Line Arguments 12.8.1 The system module—sys module 12.8.2 Write a Python program that takes command line arguments as integer numbers and computes their sum 12.9 Exceptions in Python 12.10 Write a Python Program to Demonstrate IO Error Exception when we Try to Read a Non-existing File 12.11 Write a Python Program that Computes the Sum of All Integer Numbers Stored in a File Named “data.txt” with an Exception Handling Features if the Numbers are not Integers. The Sum Should be Printed on the Command Prompt 12.12 Write a Python Program to Count the Number of Lines in a File 12.13 Write a Python Program to Find the Most Frequent Words in a Text Read from A File 12.14 Write a Python Program that Read an Input File Containing Floating Point Values and Find the Minimum and the Maximum of the Values Stored 12.15 Write a Python Program to Copy the Contents of an Input File to an Output File and also Display the Contents of Input File and Output File on the Screen 12.16 Write a Python Program to Compute the Number of Line, Words and Characters in a Given Input Test File 12.17 Python Modules 12.17.1 Importing modules 12.17.2 How to create your own modules 12.17.3 To invoke specific functions or variables from modules 12.17.4 The dir() function 12.17.5 Restoring a module 12.18 Python Packages Exercises Appendix A Pygame Installation A.1 Installation of Python 3.2 A.2 Installation of Pygame A.3 Colors in Pygame Appendix B Laboratory Exercise B.1 GCD of two numbers B.2 Square root of a number (Newton’s method) B.3 Exponentiation (power of a number) B.4 Linear search and binary search B.5 First n prime numbers B.6 Maximum of a list of numbers B.7 Selection sort and insertion sort B.8 Duplicate elements removal in a list B.9 Merge sort and quick sort B.10 Multiply matrices B.11 Command line arguments (word count) B.12 Most frequent words in a text read from a file B.13 Bouncing ball simulation using Pygame B.14 The area of trapezium B.15 User-defined function to check for prime numbers B.16 Calculate and print the sum of a series B.17 Gregory series for calculating the value of Pi B.18 Sum and average of numbers from 0 upto n B.19 Tribonacci sequence for n numbers B.20 Perfect numbers generation up to amax range B.21 Highest common factor (HCF) of two numbers B.22 Lucas sequence of N numbers B.23 User-defined function to permute (x, y) B.24 User-defined function for combination (x, y) B.25 Duplicate words removal from a given string B.26 Capitalize each word in a given sentence B.27 Return words beginning with specified letter in a sentence and also display the count B.28 White spaces insertion before and after the string B.29 Extra white spaces removal between two words in a string B.30 Return quoted word from a sentence B.31 Setting a strong password with conditions B.32 Setting a password with conditions B.33 Accept a list of numbers and a number and print in order all elements of the list that are greater than the number B.34 Accept a list of numbers and sort half of them in ascending and remaining half In descending order B.35 Convert all the principal diagonal elements to 1’s B.36 Compare two matrices of same size B.37 Check if a given matrix is a lower triangular matrix B.38 Check if a given matrix is a upper triangular matrix B.39 Check whether a given matrix is a symmetric matrix B.40 Using tuples, compute if the number of odd value elements and even value elements are the same B.41 Search a name in a given tuple of names B.42 Word jumble game simulation B.43 Read a dictionary and count the number of values that appears two or more times B.44 English to Tamil translator B.45 Add integer numbers stored in two files and their sum should be written in another file Appendix C Mini Projects Using Python C.1 Cows and bulls game C.2 Number guessing game C.3 Hollywood hangman game C.4 Encrypt and decrypt a message using Vigenere Cipher Appendix D Viva Voce Questions Appendix E Solved University Question Paper Bibiliography
Summary: If you are learning Python from a beginner’s perspective and with hands-on approach then this is the right book. The major emphasis in this book has been to solve an exhaustive number of programming examples and to understand the concepts surrounding it right from the relevant theory, syntax, and semantics to coding issues. This book is useful for engineering students, beginners and those who want to learn a new programming language. The book adapts Python 3.1 version. Key features Deals with the language fundamentals and building blocks like operators, variables, keywords, etc. User-defined functions and Python sequences like strings, tuples and lists are dealt in an exhaustive manner. Dictionaries, Files, Modules and Packages are explained in a lucid manner along with exceptions. Case studies are provided for in-depth learning. Programming exercises are provided for students to reassess their programming skills. Exhaustive laboratory exercises are solved. A brief introduction is provided to Pygame along with examples. Mini Python projects are provided for modeling security algorithms and games. University question paper is solved to reinforce academic learning. Sample viva-voce questions are provided to revise unique features of Python language.
Tags from this library: No tags from this library for this title. Log in to add tags.
Star ratings
    Average rating: 0.0 (0 votes)
Holdings
Item type Current library Collection Call number Status Date due Barcode
General Books General Books CUTN Central Library Generalia Non-fiction 004 KUL (Browse shelf(Opens below)) Available 47300


4.9.5 Python logical operators

4.9.6 Python identity operators

4.9.7 Python membership operators

4.9.8 Type conversion in Python

4.9.9 Type promotion (coercion) in Python

4.10 Python Operator Precedence

4.10.1 Python expressions

Exercises

Chapter 5 Python Input and Output Statements

5.1 Input Statements in Python

5.1.1 input () function

5.2 Output Statements in Python

5.2.1 print() function

5.3 Python String Formatting Options

5.3.1 Write a program in Python to convert a given temperature in Celsius To Fahrenheit and a given temperature in Fahrenheit to Celsius

5.4 Python Math Library

5.5 Write a Python Program to Compute Simple Interest (SI) and Compound Interest

(CI) for a Given Principal, Rate of Interest and Duration in Years

5.5.1 Theory

5.5.2 Algorithm

5.5.3 Flowchart

5.5.4 Python program: InterestCalc.py

5.6 Write a Python Program to Swap Two Variables without using a Third Variable

5.6.1 Theory

5.6.2 Algorithm

5.6.3 Flowchart

5.6.4 Python program: Swap direct.py

5.7 Write a Python Program to Print the Ones Place of any Given Integer Number

5.7.1 Theory

5.7.2 Algorithm

5.7.3 Flowchart

5.7.4 Python program: Unit.digit.py

5.8 Write a Python Program to Compute the Area of a Triangle when the Three

Sides are Given

5.8.1 Theory

5.8.2 Algorithm

5.8.3 Flowchart

5.8.4 Python program: Area Triangle.py

5.9 Random Numbers

5.9.1 Pseudo random numbers

5.9.2 To generate random integer number within a range

5.9.3 To choose a random element from a sequence

5.9.4 To return a list of unique elements from a population of sequence

5.9.5 Write a python program to generate 100 random numbers from a

given range of values

5.9.6 To shuffle a sequence randomly in place

5.9.7 To generate floating point random number

5.9.8 To generate a random number between a range

5.9.9 To generate floating point random number for any given range

5.9.10 Write a Python program to simulate a dice game between User 1 who

is a computer and User 2 who is a human. The greatest dice value

among the users determines the winner

Exercises

Chapter 6 Python Programs on Control Structures

6.1 Introduction

6.2 Conditional Statements

6.3 if Statement

6.4 Write a Python Program to Evaluate Body Mass of a Person to Determine His

Weight Status

6.4.1 Theory

6.4.2 Algorithm

6.4.3 Flowchart

6.4.4 Python program: Weight Height.py

6.5 if-else Statement

6.6 Write a Python Program to Compute Whether a Given Year is a Leap

Year or Not

6.6.1 Theory

6.6.2 Algorithm

6.6.3 Flowchart

6.6.4 Python program: LeapYear.py

6.7 Write a Python Program to Compute the Roots of Quadratic Equation

6.7.1 Theory

6.7.2 Algorithm

6.7.3 Flowchart

6.7.4 Python program: QuadRoot.py

6.8 Write a Python Program to Find the Largest Among Three Integer Numbers

6.8.1 Theory

6.8.2 Algorithm

6.8.3 Flowchart

6.8.4 Python program: BigOfThree.py

6.9 Nested Conditional Statements

6.10 Dangling Else Problem

6.11 if-elif-else Statement

6.12 Write a Python Program to Compute the Percentage and Class of Students

Given the Average of Six Subject Marks. The Maximum Mark for Each

Subject is100Marks

6.12.1 Theory

6.12.2 Algorithm

6.12.3 Flowchart

6.12.4 Python program: Ifelse.py

6.13 Repetition Statements

6.13.1 while loop

6.13.2 Infinite loop

6.13.3 while loop with else

6.14 Write a Program in Python to Compute the Factorial for a Given Number

6.14.1 Theory

6.14.2 Algorithm

6.14.3 Flowchart

6.14.4 Python program: Factorial.py

6.15 Write a Program in Python to Test Whether a Given Number is Prime or Not

6.15.1 Theory

6.15.2 Algorithm

6.15.3 Flowchart

6.15.4 Python program: Prime.py

6.16 Write a Program in Python to Generate Fibonacci Series for a Given Number

6.16.1 Theory

6.16.2 Algorithm

6.16.3 Flowchart

6.16.4 Python program: Fibonacci.py

6.17 Write a Program in Python to Compute Whether the Given Integer Number is

A Palindrome

6.17.1 Theory

6.17.2 Algorithm

6.17.3 Flowchart

6.17.4 Python program: Palindrome.py

6.18 Write a Python Program to ComputeWhether a Given Number is an Armstrong

Number

6.18.1 Theory

6.18.2 Algorithm

6.18.3 Flowchart

6.18.4 Python program: Armstrong.py

6.19 Write a Python Program to Convert a Given Decimal Number to its Corresponding

Binary Number

6.19.1 Theory

6.19.2 Algorithm

6.19.3 Flowchart

6.19.4 Python program: DecToBin.py

6.20 Write a Python Program to Convert a Given Binary Number to its Equivalent

Decimal Number

6.20.1 Theory

6.20.2 Algorithm

6.20.3 Flowchart

6.20.4 Python program: Bin to Dec.py

6.21 for loop

6.22 Write a Python Program to Compute cos(x) from the Given Series

6.22.1 Theory

6.22.2 Algorithm

6.22.3 Flowchart

6.22.4 Python program: Cos Series.py

6.23 Write a Python Program to Compute sin(x) from the Given Series

6.23.1 Theory

6.23.2 Algorithm

6.23.3 Flowchart

6.23.4 Python program: Sine series.py

6.24 Write a Python Program to Compute Pythagorean Triplets up to a Given

Maximum Value

6.24.1 Theory

6.24.2 Algorithm

6.24.3 Flowchart

6.24.4 Python program: PythaTriplet.py

6.25 for loop with else Statement

6.26 Nesting of Loops

6.27 Write a Python Program to Build a Multiplication Table from 1 to 10

6.27.1 Theory

6.27.2 Algorithm

6.27.3 Flowchart

6.27.4 Python program: MultiTable.py

6.27.5 Output

6.28 Python break statement

6.29 Role of break Statement in while with else Statement

6.29.1 Role of break statement in for with else statement

6.30 Python continue Statement

6.31 Pass Statement in Python

6.32 Case Study: Prime Number Generation

Exercises

Chapter 7 User-defined Functions

7.1 Introduction

7.2 Syntax of User-defined Function

7.3 Flowchart

7.4 Local Variables and Global Variables

7.5 Return Statement

7.6 Function Arguments in Python

7.6.1 Positional arguments

7.6.2 Keyword arguments

7.6.3 Variable length arguments

7.7 Default Parameter

7.8 Call-by-value vs. Call-by-reference in Python

7.9 Nested Functions in Python

7.10 Closure Function in Python

7.11 Anonymous Function in Python

7.12 Function Composition in Python

7.13 Write a Python Program using Functions to Generate the Floyd’s Triangle for

a Specified Number of Rows

7.13.1 Theory

7.13.2 Algorithm

7.13.3 Flowchart

7.13.4 Python program: Flyod.py

7.14 Write a Python Program using Functions to Compute the Least Common Multiple

(LCM) of Two Given Integers

7.14.1 Theory

7.14.2 Algorithm

7.14.3 Flowchart

7.14.4 Python program: lcm.py

7.15 Recursive Function in Python

7.16 Case Study

Exercises

Chapter 8 Python Programs on Strings

8.1 Strings in Python

8.2 Reading Strings from Keyboard

8.3 Accessing Strings

8.4 Modifying Strings in Python

8.5 String Concatenation

8.6 String Updating

8.7 Finding the Length of a String

8.8 Iterating through a String

8.9 String Member ship Operations

8.10 Built-in String Functions

8.10.1 Converting strings in lowercase to uppercase, vice versa and swapping

the case

8.10.2 Searching in a string

8.10.3 Splitting strings and removing whitespaces

8.10.4 String join, length, replace and miscellaneous string

functions

8.11 Escape Sequences in Python

8.12 Write a Python Program to Check Whether an Entered String is a Palindrome

or Not without using Built-in String Functions Available in Python

8.12.1 Theory

8.12.2 Algorithm

8.12.3 Flowchart

8.12.4 Python program: Palin.py

8.13 Write a Python Program to Count Separately the Vowels of a Given String

8.13.1 Theory

8.13.2 Algorithm

8.13.3 Flowchart

8.13.4 Python program: Vowel count.py

8.14 Write a Python Program to Compute the Length of an Input String without

using the Built-in Python Function len()

8.14.1 Theory

8.14.2 Algorithm

8.14.3 Flowchart

8.14.4 Python program: String length.py

8.15 Write a Python Program to Count the Number of Characters in a Given Word

8.15.1 Theory

8.15.2 Algorithm

8.15.3 Flowchart

8.15.4 Python program: Char count.py

8.16 Write a Python Program to Check the Bigger of the Two Inputted Strings

8.16.1 Theory

8.16.2 Algorithm

8.16.3 Flowchart

8.16.4 Python program: Biggest String.py

8.17 Write a Python Program to Count the Common Characters in the Two Inputted

Strings

8.17.1 Theory

8.17.2 Algorithm

8.17.3 Flowchart

8.17.4 Python program: Common char.py

8.18 Write a Python Program to Count the Occurrences of the Substring in a Given

String

8.18.1 Theory

8.18.2 Algorithm

8.18.3 Flowchart

8.18.4 Python program: Substring.py

8.19 Write a Python Program to Check Whether the Characters of an Inputted String

are in Alphabetical Order

8.19.1 Theory

8.19.2 Algorithm

8.19.3 Flowchart

8.19.4 Python program : Alpha String.py

8.20 Write a Python Program to Sort Words Entered by User in Alphabetical Order

8.20.1 Theory

8.20.2 Algorithm

8.20.3 Flowchart

8.20.4 Python program: Sort String.py

8.21 Write a Recursive Python Program to Find Permutation of all Characters in a

String

8.21.1 Theory

8.21.2 Algorithm

8.21.3 Flowchart

8.21.4 Python program: String Permu.py

8.22 Case Study

Exercises

Chapter 9 Python Lists

9.1 Introduction

9.2 How to Read a List Type from a Keyboard

9.3 Accessing Elements of a List

9.4 Modifying Elements of a List

9.5 Deleting Elements of a List

9.6 Basic List Operations

9.7 Built-in List Functions

9.8 Python List Methods

9.9 Python List Duplication and Comparison of Two Lists

9.10 Write a Python Program to Compute the Sum of Odd and Even Numbers for a

Given Range in a List

9.10.1 Theory

9.10.2 Algorithm

9.10.3 Flowchart

9.10.4 Python program: SumOddEven.py

9.11 Write a Python Program to Compute Mean, Variance and Standard Deviation

of a List of Numbers

9.11.1 Theory

9.11.2 Algorithm

9.11.3 Flowchart

9.11.4 Python program: Standard Deviation.py

9.12 Write a Python Program to Compute Prime Numbers from 0 to Maximum

Range using Sieve of Eratosthenes

9.12.1 Theory

9.12.2 Algorithm

9.12.3 Flowchart

9.12.4 Python program: Sieve Prime.py

9.13 Write a Python Program to Compute the Average of Best of Two of Three

Assignment Tests. Maximum Marks for each Assignment is 25. Fractional

Marks in Final Average are Rounded off to the Nearest and Highest Whole

Number

9.13.1 Theory

9.13.2 Algorithm

9.13.3 Flowchart

9.13.4 Python program: Avg Best 2.py

9.14 Write a Python Program to Reverse the Members of a Given List

9.14.1 Theory

9.14.2 Algorithm

9.14.3 Flowchart

9.14.4 Python program: Reverse list.py

xviii Contents

9.15 Write a Python Program to Compute the Value of a Given Polynomial of n

degree through Horner’s Method

9.15.1 Theory

9.15.2 Algorithm

9.15.3 Flowchart

9.15.4 Python program: Poly.py

9.16 Write a Python Program to Search a Given Element in an Integer List using

Binary Search Technique

9.16.1 Theory

9.16.2 Algorithm

9.16.3 Flowchart

9.16.4 Python program: Binary Search.py

9.17 Write a Python Program to Sort an Integer List using Bubble Sorting

Technique

9.17.1 Theory

9.17.2 Algorithm

9.17.3 Flowchart

9.17.4 Python program: Bubble Sort.py

9.18 Write a Python Program to Sort an Integer List using Insertion Sorting

Technique

9.18.1 Theory

9.18.2 Algorithm

9.18.3 Flowchart

9.18.4 Python program: Insertion.Sort.py

9.19 Write a Python Program to Add Two Given Matrices of Size m × n and p × q . 339

9.19.1 Theory

9.19.2 Algorithm

9.19.3 Flowchart

9.19.4 Python program: Matrix Addition.py

9.20 Write a Python Program to Compute Multiplication of Matrices of Order

m × n and p ×q

9.20.1 Theory

9.20.2 Algorithm

9.20.3 Flowchart

9.20.4 Python program: Matrix Multiplication.py

9.21 Write a Python Program to Compute Transpose of a Given Matrix

9.21.1 Theory

9.21.2 Algorithm

9.21.3 Flowchart

9.21.4 Python program: Matrix Transpose.py

9.22 Write a Python Program to Add and Find the Sum of Principal Diagonal

Elements of a Given Matrix

9.22.1 Theory

9.22.2 Algorithm

9.22.3 Flowchart

9.22.4 Python program: Matrix Add Principal.py

9.23 Write a Python Program to Add and Find the Sum of Secondary Diagonal

Elements of a Given Matrix

9.23.1 Theory

9.23.2 Algorithm

9.23.3 Flowchart

9.23.4 Python program: Matrix Add Secondary.py

9.24 Write a Python Program to Compute the Norm of a Given Matrix

9.24.1 Theory

9.24.2 Algorithm

9.24.3 Flowchart

9.24.4 Python program: Matrix Norm.py

9.25 Write a Python Program to Compute Row Sum and Column Sum of a Given

Matrix

9.25.1 Theory

9.25.2 Algorithm

9.25.3 Flowchart

9.25.4 Python program: Matrix Row Col Sum.py

9.26 Write a Python Program to Compute Whether the Given Square Matrix is a

Magic Square

9.26.1 Theory

9.26.2 Algorithm

9.26.3 Flowchart

9.26.4 Python program: matrix magic.py

9.27 Case Study

Exercises

Chapter 10 Python Programs on Tuples

10.1 Introduction

10.2 How to Read a List Type from a Keyboard

10.3 Accessing Elements of a Tuple

10.4 Modifying Elements of a Tuple

10.5 Deleting Elements of a Tuple

10.6 Basic Tuple Operations

10.7 Tuple Built-in Functions

10.8 Write a Python Program using Tuples to Accept Individual Address Details

And Display the Same

10.8.1 Theory

10.8.2 Algorithm

10.8.3 Flowchart

10.8.4 Python program: Address Display.py

10.9 Write a Python Program using Tuples to Accept Employee Salary Details and

Calculate Final Salary Based on the Overtime Hours

10.9.1 Theory

10.9.2 Algorithm

10.9.3 Flowchart

10.9.4 Python program: Salary Calc.py

10.10 Write a Python Program using Tuples to Input Student Details. The Program

Should Accept a Given Student’s Roll Number and Display His Specific

Records

10.10.1 Theory

10.10.2 Algorithm

10.10.3 Flowchart

10.10.4 Python program: Student Info.py

10.11 Write a Python Program using Tuples to Input Student Details and Compute

His Percentage and Class Based on His Average Marks for Five Subjects

10.11.1 Theory

10.11.2 Algorithm

10.11.3 Flowchart

10.11.4 Python program: Student Result.Analysis.py

10.12 Write a Python Program using Tuples to Guess the Number of Colors in a

Traffic Signal and also to Guess which Color is used to say “Stop if Possible!”.

The Program Should Evaluate Whether the Answers are Right or Wrong

10.12.1 Theory

10.12.2 Algorithm

10.12.3 Flowchart

10.12.4 Python program: Traffic Signal.py

Exercises

Chapter 11 Python Dictionary

11.1 Introduction

11.2 Creating a Dictionary and Printing a Dictionary

11.3 Accessing Dictionary Elements

11.4 Modifying a Dictionary

11.5 Delete Operations on a Dictionary

11.6 Dictionary Key Properties

11.7 Comparing Two Dictionaries

11.8 Python Dictionary Built-in Functions

11.9 How to Generate Keys, Values and Items for Python Dictionary

11.10 Copying and Updating a Dictionary

11.11 Write a Python Program using Dictionary to Generate a Small Dictionary of

Synonyms. The Program Should then Accept a Word and Generate Synonyms

for the Same

11.11.1 Theory

11.11.2 Algorithm

11.11.3 Flowchart

11.11.4 Python program: Synonym.py

11.12 Write a Python Program using Dictionary to Accept a Sentence and Generate

The Frequency of Words for the Same

11.12.1 Theory

11.12.2 Algorithm

11.12.3 Flowchart

11.12.4 Python program: Word Freq.py

11.13 Write a Python Program to Create a Dictionary Consisting of State and Their

Corresponding Dishes. The Program Should Accept a State Name from the

user and Generate the Corresponding Dishes

11.13.1 Theory

11.13.2 Algorithm

11.13.3 Flowchart

11.13.4 Python program: State Dishes.py

11.14 Write a Python Program using Dictionary to Find the Maximum and Minimum

Among the Given Values

11.14.1 Theory

11.14.2 Algorithm

11.14.3 Flowchart

11.14.4 Python program: Max Min Dict.py

11.15 Write a Python Program using Dictionary to Encrypt and Decrypt a Given

Plain Text using Additive Cipher

11.15.1 Theory

11.15.2 Algorithm

11.15.3 Flowchart

11.15.4 Python program: Subs Cipher.py

Exercises

Chapter 12 Python Files

12.1 Introduction

12.2 Writing into Files

12.3 Reading from Files

12.4 Reading Lines from Files

12.5 Stripping Characters from Files

12.6 Filenames and Paths

12.7 Format Operator

12.8 Command Line Arguments

12.8.1 The system module—sys module

12.8.2 Write a Python program that takes command line arguments as integer

numbers and computes their sum

12.9 Exceptions in Python

12.10 Write a Python Program to Demonstrate IO Error Exception when we Try to

Read a Non-existing File

12.11 Write a Python Program that Computes the Sum of All Integer Numbers Stored

in a File Named “data.txt” with an Exception Handling Features if the Numbers

are not Integers. The Sum Should be Printed on the Command Prompt

12.12 Write a Python Program to Count the Number of Lines in a File

12.13 Write a Python Program to Find the Most Frequent Words in a Text Read from

A File

12.14 Write a Python Program that Read an Input File Containing Floating Point

Values and Find the Minimum and the Maximum of the Values Stored

12.15 Write a Python Program to Copy the Contents of an Input File to an Output

File and also Display the Contents of Input File and Output File on the Screen

12.16 Write a Python Program to Compute the Number of Line, Words and Characters

in a Given Input Test File

12.17 Python Modules

12.17.1 Importing modules

12.17.2 How to create your own modules

12.17.3 To invoke specific functions or variables from modules

12.17.4 The dir() function

12.17.5 Restoring a module

12.18 Python Packages

Exercises

Appendix A Pygame Installation

A.1 Installation of Python 3.2

A.2 Installation of Pygame

A.3 Colors in Pygame

Appendix B Laboratory Exercise

B.1 GCD of two numbers

B.2 Square root of a number (Newton’s method)

B.3 Exponentiation (power of a number)

B.4 Linear search and binary search

B.5 First n prime numbers

B.6 Maximum of a list of numbers

B.7 Selection sort and insertion sort

B.8 Duplicate elements removal in a list

B.9 Merge sort and quick sort

B.10 Multiply matrices

B.11 Command line arguments (word count)

B.12 Most frequent words in a text read from a file

B.13 Bouncing ball simulation using Pygame

B.14 The area of trapezium

B.15 User-defined function to check for prime numbers

B.16 Calculate and print the sum of a series

B.17 Gregory series for calculating the value of Pi

B.18 Sum and average of numbers from 0 upto n

B.19 Tribonacci sequence for n numbers

B.20 Perfect numbers generation up to amax range

B.21 Highest common factor (HCF) of two numbers

B.22 Lucas sequence of N numbers

B.23 User-defined function to permute (x, y)

B.24 User-defined function for combination (x, y)

B.25 Duplicate words removal from a given string

B.26 Capitalize each word in a given sentence

B.27 Return words beginning with specified letter in a sentence and also display the

count

B.28 White spaces insertion before and after the string

B.29 Extra white spaces removal between two words in a string

B.30 Return quoted word from a sentence

B.31 Setting a strong password with conditions

B.32 Setting a password with conditions

B.33 Accept a list of numbers and a number and print in order all elements of the

list that are greater than the number

B.34 Accept a list of numbers and sort half of them in ascending and remaining half

In descending order

B.35 Convert all the principal diagonal elements to 1’s

B.36 Compare two matrices of same size

B.37 Check if a given matrix is a lower triangular matrix

B.38 Check if a given matrix is a upper triangular matrix

B.39 Check whether a given matrix is a symmetric matrix

B.40 Using tuples, compute if the number of odd value elements and even value

elements are the same

B.41 Search a name in a given tuple of names

B.42 Word jumble game simulation

B.43 Read a dictionary and count the number of values that appears two or

more times

B.44 English to Tamil translator

B.45 Add integer numbers stored in two files and their sum should be written in

another file

Appendix C Mini Projects Using Python

C.1 Cows and bulls game

C.2 Number guessing game

C.3 Hollywood hangman game

C.4 Encrypt and decrypt a message using Vigenere Cipher

Appendix D Viva Voce Questions

Appendix E Solved University Question Paper

Bibiliography

If you are learning Python from a beginner’s perspective and with hands-on approach then this is the right book. The major emphasis in this book has been to solve an exhaustive number of programming examples and to understand the concepts surrounding it right from the relevant theory, syntax, and semantics to coding issues. This book is useful for engineering students, beginners and those who want to learn a new programming language. The book adapts Python 3.1 version.

Key features

Deals with the language fundamentals and building blocks like operators, variables, keywords, etc.
User-defined functions and Python sequences like strings, tuples and lists are dealt in an exhaustive manner.
Dictionaries, Files, Modules and Packages are explained in a lucid manner along with exceptions.
Case studies are provided for in-depth learning.
Programming exercises are provided for students to reassess their programming skills.
Exhaustive laboratory exercises are solved.
A brief introduction is provided to Pygame along with examples.
Mini Python projects are provided for modeling security algorithms and games.
University question paper is solved to reinforce academic learning.
Sample viva-voce questions are provided to revise unique features of Python language.

There are no comments on this title.

to post a comment.

Powered by Koha