Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Study guide

Python Beginner Course Note-2

Rating
-
Sold
-
Pages
35
Uploaded on
15-09-2020
Written in
2019/2020

This is the continuation of my crash course on Python. This material contains compact, briefed concepts about Statement and String Manipulation in Python.

Institution
Course

Content preview

Day-2: Control
Statement and
String
Manipulation
22/06/2018

Workshop on “Introduction to
Python”




Department Of
Computer Science
Engineering

SKFGI, Mankundu

, Control statements:
In general, statements are executed sequentially: The first statement in a
function is executed first, followed by the second, and so on. There may be
a situation when you need to execute a block of code several number of
times.
Programming languages provide various control structures that allow for
more complicated execution paths.
A loop statement allows us to execute a statement or group of statements
multiple times. The following diagram illustrates a loop statement −




Python programming language provides following types of loops to handle
looping requirements.
Sl No. Loop Type & Description
1 while loop
Repeats a statement or group of statements while a given
condition is TRUE. It tests the condition before executing the
loop body.
2 for loop
Executes a sequence of statements multiple times and
abbreviates the code that manages the loop variable.

3 nested loops
You can use one or more loop inside any another while, for or
do..while loop.

,1.While loop:-
A while loop statement in Python programming language repeatedly
executes a target statement as long as a given condition is true. The
syntax of a while loop in Python programming language is −
while expression:
statement(s)
Here, statement(s) may be a single statement or a block of statements.
The condition may be any expression, and true is any non-zero value. The
loop iterates while the condition is true. When the condition becomes false,
program control passes to the line immediately following the loop.
Program-1:
count = 0
while count < 9:
print ('The count is:', count)
count = count + 1
print ("Exit from loop")
output:-
The count is: 0
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
Exit from loop

, Program-2
print("enter the number")
x=(int)(input())
f=1
while x > 0:
f=f * x
x= x - 1
print(f)
output:-
enter the number
6
factorial is 720
Program-3
print("enter the number")
x=(int)(input())
rev=0
while x > 0:
r=x % 10
rev=rev*10+r
x= x // 10
print("reverse is",rev)
output:-
enter the number
123
reverse is 321
Program-4
print("enter the number")
x=(int)(input())
f=x
rev=0
while x > 0:

Connected book

Written for

Institution
Course

Document information

Uploaded on
September 15, 2020
Number of pages
35
Written in
2019/2020
Type
Study guide

Subjects

$4.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
snehat1410

Get to know the seller

Seller avatar
snehat1410 MAKAUT
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
5 year
Number of followers
1
Documents
14
Last sold
5 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions