0% found this document useful (0 votes)
6 views7 pages

Python Algorithms and Programs Guide

Uploaded by

papithapichandi
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)
6 views7 pages

Python Algorithms and Programs Guide

Uploaded by

papithapichandi
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 – ALGORITHMS, FLOWCHARTS & PROGRAMS (PART■B)

--------------------------------------------

11(b)(ii) AREA & PERIMETER OF RECTANGLE

--------------------------------------------

ALGORITHM:

1. Start

2. Read length and breadth

3. Compute area = length * breadth

4. Compute perimeter = 2 * (length + breadth)

5. Print results

6. Stop

FLOWCHART (TEXT FORMAT):

Start

Input L, B

Area = L*B

Perimeter = 2*(L+B)

Print results

V
End

PROGRAM (Python):

l = float(input("Length: "))

b = float(input("Breadth: "))

area = l*b

perimeter = 2*(l+b)

print("Area:", area)

print("Perimeter:", perimeter)

--------------------------------------------

12(b)(i) MULTIPLICATION TABLE

--------------------------------------------

ALGORITHM:

1. Start

2. Read number n

3. Loop i from 1 to 10

4. Print n * i

5. Stop

FLOWCHART:

Start → Input n → For i=1 to 10 → Print n*i → End

PROGRAM:

n = int(input("Enter number: "))

for i in range(1, 11):

print(n, "x", i, "=", n*i)

--------------------------------------------
12(b)(ii) NET SALARY

--------------------------------------------

ALGORITHM:

1. Start

2. Read basic salary

3. DA = 0.10 * basic

4. HRA = 0.20 * basic

5. Net = basic + DA + HRA - deductions

6. Print net salary

7. End

FLOWCHART:

Start → Input basic → Compute DA → Compute HRA → Compute Net → Print Net → End

PROGRAM:

basic = float(input("Enter basic salary: "))

da = basic * 0.10

hra = basic * 0.20

ded = 500

net = basic + da + hra - ded

print("Net Salary:", net)

--------------------------------------------

13(b)(ii) COUNT VOWELS, CONSONANTS, DIGITS, SPACES

--------------------------------------------

ALGORITHM:

1. Start

2. Read string s

3. Initialize counts
4. For each character:

If vowel → vowel++

Else if consonant → consonant++

Else if digit → digit++

Else if space → space++

5. Print counts

6. End

FLOWCHART:

Start → Input string → Loop each char → Check categories → Update counters → Print → End

PROGRAM:

s = input("Enter string: ")

v=c=d=sp=0

for ch in s:

if ch in "aeiouAEIOU":

v+=1

elif [Link]():

d+=1

elif [Link]():

sp+=1

elif [Link]():

c+=1

print(v, c, d, sp)

--------------------------------------------

13(b)(i) SUM OF DIGITS

--------------------------------------------

ALGORITHM:
1. Input number

2. Convert to string

3. Loop and add each digit

4. Print sum

FLOWCHART:

Start → Input n → For each digit → Sum → Print → End

PROGRAM:

n = input("Enter number: ")

total = sum(int(x) for x in n)

print("Sum:", total)

--------------------------------------------

14(b)(i) DICTIONARY OPERATIONS

--------------------------------------------

ALGORITHM:

1. Create empty dictionary

2. Add items

3. Update items

4. Delete items

5. Display dictionary

FLOWCHART:

Start → Create dict → Add → Update → Delete → Print → End

PROGRAM:

d = {}

d["name"] = "John"

d["age"] = 20
d["age"] = 21

del d["name"]

print(d)

--------------------------------------------

14(b)(ii) TUPLE OPERATIONS

--------------------------------------------

ALGORITHM:

1. Create tuple

2. Access elements

3. Concatenate tuples

4. Print results

FLOWCHART:

Start → Create tuple → Access → Concatenate → Print → End

PROGRAM:

t = (1,2,3)

print(t[0])

t2 = t + (4,5)

print(t2)

--------------------------------------------

15(a)(i) COUNT LINES, WORDS, CHARACTERS

--------------------------------------------

ALGORITHM:

1. Open file

2. Read data
3. Count lines, words, characters

4. Print counts

PROGRAM:

data=open("[Link]").read()

lines=[Link]()

words=[Link]()

chars=len(data)

print(len(lines), len(words), chars)

You might also like