Cs Sheet

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Program: Computer Science

Academic Level: 2
Faculty of Semester: Fall 2021
Computer Science Course Code: CS312
Course Title: Computer Language 2
Revision Sheet: 1

Answer the following questions

Q1: What are major uses of python?


a. System Utilities - GUIs graphical user interface - Web Scripting
b. Embedded Scripting - Database Programming - Artificial Intelligence
c. Image Processing – Computer Vision - Computer Graphics
d. All of the above

Q2 How to check python in your laptop? (Which of the next statements should be used?)
a. Run cmd.exe, go to dos prompt,
b. and type python, then enter, then you will get…
c. The “Python is not recognized as an internal or external command” error is encountered in
the command prompt of Windows
d. All of the above

Q3: Python is interpreted language means…


a. you do not need to compile your python program
b. run your python program directly on the IDLE Shell
c. If any error occurs, you will detect them at a run time
d. All of the above

Q4: Many computer languages require you to compile (i.e., translate) your program into a form
that the machine understands, for example if the source Java code called Hello.java, then the
compile form is called…
a. Hello.class
b. Hello.obj
c. Hello.java
d. Hello.comp

Q5: To get the output of your python code print(‘Hello world’), you do not need any semicolon or
declaration, just go to…
a. Shell prompt and type print(‘Hello world’), then enter to run your code
b. Shell prompt and type run print(‘Hello world’), then enter to run your code
c. Shell prompt and type execute print(‘Hello world’), then enter to run your code
d. Shell prompt and type python print(‘Hello world’), then enter to run your code

Q6: Write a python code to calculate area and perimeter of a rectangle using its length and width
equal 10 cm and 5 cm respectively.
a. print("Area of rectangle = ", (10*5),"cm\u00b2", "& Perimeter rectangle = ", (2+(10*5)), "
cm")

1
With my best wishes for success
b. print((L= 10), (W=5), "Area of rectangle = ", (L*W),"cm\u00b2", "& Perimeter rectangle = ",
(2*(L+W)), " cm")
c. print("Area of rectangle = ", (10*5),"cm\u00b2", "& Perimeter rectangle = ", (2*(10+5)), "
cm")
d. print((L= 10), (W=5), "Area of rectangle = ", (L*W),"cm\u00b2", "& Perimeter rectangle = ",
(2+(L*W)), " cm")

Q7: If you type print( ) after the shell prompt, you will get…
a. syntax error
b. blank result
c. print( )
d. crash the machine

Q8: After the shell prompt, type >>> print(“Hello world”) and press enter, you will get…
a. Hello world
b. Hello World
c. Hello world!
d. Hello World!

Q9: After the shell prompt, type >>> print(" Python is\n fun!") and press enter, you will get…
a. Python is fun!
b. Python
is fun!
c. Python is
fun!
d. Python is fun

Q10: After the shell prompt, type >>> print("Happy "+"Birthday!") and press enter, you will get…
a. Syntax error
b. Happy Birthday!
c. Happy birthday!
d. Happy Birthday

Q11: After the shell prompt, type >>> print((3 + 4), "# print(3 + 4)") and press enter, you will get…
a. 7
b. (3 + 4) # print(3 + 4)
c. 7 # print(3 + 4)
d. Any of the above

Q12: After the shell prompt, type >>> print("3 + 4") and press enter, you will get…
a. 7
b. “3 + 4”
c. 3 + 4
d. Syntax error

2
With my best wishes for success
Q13: After the shell prompt, type >>> print("I like python.\n"*3) and press enter, you will get…
a. Syntax error
b. I like python.
I like python.
I like python.
c. I like python. I like python. I like python.
d. I like Python.
I like Python.
I like Python.

Q14: After the shell prompt, type >>> print(3+"4") and press enter, you will get…
a. Error: unsupported operand
b. 3+"4"
c. 7
d. 3 + 4

Q15: After the shell prompt, type >>> print(("me"*3), (3*"me")) and press enter, you will get…
a. mememe
b. Syntax error
c. mememe mememe
d. None of the above

Q16: After the shell prompt, type >>> 3 + 11/4 and press enter, you will get…
a. 5.75
b. 3
c. Syntax error
d. None of the above

Q16: After the shell prompt, type >>> abs(5.55 - 10.24) and press enter, you will get…
a. 4.69
b. -4.69
c. 4
d. -4
Q17: After the shell prompt, type >>> -45.44 + 20.22 and press enter, you will get…
a. 25.22
b. -25.22
c. Syntax error
d. None of the above
Q18: After the shell prompt, type >>> -2**4 and press enter, you will get…
a. 16
b. 8
c. -16
d. Syntax error

3
With my best wishes for success
Q19: After the shell prompt, type >>> 25%2 and press enter, you will get…
a. 12.5
b. 12
c. 1
d. None of the above

Q20: After the shell prompt, type >>> print “Hello” and press enter, you will get…
a. Hello
b. Syntax error
c. hello
d. None of the above

Q21: After the shell prompt, type


>>> L1=[1, 2, 3] and press enter
>>> L1[3] and press enter, you will get…
a. 3
b. [1, 2, 3]
c. [3]
d. Index error
Q22: After the shell prompt, type >>> age and press enter, you will get…
a. Name error
b. Age
c. age
d. ?
Q23: After the shell prompt, type
>>> value = 10 and press enter
>>> value **2 and press enter, you will get…
a. 100
b. 10
c. Operator error
d. None of the above

Q23: After the shell prompt, type


>>> value = input(“Enter the value: “) and press enter
Enter the value: 5 and press enter
>>> value + 10 and press enter, you will get…
a. Type error
b. 5 + 10
c. 15
d. + 10

4
With my best wishes for success
Q24: Write a python program that asks the user to enter their name and their age, the result
should display the year that they will turn 75 years. Complete the next code…
name = input("What is your name: ")
age = int(input("How old are you: "))
year = ------------------------------------------------ (Based on the sample run, fill the blank)
print(name, 'will be 75 years old in the year', year)
Sample run…
What is your name: Sara
How old are you: 20
Sara will be 75 years old in the year 2076
Choice the right answer…
a. year = str((2021 - age) + 75)
b. year = (2021 - age) + 75
c. year = (2021 - age) + (100 - 25)
d. Any of the above

Q25: Write a python program ask the user for a number. Depending on whether the number is
even or odd, print out an appropriate message to the user. Complete the next code…
for n in range(2):
num = int (input("Enter a number: "))
num = num % 2
------------------------------- (Based on the sample run, fill the blank)
Sample run…
Enter a number: 233
You picked an odd number.
Enter a number: 256
You picked an even number.
Choice the right answer…
a. if num > 0:
print("You picked an odd number.")
else:
print("You picked an even number.")

b. if num > 0:
print("You picked an odd number.")
else:
print("You picked an even number.")
c. if num > 0:
print("You picked an odd number.") else:
print("You picked an even number.")
d. Any of the above

5
With my best wishes for success
Q26: After the shell prompt, type >>> max(4, 2, 13, 35, ‘July’, 50, 75) and press enter, you will get…
a. Type error
b. 75
c. July
d. 50
Q27: After the shell prompt, type >>> min(45, 30, 20, 15, 7, 66) and press enter, you will get…
a. 30
b. Type error
c. 7
d. None of the above

Q28: After the shell prompt, type


>>> import math and press enter
>>> squareRoot = math.sqrt and press enter
>>> squareRoot(144) and press enter, you will get…
a. 144.0
b. Syntax error
c. ‘12’
d. 12.0
Q29: After the shell prompt, type
>>> x = int(input("Plz enter Number 1: ")) press enter
Plz enter Number 1: 25 press enter
>>> y = input("Plz enter Number 2: ") press enter
Plz enter Number 2: 55 press enter
>>> z = int(input("Plz enter Number 3: ")) press enter
Plz enter Number 3: 30 press enter
>>> print("The max of the three numbers is ", max(x, y, z)) press enter, you will get…
a. 55
b. Type error
c. 25 + 55 + 30
d. 110
Q30: The next program is used to demonstrate the if statement in python…
x = int(input(" enter the value of x: "))
y = int(input(" enter the value of y: "))
if y > x:
print(" y is greater than x ")
print(" x = ", x , " & y = ", y)
input(" Please press any key to exist!")
Then the sample run could be…
a. enter the value of x: 5
enter the value of y: 10
Please press any key to exist!

6
With my best wishes for success
b. Syntax error
c. enter the value of x: 5
enter the value of y: 10
y is greater than x
x = 5 & y = 10
Please press any key to exist!
d. None of the above
Q31: The next program is used to demonstrate the if - Else statement in python…
num1 = int(input(" Enter the num1: "))
num2 = int(input(" Enter the num2: "))
if num1 > num2:
print(' num1 is greater than num2')
print(" num1 = ", num1," & num2 = ", num2)
else:
print(' num1 is smaller than num2')
print(" num1 = ", num1," & num2 = ", num2)
print(' End of the code!')
input(" Please press any key to exist!")
Then the sample run could be…
a. Enter the num1: 5
Enter the num2: 10
num1 is smaller than num2
num1 = 5 & num2 = 10
End of the code!
Please press any key to exist!
b. Syntax error
c. Enter the num1: 10
Enter the num2: 5
num2 is greater than num1
num1 = 10 & num2 = 5
End of the code!
Please press any key to exist!
d. None of the above

Q32: The next program is used to demonstrate the multiple choices of if - if Else statement in
python…
num1 = int(input(" Enter num1: "))
num2 = int(input(" Enter num2: "))
if num1 > num2:
print(" num1 is greater than num2")
print(" num1 = ", num1, "& num2 = ", num2)
elif num1 == num2:
print(" num1 and num2 are equal")

7
With my best wishes for success
print(" num1 = ", num1, "& num2 = ", num2)
else:
print(" num1 is smaller than num2")
print(" num1 = ", num1, "& num2 = ", num2)
print(' End of the code!')
input(" Please press any key to exist!")
Then the sample run could be…
a. Enter num1: 10
Enter num2: 5
num1 and num2 are equal
num1 = 10 & num2 = 5
End of the code!
Please press any key to exist!
b. Enter num1: 5
Enter num2: 10
num1 and num2 are equal
num1 = 5 & num2 = 10
End of the code!
Please press any key to exist!
c. Enter num1: 5
Enter num2: 5
num1 and num2 are equal
num1 = 5 & num2 = 5
End of the code!
Please press any key to exist!
d. Any of the above

Q33: The next program is used to demonstrate the comparison statements in python…
After the shell prompt, type…
>>> a = 10 press enter
>>> b = 10 press enter
>>> c = 20 press enter
>>> a<b press enter, you will get…
a. True
b. False
c. Type error
d. None of the above
Q34: The next program is used to demonstrate the comparison statements in python…
After the shell prompt, type…
>>> a = 10 press enter
>>> b = 10 press enter
>>> c = 20 press enter
>>> a == b press enter, you will get…

8
With my best wishes for success
a. False
b. True
c. Type error
d. None of the above

Q35: The next program is used to demonstrate the string data type in python…
After the shell prompt, type…
>>> 'ac' in 'string' press enter, you will get…
a. Name Error
b. True
c. False
d. Not in

Q36: The next program is used to demonstrate the string data type in python…
After the shell prompt, type…
>>> ‘a’ in astring press enter, you will get…
a. True
b. False
c. Name error
d. None of the above
Q37: The next program is used to demonstrate the string data type in python…
After the shell prompt, type…
>>> ‘a’ in ‘astring’ press enter, you will get…
a. True
b. False
c. Name error
d. None of the above
Q38: The next program is used to demonstrate the while statement in python…
Type the next grogram…
i=1
while True:
print(i)
i +=1
if(i > 3):
break
Choice the sample run…
a. 1
2
b. Syntax error
c. 1
d. 1
2
3

9
With my best wishes for success
Q39: The next program is used to demonstrate the for statement in python…
Type the next grogram…
for x in range (3):
print(x)
a. 0
1
2
b. 1
2
3
c. Syntax error
d. a or b is correct

Q40: The next program is used to demonstrate the for statement in python…
Type the next grogram…
b = [0, 1, 2, 3]
for n in b:
print(n)
a. 0
1
2
3
b. 1
2
3
c. Syntax error
d. None of the above
Q41: The next program is used to demonstrate the logical operators in python…
After the shell prompt, type…
>>> a = 10 press enter
>>> b = 15 press enter
>>> c = 20 press enter
>>> a<b and a!= b press enter, you will get…
a. False
b. Type error
c. True
d. None of the above
Q42: The next program is used to demonstrate the logical operators in python…
After the shell prompt, type…
>>> a = 10 press enter
>>> b = 15 press enter
>>> c = 20 press enter
>>> a<b or a!= b press enter, you will get…

10
With my best wishes for success
a. False
b. True
c. Type error
d. None of the above

Q43: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> names = [ ] press enter
>>> names press enter, you will get…
a. False
b. True
c. Blank
d. [ ]

Q44: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> names = [‘mark’, ‘john’, July] press enter, you will get…
a. ['mark', 'john', 'July']
b. Name error
c. ['mark', 'john', July]
d. [mark, john, July]

Q45: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> names = [“mark”, “john”, “july”] press enter
>>> age = [19, 20, 18] press enter
>>> age.extend(names) press enter
>>> age press enter, you will get…
a. [19, 20, 18, ‘mark’, ‘john’, ‘july’]
b. [‘mark’, ‘john’, ‘july’, 19, 20, 18]
c. [‘mark’, 19, ‘john’, 20, ‘july’, 18]
d. Any of the above

Q46: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> age = [‘mark’, 19, ‘john’, 20, ‘july’, 18] press enter
>>> max(age) press enter, you will get…

a. 20
b. 19 + 20 + 18
c. Type error
d. None of the above

11
With my best wishes for success
Q47: The next program is used to demonstrate list in python…
After the shell prompt, type…
>>> age = [19, 20, 18] press enter
>>> average = sum(age) /3 press enter, you will get…
a. 57
b. Syntax error
c. Not defined
d. 19.0

Q48: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> age = [‘mark’, 19, ‘john’, 20, ‘july’, 18] press enter
>>> len(age) press enter, you will get…
a. Type error
b. 5
c. 6
d. None of the above

Q49: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> names = [‘mark’, ‘john’, ‘july’, 19, 20, 18] press enter
>>> names[2 : : 3] press enter, you will get…
a. ['july', 20]
b. ['john', 20]
c. ['mark', 19]
d. ['july', 18]

Q50: The next program is used to demonstrate list in python…


After the shell prompt, type…
>>> names = [‘mark’, ‘john’, ‘july’, 19, 20, 18] press enter
>>> names[ : -3] press enter, you will get…
a. ['mark', 'john']
b. ['mark', 'john', 'july']
c. ['mark']
d. ['july']

Q51: Which of the following is a multi-line comment?


a. """Multi-line Comment Here"""
b. ""Multi-line Comment Here""
c. "Multi-line Comment Here"
d. 'Multi-line Comment Here'

12
With my best wishes for success
Q52: How would you convert "Hello" to lower case?
a. "hello".lower( )
b. lower"hello"
c. lower.("hello")
d. ("hello").lower

Q53: Which keyword is used to immediately terminate a loop?


a. Stop
b. Continue
c. break
d. terminate

Q54: Which keyword is used to end the current iteration of a loop skipping the remaining
statements in the loop body and returning to the top of the loop?
a. break
b. continue
c. stop
d. terminate

Q55: What keyword is used to define a function?


a. fun
b. def
c. for
d. init

Q56: To obtain the length of a string, you can use which function?
a. Length()
b. len()
c. index()
d. length_input()

Q57: Which of the following is a valid identifier?


a. $343
b. Mile
c. 9X
d. 8+9

Q58: To following code reads two number.


Which of the following is the correct input for the code?
>>> x, y = eval(input("Enter two numbers: "))
a. 1 2
b. “1 2”
c. 1, 2
d. 1, 2,

13
With my best wishes for success
Q59: After the shell prompt, type…
>>> 2 * 3 **2 press enter, you will get…
a. 36
b. 18
c. 12
d. 81

Q60: What is the data type of m after the following statement?


>>> m = (41, 54, 23, 68) press enter
a. Dictionary
b. Tuple
c. String
d. List

Q61: What is the data type of m after the following statement?


>>> m = ['July', 'September', 'December'] press enter
a. Dictionary
b. Tuple
c. String
d. List

Q62: How many times will “Music” be printed after the following statements?
for i in range(3, 7):
print('Music')
a. 4
b. 5
c. 6
d. 1

Q63: What is the correct file extension for Python files


a. .pyt
b. .pt
c. .py
d. .pyth

Q64: How do you create a variable with the floating number 2.8?
a. X = 2.8
b. X = float(2.8)
c. X = 2.7
d. a and b are correct

14
With my best wishes for success
Q65: Which operator can be used to compare two values?
a. =
b. ==
c. <>
d. ><

Q66: How do you start writing an if statement in python?


a. If x>y:
b. if(x>y)
c. if x>y then:
d. if[x>y]

Q67: What will be the output after the following statements?


m = 'ABC'
for i in m:
print(i, end=' ')
a. A
b. ABC
c. A B C
d. I

Q68: What will be the output after the following statements?


for m in range(7):
print(m, end='')
a. 0123456
b. 01234567
c. 123456
d. 1234567

Q69: What is the output of the next python program?


After type the program…
numbers = [1, 2]
names = ['a', 'b']
for number in numbers:
print(number)
for letter in names:
print(letter)
a. 1
a
b
2
a
b

15
With my best wishes for success
b. 1 a b 2 a b
c. 1
a
b
d. None of the above

Q70: What is the output of the next python program?


After type the program…
for n in "Python":
print(n)
a. Python
b. Py
c. Pytho
d. P
y
t
h
o
n

Answer key

1 2 3 4 5 6 7 8 9 10
d d d a a c b a c b

11 12 13 14 15 16 17 18 19 20
c c b a c a b c c b

21 22 23 24 25 26 27 28 29 30
d a a d b a c d b c

31 32 33 34 35 36 37 38 39 40
a c b b c c a d a a

41 42 43 44 45 46 47 48 49 50
c b d b a c d c d b

51 52 53 54 55 56 57 58 59 60
a a c b b b b c b b

61 62 63 64 65 66 67 68 69 70
d a c d b a c a a d

16
With my best wishes for success

You might also like