Professional Documents
Culture Documents
Cs Sheet
Cs Sheet
Cs Sheet
Academic Level: 2
Faculty of Semester: Fall 2021
Computer Science Course Code: CS312
Course Title: Computer Language 2
Revision Sheet: 1
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
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
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
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
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
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
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
Q56: To obtain the length of a string, you can use which function?
a. Length()
b. len()
c. index()
d. length_input()
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
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
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. ><
15
With my best wishes for success
b. 1 a b 2 a b
c. 1
a
b
d. None of the above
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