Python while loop

Python while Loop
while loop
It works as long as the given condition is true.
Syntax:
while ():
// Statements

Example 1:
# Printing the no.1 to 10
ctr=1 #initialization

print(“While Loop Demo”)
while (ctr<=10): #condition
print (ctr)
ctr = ctr +1 #incrementing part

Example 2:
#Printing the No.s from 1000 to 100

ctr=1000
print(“While Loop Demo”)
while (ctr >=100):
print (ctr)
ctr = ctr – 100
else:
print(“else part will execute when the condition becomes false”)

Note: Else is an optional and will execute when the condition given the while loop fails.

Win Corporate Training
website: http://www.wincorptrg.com
View My Profile

Advertisements

Python – First Program

Python First Program

#First program – Comment
print(“Hello World”)

Comment – #

  1. Provides the Description about the program
  2. Code will not be executed

print  Function

  1. Prints the output at the Console.
  2. printing statements can be given within the Single or Double Quote.

Steps to Create the Program:

  1. Open the Python IDLE [ Integrated Development Learning Environment]
  2.  Type the program at the Command Prompt.
winp1

Python IDLE

 

 

 

 

How to create a file File

  1. File -> New in Python IDLE
  2. Type the program in the file and Save the file with extnesion .py.
  3. Press F5 – Function key to run the program.

winp2

 

 

 

4. View output at the command prompt.

Next Part : Python Variable and Datatype

Win Corporate Training
website: http://www.wincorptrg.com
View My Profile