0% found this document useful (0 votes)
4 views

Python 2

Uploaded by

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

Python 2

Uploaded by

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

6) # if the given number is 129475

Given_number = 129475

# since we cannot iterate over an integer

# in python, we need to convert the

# integer into string first using the

# str() function

Given_number = str(given_number)

# declare a variable to store

# the count of digits in the

# given number with value 0

Count=0

For i in given_number:

Count += 1

# print the total count at the end

Print(count)

5) # if the below list is given

List = [1,2,4,6,88,125]

For i in list:

Print(i)

4)# if the given range is 10

Given_number = 5

For i in range(11):

Print (given_number,” x”,i,” =”,5*i)

3)# if the given range is 10


Given_range = 10

# set up a variable to store the sum

# with initial value of 0

Sum = 0

For i in range(given_range):

# if i is odd, add it

# to the sum variable

If i%2!=0:

Sum+=i

# print the total sum at the end

Print(sum)

2)# if the given number is 10

Given_number = 10

# set up a variable to store the sum

# with initial value of 0

Sum = 0

# since we want to include the number 10 in the sum

# increment given number by 1 in the for loop

For i in range(1,given_number+1):

Sum+=i

# print the total sum at the end

Print(sum)
1)# if the given range is 10

Given_range = 10

For i in range(given_range):

# if number is divisble by 2

# then it’s even

If i%2==0:

# if above condition is true

# print the number

Print(i)

7)# between 0 to 10

# there are 11 numbers

# therefore, we set the value

# of n to 11

N = 11

# since for loop starts with

# the zero indexes we need to skip it and

# start the loop from the first index

For i in range(1,n):

Print(i)

You might also like