हिंदी

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

प्रश्न

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’)
टिप्पणी लिखिए
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×