CS CBSE Notes With Questions Bank
CS CBSE Notes With Questions Bank
CS CBSE Notes With Questions Bank
Answer
7. Write a program to count the number of times a character occurs in the given string.
Solution
Output
Solution
Output
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
Output
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
Output
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?
Answer
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?
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
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
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
Output