0% found this document useful (0 votes)
3 views

pythonVIII EDITED

The document provides an overview of Python programming, including its definition, development environment, data types, and basic syntax for functions like print and input. It also covers control structures such as conditional statements and loops, along with examples of various Python programs. Additionally, it explains concepts like comments, operators, and escape characters.

Uploaded by

sharminnabab7
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)
3 views

pythonVIII EDITED

The document provides an overview of Python programming, including its definition, development environment, data types, and basic syntax for functions like print and input. It also covers control structures such as conditional statements and loops, along with examples of various Python programs. Additionally, it explains concepts like comments, operators, and escape characters.

Uploaded by

sharminnabab7
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/ 13

Definitions:

1. Python: python is a case sensitive


programming language.
2. Python can be used on a server to create
web applications. Python is a
programming language that lets you
work quickly and integrate systems more
effectively. It was created by Guido Van
Rossum and was first released in 1991.
3. Python Development Environment (PDE):
python has two basic modes: script and
interactive.
The script or normal mode is the mode
where it is saved as .py files are run in
the python interpreter. We need to save
the program and after that only can run
it.
Interactive mode is a command line shell
which gives immediate feedback for each
statement. Interactive mode is a good
way to play around and try variations on
syntax.
4. print: the “print” function is used to give
the output. Its syntax is
>>>print(“text”)
program to display print statement
Q1. WAP to print your name.
>>>print(“hello, my name is ________”)
>>>print(“i study in class vi”)
>>>print (“this is my first python
program”)

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)

9. String concatenation: We use “+” symbol


to join or concatenate two strings.
Q4. WAP to concatenate two strings.
# program to join 2 strings
>>>first=”this book has ”
>>>second=” many stories in it.”
>>>print(first+second)

10. Input function: syntax -


var=input(“prompt string”)
Q5. WAP to input a number and find its
square
# program to find square
a=int(input(“enter a number”))
c=a*a
print(c)

11. Conditional statements in python: if, if…


else, if…elif…else
syntax: python follows a particular style
of indentation to mark the beginning and
end.
the if statement: if expression:

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.”)

Q7. WAP to find whether the entered


number is even or odd.
# program to check even or odd
n=int(input(“enter a number”))
if n%2==0:
print(“the number is even.”)
else:
print(“the number is odd.”)

Q8. WAP to find whether the entered


number is positive, negative or zero.
# program to check positive, negative or
zero
n=int(input(“enter a number”))
if n>0:
print(“the number is positive.”)
elif n<0:
print(“the number is negative.”)
else:
print(“the number is zero.”)
12. Conditional statements: while loop, for
loop
syntax:
the for loop: for var in sequence:
statement(s)

the while loop: while expression:


statement(s)
Q9. WAP to find cube of numbers from 1
to 10
# program to find cube
fori in range(1,11,1):
i=i*i*i
print (i)
Q10. WAP to find sum of first 10 nos
using while
# program to find sum of 10 nos
c,s=1,0
while c<=10:
s=s+c
c=c+1
print(s)

13. break statement: It is used to get out of


the loop forcefully.
syntax: if condition:
break
14. continue statement: It is used to take the
program control to the top of a loop.
syntax: if condition:
continue

15. Escape Characters:


a) \n – new line character.
b) \t – adds a horizontal tab space.
c) \v – adds a vertical tab space.
d) \\ - prints a backslash
e) \’ – prints an apostrophe
f) \” – prints double quotation marks
1. WAP in python to print your name and
surname using string concatenation
first=”good”
second=” day”
join=(first+second)
print(join)
2. WAP in python to find the ‘simple interest’
if Principal=1500, rate=2 and Time=5.
(SI=(P*R*T)/100)
p=1500
r=2
t=5
si=(p*r*t)/100
print(si)
3. WAP in python to find the cube of 31.
#program to find the cube of a number
n=31
c=n*n*n
print(c)
4. WAP to input an year and find whether it is
leap year or not.
n=int(input(“enter a number”))
if n%4==0:
print(“it is a leap year”)
else:
print(“it is not a leap year”)
5. WAP to input values of P, R and T and find
the Simple Interest.
#program to find the input of p,r and t and
find simple interest
p=int(input(“enter principle”))
r=int(input(“enter rate”))
t=int(input(“enter time”))
si=p*r*t/100
print(si)
6. WAP to input a number and find its cube
c=int(input(“enter the number”))
s= c*c*c
print(s)
#program to input a number and finds its
cube
7. WAP to input 3 angles A, B and C and check
whether they form a triangle or not. (A
triangle is formed only if A+B+C=180)
a=int(input(“enter an angle”))
b=int(input(“enter an angle”))
c=int(input(“enter an angle”))
if a+b+c==180:
print(“a triangle is formed”)
else:
print(“a triangle is not formed”)
8. WAP to print the product of first 20
numbers.
product = 1
for i in range (1,21,1):
product= product *i
print (product)

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)

You might also like