CS CBSE Notes With Questions Bank

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Computer Science(083) Question Bank with Notes

1. What are some limitations of Python programming language?


Ans.
Not the Fastest Language — As Python is an interpreted language so its execution-
times are not that fast compared to some compiled languages.
Lesser Libraries than C, Java, Perl — Library collection of C, Java, Perl is better
than Python.

Not strong on Type-Binding — Python interpreter is not very strong on catching


'Type-Mismatch' issues.

Not easily convertible — Translating Python programs to other languages is difficult


due to its lack of syntax.

2. What are advantages/disadvantages of working in Interactive mode in Python?.


Ans. Interactive mode is useful for testing code. We can type the commands one by one and
get the result of error immediately for each command. Disadvantages of Interactive mode
are that it does not save commands in form of a program and also output is sandwiched
between commands.

3. Mention steps you would follow while writing a program.


4. Draw flowchart to add two numbers, along with algorithm in simple English.
5. What is the importance of the three programming constructs?

Answer

The importance of the three programming constructs is a given below:

1. Sequence — Statements get executed sequentially.


2. Selection — Execution of statements depends on a condition test.
3. Repetition\Iteration — Repetition of a set of statements depends on a condition test.

6.Explain concept of Hardware and Software.

7. Write a program to count the number of times a character occurs in the given string.

Solution

str = input("Enter the string: ")


ch = input("Enter the character to count: ");
c = str.count(ch)
print(ch, "occurs", c, "times")

Output

Enter the string: KnowledgeBoat


Enter the character to count: e
e occurs 2 times
.
8. Write a program which replaces all vowels in the string with '*'.

Solution

str = input("Enter the string: ")


newStr = ""
for ch in str :
lch = ch.lower()
if lch == 'a' \
or lch == 'e' \
or lch == 'i' \
or lch == 'o' \
or lch == 'u' :
newStr += '*'
else :
newStr += ch
print(newStr)

Output

Enter the string: Computer Studies


C*mp*t*r St*d**s

9. Write a program that prompts for a phone number of 10 digits and two dashes, with
dashes after the area code and the next three numbers. For example, 017-555-1212 is a legal
input. Display if the phone number entered is valid format or not and display if the phone
number is valid or not (i.e., contains just the digits and dash at specific places.)

Solution

phNo = input("Enter the phone number: ")


length = len(phNo)
if length == 12 \
and phNo[3] == "-" \
and phNo[7] == "-" \
and phNo[:3].isdigit() \
and phNo[4:7].isdigit() \
and phNo[8:].isdigit() :
print("Valid Phone Number")
else :
print("Invalid Phone Number")

Output

Enter the phone number: 017-555-1212


Valid Phone Number
10..Explain for loop in python with example.
11. What is cyber safety? Why is it important?

12. Write a Python script that asks the user to enter a length in centimetres. If the user
enters a negative length, the program should tell the user that the entry is invalid.
Otherwise, the program should convert the length to inches and print out the result. There
are 2.54 centimetres in an inch.

Solution

len = int(input("Enter length in cm: "))


if len < 0:
print("Invalid input")
else:
inch = len / 2.54
print(len, "centimetres is equal to", inch, "inches")

Output

Enter length in cm: 150


150 centimetres is equal to 59.05511811023622 inches

13.Explain if-else statement with syntax? Give example.


14. difference between copyright and Content.
15. difference between Active and Passive footprints
16. explain Break and Continue Statement.
17. define a. python keywords b. Identifier c. Variable
18. What is Operator? Define Arithmetic and Relational operator.
19. Draw block diagram of computer System and explain its functions.
20. Consider the following loop:

j = 10
while j >= 5:
print("X")
j=j-1
Which of the following for loops will generate the same output as the loop shown
previously?

1. for j in range(-1, -5, -1):


print("X")
2. for j in range(0, 5):
print("X")
3. for j in range(10, -1, -2):
print("X") ✓
4. for j in range(10, 5):
print("X")
5. for j in range(10, 5, -1):
print("X")
21. What is a flowchart? How is it useful?

Answer

A flowchart is a pictorial representation of an algorithm. It uses boxes of different shapes to


represent different types of instructions. These boxes are connected with arrow marks to
indicate the flow of operations. It helps in:

1. Communication — The pictorial representation of the flowchart provides better


communication. It is easier for the programmer to explain the logic of a program.
2. Effective Analysis — It is a very useful technique, as flowchart is a pictorial
representation that helps the programmer to analyze the problem in detail.

22.Draw flowchart for displaying first 10 odd numbers.


Ans.

23.What are the four elements of a while loop in Python?


Answer

The four elements of a while loop in Python are:

1. Initialization Expressions — It initializes the loop control variable and it is given


outside the while loop before the beginning of the loop.
2. Test Expression — If its truth value is true then the loop-body gets executed
otherwise not.
3. The Body of the Loop — It is the set of statements that are executed repeatedly in
loop.
4. Update Expressions — It updates the value of loop control variable and it is given
inside the while loop.

24. What is the error in following code? Correct the code:

weather = 'raining'
if weather = 'sunny' :
print ("wear sunblock")
elif weather = "snow":
print ("going skiing")
else :
print (weather)
Answer

In this code, assignment operator (=) is used in place of equality operator (==) for
comparison. The corrected code is below:

weather = 'raining'
if weather == 'sunny' :
print ("wear sunblock")
elif weather == "snow":
print ("going skiing")
else :
print (weather)

25. What is following code doing? What would it print for input as 3?

n = int(input( "Enter an integer:" ))


if n < 1 :
print ("invalid value")
else :
for i in range(1, n + 1):
print (i * i)
Answer

The code will print the square of each number from 1 till the number given as input by the
user if the input value is greater than 0. Output of the code for input as 3 is shown below:
Enter an integer:3
1
4
9

26.A year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap
years unless they are also divisible by 400. Write a program that asks the user for a year
and prints out whether it is a leap year or not.

Solution

year = int(input("Enter year: "))

if year % 400 == 0 :
print(year, "is a Leap Year")
elif year % 100 == 0 :
print(year, "is not a Leap Year")
elif year % 4 == 0 :
print(year, "is a Leap Year")
else :
print(year, "is not a Leap Year")

Output

Enter year: 1800


1800 is not a Leap Year

27. Write a program to input length of three sides of a triangle. Then check if these sides
will form a triangle or not.
(Rule is: a+b>c;b+c>a;c+a>b)

Solution

a = int(input("Enter first side : "))


b = int(input("Enter second side : "))
c = int(input("Enter third side : "))

if a + b > c and b + c > a and a + c > b :


print("Triangle Possible")
else :
print("Triangle Not Possible")

Output

Enter first side : 3


Enter second side : 5
Enter third side : 6
Triangle Possible

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy