Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 1.1
Student Name: Harsh Raj UID: 21BCS8426
Branch: CSE Section/Group: 719/A
Semester: 4th Date of Performance: 14/02/23
Subject Name: Python for Lab Subject Code: 21CSP-259

1. Aim: Writing python programs in various modes and printing and assigning values
assigned to the variables.
1. Write a  program  to accept different datatype values for two numbers from the user and
perform all arithmetic operations.
2. Write the python code to show all the Valid and invalid ways of assigning values to the
variables.
3. Write the python code showing any 3 methods and checking their class.
4. Write a  program to enter length in centimeter and convert it into meter and kilometer.

2. Source Code:
1.
a= int(input("Enter the first number: "))
b= int(input("Enter the second number: "))
c=a+b; d=a-b; e=a*b; f=a/b; g=a//b; h=a%b; i=a**b;
print("Addition=",c,"\n""Subtraction=",d,"\n""Product=",e,"\n""Divide=",f,"\n"
"Quotient=",g,"\n""Remainder=",h,"\n""Exponent=",i)

2.
# Valid ways of assigning
a=15
b=19
print(a,b)
15 19

a,b=15,19
print(a,b)
15 19

a=15;b=19
print(a,b)
15 19

# Invalid ways of assigning values

a=15,b=19
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

a=15: b=19
SyntaxError: invalid syntax

a=15 b=19
SyntaxError: invalid syntax
3.
x=10
print(type(x))
<class 'int'>

a='Welcome'
print(type(a))
<class 'str'>

x='Harsh Raj'
print((x*4))
Harsh RajHarsh RajHarsh RajHarsh Raj

4.
cm=int(input("Enter the length: "))
m=cm/100;km=cm/100000
print("Length in meter=",m,"\n""Length in Kilometer=",km)
3. Screenshot of Outputs:
1.

2.
3.

4.

You might also like