Computer Science, asked by Mrayush8269, 11 months ago

Answer for ch 6 class 11 computer

Answers

Answered by harsita5
0

Answer:

Question1. What is the difference between else and elif construct of if statement?

Answer:

Else

elif

Else is a part of if statement.

The elif is short for else if.

Else statement is executed whenever the if statement is getting false.

Elif executed block of code whenever one of the condition evaluate true.

Example:

If(a<b)

Print “a less than b”

Else

Print “ a is not less than b”

 

Example:

If num> 0;

Print “positive number”

Elifnum == 0;

Print “zero”

Else:

Print “negative number”

 

 

Question 2. What is the purpose of range() function? Give one example.

Answer:

Function range() is used for creating a list containing the integer values in sequence from start value to stop value. Sometimes it is used for generating the number sequentially in for loop.

Example:

" i-amphtml-auto-lightbox-visited="" style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 18px; vertical-align: baseline; background: transparent; max-width: 100%; display: block !important;">

Question 3. Differentiate between break and continue statements using examples.

Answer:

Break Statement

Continue Statement

Break statement is to break the loop.

Continue statement is used to to continue the loopBreak statement is used with switch statement

Continue statement is not used with switch statements

Keyword: break

Keyword: continue

Question 4. What is an infinite loop? Give one example.

Answer:

Infinite loop execute when while condition never become falseIf condition remain true. the loop will never get terminated.The control enters in loop and keeps repeating the same block code and loop never end.

Example:

a = 1

while a==1:

b = input(“what’s your birthdate?”)

print(“your birthdate is ”, b)

Output:

What’s your birthdate?

13

your birthdate is 13

What’s your birthdate?

14

your birthdate is 14

What’s your birthdate?

15

your birthdate is 15

What’s your birthdate?

16

your birthdate is 16

:

:

:

Question 5. Find the output of the following program segments:

(i) a = 110

while a > 100:

print(a)

a  -= 2

Output: 110

108

106

104

(ii) for i in range(20,30,2):

print(i)

Output: 20

22

24

26

28

(iii) country = ‘INDIA’

for i in country:

print (i)

Output:

I

N

D

I

A

(iv) i = 0; sum = 0

while i < 9:

if i % 4 == 0:

sum = sum + i

i = i + 2

print (sum)

Output: 12

v) for x in range(1,4):

for y in range(2,5):

if x * y > 10:

break

print (x * y)

 

Output:

2

3

4

4

6

8

6

9

(v) var = 7

whilevar> 0:

print (‘Current variable value: ‘, var)

var = var -1

if var == 3:

break

else:

if var == 6:

var = var -1

continue

print (“Good bye!”)

Output:

Current variable value:  7

Current variable value:  5

Good bye!

Current variable value:  4

Programming Exercises

Question 1. Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years).

Answer:

" i-amphtml-auto-lightbox-visited="" style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 18px; vertical-align: baseline; background: transparent; max-width: 100%; display: block !important;">

Question 2. Write a function to print the table of a given number. The number has to be entered by the user.

Answer:

" i-amphtml-auto-lightbox-visited="" style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 18px; vertical-align: baseline; background: transparent; max-width: 100%; display:

Explanation:

hope it help you

please mark me as brainlist

Similar questions