English

Atharva is a Python programmer working on a program to find and return the maximum value from the list. The code written below has syntactical errors. Rewrite the correct code and underline - Computer Science (Python)

Advertisements
Advertisements

Question

Atharva is a Python programmer working on a program to find and return the maximum value from the list. The code written below has syntactical errors. Rewrite the correct code and underline the corrections made.

def max_num (L):
        max=L(O)
        for a in L:
                if a > max
                 max=a
        return max
Code Writing
Advertisements

Solution

Errors in code: 

def max_num(L):
       max=L(0)
       for a in L:
              if a>max
              max=a 
return max

Corrected code:

def max_num(L):
       max=L[0] 
       for a in L:
              if a>max: 
                 max = a 
       return max
shaalaa.com
Syntax Errors in Python
  Is there an error in this question or solution?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×