11 CSWTOct 2022 RTAns Key

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

Class XI First Term Computer Science Weekly Retest 26-Oct-2022 Answer Key

1. Identify the list containing exactly two correct and two incorrect Python identifier names. [1]
a) None, true, False, For
b) none, true, false, for
c) NONE, TRUE, FALSE, FOR
d) None, True, False, for

2. Identify the list containing only functions from Python's math module. [1]
a) log(), log10(), sin(), eval()
b) log(), log10(), abs(), cos()
c) log(), log10(), sin(), cos()
d) len(), log10(), sin(), cos()

3. Identify the list of built-in functions that can be used with str (string) type data. [1]
a) len(), max(), eval(), upper()
b) len(), max(), eval(), min()
c) len(), max(), eval(), chr()
d) len(), max(), eval(), round()

4. Identify the list of Python operators that work from right to left. [1]
a) +=, //=, /=, !=
b) +=, ==, /=, **
c) >=, //=, /=, **
d) +=, //=, /=, **

5. Identify the list of Python operators that work with str (string) type data. [1]
a) *, -=, *=, +
b) *, +=, *=, +
c) *, +=, /=, +
d) *, +=, *=, //

6. print('Mango' or 234.75 and 62017) will display: [1]


a) 62017
b) Mango
c) 'Mango'
d) 234.75

7. Rewrite the script after removing all the errors (Underline the corrections): [2]
n=int(input(Input n? ")) n=int(input("Input n? "))
k, s=4, 0 k, s=4, 0
while k<=4n: while k<=4*n:
print[k] print(k)
s+=k s+=k
k+==4 k+=4
print('Sum=',s) print('Sum=',s)

8. Identify the data type of the Python variables created given below: [2]
a) w=input() str / string
b) x=100>=85 or 'False' bool / boolean
c) y=round(12.735, 2) float / floating-point
d) z=pow(-5, 1//2) int / integer

Page 1 / 3
Class XI First Term Computer Science Weekly Retest 26-Oct-2022 Answer Key
9. Give output of the Python script given below: [2]
a,b=5,7
a*=b
b*=a
print(a,b) Output
a+=a+b 35 245
b+=a+b 315 805
print(a,b)

10. Differentiate between logical error and run-time error. [2]


Run-time Error Logical Error
 Syntactically correct Python statement  Syntactically correct Python statement
performs illegal operation because the producing unexpected result / output due to
statement encounters unexpected data flaw or error in the logic / design of the code
 Python script is terminated abruptly  Execution of Python script is never terminated

11. Write a Python script to input a temperature in Fahrenheit. Convert the inputted temperature in
Celsius and Kelvin. Display the temperatures in Celsius and in Kelvin on the screen.
[2]
Let f, c, k be the temperatures in Fahrenheit, Celsius and Kelvin respectively, then
c f −32 f k−459.67
= =
5 9 9 5
far=eval(input('Temperature in Fahrenheit? '))
cel=5/9*(far-32)
kel=5/9*far+459.67
print('Celsius=', cel)
print('Kelvin=', kel)

12. Write a Python script to input the following:


Employee Code integer
Employee Name string
Gross Salary floating point
Calculate the following:
City Allowance floating point (20.0% of the Gross Salary)
PF Deduction floating point (8.0% of the Gross Salary)
Income Tax floating point (7.0% of the Gross Salary)
Net salary floating point (Gross salary + City Allowance - PF Deduction - Income Tax)
Display employee code, employee name, gross salary, city allowance, pf deduction, income tax and
net salary on the screen. [3]
code=int(input('Code? '))
name=input('Name? ')
gsal=float(input('Gross Salary? '))
cca=0.20*gsal
pfd=0.08*gsal
itax=0.07*gsal
nsal=gsal+cca-pfd-itax
print('Code=', code)
print('Name=', name)
print('Gross Salary=', gsal)
print('City Allowance=', cca)
print('PF Deduction=', pfd)
print('Income Tax=', itax)
print('Net Salary=', nsal)

Page 2 / 3
Class XI First Term Computer Science Weekly Retest 26-Oct-2022 Answer Key

13. Write a Python script to input length of three sides of a triangle (assume all the inputs are positive).
Check if the inputs are correct (sum of the length of any two sides must exceeds the third side). If the
inputs are correct, then calculate the perimeter of the triangle and the area of the triangle using
Heron's formula. Display the perimeter of the triangle and the area of the triangle on the screen. If
the inputs are incorrect, then display an appropriate message on the screen.
[3]
Let a, b and c be the length of three sides of a triangle, then
Perimeter (p)=a+b+c Semi Perimeter (s)=p/2 Area=√ s (s−a)(s−b)(s−c )
a=eval(input('Length of 1st Side? '))
b=eval(input('Length of 2nd Side? '))
c=eval(input('Length of 3rd Side? '))
if a+b>c and b+c>a and c+a>b:
peri=a+b+c
s=peri/2
area=pow(s*(s-a)*(s-b)*(s-c), 0.5)
print('Perimeter=', peri)
print('Area=', area)
else:
print('Invalid Input!')

14. Write a Python script to input a single character string. If the inputted string contains single
character, then display the type of alphabet / letter (uppercase vowel / uppercase consonant /
lowercase vowel / lowercase consonant). If the input is not an alphabet, then display the message
'Not an alphabet'. If the string contains more than one characters or does not contain any character,
then display an appropriate message. Don't use any string methods.
[4]
ch=input('Input a character? ')
if len(ch)==1:
if 'A'<=ch<='Z':
if ch=='A' or ch=='E' or ch=='I' or ch=='O' or ch=='U':
print(ch,'Uppercase Vowel')
else:
print(ch,'Uppercase Constant')
elif 'a'<=ch<='z':
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
print(ch,'Lowercase Vowel')
else:
print(ch,'Lowercase Constant')
else: print(ch,'Not an alphabet')
else:
print('Invalid Input!')

15. Write a Python script to input a positive integer (n) and display the sum of the following series using
a while-loop and without using math.factorial(): [4]
1!+2!+3!+4!+ … + n!
n=int(input('Input an Integer? '))
k, f, s=1, 1, 0
while k<=n:
f*=k
s+=f
k+=1
print('Sum=', s)

Page 3 / 3

You might also like