CodeTantra Python Programming L2 Solution

Hello Coders, In this blog post, you will find all the Solutions to the L2 questions of the Codetantra Python Programming Course. Here are the answeres to these questions:- 

Codetantra Python Solution L2

Q1:-L2/Comments/Understanding Python Comments :- Make the following changes in the code given:
1. Remove the comment on the line which prints "I am a Python Guru"
2. Add a comment on the line which prints "Python is not cool"

# This is my first program
print(“I am a Python Guru”)
#print(“Python is not cool”)
# print() is used to print the message on console

Q2:-L2/Comments/Problem Solving in Comments :- Comment and uncomment appropriate lines of code so that the given program prints only odd numbers

print(“1”)

# print(“2”)

print(“3”)

# print(“4”)

print(“5”)

#print(“6”)

print(“7”)

#print(“8”)

print(“9”)

# print(“10”)

print(“11”)

# print(“12”)
print(“13”)

Q3:-L2/Comments/Understanding Docstring in Python :- Write the print statements in the code editor to print the one-line docstring for add() method and the multi-line docstring of power () method.

def add(a, b):
“””Return sum of given arguments.”””
        return a + b

def power (b, e):

“””Return the power value.
b — is the base is the exponent
e–
“””
        return b** e
# print docstring of add method

print(add._doc_)

print(power.__doc_)
# print docstring of power method

Q2.1:-L2/Identifiers and Keywords/Understanding Identifiers in Python :- Select all the correct statements from the given options.

Identifiers are used for identifying entities in a program.
We can use any special character like @,#,$ as part of identifiers.
1st string is a valid identifier.
string 1 is valid identifier.
Identifiers can be of any length.

Q2.2:-L2/Identifiers and Keywords/Understanding Python Keywords :- Select all the correct statements.

Python version 3.5 has 33 keywords.
true is a valid keyword in Python.
The keyword nonlocal does not exist in Python 2.
Interpreter raises an error when you try to use keyword as a name of an entity.
A programmer can easily modify the keywords.

Q2.3:-L2/Identifiers and Keywords/Fill in the missing code :- Fill in the missing code in the below program to print whether the given words-exec, nonlocal and False are keywords or not in Python

import keyword
print(‘and is a keyword, keyword.iskeyword(‘and’))

#Fill in the missing code in the below lines

print(‘exec is a keyword :’, keyword.iskeyword(‘exec’))

print(‘nonlocal is a keyword :’, keyword.iskeyword(‘nonlocal’))

print(‘False is a keyword :’, keyword.iskeyword(‘False’))

Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.

Leave a Comment

Your email address will not be published. Required fields are marked *