Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

more on python

The document covers advanced concepts in Python programming, focusing on loops, conditional statements, and functions. It includes examples of using 'for' and 'while' loops, as well as the 'range()' function for generating sequences. Additionally, it discusses jump statements like 'break' and 'continue' to control loop execution.

Uploaded by

snlpndrkr6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

more on python

The document covers advanced concepts in Python programming, focusing on loops, conditional statements, and functions. It includes examples of using 'for' and 'while' loops, as well as the 'range()' function for generating sequences. Additionally, it discusses jump statements like 'break' and 'continue' to control loop execution.

Uploaded by

snlpndrkr6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Std- VIlI Sub- ICT

Ch-8 more about python

QA State true or false

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):

print ("palindrome number")

Else

print ("not a palindrome number")

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:

print ("not a perfect number")

3. n= int(input(enter number:))

mod=n%10

if mod==8:

print ("ends with 8")

elif mod ==4:

print ("ends with 4")

else:
print ("ends with neither")

4. n=int(int("enter a number:"))

sum1=0

while (n>0):

sum1=sum1+n

n=n-1

print ("the sum of first n natural numbers is ",sum1)

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.

You might also like