0% found this document useful (0 votes)
27 views6 pages

Python Programming Exercises Guide

Uploaded by

Kisna Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Python Programming Exercises Guide

Uploaded by

Kisna Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write a program to demonstrate the use of built-in


functions: type (), print (),input(), range().
k = int(input("Enter the integer for range function: ",))
for i in range(k):
print(i)

print(type('str'))
print(type(8))
print(type(True))

2. Write a program to demonstrate the use of various


data types (numeric,sequence, boolean, set, dictionary).
Provide input from user and print the data type of input
value.
numeric = int(input("Enter the values of numeric: ",))
print(type(numeric))

boolean = bool(input("ENter the value of boolean: ",))


print(type(boolean))

string = input("Enter the string: ",)


print(type(string))

3. Write a program to Exchange value of two variables.


(a) using third variable.

a = int(input("Enter the first number: ",))


b = int(input("Enter the second number: "))

print('Before changing first number: ',a)


print('Before changing second number: ',b)
c=b
b=a
a=c

print('After changing first number: ',a)


print('After changing second number: ',b)

(b) without using third variable.


a = int(input("Enter the first number: ",))
b = int(input("Enter the second number: "))

print('Before changing first number: ',a)


print('Before changing second number: ',b)
a = a/b
b = a*b
a = (1/a)*b
print('After changing first number: ',int(a))
print('After changing second number: ',int(b))

4. Write a program to demonstrate the use of operators


like, addition, subtraction, multiplication, division,
modular, exponentiation.
fstno = int(input('enter a number: ',))
scndno = int(input('enter scnd number: ',))
operators = input('enter the operator: ',)#Here enter the operator like -
/+/*///%/**:
if operators == '+':
print(fstno + scndno)
elif operators == '-':
print(fstno - scndno)
elif operators == "*":
print(fstno*scndno)
elif operators == '/':
print(fstno/scndno)
elif operators == '%':
print(fstno%scndno)
elif operators == '**':
print(fstno**scndno)

5. Write a program to find area of rectangle, square and


circle
pi = 3.14
shape = input("enter the shape :",)

if shape == 'circle':
radius = int(input('radius: ',))
print('area of circle is: ',pi*radius*radius)
elif shape == 'square':
side = int(input('Enter the sidelength: ',))
print('area of square is',side*side)
elif shape == 'rectangle':
l = int(input('Enter length: ',))
b = int(input('Enter breadth: ',))
print('area of rectangle: ',l*b)

6. Given the principal amount, rate of interest and time.


Take suitable data type value as input from the user.
Find the simple interest and compound interest.
t = int(input("Enter the time period in years to find intrest:",))
r = int(input("ENter the rate of interest anually",))
p = int(input("Enter the principal amount: ",))
si = p + p*(r/100)*t
ci = p*((1 + (r/100))**t)
print("principal amount after compound interest: ",ci)
print("principal amount after simple interest: ",si)
7. Write a program to find the odd/ even.

N = int(input('Enter the number to check: ',))


r = N%2
if r == 0:
print('The number',N,'is even')
else:
print('The number',N,'is odd')

8. Write a program to find the grade of students. Take


input marks from user and
provide the output based on NITJ grading system.
m = int(input("Enter the marks: ",))
if m > 90:
print("Grade: S")
print("Points: 10")
print("Performance: Outstanding")
elif m > 80:
print("Grade: A")
print("Points: 09")
print("Performance: Excellent")
elif m > 70:
print("Grade: B")
print("Points: 08")
print("Performance: Very Good")

elif m> 60:


print("Grade: C")
print("Points: 07")
print("Performance: Good")

elif m > 50:


print("Grade: D")
print("Points: 06")
print("Performance: Average")

elif m > 40:


print("Grade: E")
print("Points: 05")
print("Performance: Marginal")

elif m <40:
print("Grade: I")
print("Points: 04")
print("Performance: Incomplete")
elif m > 100:
print('Error')

9. Write a program to find the maximum between two


numbers.

n1 = int(input("Enter first number: ",))


n2 = int(input("Enter second number: ",))

if n1 > n2:
print('Bigger number is ',n1)
elif n1 == n2:
print('Both equal')
else:
print('Bigger number is ',n2)

10.Write a program to find the maximum between


three numbers.

n1 = int(input("Enter first number: ",))


n2 = int(input("Enter second number: ",))
n3 = int(input("Enter third number: ",))

if n1>n2:
if n1>n3:
print('Bigger number is ',n1)
elif n3>n1:
print('Bigger number is ',n3)
if n2>n1:
if n2>n3:
print('Bigger number is ',n2)
elif n3>n2:
print('Bigger number is ',n3)

11.Write a program to check number is positive,


negative or zero.

n = int(input("Enter the number: ",))

if n > 0:
print('number',n,'is positive')
elif n < 0 :
print('number',n,'is negative')
elif n == 0:
print('number is zero')

You might also like