Wednesday

Chapter – 4: CONDITIONAL AND ITERATIVE STATEMENTS || Computer Science || Class 11

 

Chapter – 4: CONDITIONAL AND ITERATIVE STATEMENTS

Short Answer Type Questions Q.1 What a range() function does? Give an example.

Ans: The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. its syntax is range(start, stop, step) e.g.

           x = range(3, 6)                            x = range(1, 10,2)        for n in x:                                   for n in x:   print(n)                                           print(n)

              #This code will print 3 4 5                                                 #This code will print 1 3 5 7 9

 

Q.2    What are loops in Python? How many types of loop are there in Python?

Ans: Loops are iteration constructs in Python. Iteration means repetition of a set of statements depending upon a condition test. Loops has three basic elements within it to repeat the statements – 

                  Initialization (Start)

                  Check Condition (Stop)

                  Updation (Step) 

Python provide two types of loop

(i)   Conditional Loop while( (Condition based loop)

(ii)  Counting loop for (loop for a given number of times). Q.3         What is the syntax of if-elif statement in Python?

Ans: The syntax of if-elif statement in python is as follows:

                                      If condition1:

              #code-block of statements when condition1 is true         elif condion2:

              #code-block of statements when condition2 is true         elif condition3:

                                                      #code-block of statements when condition3 is true

                                      .

                                      .

  .  else:

                                                      #code-block of statements when all above conditions are false.

Q.4   What are jump statements in Python? Name jump statements with example.

Ans: Python offers two jump statements to be used with in loops to jump out of loop-iterations.

These are  break and continue statements.

 

Q.6       What is the error in following code. Rewrite the correct code.

Q.7     Rewrite the following code fragment using while loop.

 

 

Ans:  

Skill Based Questions Q.1 WAP that searches for prime numbers from 15 through 25.

Ans: 

 

 

 

 

Q.2     WAP to test if given number is prime or not.

Ans: 

 

 

 

 

 

 

Q.3    WAP to compute the result when two numbers and one operator is given by user.

Ans:   

 

 

 

 

 

 

 

 

Q.4     WAP to calculate the roots of a given quadratic equation.

Ans: 

 

 

 

 

 

 

 

 

Q.5         WAP to input a digit and print it in words.

Ans: 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Q.6 WAP to check whether square root of a given number is prime or not.

Ans: 

 

 

 

 

 

 

 

 

Q.7       WAP to print first n odd numbers in descending order.

Ans:  

 

 

 

 

Q.8 WAP to print the following series –   (i) 1  4   7  10  . . . . . . .40

           (ii)      1  -4   7  -10  . . . . . . . . -40

Ans: (i)  

   

   (ii)  

 

 

Q.9     WAP to find the average of the list of the numbers entered through keyboard.

Ans: 

 

 

 

 

 

 

Q.10 WAP to find the largest number from the list of the numbers entered through keyboard.

Ans: 

 

 

 

 

 

Q.11 WAP to find the 2nd largest number from the list of the numbers entered through keyboard. (This program is from List Chapter) Ans: 

 

 

 

 

 

Q.12 WAP to find the sum of n natural numbers.

Ans: 

 

 

 

 

Q.13 WAP to find the sum of first n even numbers.

Ans: 

 

 

 

 

Q.14 WAP to find the sum of first n odd numbers.

Ans:

 

 

 

 

 

Q.15 WAP to print the following pattern

           (a)      *                               (b)       *                     (c)      A                                       (d)     0

*  *                                    * *                           A B                                      2 2

*  * *                   * * *                             A B C                           4 4 4

*  * * *                        * * * *                           A B C D                               8 8 8 8 

*  * * * *                  * * * * *                           A B C D E                             

Ans: (a) 

 

 

 

(b) 

 

 

 

 

 

(c) 

 

 

 

 

(d) 

 

 

 

 

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.