Recording the history of Nellore


Python Exercise4

1. Write a program to create list of squares of all odd numbers below 50 and print the list.


for x in range(1,50,2):




2.Initialize a variable with number, Write a program to guess (take input from user)

the number that has been initialized in the program

if the guessed number is lower than the number : print guess higher number

if the guessed number is higher than the number : print guess lower number

if the guessed number is correct print “your guess is right”


numb = 35

guess = int(input(“Take a guess: “))

while (guess != numb):

    if (guess > numb):

        print(“Guess the Lower number”)


        print (“Guess the Higher number”)

guess = int(input(“Take a guess: “))

print(“You guessed it!  The number was”, numb)


3. Program to get the grade of 10 students in a class and find average of the class


total = 0        

gradeCounter = 1 

 while gradeCounter <= 10:               # loop 10 times

   grade = input( “Enter grade: ” )     # get one grade

   grade = int( grade )                 # convert string to an integer

   total = total + grade

   gradeCounter = gradeCounter + 1

average = total / 10                    # integer division

print (“Class average is”, average)


4.Write a program to print fibonacci series below 10 (0,1,1,2,3,5,8)


a, b = 0, 1

while a < 10:

    print a

    a, b = b, a+b



Back to Main Page

Visit 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