Python Revision Class 9
Python Revision Class 9
RESTART: CAUsers/BRAINWAVEJAppData/LocaVPrograms/P
In this program, we ask the user for a number and find the square ython/Python37-32/P1.py
Enter a umber: 4
root using the $* exponent operator. This program works for all The square root of 4.0 = 2.0
>»>|
positive real numbers.
3: Program tocalculate the area of triangle using base and height. Hint: The base is one side of the triangle and
the height is the measure of the tallest point on atriangle. Area=1/2(basexheight)
# To calculate the area of triangle using base and height
b=float (input( 'Enter the base in centime ters '))
h=float (input( 'Enter the height in centimeters '))
area=( (b*h) )/2
print( 'The base value of the triangle in centimeters= , b)
print ( 'The height value of the triangle in centimeters ', h)
print( The area of the triangle in centimeters = ,area)
# Python program to
swap two
xinput(' Enter
input( Enter
value of x: ) variablea provided by the user
value of y: ')
# areate a
temp x
temporary varlable and awap the
values t t hat bsbu
# calculate miles
miles= kilometers * conv fac
print( kilometers, ' kilometers is equal to', '=
, miles, 'miles')
6: Program to convert Celsius to Fahrenheit.
# Python Program to convert temperature in
celsius to fahrenheit
# Input is provided by the user in degree celsius
celsius = float (input('Enter in degree Celsius: '))
# calculate fahrenheit
in this program, we can convert Fahrenheit into Celsius. We ask RESTART: CANsers BRAINWAVEJAppDataiLocalProgramsP
ythonvPython37-32/P1.py
the user for temperature in Fahrenheit and use the following Enter in degree Cesius: 28
28.0 degree celsius = 82.4 fahrenheit
formula to convert it into Celsius.
ARTI
electricitybill.
7: Programnto calculate the electricity bil
calculates the
program
# this reading: ")
ohon 12Shelt
Options Window Helo
Cr=input('Enter the
the last meter
current meter reading: ) File Edit Shei Debug
Python 3.7.2 (tags/v3.7.2:9a3fc0492 Dec 23 2018 ,22:20:52):
lr=input('Enter
(MSC v.1916 32 bit (Intel)] on win32
"help", "copyright", "credits" or "icense() for more
Type
unit:')) tion. infoma
(input('Enter the rate per RESTART: C:Users/BRAINWAVEIAppData/LocalPrograms/P
rate=eval ython/Python37-32IP1.py
Enter the last meter reading: 120380
uc=int (cr) -int (lr) Enter the current meter
reading:
unit:5.5
Enter the rate per
bill=uc*rate Total bill consumption is 260
1430.0
Total bill amount
consumption is',uc)
print ('Total bill
amount=',bill) Cot
print(Totalbill
and average of three subject marks.
8: Program tocalculate the total
student: ')
n=input('Enter name of the
the marks in English: '))
ereval (input ('Enter
'))
the marks in Math:
m=eval (input('Enter
marks in Science:'))
L Pythan372 Shell
indow Heto
ython/Python37-32/P1.py
student',n) student:SAM
print('Name of the Enter name of the
English:80
Enter the marks in Math:85
Marks=',total) Enter the marks in
print(Total Enter the marks in
Science:75
Name of the student SAM
print ('Average Marks=',avg) Total Marks= 240
|Average Marks= 80
fe12 Ck
interest.
9: Program to calculate the simple
Python program to find simple interest
#
("Enter the principal amount : "))
p= float (input
interest : "))
("Enter the rate of
r= float (input
time in years: "))
t= float (input ("Enter the LPthon372Shel
interest Help 22:20:52)
Options Window
# calculating simple (tagsv3.7.2:9a3fic0492, Dec 23 2018,
File Edit Shel Debug
Python 3.7.2 on win32
MSC v.1916 32 bit (Intel)]
"credits" or icense() for
more infoma
si = (p*r*t)/100 Type "help", "copyright,
tion.
# printing the values RESTART: C:Nsers/BRAINWAVEJAppDataLoca/ProgramsiP
ython/Python37-32P1.py
print ("principal amount: ", p) Enter theprincipal amount:
15000
Enter the rate of interest :12
print ("Interest rate: " ,r) Enter the time in years: 2
principal amount: 15000.0
Interest rate: 12.0
print ("Time in years : ",t) Time in years: 2.0
Simple Interest: 3600.0
print ("Simple Interest : ", si) >>>
LR12 Cat4
ARTIFICIAL INTELLIGENCE-IX
298
ACTIVITY4.14;: Al Quiz Time
A. Readthe following statements and select ) the correct option.
1. One off the following is not true for Python.
lal Itis high levelprogramming language. (b) It can be run on MS
Icl It is only available after paying license fee for Windows, Linux and Mac OS.
using it.
Which of the following data types is not supported in python?
(a) Alphanumeric (b) Integers (c) Strings (d) Floating Numbers
3, One of them developed the Python Language.
(a) Bill Gates (b) Guido van Rossum (c) Charles Babbage
A This is the prompt of the interactive shell of the
Python window.
(a) <<< (b) >>>
(c)
E Oneof the following statement is not valid for
variable names.
(a) Special character like &,@,?$are not allowed
(b) It should begin with an alphabet in
lowercase (c) Spaces are not allowed
(d) Letters, numbers and the underscore )character are allowed
6. The operator used in assignment statements.
(a) Equals to(-) (b)
Hash sign (#) (c) Asterisk(*)
7. Programming statements used to decide which instructions are to be executed under a given conditions.
(a)Order statements (b) Loop statements (c) Control statements
8. In Python all flow control statements are ended with one of the following
character.
(a) Semicolon(:) (b) Hash sign(#) (C) Colon(:)
D. Tne process wherein a set of instructions are repeated in a sequence either specified number of times or
untila condition is met.
(a)
Looping (b) Iteration (c) Any of them
0 nis type of error occurs when a program does not conform to the grammar of a programming language.
(a)Logical error (b) Syntax error (c) Grammatical error
11. Select the correct output of following python code.
a= "Hello"
b= "Python"
c=a-b
print (c)
(a) hello-world (b) helloworld (c) Error
12. What is
the output of this expression, print(12.4//2)
(a) 6
(b) 6.0 (c) 0.4