Posts

Showing posts from February, 2024

Numeric Literals in Python

                                                              Numeric Literals in Python  *          A  numeric literal is a literal containing only the digits 0-9 ,  an optional sign character (+ or - ) ,  and a possible decimal point.  Commas are never used in numeric literals. *          If a numeric literal does not contain a decimal point,  then it  denotes an integer (int) value.  *          If a numeric literal contains a decimal point, then it denotes a floating-point (float) value. Limits of Range in Floating-Point Representation  *          There is no limit to the size of an integer that can be represented in Python.  But  floating-point values have both a limited range ...

Python Interactive Mode

                                                              Python Interactive Mode        Python allows the user to work in an interactive mode .  It is a way of using the Python interpreter by executing Python commands from the command line with no script.       This allows the user to type an expression,  and immediately the expression is executed and the result is printed.        To start an interactive mode. we will see that the Python command line window  appears as shown in Fig.1 Python 3.6 (32-bit)                     Python 3.6.0  <v3.6.0:41df79263all,  Dec  23  2016, 07:18:10>  [MSC v. 1900 32 bit <Intel>] on win32               ...

Python Interpreter mode

                                                              Python Interpreter mode       The Python interpreter is a program that reads and executes Python code, in which Python statements can be stored in a file.  The Python system reads and executes the commands from the file, rather than from the console.  Such a file is termed as Python program.            Depending on the  environment, start the interpreter by clicking on an icon, or by typing python on a command line.  When it starts. the output  will be shown in      Fig.1 Python 3.6.0 Shell           Python 3.6.0 (v3.6.0:41df79263all, Dec  23 2016, 07:18:10)  [MSC v.1900 32 bit (Intel)]  on win32           Type "copyrigh...

Guessing an Integer Number in a Range in Python

Image
                                               Guessing an Integer Number in a Range Problem statement       The objective is to randomly generate integer number from 0 to n.  Then the player has to guess the number. If the player guesses the number correctly output an appropriate message.      If the guessed number is less than the random number generated, output the message "Your guess is lower than the number.  Guess again." , otherwise output the message "Your guess is higher than the number.  Guess again:.      Then the player guesses another number.  This process is repeated until the player guesses the correct number.   Algorithm       1.  Start.       2.  Generate a random numbers and read num.           ...

Inserting a Card in a List of Sorted Cards in Python

Image
                                                Inserting a Card  in a List of Sorted Cards Problem Statement       Imagine that you are playing a card game.  You are holding the cards in your hand and these cards are sorted.  You are given exactly one new card.  You have to put it into the correct place so that the cards you are holding are still sorted. Algorithm             Step 1 : Start.           Step 2 : Read all numbers in an array A .           Step 3 : Read Key .           Step 4 : From first position to the end of the array compare key and array element .           Step 5 : If Key < A [ i ] then assign i to pos, and return pos .           Step 6 : From n-1 to pos ...

Tower of Hanoi Problem in Python

Image
                                              &nbspTower of Hanoi;               Tower of Hanoi Problem Problem Statement       Tower of Hanoi is one of the classical problems of computer science.  The problem states that ,                 1. There are three stands on which a set of disks, each with a different diameter, are placed .                2. Initially, the disks are stacked on Stand 1 , in order of size, with the largest disk at the bottom .       The initial structure of Tower of Hanoi with three disk is shown in .Fig. 1 Fig.1   Tower of Hanoi with Three Disks      The "Tower of Hanoi problem" is to find a sequence of disk moves so that all the disks moved from Stand-1 to Stan...