def add(a, b): result = a + b return result sum = add(5, 3) print(sum)In this example, the function add() returns the sum of a and b
def Change(X): for K, V in X.items(): L1.append(K) L2.append(V) D = {1: "ONE", 2: "TWO", 3: "THREE"} L1 = [] L2 = [] Change(D) print(L1) print(L2) print(D)
PASSENGERS.DAT
stores the records of passengers using the following structure:Create()
– to input data for passengers and write it in the binary file PASSENGERS.DAT
.SearchDestn(D)
– to read contents from the file PASSENGERS.DAT
and display the details of those Passengers whose DESTN matches with the value of D
.UpdateFare()
– to increase the fare of all passengers by 5% and rewrite the updated records into the file PASSENGERS.DAT
."P_record.csv"
contains the records of patients in a hospital. Each record of the file contains the following data:["Gunjan", "Jaundice", 4, 15000]
read_data()
which reads all the data from the file and displays the details of all the 'Cancer' patients.count_rec()
which counts and returns the number of records in the file.('Yellow', 237, 250, 68)
.push_Clr(ClrStack, new_Clr)
: This function takes the stack ClrStack and a new record new_Clr as arguments and pushes this new record onto the stack.pop_Clr(ClrStack)
: This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display the message "Underflow".isEmpty(ClrStack)
: This function checks whether the stack is empty. If the stack is empty, the function should return True, otherwise the function should return False.def ExamOn(mystr): newstr = "" count = 0 for i in mystr: if count % 2 != 0: newstr = newstr + str(count - 1) else: newstr = newstr + i.lower() count += 1 newstr = newstr + mystr[:2] print("The new string is:", newstr) ExamOn("GenX")
Complete and balance the following chemical equations: (a) \[ 2MnO_4^-(aq) + 10I^-(aq) + 16H^+(aq) \rightarrow \] (b) \[ Cr_2O_7^{2-}(aq) + 6Fe^{2+}(aq) + 14H^+(aq) \rightarrow \]