0% found this document useful (0 votes)
10 views8 pages

Python Basics and Practical Exercises

Chapter 7 introduces Python programming concepts including operators, data types, and basic syntax. It provides various exercises such as fill-in-the-blanks, true/false questions, and programming tasks to practice Python skills. Additionally, it includes example programs for calculating areas, converting units, and performing arithmetic operations.

Uploaded by

kashvireddygoat
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)
10 views8 pages

Python Basics and Practical Exercises

Chapter 7 introduces Python programming concepts including operators, data types, and basic syntax. It provides various exercises such as fill-in-the-blanks, true/false questions, and programming tasks to practice Python skills. Additionally, it includes example programs for calculating areas, converting units, and performing arithmetic operations.

Uploaded by

kashvireddygoat
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

Chapter 7-Introduction to Python

Page: 61
[Link] the correct option:
a. iv
b. i
c. iv
d. iv
e. iv
2. Fill in the blanks:
a. ==,>,<=
b. Comment
c. Dictionary
d. and
e. **(Exponent)
3. True or False
a. False
b. True
c. True
d. False
e. False
4. Match the following:
a. iv
b. i
c. v
d. ii
e. iii
5. One Word Answers:

a. Syntax
b. Variable
c. Keywords
d. Comment
e. Primary Prompt

6. Very Short answers:-

a. Integrated Development Learning Environment.

b. A keyword is a reserved word that has a predefined meaning. Ex: input, int.
c. Interactive mode and Script mode.

d. An Example of dictionary
StudentRecord={‘Sumit’:340,’Amit’:234}

e. The rules for a variable in Python is given below:


 A variable can be of any length
 It can contain letters, digits or underscore
 The first character must be a letter or an underscore but must not be a digit
 Punctuation marks and spaces are not allowed in a variable name
 A keyword cannot be used as a variable
 Python is a case-sensitive language. Therefore, ’total’, ’Total’, and
‘TOTAL’ are different variable names.

7. Short Answers:-

a. The reserved words in Python are not, and, or, True.

b. i) (25+10)%7 =0
ii) 25+10%7=28
c.

Arithmetic Operators Relational Operators Logical Operators


+,-,*,//,/,** >,<=,>=,<,!=,== and, or, not

d. The different logical operators with output is explained below assuming that
variable a holds the value 10 and variable b holds the value 20.

Operators Example Output Explanation


and a==10 and b>20 False If both the expressions are true, then
a>=5 and b<=20 True the result is True otherwise False
or a==10 or b>20 True If any of the expressions is true, then
a>=10 or b<20 True the result is True otherwise False
a!=5 or b>20 True
not not(a!=10 and b>20) True This operator reverses the result of
the logical expression. i.e ,If the
expression is True, the result after
not operation will be False, and vice
versa.

8. Descriptive Type Answers:-

a.
# Program to find the Base to the power of exponent
Base=5
Exponent=3
print("BaseExponent is ",Base**Exponent)

b.
# Program to convert Celsius to Fahrenheit
Celsius=89.5
Fahrenheit=(Celsius*9/5)+32
print("The equivalent Fahrenheit value of 89.5 is",Fahrenheit)

c.
# Program to convert minutes to Hour and Minutes
Minutes=234
Hour=Minutes//60
Min=Minutes%60
print("The corresponding hours and minutes of 234 minutes is",Hour,”hrs: “,end=(‘’))
print(Min,”mins”)

d.
# Program to find the Area and Perimeter of the rectangle
length=45
breadth=31
area=length*breadth
perimeter=2*(length+breadth)
print("Area of the rectangle is :",area)
print("Perimeter of the rectangle is:", perimeter)

List of programs for the practical examination:

1. Write a Python program to accept the radius of the circle and print area and
Circumference of the circle.
2. Write a Python program to accept the Length and breadth of the rectangle and
print area and perimeter of the rectangle.
3. Write a Python program to accept the principal, time in years and rate of
interest, and print the simple interest and amount( si=p*t*r/100, amount=p+si)
4. Write a Python Program for accepting 5 subject marks and printing total,
average and total percentage of marks.
5. Write a Python Program to convert minutes to Hour and Minutes.

Python Programs to practice :

1. Display the sum of two numbers


print("hello")
print("welcome to the cs class")
# assigning values to the variables a,b
a=90
b=780
# calculating sum
c=a+b
#displaying sum
print("sum is",c)

Output:

hello
welcome to the cs class
sum is 870

2. Program for assigning and displaying the variables and values

# Variable holds the recently updated value


a1=45
b4=10
print("a is ",a1,"b4 is",b4)
a1=a1+100
b4=b4+1000
print("a is ",a1,"b4 is",b4)
c=a1+b4
print("c is",c)

Output:

a is 45 b4 is 10
a is 145 b4 is 1010
c is 1155
3. Program using Assignment operator and its function
#Program illustrating Assignment operator =
# Always right side value will be assigned to the left side variable
a=10
b=90
print("initial value of a",a,"initial value of b",b
b=a
b=b+10
print("updated value",a)
print("updated value",b)

Output:

initial value of a 10 initial value of b 90


updated value 10
updated value 20

4. Python Program for accepting the height and base of the triangle and
display the area of the triangle.
# accepting input for h,b
h=int(input("enter height"))
b=float(input("enter base"))
# calculating area of the triangle
area=1/2*b*h
#displaying output
print(h,b,area)

Output:
enter height 20
enter base 60
20 60.0 600.0
5. Python Program for accepting the radius of the circle and display the
area and circumference of the circle.
# accepting input for r
r=float(input("enter radius"))
#calculating area and Circumference
area=3.14*r*r
circum=2*3.14*r
#displaying output
print("area of the circle:",area)
print("circumference of the circle",circum)
Output:
enter radius23
area of the circle: 1661.06
circumference of the circle 144.44
6. Program for accepting 5 subject marks and printing total, average and
total percentage of marks
#accepting input
m=float(input("enter maths marks out of 60"))
p=int(input("enter physics marks out of 60"))
c=int(input("enter chemistry marks"))
cs=int(input("enter Computer sci marks"))
e=int(input("enter english marks"))
total=m+p+c+cs+e
average=total/5
percentage=(total/300)*100
print("the total is",total)
print("the average",average)
print("the percentage",percentage)

Output:

enter maths marks out of 6060


enter physics marks out of 6060
enter chemistry marks60
enter Computer sci marks60
enter english marks60
the total is 300.0
the average 60.0
the percentage 100.0

7. Program for accepting 2 numbers and performing arithmetic operations

#Accepting input
a=int(input("enter a"))
b=int(input("enter b"))
# Performing Arithmetic operations on two numbers
sum1=a+b
product=a*b
quotient=a/b
#integer division // operator gives the integer part of the quotient(no decimal)
intquotient=a//b
# exponent ** gives the power(25=2*2*2*2*2)
exponent=a**b
# % called moduls operator returns remainder, 10%3=1)
remainder=a%b
print("sum is",sum1,"product is",product,"quotient is",quotient)
print("exponent",exponent,"integer part of the quotient",
intquotient,"remainder", remainder)

Output:

enter a30
enter b4
sum is 34 product is 120 quotient is 7.5
exponent 810000 integer part of the quotient 7 remainder 2
8. Python Program displaying the priority of Arithmetic Operators

#Precendence of Operators
#1. ( ), 2.**, 3. /,//,%,*(having same priority, which comes first from left
hand side will be evaluated first, 4. +,-)
print((23-3)%5+7**2-10)
print(20-8/4*5+10)
print(24%7+5**3-10+90//8)

Output:
39
20.0
129

9. Python program to accept number of days ,print the [Link] years,months


&days(assume 1 year=365 days, 1 month=30 days)
n=int(input("enter the [Link] days"))
years=n//365
rem=n%365
months=rem//30
days=rem%30
print("the [Link] years",years,"[Link] months",months,"days",days)

Output:
enter the [Link] days400
the [Link] years 1 [Link] months 1 days 5
[Link] program to accept the principal amount, time in years and rate
of interest, and print the simple interest and amount

p=int(input("enter principal amount"))


r=float(input("enter rate of interest"))
t=int(input("enter time period in years"))
si=p*t*r/100
amount=p+si
print("The Simple interest is:",si)
print("The amount is ",amount)

Output:
enter principal amount100000
enter rate of interest6.8
enter time period in years5
The Simple interest is: 34000.0
The amount is 134000.0

You might also like