Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Flowchart Pseudocode Python

The document contains pseudocode and Python implementations for various programming exercises, including multiplication of numbers, calculating height from velocity, finding the volume of a cylinder, grading student marks, summing consecutive numbers, determining if a number is odd or even, and responding to age input. Each exercise is presented with both pseudocode and corresponding Python code. The exercises cover basic programming concepts such as input/output, conditionals, loops, and arithmetic operations.

Uploaded by

masumuws03
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 views8 pages

Flowchart Pseudocode Python

The document contains pseudocode and Python implementations for various programming exercises, including multiplication of numbers, calculating height from velocity, finding the volume of a cylinder, grading student marks, summing consecutive numbers, determining if a number is odd or even, and responding to age input. Each exercise is presented with both pseudocode and corresponding Python code. The exercises cover basic programming concepts such as input/output, conditionals, loops, and arithmetic operations.

Uploaded by

masumuws03
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/ 8

Ex-1.

Multiplication of numbers

Pseudocode:

DECLARE: FirstNumber, SecondNumber, Result : REAL


OUTPUT “Enter FirsttNumber”
INPUT FirstNumber
Output “Enter SecondNumber”
INPUT SecondNumber”
Result OUTPUT FirstNumber * SecondNumber
“The result of multiplication is:” Result

Python:
FirstNumber = float(input("Enter the FirstNumber: "))
SecondNumber = float(input("Enter the SecondNumber: "))
result = FirstNumber * SecondNumber
print("The result of multiplying the two numbers is:", result)
Ex-2 If you throw a ball with a vertical component of velocity of 12.5 m/s. The following
calculates the height it reached:

Pseudocode:
DECLARE v,g,h : REAL
OUTPUT “Enter the initial velocity”
INPUT v
OUTPUT “Enter the gravity”
INPUT g
h ← ROUND ((v*v)/(2*g), 2)
OUTPUT “Height h = “ , h

Python:

v = float(input("Enter the initial velocity: "))

g = float(input("Enter the gravity: "))

h = v**2/(2*g)
h = round (h ,2)
print("Height h = ", h)
Ex-3. Find the volume of a cylinder

Pseudocode:
DECLARE radius, height, volume: REAL
DECLARE pi : REAL
CONSTANT PI 3.142
OUTPUT “Enter radius of the cylinder”
INPUT radius
OUTPUT “Enter height of the cylinder”
INPUT height
Volume ← pi * radius * radius * height
OUTPUT “The volume of the cylinder is :” volume

Python:
pi = 3.142
radius = float(input("Enter the radius of the cylinder: "))
height = float(input("Enter the height of the cylinder: "))
volume = pi * (radius ** 2) * height
volume = round(volume,2)
print("The volume of the cylinder is:", volume)
Ex. Input student mark and output grade according to the mark.

DECLARE mark : INTEGER


DECLARE grade : STRING
OUTPUT "Enter the student's mark (0–100): "
INPUT mark
IF mark >= 90 AND mark <= 100 THEN
grade ← "A*"
ELSEIF mark >= 80 AND mark <= 89 THEN
grade ← "A"
ELSEIF mark >= 70 AND mark <= 79 THEN
grade ← "B"
ELSEIF mark >= 60 AND mark <= 69 THEN
grade ← "C"
ELSEIF mark >= 50 AND mark <= 59 THEN
grade ← "D"
ELSEIF mark >= 40 AND mark <= 49 THEN
grade ← "E"
ELSE 18 grade ← "U"
ENDIF
OUTPUT "The grade is: ", grade

Python

mark = int(input("Enter the student's mark (0–100): "))

if mark >= 90 and mark <= 100:


grade = "A*"
elif mark >= 80 and mark <= 89:
grade = "A"
elif mark >= 70 and mark <= 79:
grade = "B"
elif mark >= 60 and mark <= 69:
grade = "C"
elif mark >= 50 and mark <= 59:
grade = "D"
elif mark >= 40 and mark <= 49:
grade = "E"
else:
grade = "U"

print(f"The grade is: {grade}”)


Ex.4 To find the sum of consecutive numbers. The program will take a number as input
and start adding from 1 to the nth number taken as input.

Pseudocode:
DECLARE n, total: INTEGER
OUTPUT "Enter a positive number: "
INPUT n
WHILE n <= 0 DO
OUTPUT "Please enter a positive number."
OUTPUT "Enter a positive number: "
INPUT n
ENDWHILE
total ← 0
FOR i ← 1 TO n
total ← total + i
NEXT i
OUTPUT "Sum from 1 to ", n, " is ", total

Python:
while True:
n = int(input("Enter a positive number: "))
if n > 0:
break
else:
print("Please enter a positive number.")
total = 0
for i in range(1, n + 1):
total = total + i
print("Sum from 1 to", n, "is", total)
Ex.5 To find if the input number is odd or even. The program will take multiple inputs, until 0.

Pseudocode:
DECLARE number: INTEGER
REPEAT
OUTPUT "Enter a number (0 to stop): "
INPUT number
IF number = 0 THEN
OUTPUT "Program ended."
ELSE IF number MOD 2 = 0 THEN
OUTPUT number, "is Even"
ELSE
OUTPUT number, "is Odd"
ENDIF
UNTIL number = 0

Python:
while True:
number = int(input("Enter a number (0 to stop): "))
if number == 0:
print("Program ended.")
break
elif number % 2 == 0:
print(f"{number} is Even")
else:
print(f"{number} is Odd")
Ex.6 Take age as input. If age is between 1 and 5 print “Happy”. If the age is between 6 and 12
print “Joy” and for any other age print “Smile”. For -1 as input, program will end.

Pseudocode:

DECLARE age: INTEGER


REPEAT
OUTPUT "Enter age (-1 to end): "
INPUT age
IF age = -1 THEN
OUTPUT "Program ended."
ELSE IF age >= 1 AND age <= 5 THEN
OUTPUT "Happy"
ELSE IF age >= 6 AND age <= 12 THEN
OUTPUT "Joy"
ELSE
OUTPUT "Smile"
ENDIF
UNTIL age = -1
Python:

while True:
age = int(input("Enter age (-1 to end): "))

if age == -1:
print("Program ended.")
break
elif 1 <= age <= 5:
print("Happy")
elif 6 <= age <= 12:
print("Joy")
else:
print("Smile")

You might also like