English

Write the output of the code given below: a = 30 def call (x): global a if a%2==0: x+=a else: x−=a return x x=20 print (call (35), end="#") print (call (40), end="@") - Computer Science (Python)

Advertisements
Advertisements

Question

Write the output of the code given below:

a = 30
def call (x):
          global a
          if a%2==0:
             x+=a
          else:
             x−=a
          return x 
x=20
print (call (35), end="#") 
print (call (40), end="@")
Short Answer

Solution

Output:

65#70@ 

Explanation:

The call() method examines the value of the global variable a. Because a is 30 and 30 % 2 returns 0 in both function calls, the expression x+=a is executed, resulting in the numbers 30 + 35 and 30 + 40 in the respective calls.

shaalaa.com
Creating User Defined Function
  Is there an error in this question or solution?
2022-2023 (March) Set 4

RELATED QUESTIONS

Observe the following program carefully, and identify the error:

def create (text, freq):
            for i in range (1, freq):
              print text
create(5)           #function call

Write a program that creates a GK quiz consisting of any five questions of your choice. The questions should be displayed randomly. Create a user-defined function score() to calculate the score of the quiz and another user-defined function remark (scorevalue) that accepts the final score to display remarks as follows:

Marks Remarks
5 Outstanding
4 Excellent
3 Good
2 Read more to score more
1 Needs to take an interest
0 General knowledge will always help you. Take it seriously.

Write a function EOReplace() in Python, which accepts a list L of numbers. Thereafter, it increments all even numbers by 1 and decrements all odd numbers by 1.

Example:

If Sample Input data of the list is:

L = [10, 20, 30, 40, 35, 55]

Output will be:

L = [11, 21, 31, 41, 34, 54]

Write the output of the code given below:

def short_sub (1st, n):
for i in range (0, n):
      if len (1st) > 4:
          lst [i] = lst [i] + lst [i]
      else:
          lst [i] = lst [i]
subject = ['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS'] 
short_sub (subject, 5)
print (subject)

Write a program in Python that defines and calls the following user-defined functions:

  1. Add_Book(): Takes the details of the books and adds them to a CSV file ‘Book. csv'. Each record consists of a list with field elements such as book_ID, B_name and pub to store book ID, book name and publisher, respectively.
  2. Search_Book(): Takes publisher name as input and counts and displays the number of books published by them. 

What will be the output of the following statement:

print(3-2**2**3+99/11)

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×