0% found this document useful (0 votes)
29 views5 pages

PFP191_Practical Exercise

The document outlines practical exercises for learning Python programming, covering topics such as operators, data types, variables, conditional statements, loops, collections, and string manipulation. It includes specific tasks like printing messages, performing arithmetic operations, handling user input, and managing data structures. Each exercise is designed to reinforce programming concepts through hands-on coding practice.

Uploaded by

nh033262
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)
29 views5 pages

PFP191_Practical Exercise

The document outlines practical exercises for learning Python programming, covering topics such as operators, data types, variables, conditional statements, loops, collections, and string manipulation. It includes specific tasks like printing messages, performing arithmetic operations, handling user input, and managing data structures. Each exercise is designed to reinforce programming concepts through hands-on coding practice.

Uploaded by

nh033262
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/ 5

PRACTICAL EXERCISE PFP191

I. Required knowledge: Operators, Data types, Variables and expression, Basic input/output

1. Write a Python program to print “Hello World!”

2. Write a Python program to print student informaion: student name, student ID, Class ID,
date of birth and mobile number.
Student Name:
Student ID:
Class ID:
Date of birth
Mobile Number:

3. Write a program in Python that reads a forename, surname and year of birth and display the
names and the year one after another sequentially
Ex: Expected Output :
Input your firstname: Tom
Input your lastname: Davis
Input your year of birth: 1982
Tom Davis 1982

4. Write Python program to print following characters:

5. Write a program to input two numbers and find their sum.

6. Write a program to input two numbers and find their quotient and modulus.

7. Write a program to input two numbers and perform all arithmetic operations: sum,
difference, product, quotient and modulus.
8. Write a program to input length and width of a rectangle and calculate perimeter and area
of the rectangle.
9. Write a program to input radius of a circle from user and find diameter, circumference and
area of the circle.

10.Write a program to input a positive integer N with 2 digits from the keyboard, output to the
screen the sum of the digits of N.
Ex: Input: N=48. Output: 4+8=12.

11.Write a program to input temperature in degrees Celsius and convert to Fahrenheit, using
the conversion formula:

12. Write a program that allows input hours, minutes and seconds and convert it to seconds
and print the result.
Ex: Input: h=1, m=2, s=2. Output: 3722 seconds.

13.Write a program in C that takes minutes as input, and display the total number of hours and
minutes

14.Write a program to input number of days from user and convert it to years, weeks and
days.
Ex: Input: Enter days: 373.
Output: Years: 1
Weeks: 1
Days: 1

15.Write a program to enter length in centimeter and convert it into meter and kilometer.

16.Write a program to calculate the perimeter and area of shapes: triangles, squares, rectangles
and circles with the information that needs to be entered from the keyboard.

II. Conditional Statement


(if…else)

17.Write a program to enter two integers a and b. Print the maximum value to the screen.

18.Write a program to check whether an integer entered number by the user is odd or even.

19.Write a program to check number is positive, negative or zero.


20.Write a program to find the largest number among three number.

21.Write a program input three numbers a,b,c. Print to the screen in ascending order of
numbers.

22.Write a program to find the largest number using Conditional Operator.

23.Write a Python program to find whether a given year is a leap year or not.
(A leap year is a year that is divisible by 4 and not by 100. Or it is divisible by 400)
Ex: Enter year : 2016
Output : 2016 is a leap year.

24. Write a program to solve the linear equation of one variable: ax + b = 0.

25. Write a program to solve quadratic equation : ax2 + bx + c = 0.

26.Write a program to read temperature in centigrade and display a suitable message


according to temperature state below:
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot

27.Write a program to input a three-digit integer n. Output to the screen in ascending order of
digits.
Ex: Enter n : 291
Output : 129

28.Write a program in C to read any day number in integer (2….8) and display day name in
the week
Test Data : 4
Expected Output :Wednesday

III. Loop

29.Calculate: 𝑛! (𝑛 >0)

30.Calculate: 𝑆(𝑛) = 1 + 3 + 5 + ⋯ . +(2 × 𝑛 + 1), 𝑛 ≥0


31.Calculate: 𝑃(𝑛) = 1.3.5 … (2. 𝑛 + 1), 𝑛≥0

32.Calculate: 𝑆(𝑛) = 1 + 1.2 + 1.2.3 + ⋯ + 1.2.3 … . 𝑛, 𝑛 >0)

33.Calculate: 𝑆(𝑛) = 1 − 2 + 3 − 4 + ⋯ + (−1)𝑛+1 𝑛, 𝑛 > 0


1 1 1
34.Calculate: 𝑆(𝑛) = 1 + + + ⋯ + , 𝑛>0
2 3 𝑛

35.Write a program to count the number of divisors of a positive integer N.


Ex: Enter n : 12
Output : 6

36.Write a program to input two positive integers a and b. Find the greatest common divisor
and least common multiple of a and b.

37.Write a program to input a positive integer n. Checks whether n is prime or not.

IV. Collection
38.Write a program in Python to store elements in an list and print it.

39.Write a program in Python to read n number of values in an list and display it in reverse
order

40.Write a program in Python to find the sum of all elements of the list

41.Write a program in Python to find the maximum and minimum element in an list

42.Write a program in Python to separate odd and even integers in separate lists.

43.Write a program in Python to sort elements of list in ascending order

44.Write a program in Python to sort elements of the list in descending order

V. String & Class

45.Write a Python program that inputs a string and prints the reversed string.
46.Write a Python program that counts special characters in a string. Special characters are

non-alphabetic or non-numeric characters)

47.Write a Python program to input a list of item names and print the list with the item names

sorted in ascending order

48.Write a Python program to input a string anh print number of words in the string (each

word is separated by a space)

49.Write a Python program to count occurrences of words in a text file.

50.Write a Python program manage employees (EmployeeID, EmployeeName, DateOfBirth,

Email, Phone, Salary) include functions: add new, search by name, remove, update, and

print a list of employees by descending salary.

You might also like