Recording the history of Nellore

Uncategorized

Python Exercise5

Print values from 0 to 10.

for i in range(11):

    print(i)

Print values from 10 to 0

 for x in range(10,-1,-1):

    print(x)

Print values from 100 to 170

 for x in range(100,171):

    print(x)

Print all the even numbers from 0 to 100

for x in range(0,100,2):

    print(x)

 Create a list with different string values, and print all the values

 cars=[“maruti”,”hyundai”,”bmw”,”benz”]

for car in cars:

    print(car)

 

Initialize a variable with a string and print each character

 city=”Bangalore”

for char in city:

    print(char)

 

convert the below c for loop into python

for (i=65;i<=345;i=i+5)

{

printf i*i;

}

 

for i in range(65,346,5):

               print i*i

 

convert the below c for loop into python

for (i=365;i>=45;i=i-5)

{

print i*i;

}             

 

for i in range(365,44,-5):

               print i*i

 

Write a program to take input from the user and then count the number of vowels

contained in the string.

Eg: Input: Indira Output:Number of Vowels are :3

    Input: indira Output:Number of Vowels are :3

 

count = 0

char = input(“Enter some word:”)

vowels=[‘a’,’e’,’i’,’o’,’u’]

for x in char:

    if x.lower() in vowels:

        count=count + 1

print(“Number of vowels are : “,count)

 

Write a program to remove the duplicates from the list

s=[24,20,2,60,70,80,24,2,100,60,70]

 

s=[24,20,2,60,70,80,24,2,100,60,70]

newlist=[]

for x in s:

    if(x not in newlist):

        newlist.append(x)

print(newlist)

 

Write a  program to print all numbers in a range divisible by a given number

Eg: Enter lower range limit:1

Enter upper range limit:10

Enter the number to be divided by:2

2

4

6

8

10

 

lowerlimit=int(input(“Enter lower range limit:”))

upperlimit=int(input(“Enter upper range limit:”))

n=int(input(“Enter the number to be divided by:”))

for i in range(lowerlimit,upperlimit+1):

    if(i%n==0):

        print(i)

 

Write a program to print all integers that are not divisible by

either 2 or 3 and lie between 1 and 50

 

for i in range(0,51):

    if(i%2!=0 and i%3!=0):

        print(i)

 

Write a program to print an inverted star pattern

Enter number of rows: 3

***

 **

  *

 

n=int(input(“Enter number of rows: “))

for i in range (n,0,-1):

    print((n-i) * ‘ ‘ + i * ‘*’)

 

Create a list with names in it. Print all the names whose length is >5 

 

names=[“Ujwal”,”Shilpa”,”Sandya”,”Vishal”,”Keerthi”,”Shankari”,”Ram”]

for name in names:

    if(len(name)>5):

        print(name)

 

Back to Main Page

Visit www.mongofactory.com to know more about the trainer.

Leave a Reply

Discover more from Nellorean

Subscribe now to keep reading and get access to the full archive.

Continue reading