























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























After completing this lab course you will be able to:
Steps involved in program development:-
To develop the program in high level language and translate it into machine level language following steps have to be practiced.
Algorithm:-
It is a method of representing the step by step process for solving a problem. Each step is called an instruction.
Characteristics of algorithm are:
Example of algorithm to find sum of two numbers:
Step1: BEGIN Step2: READ a, b Step3: ADD a and b and store in variable c Step4: DISPLAY c Step5: STOP
Hardware Requirement: Desktop Computer / laptop computer.
Software Requirement: Windows 7 or later, mac OS, and Linux.
Windows
The latest version of Windows is Windows 10. Generally, you should be on the latest version of the OS, but if you have an older machine or other software requires it, you might be stuck with Windows 7 or older. You should be fine with both, but be aware that if you want to use Python 3.5 or above, Windows XP is not supported. If you go for Windows, there are some shell options for you. Windows comes with the Command line, but also PowerShell that feels more like a normal terminal you would know from the Linux- or Mac world. A newcomer that is even better is Windows Terminal. This highly customizable terminal is a blast to use.
Linux
Linux Linux is not really the operating system, it’s a kernel. What you would consider an OS is the distributions/distros. One of the benefits of using Linux is that these distros are lightweight and super customizable. You can shop around and find the one that fits you perfectly. Some popular distros are Ubuntu, Mint, Fedora, and CentOS. Linux is great for development. It comes with a terminal as well and a lot of the text editors and IDEs work on Linux. Linux is open-source so it is a budget- friendly alternative.
Python
Of course, you need Python. Head over to python.org, download the installer, and run it. If you write “python3” in a terminal (if you downloaded a python3 version) you should see it execute and print what python version you are running.
Text Editors and IDEs
There are many text editors out there. Some things you are looking for in a text editor is: Syntax highlighting: Python is a popular language so most text editors have this as standard or as a downloadable extension. Code prediction: If you have made a variable called ninja_turtles, it is nice that the editor will predict your variable name after you start typing ninja… Having the software look for modules while you type can be used for quick coding and learning.
Tab indent: Most editors allow you to choose how many spaces you want in a tab. Python’s PEP8 (the holy bible) states you should be using 4 spaces. Python 3 even disallows mixing tabs and spaces. Few Common ones are: PyCharm, Atom, Thonny, Pydroid (For running Python Code on Android). You can also Program online.
Python supports a rich set of operators, which are symbols used within an expression to specify the manipulations to be performed while evaluating that expression. Python has the following operators:
SALIENT FEATURES OF PYTHON Python language has some characteristics that define the language and also have led to its popularity as a programming language. Easy to Learn and Use: Python is easy to learn and use. It is developer-friendly and high level programming language. Expressive Language: Python language is more expressive means that it is more understandable and readable. Interpreted Language: Python is an interpreted language i.e. interpreter executes the code line by line at a time. This makes debugging easy and thus suitable for beginners. Cross-platform Language: Python can run equally on different platforms such as Windows, Linux, UNIX and Macintosh etc. So, we can say that Python is a portable language. Dynamically Typed language: it is dynamically-typed as variable type is checked during run-time when they are bound to the object with possibility of binding the same variables with different type object during program execution leading to less optimized code avoiding run-time errors. Free and Open Source: Python language is freely available at official web address. The source-code is also available. Therefore it is open source. Object-Oriented Language: Python supports object oriented language and concepts of classes and objects come into existence. Extensible: It implies that other languages such as C/C++ can be used to compile the code and thus it can be used further in our python code. Large Standard Library: Python has a large and broad library and provides rich set of module and functions for rapid application development. GUI Programming Support: Graphical user interfaces can be developed using Python. Integrated: It can be easily integrated with languages like C, C++, and JAVA etc.
This Lab Manual is prepared to help the students with their practical understanding and development of programming skills, and may be used as a base reference during the lab/practical classes.
Students have to submit Lab Exercise report of previous lab into corresponding next lab, and can be collected back after it has been checked and signed. At the end of the semester, students should compile all the Lab Exercise reports into a single report and submit during the end semester sessional examination.
“ Sample of Lab report” is shown for LAB Exercise #1 in this manual. For the
rest of the labs, the reporting style as provided is to be followed. The lab report to
be submitted during the end semester Sessional Examination should include at
least the following topics:-
Students are to show the coding and output to the instructor/course coordinator for the additional lab exercises given in each lab module.
Note: The lab exercises may not be completed in a single specific lab. Students are
encouraged to complete the programming questions given in the exercise prior to
come to the lab hour and do the lab for the given programs.
Preston University Kohat Islamabad Campus Department of Computer Science
LAB Sheet #
Programming Fundamentals Lab Report Submitted By:
Name: ___________________
Reg. No: ___________________
Submitted To:
Department of Computer Science
Lab Date: Marks & Signature
Submission Date:
Flowchart:
Code:
h = 10 w = 12 d = 8
vol = h * w * d
print("The Volume of the cube is:", vol)
Output (Compilation, Debugging & Testing)
The Volume of the cube is: 960
Discussion and Conclusion
This is the first code written in Python program. The program is focused on the
calculation of volume of a cube for the given height, width and depth. From this
lab, I understood the basic structure of Python programming including the meaning of steps to solve the problem. Hence, volume of a cube is calculated and
displayed.
Lab exercises (please code yourself and show the output to instructor):
1. Personal Information: Write a program that displays the following information: - Your name - Your address, with city, state, and ZIP - Your telephone number - Your college major 2. Sales Prediction A company has determined that its annual profit is typically 23 percent of total sales. Write a program that asks the user to enter the projected amount of total sales, then displays the profit that will be made from that amount. **Hint: Use the value 0.23 to represent 23 percent.
Objective(s):
To be familiar with decision structure and Boolean logic in Python.
Title:
1. Number Analyzer Write a program that asks the user to enter an integer. The program should display “Positive” if the number is greater than 0, “Negative” if the number is less than 0, and “Zero” if the number is equal to 0. The program should then display “Even” if the number is even, and “Odd” if the number is odd. 2. Areas of Rectangles The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same. 3. Quarter of the Year Write a program that asks the user for a month as a number between 1 and 12. The program should display a message indicating whether the month is in the first quarter, the second quarter, the third quarter, or the fourth quarter of the year. Following are the guidelines: If the user enters either 1, 2, or 3, the month is in the first quarter. If the user enters a number between 4 and 6, the month is in the second quarter. If the number is either 7, 8, or 9, the month is in the third quarter. If the month is between 10 and 12, the month is in the fourth quarter. If the number is not between 1 and 12, the program should display an error. 4. Mass and Weight Scientists measure an object’s mass in kilograms and its weight in newtons. If you know the amount of mass of an object in kilograms, you can calculate its weight in newtons with the following formula: Weight = mass x 9. Write a program that asks the user to enter an object’s mass, then calculates its weight. If the object weighs more than 500 newtons, display a message indicating that it is too heavy. If the object weighs less than 100 newtons, display a message indicating that it is too light.
5. Roman Numerals Write a program that prompts the user to enter a number within the range of 1 through 10. The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message. The following table shows the Roman numerals for the numbers 1 through 10:
Number Roman Numeral 1 I 2 II 3 III 4 IV 5 V 6 VI 7 VII 8 VIII 9 IX 10 X