pythonVIII EDITED
pythonVIII EDITED
5. Datatypes:python data
types are used to define the type of a
variable. There are 5 datatypes defined
in python- numeric, string, list, dictionary
and tuple.
6. Elements of python:
Keywords: these are the reserved words
and are total 33 in number.
Identifiers:an identifier is simply the
name of the variables within a program
that are used to identify the relevant
data/info. Typically, identifiers must
start with a letter, can contain numbers
or underscore(_) and must not have any
spaces in them.
Variables: variables are named memory
locations where value is stored.
7. Operators: arithmetic, comparison,
logical, assignment operators
8. Comments: a comment is a line of code
ignored by an interpreter and does not
display an output.
Example programs
Q2. WAP to add two numbers.
# program to display sum of 2 nos ( this is
the comment line)
>>>a=5
>>>b=7
>>>c=a+b
>>>print(c)
Q3. WAP to display personal details using
variables.
# program to display details
>>>name=”name”
>>>f_name=”father’s name”
>>>m_name=”mother’s name”
>>>print(name)
>>>print(f_name)
>>>print(m_name)
statement(s)
the if…else statement: if expression:
statement(s)
else:
statement(s)
the if…elif…else statement: if
expression:
statement(s)
elif
expression2:
statement(s)
else:
statement(s)
Q6. WAP to find whether the person can
vote or not.
# program to check eligibility
age=int(input(“enter age”))
if age>=18:
print(“the person can vote.”)
c,s=1,1
while c<=20:
s=s*c
c=c+1
print(s)
9. WAP to input marks in a subject and print
whether the student is passed or not. (A
student is passed if marks>40).
m=int(input(“enter marks”))
if m>=40:
print(“you have passed”)
else:
print(“you have failed”)
10. WAP to print your name 20 times.
#program to print your name 20 times
for i in range(1,21,1):
print(“SJCS”)
11. reverse order
for i in range(10,-1,-1):
print(i)