more on python
more on python
1.continue
2.break
3.else
4.true
5.while
1. for x in range(5,10,2):
print (x+10)
2. x=5
QB
while (x<20):
print (x)
x+=5
1. 1,2,3,4,
2. S
t
r
QC
i
n
g
Over
1. n= int(input("Enter number:"))
temp=n
rev=0
while (n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
Else
2. n= int(input("enter number:"))
sum=0
for i in range(1,n-1):
mod = n%i
if mod==0:
sum=sum+i
if sum ==n:
QD
print (perfect number)
else:
3. n= int(input(enter number:))
mod=n%10
if mod==8:
else:
print ("ends with neither")
4. n=int(int("enter a number:"))
sum1=0
while (n>0):
sum1=sum1+n
n=n-1
1. Sometimes there is a need to repeat a set of statements more than once based on a
certain condition this process of repetition is called loop or iteration in programming a
loop is thus used to repeat a block of statements specific number of times the loop used
in Python are for loop and While loop.
2. The range() function is used to create a list containing a sequence of number starting
from start and ending with one less than the stop.syntax- range([start],stop,[step])
Ex. >>>range(10);
QE Output - [0,1,2,3,4,5,6,7,8,9]
3. For ..... Structure is used when you want to perform a loop specific number of times it
uses a counter variable which is incremented or decremented with each repetition of the
loop while loop executes a block of code repeatedly as long as the test condition of the
loop is true it is ideally suited when the number of preparations are not known prior to the
execution of the loop.
4. Python offers two jump statements to be used with in loops to jump out of loop
iterations these are break and continue statements it alters the flow of control in a loop.