Professional Documents
Culture Documents
Lab Assignment-2
Submitted by
Submitted to
Dr. Hemant Petwal
1. Install Python and understand difference between scripting and interactive modes in
IDLE.
Solution:
Scripting mode in idle:
In this file can be saved and executed using command prompt.
We can view and edit the file at any time when we want.
It is very suitable for writing long pieces of code.
In this file are saved by “.py” extension.
Interactive mode in idle:
In this file can’t be saved.
We can view the code at once and we can’t store that.
It is very convenient for writing very short line of codes.
It is also very suitable for beginners because it helps them evaluate their code line by
line and understand the code well.
2. Write Python programs to print strings in the given manner:
a. Hello Everyone !!!
b. Hello World
c. Hello World
d. Rohit’s date of birth is 12\05\1999
Solution:
Code:
3. Declare a string variable called x and assign it the value “Hello”. Print out the value
of x.
Solution:
Code: Output:
x= ”Hello”
print(x)
4. Take different data types and print values using print function.
Solution:
Code:
a=123 Output:
b=12.10
c="hello"
d=[1, 2, 3]
print ("a is ", type (a) )
print ("b is ", type (b) )
print ("c is “, type (c))
print ("d is ", type (d))
5. Take two variables, a and b. Assign your first name and last name. Print your Name
after adding your First name and Last name together.
Solution:
Code:
a=”Arpit”
b=”Gupta”
print(“Full name is “,a+b)
Output:
6. Declare three variables, consisting of your first name, your last name and Nickname.
Write a program that prints out your first name, then your nickname in parenthesis and
then your last name.
Example output: George (woody) Washington.
Solution:
Code:
a=”Arpit”
b=”Kumar”
c=”Gupta”
print(a+ ”(“ + b +”)” +c)
Output:
7. Declare and assign values to suitable variables and print in the following way:
NAME: NIKUNJ BANSAL
SAP ID: 500069944
DATE OF BIRTH: 13 Oct 1999
ADDRESS: UPES Bidholi Campus
Pincode: 248007
Programme: AI & ML
Semester: 2
Solution:
Code:
a="NIKUNJ BANSAL"
b=500069944
c="13 ОСТ 1999"
d="UPES Bidholi Campus"
e=248007
f="AI & MI"
g=2
print ("NAME: ", a)
print ("SAP ID: ", b)
print ("DATE OF BIRTH: ", c)
print ("ADDRESS: ", d)
print ("PINCODE: ", e)
print ("PROGRAMME: “, f)
print(“SEMESTER: “,g)
Output: