You are on page 1of 6

(Established under the Presidency University Act, 2013 of the Karnataka Act 41 of 2013)

ACA-2[2019]
SCHOOL :SOE DEPT.: PET DATE:8.2.2020
SEMESTER/YEAR:6/2020
COURSE INSTRUCTOR: Mr. K PRUDHVI RAJ, Assi. Prof. GANGA

AFTER EXECUTION OF EVERY PROGRAM MAKE SURE YOU WRITE IN YOUR OBSERVATION NOTES
ALONG WITH OUTPUT.

General Instructions for all programs:


1. open new file in spyder software, click New→ New file→ type file name
2. type the python program
3. click run key in spyder.
Learning Objective:
Operators and Conditional statements in Python.
Q1. Type below python program in Spyder editor save it with file name type.py, run it.[5 min]
a=10
b=34.3
c="Presidency University"
print(type(a))
print(type(b))
print(type(c))

Note: This Program is returning the type of those a, b, c variable, even though we didn’t declare it’s type python
automatically taking it. Understand that

Q2. Type below python program in Spyder editor, save it with file name reading.py, run it.[5 min]
a= input()
b= input()
c= a+b
print(c)
Note
input() is one function which will help us to read values while program in running. So after execution as program is waiting
for you input, give two input values and note down the output.

Q3. Change Q2 as below, save it and run it.[3 min]


a=input()
b=input()
print(type(a))
print(type(b))
c=a+b
print(c)

Note:
Because input is returning string type not integer type so result is not expected.

Q4. Change Q2 like below and observe the output.[3 min]


a=int(input())
b=int(input())
c=a+b
print(c)

Note:
output is as expected we are changing string type to int type with extra function int()
Q5. Change Q4 as below and observe the difference.[3 min]
a=int(input("Enter a value"))
b=int(input("Enter b value"))
c=a+b
print(c)

Note:
Input() function has optional parameters that is like above. It will print on screen.
Extra line are printed before reading some value.
Q6. Change Q5 like below and observe the difference.[3 min]
a=int(input("Enter a value"))
b=int(input("Enter b value"))
c=a+b
print("C value is",c)

Note:
Extra string is printed before result.
Note down the variations in print() from previous question.
Operators in Python

Arithmetic Operators

Relational operators

Logical operators

Arithmetic Operators:

Q7. Open new file in Spyder editor, type the below program which reads two values from user and perform all Arithmetic
operations. Fill in the blanks with Proper syntax, save it as arithmetic.py, run it.[10 min]

c=int(_______ ())

d=int(_______())

add=c+d

sub=c-d

mul=c*d

div=c/d

mod=c%d

print("add result is ",add)

print("sub result is ",___)

print("mul result is ", mul)

print("div result is ",____)

print("Mod result is ",mod)


Note:

Input1:

25

Input2:

25

Q8. Open new file in Spyder editor, type the below program which reads two values from user and perform some
relational operations. Fill in the blanks with Proper syntax, save it with relaiton1.py, run it.[8 min]

a=int(input("Enter a number"))

b=int(input("Enter one more number"))

c=a<b

d=a>b

print('c value is',__)

print('d value is ',__)

Input1:

Input2:

10

10

Q9. Change in Q8 instead of c=a<b type c=a<=b, and instead of d=a>b type d=a>=b. Save it and run it.[5 min]

Input1:

Input2:

10

10
Q10. Type below program in Spyder editor, save it and run it.[5 min]

re1=0 and 0

re2=0 and 1

re3=1 and 0

re4=1 and 1

print("re1 is ",re1)

print("re2 is ",re2)

print("re3 is ",re3)

print("re4 is ",re4)

Q11. Change Q11 program and to or and save it, run it [5 min]

Q12. Type below program in Spyder editor, which reads age of a person and check whether he/she is eligible to vote or
not in India.[10 min]

age=int(input("Enter age of person"))

if(age>=18):

print("Eligible")

else:

print("Not eligible")

print("Thank you.")

Q13. Write a python program to check weather student is pass or fail in one subject. Pass criteria is 35 marks out of 100.

Read student marks. Check in if condition. Print result.[10 min]

Hint:

Take Q10 help.

Q14. Write a python program to check whether given input is “heat” or not. Read string from user. Compare with heat if
satisfy print true if not false.[10 min]

temp=input("Enter a string")

if(temp == 'heat'):

print("True")

else:

print("False")
Note:

Think why we are not writing int before input.

DRM Software Review

You might also like