Professional Documents
Culture Documents
solutions
solutions
Q1.What are tokens in python? How many types of tokens are allowed in python?
Exemplify your answer.
Ans: The smallest individual unit in a program is known as a Token or a lexical unit.
Python has following tokens:
1.Keywords
2.Identifiers
3.Literals
4.operators
5.punctuators
if max_price>0:
print( max_price )
else :
Pass
Q: 2.Predict the outputs of the following programs :
Q:2.a)
count=0
while count<10:
print(“hello”)
count +=1
Answer:
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
Q:2.b)
x=10
y=0
while x>y:
print(x,y)
x=x-1
y=y+1
Answer:
10 0
91
82
73
64
Q:2.c)
Keepgoing= True
x=100
while keepgoing:
print(x)
x=x-10
if x<50:
keepgoing=false
Answer:
100
90
80
70
60
50
Q:2.d)
x=45
while x<50:
print(x)
Answer:
45
45
45…..print like this infinite times
Q:2.e)
for x in [1,2,3,4,5]:
print(x)
Answer:
1
2
3
4
5
Q:2.f)
for p in range (1,10):
print(p)
Answer:
1
2
3
4
5
6
7
8
9
Q:2.g)
for z in range (-500,500,100):
print(z)
Answer:
-500
-400
-300
-200
-100
0
100
200
300
400
Q:2.h)
x=10
y=5
for x in range (x-y*2):
print(“%”,i)
Answer:
No output
Q:2. i)
c=0
for x in range (10):
for y in range(5):
c+=1
print(c)
Answer:
50
Q:2. j)
x=[1,2,3]
counter=0
while counter < len(x):
print(x[counter]*”%”)
for y in x:
print(y*’*’)
counter +=1
Answer:
%
*
**
***
%%
*
**
***
%%%
*
**
***
Q:2. k)
for x in ‘lamp’:
print(str.upper(x))
Answer:
L
A
M
P
Q:2. l)
x=’one’
y=’two’
counter=0
while counter < len(x):
print(x[counter],y[counter])
counter +=1
Answer:
ot
nw
eo
Q:2. m)
x=”apple,pear,peach”
y=x.split(“,”)
for zin y:
print(z)
Answer:
apple
pear
peach
Q:2. n)
x=’apple,pear,peach,grapefruit’
y=x.split(“,”)
for z in y:
if z<‘m’:
print(str.lower(z))
else:
print(str.upper(z))
Answer:
apple
PEAR
PEACH
grapefruit
Q: 3.Find and write the output of the following python code:
for Name in [‘jayes’,’ramya’,’Taruna’,’suraj’]:
print(Name)
if Name[0]==’T’:
break
else:
print(‘Finished!’)
print(‘Got it ! ‘)
Answer:
jayes
Finished!
ramya
Finished!
Taruna
Got it !
Q: 4.How many times will the following for loop execute and what’s the output?
(i)
for i in range(-1,7,-2):
for j in range(3):
print(1,j)
Answer:
No output
Q: 4 (ii)
for i in range(1,3,1):
for j in range(i+1):
print(‘*’)
Answer:
*
*
*
*
*
Q: 5. Is the loop in the code below infinite? How do you know before you run it?
m=3
n=5
while n<10:
m=n-1
n=2*n-m
print(n,m)
Answer:
The code is finite.
we can find whether the code is infinite by checking the while condition . Which changes
or remain the same and always all time according to that condition is checked it comes
out true.
index = days.index(firstday)
print(days[index+(day%7)])
Q: 6. One foot equals 12 inches. Write a function that accepts a length written in
feet as an argument and returns this length written in inches. Write a second
function that asks the user for a number of feet and returns this value. Write a
third function that accepts a number of inches and displays this to the screen. Use
these three functions to write a program that asks the user for a number of feet
and tells them the corresponding number of inches.
Answer:
ft=float(input(“Enter the ft”))
inch=ft*12
print(inch, “this is the number of inches”)
Q: 7. Write a program that reads an integer N from the keyboard computes and
displays the sum of the numbers from N to (2*N) if N is nonnegative. If N is a
negative number, then it’s the sum of the numbers from (2*N) to N. The starting
and ending points are included in the sum.
Answer:
n = int(input(“Enter a number: “))
m=2*n
if n > 0:
sum = 0
for i in range(n, m+1):
sum += i
print(sum)
elif n < 0:
sum = 0
for i in range(m, n+1):
sum += i
print(sum)
else:
print(“Enter a valid no. “)
Q: 8. Write a program that reads a date as an integer in the format MMDDYYYY.
The program will call a function that prints print out the date in the format
<Month Name><day>, <year>.
Answer:
dt = input(“Enter date in the format MMDDYYYY: “)
if dt[0] == “0”:
if dt[1] == “1”:
a = “January”
elif dt[1] == “2”:
a = “February”
elif dt[1] == “3”:
a = “March”
elif dt[1] == “4”:
a = “April”
elif dt[1] == “5”:
a = “May”
elif dt[1] == “6”:
a = “June”
elif dt[1] == “7”:
a = “July”
elif dt[1] == “8”:
a = “August”
elif dt[1] == “9”:
a = “September”
elif dt[1] == “10”:
a = “October”
elif dt[0] == “1”:
if dt[1] == “2”:
a = “November”
elif dt[1] == “12”:
a = “December”
print(a,” “, dt[2],dt[3],”,”, ” “, dt[4:], sep = “”)
Q.9.Write a program that prints a table on two columns – table that helps
converting miles into kilometers.
Ans:
mile = []
kilometer = []
choice = 1
while choice != 0:
a = int(input("Enter the distance in miles: "))
mile.append(a)
kilometer.append(a*1.6)
for i in range(len(mile)):
kilogram = []
choice = 1
while choice != 0:
pound.append(a)
kilogram.append(a*0.45)
print(" Pounds|Kilograms")
for i in range(len(pound)):
c = b - a
if c > 1000:
c = str(c)
c = str(c)
print(c[0], " ", "hours", " ", c[1],c[2]," ", "minutes", sep
= "")
b) is a * 3 equivalent to a + a + a?
Yes, they both are equal to (1, 2, 3, 1, 2, 3, 1, 2, 3)
if len(n) == 12:
count = 0
#print(i)
for i in n:
if i.isdigit():
count+=1
if count == 10:
print("Valid Number")
else:
else:
#print(i)
else:
print("Invalid Length")
2. Write a program that should prompt the user to type some sentence(s) followed
by “enter”. It should then print the original sentence(s) and the following statistics
relating to the sentence(s):
Ans:
a = input("Enter a sentence and type enter at the end: ")
l=a.split()
alnum = -5
for i in a:
if i.isalnum():
alnum+=1
else:
a = []
for i in range(len(l)):
a.append(l[i]+n[i])
print(a)
4.Write a program that rotates the elements of a list so that the element at the first
index moves to the second index, the element in the second index moves to the
third index, etc., and the element in the last index moves to the first index..
Ans:
n = eval(input("Enter a list: "))
n.insert(0,n[-1])
del n[-1]
print(n)
5.Write a short Python code segment that prints the longest word in a list of
words.
Answer:
a = eval(input("Enter a list of strings: "))
large = ''
for i in a:
if len(i)>len(large):
large=i
print(large)
6. Write a program that creates a list of all the integers less than 100 that are
multiples of 3 or 5.
Answer:
a = []
if i%3==0 or i%5==0:
a.append(i)
print(a)
7.Define two variables first and second so that first = “Jimmy” and second =
“Johny”. Write a short Python code segment that swaps the values assigned to
these two variables and prints the results.
Answer:
first = "Jimmy"
second = "Johnny"
print(first)
print(second)
8.Write a Python program that creates a tuple storing first 9 terms of Fibonacci
series.
Answer:
l = [0,1]
a = 0
b = 1
c = 0
for i in range(7):
c = a+b
a = b
b = c
l.append(c)
print(tuple(l))
9.Create a dictionary whose keys are month names and whose values are the
number of days in the corresponding months.
Answer:
for i in d.keys():
if i==a:
print()
b=[]
for i in d.keys():
b.append(i)
b.sort()
print(b)
print()
for i in d.keys():
if d[i]==30:
print(i, end="")
print()
print()
c = [("February",28)]
for i in d.keys():
if d[i]==30:
c.append((i,30))
for i in d.keys():
if d[i]==31:
c.append((i,31))
print(c)
10. Write a function called addDict(dict1, dict2) which computes the union of two
dictionaries. It should return a new dictionary, with all the items in both its
arguments (assumed to be dictionaries). If the same key appears in both
arguments, feel free to pick a value from either.
Answer:
dict1.update(dict2)
print(dict1)
print(addict(a,b))
11.Write a program to sort a dictionary’s keys using Bubble sort and produce the
sorted keys as a list.
Answer:
a = eval(input("Enter a dictionary: "))
b = a.keys()
c = []
for i in b:
c.append(i)
for i in range(len(c)):
for j in range(len(c)-i-1):
if c[j]>c[j+1]:
c[j],c[j+1]=c[j+1],c[j]
print(c)
12. Write a program to sort a dictionary’s values using Bubble sort and produce the
sorted values as a list.
Answer:
a=eval(input("Enter a dictionary: "))
b=a.values()
c = []
for i in b:
c.append(i)
for i in range(len(c)):
for j in range(len(c)-i-1):
if c[j]>c[j+1]:
c[j],c[j+1]=c[j+1],c[j]
print(c)
Computer Network
Answer:
Two or more autonomous computing devices connected to one another to exchange
information or share resources, form a computer network.
Answer:
Advantages of network-
Share resources : such as printers and scanners. This is cheaper than buying equipment
for each computer.
Share storage : being able to access files from any machines on the network can share
data.
Can share software : Software can be installed centrally rather than on a machine.
Metering software can then be usednto limit the number of copies being run at any one
time.
Improve communications: Messages can be sent
Disadvantages of network-
The system are more sophisticated and complex to run. This can add to costs and you
may need specialist staff to run the network.
If networks are badly managed, services can become unusable and productivity falls.
If software and files are held centrally , it may be impossible to carry out any work if the
center server fails. People become reliant on the communication, if these fail, it can cause
havoc.
File security is more important especially if connected to WANs e.g.. protection from
viruses.
Answer:
(a) Host or Nodes. The term host or node refers to computers that are attached to a
network and are seeking to share the resources of the network.
(b) Server. A server facilitates networking tasks like sharing of data, resource-sharing,
communication among hosts etc.
(c)Clients. A client is a host computer that request from some service from a server.
(d)Network hardware. Establishing corrections, controlling network traffic etc. Example-
NIC,HUB,SWITCH,ROUTER, many others.
(e)Communication channel. Can be wired or wireless.
(f) Software. The software layers of a network makes networking possible. These
comprise of network protocols,network operating system etc.
(g)Network services- Application that provide different functionalities over a network,
such as DNS(Domain name System),file sharing, VOIP and many more.
Answer:
LAN(local area network) are confined to a localised area Network.
WAN(wide area network) is a group of computers that are separated by large distances
and tied together.
Answer:
Peer – to – Peer networks: Each computer on a peer-to -peer network is equal. Each
componenet can play the role of a client or a server.
Client- server network: Bigger networks prefer to have centralized control. They do this
clearly designating servers and clients. Such network are called client-server networks oe
even master-slave networks.
Answer:
client-server P2P
The server controls security of the
security No central control over security
network.
The server manages the network. Need a
No central control over the
Management dedicated team of people to manage the
network. Anyone can set up.
server.
clients are not dependent on a
Dependency client are dependent on the server.
central server.
If machines on the network are
The server can be upgraded to be made
Performance slow they will low down other
more powerful to cope with high demand.
machines.
Q.7. Type of network based on communication channel.
Answer:
(i) Wired Computer Networks
a. Twisted pair cable- is a pair of insulated wires that are twisted together to improve
electromagnetic capability and to reduce noise from outside sources.
b. Co-axial Cable- consists of a solid wire core surrounded by one or more foil or wire
shields, each separated by some kind of plastic insulator.
c. Fibre Optic Cable- A fibre optic cable consists of a bundle of glass threads each of
which is capable of transmitting messages modulated onto light waves.
(ii)Wireless computer network
a. Microwave- used in mobile phone
b. Radio- used in radio program.
(iii) Satellite- is a case of microwave relay system.
Answer: Network- interface -card is a device that is attached to each of the workstations
and the server. NIC is also called Terminal Access Point (TAP).
Answer: A unique physical address to each NIC , this physical address is known as Media
Access control address.
Answer:
A hub is a hardware device used to connect several computer together. A hub contains
multiple independent but connected modules of network and inter-networked
equipment. A similar term is concentrator. A concentrator is a device that provides a
central connection point for cables from workstation, servers and peripherals.
Two type of hubs
Active hubs – electrically amplify the signal as it moves from one connected device to
another.A ctive hubs are used like repeaters to extend the length of the network.
Passive hubs- allow the signal to pass from one computer to another without any
change.
Class 12 Computer Science Computer Network Notes
Q.11.What is a Switch?
Answer: A switch is a device that is used to segment networks into different subnetworks
called subnets or LAN segments.
Answer: Bridges are smart enough to know which computers are on which side of the
bridge, so they only allow those messages that need to get to the other side to cross the
bridge.
Answer: Based on a network road map called routing table , routers can help ensure that
packets are travelling the most efficient path to their destinations.
Answer: The gateway is the computer that routes the traffic from a workstation to the
outside network that is serving the web pages.
Answer: An access point (AP), also called wireless access point(WAP), is a hardware
device that establishes connections of computing devices on wireless LAN with a fixed
wire network.
Answer:
1. Private clouds-These are the clouds for exclusive use by a single organization and
typically controlled, managed and hosted in private data centers.
2. Public clouds- These are the clouds for use by multiple organization (tenants) on a
shared basis and hosted and managed by a third party service provider.
3.community clouds- These are the clouds for use by a group of related organizations
who wish to make use of a common cloud computing environment
4.Hybrid clouds- When a single organization adopts private and public clouds for a
single application in order to take advantage of the benefits of both.
Answer- IOT is a technology that connects the things to the internet over wired or
wireless connections
Answer: RFID (Radio Frequencies Identification) is designed to use radio waves to read
and capture information stored on a tag, called an RFID tag attached to an object.
Answer:
a) Home appliances
b) Wearables
c) Vehicles
d) Factories
e) Agriculture
f) Food
Answer: A message signal that carries the data to be transmitted, needs to be imposed
on top of the carrier signal. These process is termed as modulation. Demodulation is the
reserve process of modulation where data is extracted from the received signal.
Answer:
Amplitude modulation-That amplitude is the height of the carrier wave, if, we can tweak
the height of the carrier so that it shows the impact of data/message signal.
Frequency modulation- The frequency modulation, the frequency of the carrier signal is
varied as per the changes in the amplitude of the modulating signal.
Answer: Transmitting over a shared communication medium requires that at a time, only
one sender and one receiver use the communication medium. If multiple nodes on the
same network transmit data at the same time, it leads to a condition called collision and
data gets lost. In a computer network , collision is a specific condition that occurs when
two or more nodes on a network transmit data at the same time.
Answer:
Two way communication where sending and receiving takes place simultaneously, is
called full Duplex.
Wireless network cannot listen while transmitting is called Half Duplex.
Q.25. Which method is used for collision detection in wired and wireless ?
Answer:
CSMA/CA(carrier sense multiple access/ collision avoidance) for wireless , CSMA/CD
(carrier sense multiple access/collision detection for wired.
Answer:
Single-bit error- If only one bit of the transmitted data got changed from 1 to 0 or from
0 to 1.
Multiple-bit error- If two or more consecutive bits in data changed from 0 to 1 or from 1
to 0.
Burst Error- If two or more consecutive bits in data got changed from 0 to 1 or from 1 to
0.
Q.28. What is Single Dimensional Parity Checking? Advantages and disadvantages?
Answer:
Numbers of 1’s is counted in the actual data unit
Add an extra bit called the parity bit to actual data so that the number of 1 ‘s along with
the extra bit, become or remain even.
Advantages-
1) It is a simple mechanism, which is easy to implements.
2) It is an inexpensive technique for detecting the errors in data transmission.
Drawbacks-
1)It can detect only single-bit errors which occur rarely.
2) If, in the data transmitted , two bits gets interchanged then even through data gets
affected , but the parity bit remain correct . In such cases , this technique cannot detect
the errors.
Answer:
Calculating the parity bits for each data unit row- wise and column-wise.
Advantage of two- Dimensional –
(I) It is more efficient than single dimensional parity technique.
(ii) It can detect multiple bit error also, which sometimes single dimensional parity
checking technique cannot.
Disadvantage-
(I) Cannot detect compensating multiple bit errors.
(ii) This technique cannot detect 4 – or more-bits errors in some cases.
Answer:
The checksum refers to a sum of data bits calculated from digital data that is used to
ensure the data integrity at the reciever’s end.
Operates like-
a) At the sender node , before transmission
(i) The data being transmitted is divided into equal sized k number of segments , where
each segment contains m number of bits.
(ii) The divided k segments are added using 1’s complement arithmetic and extra bits are
added back to the sum.
(iii)The final sum’s complement is calculated . This is the checksum.
(iv) Now all the data segment is sent along with the checksum.
b) At the reciever node, after transmission
(V) Step (II) is repeated at the reciever end , all the data segments are added using 1’s
complement arithmetuic to get the new sum.
(vi) This calculated new sum is added with the recieved check sum and then
complemented.
Now,
(a) If the result is all 0’s, the transmission is successful- Accept the data.
(b) If the result is not all 0’s, the transmission is Erroneous – Reject the data.
Answer:
Routing is the process of efficiently selecting a path in a network along which the data
packets will travel to their destination.
A routing table is a table maintained by routers that maintains routing information based
on which router determines best path to reach a network.
Answer: Finding the best route from every destination for data transmission.
Answer: TCP/IP suite is the current standard for both local and wide area networking.
TCP/IP is a collection of protocols that includes TCP, IP ,UDP(USER DATAGRAM
PROTOCOL) and many other.
TCP – TCP ensures reliable communication and uses ports to deliver packets. It is a
connection- oriented protocol. TCP also fragments and reassembles messgaes, using a
sequencing function to ensure that packets are reassembled in the correct order. In TCP,
a connection must be built using a handshake process before information is sent or
received.
UDP- UDP is a connectionless protocol. It allows information to be sent without using a
handshake process.
IP- IP is a connectionless protocol responsible for providing address of each computer
and performing routing.
Answer:
(i) Excessive packet delay
(ii) Loss of data packets
(iii) Retransmission
Answer:
HTTP(Hypertext Markup Language (HTML) uses Internet addresses in a special format
called Uniform Resource locator or URL.
Elements of a URL –
(a) The type of server or protocol.
(b) The name/address of the server on the Internet.
(c) The location of the file on the server.
Answer:
IP address is a unique numerical label as a string of numbers separated by dots , used to
identify a device on the internet.
IPV4- uses a 32-bit address scheme allowing for a total of 2**32 address (just over 4
billion addresses).they have reached limit
IPV6- uses a 128 bit long IP addreses. They are being assigned.
IPV6(DUAL) uses IPV6 and IPv4 address combined.
Answer: The url of a website is also known as its domain name. The domain name is
unique name of a website.
(i) www
(ii) name describing the website purpose.
(iii)TLD (Top Level Domain) such as .com,.net,.org etc.
Q.40.Explain features of cellular or wireless networks depend hevily on wireless
connectivity protocols such as 2G,3G,4G etc?
Answer:
2G GSM (1992) – the second generation: Allows data along with calls in the form of text
messages.GSM can handle data speed of upto 250 kbps.
The GSM standard is transmitted at the frequencies between 900 Mhz and 1800 Mhz.
3G(2000)- the third generation – 3G offers speed of 500 Kbps to 2 Mbps. 3G is
transmitted at frequency 2100 Mhz.
4G(2013)-the fourth generation- Range of 10-15 Mbps which can go upto 50 Mbps and
even higher. The frequency range are 1800 Mhz to 2300 Mhz.
Answer: Wi-Fiprotocol governs the rules to connect to the Internet without a direct line
from our PC to the ISP.
Answer:
(a)To test the connectivity between two hosts, you can use the PING command. PING
determines whether the remote machine can receive the test packet and reply. Ping
serves two purposes:
1. To ensure that a network connection can be established.
2. Timing information as to the speed of the connection.
(b)traceroute or tracert is very similar to ping, expect that it identifies which network
pathways it takes along each hop, rather than the time it takes for each packet to return.
(c)NSLOOKUP: Displays the name and IP address of your computer default DNS server.
(d) IPCONFIG: Command gives more detailed information such as DNS servers, DHCP
enabled or not, MAC Address along with other helpful information.
(e)WHOIS : is used to get information on a specific domain name such as who registered
it , when was it registered and when the domain will expire etc.
(f)To check the download and upload speed of your network go to the site speedtest.net
click on Go. It will check the current speed and show.
Q.43.Explain:
(a)HTTP: The Hyper text Transfer Protocol is an application-level protocol with the
lightness and speed necessary for distributed, collaborative, hypermedia information
systems. It is a generic , stateless, object-oriented protocol which can be used for many
tasks.
(c) POP(post office protocol): The POP3 has become a standard mail protocol.POP3
protocol works on two ports:
1.Port 110-default pop3 non -encrypted port.
2.Port 995-the encrypted port used for secure email communication.
Answer: Protocol HTTP works over the protocol TCP/IP. There are HTTP clients that make
requests via HTTP protocol and HTTP servers that respond to HTTP requests. Working-
(i) For web communications, the request message , is sent to an HTTP server in the form
of URLs by the HTTP client.
(ii) The HTTP server receives the HTTP request, fetches the information as per the request
and sends it to the HTTP client.
(iii)The HTTP client receives the response message, interprets the message and displays
the contents of the message on the browser’s window.
Answer:
(i) You compose and send an email from your email client. Your email has the recipient’s
email address along the email message.
(ii) Now your email client connects to the outgoing SMTP server and hands over the
email message in the required format.
(iii) The outgoing SMTP first validates the sender details and if valid processes the
message for sending and places it in outgoing queue.
(iv) Next DNS look up takes place. The SMTP server based on the domain details in the
recipient address, looks up the DNS server of the domain and retrieves the recipient
server information of the recipient domain
(v) Then the SMTP serve connects with the Recipient email server and sends the email
through SMTP protocol.
(vi) The Recipient server in turn validates the recipient account and delivers the email to
the users mail account.
(vii) The user logs into own email account and views the received email using e-mail
client that will use POP3/IMAP protocol.
Answer:
Answer:
Person can work on the desktop of another computer in the same manner as if that
computer is right in front of the person. There are two programs: TELNET and SSH that
facilitate remote login on the internet. Specify the remote machine on which you want to
work and these programs will help you connect to it.