English

Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the correct code and underline the corrections made. def prime()

Advertisements
Advertisements

Question

Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the correct code and underline the corrections made.

def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n’)
Short/Brief Note
Advertisements

Solution

def prime():
  n=int(input("Enter number to check :: "))    #bracket missing
  for i in range (2, n//2):
    if n%i==0:                            # = missing
      print("Number is not prime \n")
      ___break                            #wrong indent
        else:
            print("Number is prime \n)   # quote mismatch

shaalaa.com
Built-in Exceptions in Python
  Is there an error in this question or solution?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×