0% found this document useful (0 votes)
5 views3 pages

Python Basics: Variables & Conditionals

The document provides three Python programs focusing on variables, expressions, and conditional statements. It outlines the aims, algorithms, and example code for each program, demonstrating how to declare variables, evaluate arithmetic expressions, and check the sign of a number. Each section includes a clear structure for writing and executing the respective programs.
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)
5 views3 pages

Python Basics: Variables & Conditionals

The document provides three Python programs focusing on variables, expressions, and conditional statements. It outlines the aims, algorithms, and example code for each program, demonstrating how to declare variables, evaluate arithmetic expressions, and check the sign of a number. Each section includes a clear structure for writing and executing the respective programs.
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

Python Programs - Variables, Expressions, and Conditional Statements

1. Program on Variables

Aim:

To declare and use variables in a Python program.

Algorithm:

1. Start the program.

2. Declare variables and assign values.

3. Perform a simple operation using those variables.

4. Print the result.

5. End.

Program:

a = 10

b=5

sum = a + b

print("The sum of", a, "and", b, "is", sum)

2. Program on Expressions

Aim:

To evaluate arithmetic expressions using variables.

Algorithm:

1. Start the program.


2. Declare variables and assign values.

3. Evaluate expressions (addition, subtraction, etc.).

4. Print the results.

5. End.

Program:

x = 15

y=4

add = x + y

sub = x - y

mul = x * y

div = x / y

print("Addition:", add)

print("Subtraction:", sub)

print("Multiplication:", mul)

print("Division:", div)

3. Program on Conditional Statements

Aim:

To check whether a number is positive, negative, or zero using conditional statements.

Algorithm:

1. Start the program.

2. Read a number from the user.

3. Use if-elif-else to check conditions:


- If number > 0, print positive.

- If number < 0, print negative.

- Else, print zero.

4. End.

Program:

num = int(input("Enter a number: "))

if num > 0:

print("The number is positive.")

elif num < 0:

print("The number is negative.")

else:

print("The number is zero.")

You might also like