In: Computer Science
Given the code segment:
def f1(a, b = 2):
if a :
print(1)
f1(1)
what is the result of executing the code segment?
a) Syntax error
b) Runtime error
c) No error
d) Logic error
in which scenario(s) is using a dictionary useful?
a) To store the dates of lesson that each student is absent for so that warning letters may be issued to student exceeding a limit.
b) To store the student numbers for students who sat for an exam
c) To retrieve email of students who are absent for an exam. The student numbers will be entered into the recipient field and the system should display the student email.
d) The marks should be entered into the exam system. The exam system displays rows of student number, and the marks can be entered against the student number. The grade will be computed and reflected in the student row .
which expression returns True when a number, x is not and odd number between 1 (inclusive) and 100 (inclusive), and returns False otherwise?
a) x not in range(100) and x % 2 !=0
b) x not in range(1,101) and x % 2 !=0
c) not( x in range(1,101) and x % 2 1=0
d) x not in range(1,101) or x % 2 !=0
Question 1:
Answer;option c (No error)
Explanation: There is no error in the given code and it will output 1 on execution of the program.
Question 2:
Answer:Dictionary in python is useful in 3 above scenarios
1. To store the dates of lesson that each student is absent for so that warning letters may be issued to student exceeding a limit.
Example: {studentRollNo:[Date1,Date2,..]}
2.To retrieve email of students who are absent for an exam. The student numbers will be entered into the recipient field and the system should display the student email.
Example: {studentRollNo : StudentEmail }
3.The marks should be entered into the exam system. The exam system displays rows of student number, and the marks can be entered against the student number. The grade will be computed and reflected in the student row .
Example: {studentRollNo : MarksObtained }
Question 3:
Answer:option B ( x not in range(1,101) and x % 2 !=0)
Explanation: The above expression returns true when x is not and odd between 1(inclusive) and 100(inclusive).Otherwise returns false.