Computer Science
Write the output of the code given below:
p=8
def sum(q=5, r=6) :
p=(r+q)**2
print(p, end= '#')
sum(p)
sum(r=3,q=2)
Python
Python Functions
2 Likes
Answer
Output
196#25#
Working
In the given code, the variable p is initially set to 8, and a function sum is defined with two parameters q and r, each having default values. When the function sum(p) is called, it overrides the default value of q with the value of p, resulting in q becoming 8. Inside the function, p is calculated as the square of the sum of q and r, which evaluates to 196. The function then prints 196# due to the end='#' parameter in the print statement. Subsequently, the function sum(r=3, q=2) is called with specific values for q and r, which are 2 and 3 respectively. Inside this call, p is calculated as 25 and printed as 25#. Therefore, the output of the code is 196#25#.
Answered By
2 Likes
Related Questions
Sonia was writing a code to insert multiple rows in the cust.csv file. By mistake her younger sister removed some parts of it. Now she is totally confused about used module and other options:
from csv import writer with ............... ("cust.csv", "a", newline = "\n") as f: #line 1 dt = writer(...............) #line 2 while True: #line 3 sno= int (input ("Enter Serial No: ") ) cust_name = input ("Enter customer name: ") city = input ("Enter city: ") amt = int (input ("Enter amount: ") ) dt. ............... ( [sno, cust name, city, amt] ) #line 4 print ("Record has been added.") print ("Want to add more record?Type YES!!!") ch = input() #line 5 ch = ch.upper() if ch=="YES": print("*") else: breakAttempt any 4 out of the given questions:
(i) Name the method Sonia should use in Line 1.
(ii) Which object Sonia should use to connect the file in Line 2?
(iii) What is the use of Line 3?
(iv) Name the method she should use in Line 4.
(v) What is the use of Line 5?
To provide telemedicine facility in a hilly state, a computer network is to be set up to connect hospitals in 6 small villages (V1, V2, …, V6) to the base hospital (H) in the state capital. This is shown in the following diagram.

No village is more than 20 km away from the state capital. Imagine yourself as a computer consultant for this project and answer the following questions with justification:
(i) Out of the following, what kind of link should be provided to set up this network: Microwave Link, Radio Link, Wired Link?
(ii) Many a time doctors at the village hospital have to consult senior doctors at the base hospital. How should they contact them—through email, SMS, telephone or video conference?
(iii) Out of SMTP and POP3, which protocol is used to receive emails?
(iv) Expand the following terms:
(a) VoIP
(b) HTTPS
(v) Mention any two advantages of using Star topology.
The code given below accepts the roll number of a student and deletes the record of that student from the table STUDENT. The structure of a record of table Student is: RollNo — integer; Name — string; Class — integer; Marks — integer.
Note the following to establish connectivity between Python and MySQL:
• Username is root, Password is A5_b23.
• The table exists in a MySQL database named SCHOOL.Write the following missing statements to complete the code:
Statement 1— to create the cursor object
Statement 2 — to execute the query
Statement 3 — to make the deletion in the database permanent
import mysql.connector as mysql def sql data(): conn=mysql.connect(host="localhost", user="root", password=" ", database="school") ............... #Statement 1 rno=int(input("Enter Roll Number : ")) qry="delete from student where RollNo={}".format(rno) ............... #Statement 2 ............... #Statement 3 print ("Record deleted")What is meant by serialization and deserialization in the context of binary files?