WorksheetsPython and Unix
Total questions: 100
Worksheet time: 59mins
What is Unix?
Unix is a programming language
Unix is a software program
Unix is an operating system
Unix is a text editor
In which language UNIX is written?
C++
C
Java
Python
Which of the following is not a part of all the versions of Unix?
System Calls
Graphical user interface
Kernel and Shell
Commands and utilities
Which Unix command is used for changing the current directory?
pwd
rm
cd
cp
Which command is used for displaying the contents of a file in Unix?
mkdir
cat
rm
cp
Which of the following commands is known as stream editor?
grep
tr
sed
td
Which of the following is not a type of shell?
The C Shell
The Korn Shell
The Bourne Shell
The Perl Shell
The prompt issued by the shell is called ______
prompt
command translator
command prompt
command executor
What is the default symbol for command prompt in Bourne shell?
!
#
$
@
What is a shell script?
group of commands
a file containing a series of commands
group of functions
a file containing special symbols
Which of the following commands is used to display the directory attributes
cat
ls
mkdir
cp
Which command is used to remove a file?
remove
del
rm
mv
The following command can list out all the current active logins.
A - whoami
B - who am i
C - who
D - None of the above.
The mv command changes
Only the directory entry
Only the directory entry and i-node
Only the i-node number
None of the above
Unix is a
Single User, Single tasking OS
Single User, Multi-tasking OS
Multi-User, Multi- tasking OS
None
To Display line of text/string that are passed as an argument with a command
cat
echo
ls
none of the above
Unix shell command that lists directory contents of files and directories with hidden files.
ls -d
ls -F
ls -a
ls -l
Which command is used to get information about currently logged in user on to system
who am i
who
who i am
None of the above
Date command is used to support format specifier
True
False
Which command in UNIX is used to change the user account passwords.
pwd
password
passwd
none of the above
In Unix, Combining commands are
& %
&& %
; &&
; &
which command is used to see the calendar of any specific month or a complete year
calendar
cal
none of the above
Shell scripts are executed in a separate child shell process.
a) True
b) False
The first line in any shell script begins with a _____
a) &
b) !
c) $
d) #
This is an important OS function
Printing
Resource (Memory, Processor, Device, etc) Management
Video editing
Scanning
Gaming
What year did Unix started?
1969
1981
1979
2015
What is an example of a special character
&
A
:
K
The --------------------- is responsible for the management of processes.
Shell
User
Kernel
Administrator
What is the Python built-in function used to display numbers and text on the screen?
input
output
command
What is the output from the following code?
print ("hello world")
Which of the following code is a Python Comment?
#this is a comment
{ this is a comment }
" this is a comment "
( this is a comment )
1==0
True
False
A: Strings can be changed during execution
B. Strings can be enclosed within single, double or even triple quotes
C. Strings are immutable
A,B & C are True
A,B are True but C is False
B, C are True but A is False
A,C are True but B is False
Find the output of the following code:
>>>str1='Save Soil'
>>>str1.isalnum( )
Save Soil
True
False
Identify the string membership operators of Python
in, not in
like, not like
as, not as
between, not between
Predict the output:
>>>str1="Rajathi Raja"
>>>print(str1.count('Raja'))
1
2
Error
Raja
Match the following:
1. \n A) Carriage return
2. \v B) BackSpace
3. \b C) new line
4. \r D) Vertical tab
1-C, 2-D, 3-B, 4-A
1-A, 2-C, 3-B, 4-D
1-C, 2-D, 3-A, 4-B
1-C, 2-A, 3-B, 4-D
Predict the output:
>>>saint="Thiruvalluvar"
>>>print(saint[5:])
valluvar
Thiruvalluvar
uvalluvar
Thiru
MATCH THE FOLLOWING:
1. concatenation A) +=
2. Append B) [ ]
3. String Slicing C) *
4. Repeating D) +
1-B. 2-A, 3-C, 4-D
1-D. 2-A, 3-B, 4-C
1-A,2-B,3-C,4-D
1-A,2-D,3-C,4-B
The unexpected event happened during program execution should be handled by
EXCEPTION
EXPERIMENT
ASSERTION
EXTRAORDINARY
try:
a=int(input("\n Enter a Value"))
b=int(input("\n Enter a Value "))
c=a/b
print (c)
except:
print("\n Something Went Wrong")
Assume a = 10 and b = 5, then the output will be
5.0
Something Went Wrong
Arithmetic Error
2.0
Exception disrupts the
Normal flow of the program
Abnornal flow of the program
Hard Disk
None of the Above
The suspicious code is put inside the
Try Block
Finally Block
Else Block
Except Block
________ statement can also be used without specifying Exception.
Try
Finally
Except
Else
try:
a=10/5
print (a)
except ArithmeticError:
print ("This statement is raising an exception" )
finally:
print (" final block executed " )
2.0
final block executed
This statement is raising an exception
final block executed
final block executed
2.0
An exception can be manually triggered by the command
raise
try
except
trigger
User defined Exceptions are created from the _________ Parent Class
Exception
Except
Handler
User Defined Exception
How many except statements can a try-except block have?
zero
one
more than one
more than zero
When will the else part of try-except-else be executed?
a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block
Is the following Python code valid?
try:
# Do something
except:
# Do something
else:
# Do something
no, there is no such thing as else
no, else cannot be used with except
no, else must come before except
yes
What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
a) NameError
b) ValueError
c) IndexError
d) TypeError
IndexError: list index out of range
13
10
12
9
Orange
Mango
Apple
Orange
Mango
Mango
Orange
Apple
Mango
Apple
Apple
Mango
ValueError: list.remove(x): x not in list
Apple
Mango
Orange
orange
Kiwi
Mango
Orange
Apple
Error
Error
[6.7, 7.7, 8.2, 8.1, 7.9, 5.8]
[5.8, 6.7, 7.7, 8.2, 8.1, 7.9]
[6.7, 7.7, 5.8, 8.2, 8.1, 7.9]
[6.7, 7.7, 8.2, 8.1, 7.9]
(6.7, 7.7, 8.2, 8.1, 7.9)
Error
6.7, 7.7, 8.2, 8.1, 7.9
[6.7, 7.7, 8.2, 8.1, 7.9]
"6.7, 7.7, 8.2, 8.1, 7.9"
Choose the appropriate code snippet which prints the following output.
My grade is 7
# For the given code snippet, choose the appropriate code snippet to print the mark of NSS.
print(marks['Non-academics']['NSS'])
print(marks['NSS'])
print(marks['NSS'])
print(marks['Non-academics'])
print(marks)
Error
Physics
80
Physics : 80
{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}
Error
( )
{'Physics': 80, 'Chemistry': 88, 'Mathematics': 92}
{'Chemistry': 88, 'Mathematics': 92}
{'Physics': 80, 'Chemistry': 88}
What will be the output of the following Python code?
a) 1
2
3
b) error
c) 1
2
d) none of the mentioned
What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
What will be the output of the following Python program?
a) error
b) 0 1 2 0
c) 0 1 2
d) none of the mentioned
What will be the output of the following Python code?
a) 1 2 3 4 5 6
b) 1 2 3 4 5 6 7
c) error
d) none of the mentioned
What will be the output of the following Python code?
a) 1
b) 1 3 5 7.....
c) 1 2 3 4..... .
d) none of the mentioned
What will be the output of the following Python code?
a) a b c d
b) 0 1 2 3
c) error
d) none of the mentioned
What will be the output of the following Python code?
a) a b c d
b) 0 1 2 3
c) error
d) 1 2 3 4
What will be the output of the following Python code?
a) 0 1 2
b) a b c
c) {0: 'a', 1: 'b', 2: 'c'}
{0: 'a', 1: 'b', 2: 'c'}
{0: 'a', 1: 'b', 2: 'c'}
d) none of the mentioned
What will be the output of the following Python code?
for i in range(0):
print(i)
a) 0
b) no output
c) error
d) none of the mentioned
What will be the output of the following Python code snippet?
a) 0 1 2 3 4 …
b) 0 -2
c) 0
d) error
What will be the output of the following Python code?
a) 0 1 2 3 4 Here
b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4
d) 1 2 3 4 5
#! Is called as
Shebang
Hebang
Hash prompt
Begin
Which of the following is not a kind of shell?
bash
ksh
csh
dsh
[ is equivalent to
Test
For
While
Then
The difference between printf and echo is
Echo adds fa new line after printing, printf does not
Printing adds a new line after printing, echo does not
Both are same
None of the above
“.” Is used to match
Any one character
Any number of characters
Only "."
Only special characters
Which of the following symbols is used as prefix to access the variables in scripting
#
$
^
&
The comparison operator " -eq " is used for
Numbers
Charaters
Strings
Any kind of data
A comment line in a script begins with
#
$
^
&
Every line in a shell script ends with
;
:
>
There is no rule
Scripts are made executable using the command
Chown
chmod
Exe
Run
Who can change the password of any user?
Everyone
Super user
Supervisor
End-User
All configuration files are stored under which directory
/home/etc
/etc
/bin
/
Which of the following command is file editor command ?
cat
vi
echo
grep
which of the following command is used to change the file permission?
usermod
umask
chage
chmod
Which of the following is used to append the contents of a file?
=
>>
<
>
Which command displays the contents of a file?
cat
pipe
ls
tee
Which of the command is used to change the password?
password
passwd
changepasswd
gpasswd
User passwords are stored in which file?
/etc/password
/root/password
/etc/passwd
/etc/shadow
How do you delete user along with home directory?
userdel
userdel -r
deleteuser
userdel -d
if normal user wants to run super users command he must be added in the which of the following file?
/etc/login.defs
/etc/sudoers
/etc/passwd
/etc/group
In vi editor a tilde (~) represents ________
used
line
unused line
blocked
header
The vi editor has two modes
command and input
read and write
write
read
The vi always starts in _______ mode
insert
read
command
write
In Vi editor command mode delete character under cursor we use ____
x
d
p
yy
To save and exit the file in vi editor we use
":q"
":sw"
": wq"
":qs"
