Question

In: Computer Science

Given the code segment: def f1(a, b = 2): if a : print(1) f1(1) what is...

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

Solutions

Expert Solution

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.


Related Solutions

def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2:...
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2: print("./") print("*") print(".\\") elif n == 3: print("../") print("./") print("*") print(".\\") print("..\\") elif n == 4: print(".../") annoying_valley(3) print("...\\") elif n == 5: print("..../") annoying_valley(4) print("....\\") elif n == 6: print("...../") annoying_valley(5) print(".....\\") else: print("." * (n - 1) + "/") annoying_valley(n - 1) print("." * (n - 1) + "\\") def annoying_int_sequence(n): if n == 0: return [] elif n == 1: return...
Consider the following code segment:    count = 1    while count <= 10:       print(count,...
Consider the following code segment:    count = 1    while count <= 10:       print(count, end=" ") Which of the following describes the error in this code? The loop control variable is not properly initialized. The comparison points the wrong way. The loop is infinite. The loop is off by 1. Does this code contain an error? If so, what line is the error on? 0: ans = input("Yes/No? ") 1: if ans == "Yes": 2: print("Confirmed!") 3: else...
Show what is written by the following segment of code, given item1, item2, and item3 are...
Show what is written by the following segment of code, given item1, item2, and item3 are int variable: item1 = 4; item3= 0; item2 = item1 + 1; stack.Push(item2); stack.Push(item2 +1); stack.Push(item1); item2 = stack.Top(); stack.Pop(); item1 = item2 + 1; stack.Push(item1); Stack.Push(item3); while (!stack.IsEmpty()) {      item3 = stack.Top():      cout <<item3<<endl;      stack.Pop(); } cout<<item1 <<endl <<item2<<endl<<item3<<endl;
import sys var = 1 print(var) def function1(myVar):     print(myVar)     var = myVar + 1...
import sys var = 1 print(var) def function1(myVar):     print(myVar)     var = myVar + 1     print(var)     function2(var) def function2(myVar):     print(myVar)     var = myVar + 1     print(var)     function3(var) def function3(myVar):     print(myVar)     var = myVar + 1     print(var) def main(argv):     var = 10     print(var)     function1(var) if __name__=="__main__":     main(sys.argv) 1. As the program runs, what is the first line that will be interpreted by Python, and what action will...
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of...
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of the matrix.
I. Given the following code segment below what is the best description of line 5 and...
I. Given the following code segment below what is the best description of line 5 and line 6? Identify the public and private members. 1. #include <iostream.h> 2. class SimpleCat 3. { 4. public: 5. SimpleCat (int age, int weight); 6. ~SimpleCat(){} 7. int GetAge() {return itsAge;} 8. int GetWeight() {return itsWeight;} 9. private: 10. int itsAge; 11. int itsWeight; 12. }; II. Multiple Choice questions 1. A function that is called automatically each time an object is created or...
Question 1 (a) Discuss the difference between a Reportable segment and an Operating segment. (b)What are...
Question 1 (a) Discuss the difference between a Reportable segment and an Operating segment. (b)What are the disclosure requirements of IFRS 8? Question 2 (a) Distinguish between Interim period and Interim financial report. (b) What are the minimum contents prescribed by IAS 34 for an interim report? (c) What are the periods that should be covered by the interim financial statements?  
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s):...
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s): prev = 0 for current in range(1, len(s) - 1): prev = current - 1 next = current + 1 if s[prev] == s[next]: break else: continue return 0 return prev s = 'Good decision!' print(mirrorOnWheels(s)) 3. mixture = {1:[1, 2, 0], 2:[2, 0, 1], 0:[0, 1, 2]} print(mixture[2][2]) 4. noOddHeroes = [] heroes = ['superman', 'batman', 'aquaman'] for hero in heroes: if len(hero)...
Compute each of the following: a. F1+F2+F3+F4+F5 b. F1+2+3+4 c. F3xF4 d. F3X4 Given that FN...
Compute each of the following: a. F1+F2+F3+F4+F5 b. F1+2+3+4 c. F3xF4 d. F3X4 Given that FN represents the Nth Fibonacci number, and that F31 =1,346, 269 and F33 = 3,524,578, find the following: a. F32 b. F34 25. Solve the quadratic equation using the quadratic formula: 3x^2-2x-11=0
What is the Θ( ) for each code segment below? (a) for( int i = 1,...
What is the Θ( ) for each code segment below? (a) for( int i = 1, i<= n, i = i*2){       some constant operation } (b) for( int i = 1, i<= n, i++){      for( int j = 2*i, j<=n, j++){           some constant operation      } } (c) for( int i = 1, i<= n, i = i*2){      for( int j = 1, j<=n, j = j*2){           some constant operation      } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT