Informatics Practices
Find out the errors in the following code snippet and rewrite the code by underlining the corrections made.
30=y
for i in range (2, 6)
print (true)
else:
print ("Loop over")
Python Control Flow
4 Likes
Answer
30=y #Error 1
for i in range (2, 6) #Error 2
print(true) #Error 3
else:
print ("Loop over") #Error 4
Error 1 — This is an invalid assignment statement. The variable should be on the left side.
Error 2 — The for loop header is missing a colon at the end.
Error 3 — 'true' should be 'True' to be a valid boolean value in Python.
Error 4 — The else block is not properly indented.
The corrected code is:
y = 30
for i in range(2, 6):
print(True)
else:
print("Loop over")
Answered By
2 Likes
Related Questions
Consider the following list.
emp=["Aditya", 40000, "Deepak",50000, "Yashmit", 60000, "Bhavya", 80000](i) To Insert the value "Ramit" at index number 4.
(ii) To check whether element 50000 is present in the list or not.
(iii) To display the first 3 elements from the list.
(iv) To remove the fifth element from the list.
An organization wants to create a table EMPLOYEE, DEPENDENT to maintain the following details about its employees and their dependents.
EMPLOYEE (EmployeeID, AadhaarNumber, Name, Address, Department)
DEPENDENT (EmployeeId, DependentName, Relationship).
There are 10 records each in both tables.
(i) Name the attributes of the Employee, which can be used as candidate keys.
(ii) What is the degree of the Employee Table?
(iii) What is the Cardinality of a Dependent Table?
(iv) Which is the Primary key of Dependent Table?
Consider the following dictionary and write the answers of the following:
DAYS={"day1": "Sunday", "day2": "Monday", "day3":"Tuesday", 'day5':" Thursday"}(a) Add 'Wednesday' to the dictionary DAYS as a key 'day4'.
(b) Remove 'day5' item from the dictionary.
(c) Given the Dictionary metal, what is the output generated by the following code:
metal={"first":"gold", "second":"silver", "first":"copper"} print(metal)Write a program to accept a number from the user and check whether it is a prime number or not.