Showing posts with label questionAndAnswer. Show all posts
Showing posts with label questionAndAnswer. Show all posts

Thursday, July 18, 2019

Class Test – 15th July 2019 (Computer Science) - 12 SC


Question and Answers for the class test 1  15th july – COMPUTER SCIENCE - 12 SC

Q1. Write a function called my_buzz that takes a number.
If the number is divisible by 3, it should return “Fizz”.
If it is divisible by 5, it should return “Buzz”.
If it is divisible by both 3 and 5, it should return “FizzBuzz”.Otherwise, same no.
Ans1.     Program:
1.  def my_buzz(n):  
2.      if n % 3==0 and n % 5==0:  
3.          return 'FizzBuzz'  
4.      elif n % 3 == 0:  
5.          return 'Fizz'  
6.      elif n % 5 == 0:  
7.          return 'Buzz'  
8.      else:  
9.          return n  
10.   
11. a=int(input('enter a number'))  
12. print(my_buzz(a))  
Input and Output:
1.  ==== RESTART: D:\pythonVirtualEnv\practicePro\examplePro\classTestPro.py ====  
2.  enter a number15  
3.  Fizz  
4.  >>>   
5.  ==== RESTART: D:\pythonVirtualEnv\practicePro\examplePro\classTestPro.py ====  
6.  enter a number20  
7.  Buzz  
8.  >>>   
9.  ==== RESTART: D:\pythonVirtualEnv\practicePro\examplePro\classTestPro.py ====  
10. enter a number11  
   11  
Q2. Find the output of the following:

a.    1.  def increment(n):  

2.      n.append([4])  
3.      return n  
4.  l=[1,2,3]  
5.  m=increment(l)  
6.  print(l,m)                                                                b. 


 Ans (a). [123, [4]] [123, [4]] 
      

    1.  def increment(n):  
2.      n.append([49])  
3.      return n[0], n[1], n[2], n[3]  
4.  l=[23,35,47]  
5.  m1,m2,m3,m4=increment(l)  
6.  print(l)  
7.  print(m1,m2,m3,m4)  
8.  print(l[3] == m4)  


Ans (b). [233547, [49]]
           23 35 47 [49]
            True

Q3. Write a python program to read last 2 lines of a text file.
Ans3. Program:
1.  f=open('newFile.txt','r')  
2.  ls=f.readlines()  
3.  print('The Last two lines of the file are')  
4.  print(str(ls[-2]),end='')  
5.  print(str(ls[-1]),end='')  
Output:
1.  ==== RESTART: D:\pythonVirtualEnv\practicePro\examplePro\classTestPro.py ====  
2.  The Last two lines of the file are  
3.  so its a rainy day  
4.  so you get a raincoat  
Q4. Write a method in python to write multiple lines of text contents into a text file mylife.txt.
Ans4. Program:
1.  f=open('newFile.txt','a')  
2.  ls=['but its a nice day\n','so its a fun\n','lets have fun then\n']  
3.  f.writelines(ls)  
4.  f.close()  
Q5. Write a method in python to read the content from a text file diary.txt line by line and display the same on screen.
Ans5. Program:
1.  f=open('newFile.txt','r')  
2.  print(f.read())  
Output:
1.  ==== RESTART: D:\pythonVirtualEnv\practicePro\examplePro\classTestPro.py ====  
2.  but its a nice day  
3.  so its a fun  
4.  lets have fun then  
5.  but its a nice day  
6.  so its a fun  
7.  lets have fun the  





Share:

Sunday, July 14, 2019

Class Test 3 CS/IP 15-7-2018 - CLASS 11

Question and Answers of Class Test 3 – 15th July 11 

Q1. Distinguish internal and external memory of a computer?
Ans1.
Internal Memory
External Memory
This type of memory is usually fixed on the motherboard itself This type of memory is connected to the motherboard via some cables and not directly on it
The read/write speed is very fast compared to External memory The read/write speed is slow as compared to Internal memory
Cost per bit is high compared to external Memory Cost per bit is low compared to internal Memory
More connecting pins to transfer data at higher rate Less connecting pins
Less portable Highly portable
Example: RAM, eMMC(embedded MultiMediaCard) Example: HDD, DVD, Pendrive

Q2. Differentiate compiler and interpreter.
Ans2.
Compiler
Interpreter
Read the complete program entirely and generates an executable(usually bytecode) if no errors exists Converts one statement to machine executable code at a time
Code analysis time is more but the execution time is less Code analysis time is less but execution is more
Once the executable is generated,  compiler is not required for the execution Interpreter is required for the entire process of execution
Less memory efficient as an bytecode gets generated More memory efficient as no bytecode is generated
Modification of the features of the program is lengthy Modification of the features of the program is easy and less time consuming
Removing of bugs in the code is complicated as all the errors are presented at once at the end Removing of bugs are easy as errors are generated instantly
Example: c, c++, Example: Python, javascript, MATLAB

Q3. What is the role of input unit in a computer?
Ans3. The role of input device is to take data and instruction form the user or from any other source and convert the data/instruction in such a format (through encoding) that is usable by the computer. Example of input unit are-Keyboard, mouse, microphone etc.

Q4. What are the jobs of the Operating System?
Ans4. Few jobs of the operating system is listed below
  1. Processor management
  2. Process management
  3. Memory management
  4. Device management
  5. Storage management
  6. Application interface
  7. User interface
Q5. What are the types of Operating System with example?
Ans5. One of the classifications of OS can be:
  • Single-User, Single Task Operating System: only one user and one application can be handled by the operating system. Example:- CPM (Control program for microprocessor), DOS(Disk operating system).
  •     Single-User, Multi-Task Operating System: Only one user but multiple applications can be handled by the OS. Example:- windows 95 etc.
  •   Multiuser Operating System: This type operating system is able handle multiple users and multiple applications. Eg:- Linux (can support 4294967296 (2^32) hosts)
  •  Multiprocessing Operating System: The OS is able to schedule (i.e. handle) multiple processor. Eg:- linux, windows 7
  •  Embedded Operating System: These types of OS are tailored to do one job and does not support all the features general purpose operating OS. Eg:- OS for cars, Traffic lights, POS(point of sale) terminal, elevators etc
  •  Distributed Operating System: A distributed operating system runs over a collection of independent, networked, communicating, and physically separate computational nodes. These OS is able handle jobs which are serviced by multiple CPUs. Each individual node holds a specific software subset of the global aggregate operating system. Eg:- WWW is the largest distributive operating system, DYSEAC.

Share:

Monday, July 1, 2019

Class Test 3 - CS 12 - 28/6/2019


Class Test 3 - CS 12
Q1. What is the advantage of having function in a program?
Ans1. The advantages are:
  1. With function we can have code reuse
  2. The debugging process becomes easy
  3. Implementation of new features and removing existing features becomes easy
  4. Reduction of duplicate code
  5. Decomposing complex problems into simple pieces
  6. Information hiding
Q2. Differentiate between Arguments and Parameters with code(python).
Ans:- Parameter:- The variables that are used in the function header during function declaration are    called as parameters. Eg
               def  add(a, b, c): # Here a,b,c are the parameters
                              return a+b+c
               Types of parameter are:
  1. Positional -         add(a,b)
  2. Default -              add(a=10, b=5)  
  3. Variable length - add( *a)
          Arguments:- The actual values that are passed to the function  during function call. Eg
               add(10,45,23)     #  Here 10, 45, 23 are the Arguments (Positional)

Share: