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

Lab - 3

The document contains instructions for 5 Python programming exercises on fundamental concepts like statements, loops, lists, functions, classes and objects. The exercises include writing programs to find numbers divisible by 7 between 1500-2700, converting temperatures between Celsius and Fahrenheit, guessing a number, constructing patterns using nested loops, reversing strings, performing basic list operations like summing and multiplying items, calculating factorials, defining classes with methods.

Uploaded by

Sangar Mahmood
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)
53 views3 pages

Lab - 3

The document contains instructions for 5 Python programming exercises on fundamental concepts like statements, loops, lists, functions, classes and objects. The exercises include writing programs to find numbers divisible by 7 between 1500-2700, converting temperatures between Celsius and Fahrenheit, guessing a number, constructing patterns using nested loops, reversing strings, performing basic list operations like summing and multiplying items, calculating factorials, defining classes with methods.

Uploaded by

Sangar Mahmood
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/ 3

Python Fundamentals

11-08-2021
Lab 3 – Problem Solving
Section One: Statements and loops
1. Write a Python program to find those numbers which are divisible by 7 and multiple of
5, between 1500 and 2700 (both included).

2. Write a Python program to convert temperatures to and from celsius, fahrenheit.


[ Formula : c/5 = f-32/9 [ where c = temperature in celsius and f = temperature in
fahrenheit ]
Expected Output :
60°C is 140 in Fahrenheit
45°F is 7 in Celsius

3. Write a Python program to guess a number between 1 to 9.


Note : User is prompted to enter a guess. If the user guesses wrong then the prompt
appears again until the guess is correct, on successful guess, user will get a "Well
guessed!" message, and the program will exit.

4. Write a Python program to construct the following pattern, using a nested for loop.
*
**
***
****
*****
****
***
**
*
5. Write a Python program that accepts a word from the user and reverse it.
Section Two: List - Exercises

1. Write a Python program to sum all the items in a list.

2. Write a Python program to multiply all the items in a list.

3. Write a Python program to get the largest number from a list.

4. Write a Python program to get the smallest number from a list.

5. Write a Python program to count the number of strings where the string length is 2 or
more and the first and last character are same from a given list of strings.
Sample List : ['abc', 'xyz', 'aba', '1221']
Expected Result : 2

Section Three : Functions


1. Write a Python function to find the Max of three numbers.

2. Write a Python function to sum all the numbers in a list.


Sample List : (8, 2, 3, 0, 7)
Expected Output : 20

3. Write a Python function to multiply all the numbers in a list.


Sample List : (8, 2, 3, -1, 7)
Expected Output : -336
4. Write a Python program to reverse a string.
Sample String : "1234abcd"
Expected Output : "dcba4321"
5. Write a Python function to calculate the factorial of a number (a non-negative integer).
The function accepts the number as an argument.
Section Four: Class and Objects
• Write a Python class which has two methods get_String and print_String.
get_String accepts a string from the user and print_String print the string in upper
case.
• Write a Python class named Rectangle constructed by a length and width and a
method which will compute the area of a rectangle.
• Write a Python class named Circle constructed by a radius and two methods which
will compute the area and the perimeter of a circle.
• Write a Python program to get the class name of an instance in Python.

You might also like