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’)
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
APPEARS IN
RELATED QUESTIONS
Which of the following statements is not true?
Accidentally hitting the "Delete" or "Escape" key while a program is executing will raise:
What would be the output of the following code?
def evenNumber (number):
assert (number % 2 == 0), "not even"
print ("Number is even")
evenNumber (7)
When are the following built-in exceptions raised? Give examples to support your answer.
ImportError
When are the following built-in exceptions raised? Give examples to support your answer.
IOError
When are the following built-in exceptions raised? Give examples to support your answer.
NameError
When are the following built-in exceptions raised? Give examples to support your answer.
ZeroDivisionError
Which of the following statement(s) would give an error after executing the following code?
S="Welcome to class XII" # Statement 1
print(S) #Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5