Model Answer VTU-ADP-18CS55-Feb 2021 Dr. Paras Nath Singh, Professor ...

Model Answer

VTU-ADP-18CS55-Feb 2021

Dr. Paras Nath Singh, Professor(CSE/ISE), 2021-22

1.

a. Demonstrate with example print(), input() and string replication. 6 M

Ans:

The print() function: The print() function displays the string value and value of

the variable inside the parentheses on the screen.

>>> print("sona-sona")

sona-sona

>>> n=20

>>> print("The value of n is",n)

The value of n is 20

The input() function: The input() function waits and reads the entered text by

the user from the keyboard.

>>> name=input("Enter your name :")

Enter your name :Kumar

>>> print("Hi",name)

Hi Kumar

>>> num=int(input("Enter a number : "))

Enter a number : 78

b. Explain elif, for, while, break and continue statements in Python with

examples for each.

10 M

Ans:

elif statement:

The elif statement is an ¡°else if¡± statement that always follows an if or another

elif statement. It provides another condition that is checked only if any of the

previous conditions were False.

Example:

if marks>= 90':

print(You are in A+ grade.')

elif marks>=60:

print('You are passed with first class.')

else:

printf(¡°You are below first class.¡±)

for statement:

for is a looping statement runs for certain number of times and for

number of items in a collection:

for var in range orcollection:

statements

Example

>>> for val in range(10):

print(val,end=' ')

0123456789

>>> for name in ['Ina','Meena','Dika']:

print(name,end=' ')

Ina Meena Dika

while statement:

while is a looping statement under which block of statements execute till

condition is satisfied:

while condition:

statements

Example:

>>> n=13

>>> while n ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download