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

Class 7 Python Programming

This document covers the basics of Python programming, including how to write and execute a program using Python IDLE. It explains the use of the print() function for output and introduces decision structures using if...else statements for conditional execution. Additionally, it demonstrates how to input values at runtime using the input() function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Class 7 Python Programming

This document covers the basics of Python programming, including how to write and execute a program using Python IDLE. It explains the use of the print() function for output and introduces decision structures using if...else statements for conditional execution. Additionally, it demonstrates how to input values at runtime using the input() function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Unit -03 Python Programming

3.1.1 Writing and Compiling a Program:


You have learned the basics about python programming language.
In this section, you will learn how to open python IDLE (Integrated
Development Learning Environment), write a program and
execute it.
To create and run a python program, you need to do the following
steps:
1. Open an IDLE text editor to write a program
2. Save your program with .py extension
3. Compile and execute a program by pressing F5
Step 1: Click on Start Button
Step 2: Choose Python IDLE
 Step 3: Click on File Menu ->New option and write program and
save file with .py extension.
 Step 4: Now you can compile and execute this program by pressing
F5 key. You will get the result on the python shell.
3.1.2 Creating First Program:
My first program :- print(“Hello world”)
3.1.3 Understanding print() method:
print() function is used to print or display or display output.
Syntax: print(variable/message)
Example 1:
A=5
B=6
S=A+B
print(S) # here variable S is given and the value
of variable
print.
will You will get output as 11 because the value of S is 11.
3.2 Python Programming – Decision Structure
3.2.1 Inputting Values
Dear students, you learnt about programming basics and
development of program in the previous chapter. You know each
program may consist of input, process and output. In the previous
chapter, programs generated output on the basis of fixed value.
Example 1:
Program to find sum of A and B.
A=5
B=6
S=A+B
print(“Sum of A and B is”, S)
You will get output as: Sum of A and B is 11.
In this example, you will always get the same output on execution of
program, because the values of A and B are fixed. Can you give
value of A and B at the time of execution of program? Yes, you can
give values of A and B at run time. To input values at run time, you
require an input () function. Syntax: variable = input(message)
3.2.2 Decision Structure:
Decision structure in programming allows you to execute
statements on the basis of given condition. If condition evaluates to
True one set of statements executed otherwise another set of
statements executed.
In python, decision structure is implemented through if…else
statement. The if…else statement evaluates test expression and will
execute the body of if only when the test condition is True. If the
condition is False, the body of else is executed. Statements that are
written at the same indent form a block.
Syntax:
if<condition>:
Statement1
Statement2
….
else:
Statement1
Statement2
 Program 7: Program to check whether inputted number is positive
or negative. You will write the following code.
 Code:
Num=int(input(“Enter a number”))
if Num>0: Executes when condition is True.
print(“Number is positive”)
else:
print(“Number is negative”) Executes when condition is
False.
You can observe, we have applied a condition Num>0. If number is
greater than 0 then its positive otherwise number is negative. We
can write single statements or multiple statements in any part of a
decision statement.
Thank you end the unit-03

You might also like