Introduction to Programming - STEM 1502 Lecture Notes PDF

Document Details

ResoluteSerpentine7510

Uploaded by ResoluteSerpentine7510

CINEC Campus

Ms. Anuththara Dikovita

Tags

programming programming language python computer science

Summary

These lecture notes cover the basics of programming concepts. The notes explain the evolution of programming techniques and introduce fundamental ideas like procedural and object-oriented programming. The notes offer an overview of general programming fundamentals, as well as a special focus on the Python programming language and its capabilities.

Full Transcript

Problem Solving in Science and Technology - STEM 1502 Introduction to Programming MS. ANUTHTHARA DIKOVITA DEPARTMENT OF INFORMATION AND TECHNOLOGY FACULTY OF COMPUTING Learning Outcomes On the completion of this module, you will be able LO1: To critically analyze and break down complex problems...

Problem Solving in Science and Technology - STEM 1502 Introduction to Programming MS. ANUTHTHARA DIKOVITA DEPARTMENT OF INFORMATION AND TECHNOLOGY FACULTY OF COMPUTING Learning Outcomes On the completion of this module, you will be able LO1: To critically analyze and break down complex problems in specific Science and Engineering subjects to identify key issues and variables. LO2: To formulate and present effective solutions to disciplinary problems, demonstrating clear and appropriate communication skills. LO3: To accurately compute and solve numerical problems, and effectively visualize and interpret the results using suitable IT applications. LO4: To demonstrate proficiency in a variety of IT applications relevant to Science and Engineering, showcasing the ability to apply these tools in practical scenarios. 2 Book Resources Thinking skills: critical thinking and problem solving ,Butterworth, John,Second edition, 2013, Cambridge University Press, Weverka P. Office 365 All-in-One for Dummies. Second edition. (Wade M, ed.). John Wiley & Sons Incorporated; 2022. McKinney W. Python for Data Analysis, 3rd Edition. 3rd edition. O’Reilly Media Inc; 2022. Lutz M. Learning Python /. Fifth edition. O’Reilly Media, Inc, USA,; 2013. Lyon Carl. Successful Problem Solving for AQA AS ICT /. (Rogers Jackie, ed.). Payne-Gallway; 2008. 3 Programming techniques Evolution of Programming Techniques Programming began in the 1940s, using memory addresses and machine code directly Higher level languages were developed to allow English-like instructions Older programs were “monolithic,” and ran from beginning to end Newer programs contain modules that can be combined to form programs 5 Major programming techniques There are Two major programming techniques: ◦ Procedural programming ◦ Object-oriented programming Both techniques employ reusable program modules 6 What is a Programming Language? A programming language is the set of instructions through which humans interact with computers. The programming code is pretty much like writing a paragraph of instruction or creating a to-do list to computers. With code and programming, you can get the computer to draw complex shapes and create rich computer graphics 7 Procedural programming Focuses on the procedures. The one that directly instructs a device on how to finish a task in logical steps. This paradigm uses a linear Top-down approach and treats data and procedures as two different entities. Examples: C, FORTRAN, Pascal, Basic etc. 8 Object-oriented programming Focuses on objects that represent real-world things and their attributes and behaviors. Organizes software design around data, or objects, rather than functions and logic. Examples: C++, Java, C# etc. 9 Machine Language A language that controls the computer’s on/off circuitry. Machine language is the only language a computer is capable of understanding. 10 Compiler and Interpreter We generally write a computer program using a programming language, which is a high-level language. But computers only understand machine language. A program written in a high-level language is called source code. We need to convert the source code into machine code and this is accomplished by these compilers and interpreters. 11 Compiler Vs Interpreter Compiler Interpreter Takes the entire program and converts it into object Interpreters convert code into machine code when code or machine code before program runs and it is the program is run. Therefore, this is memory typically stored in a file. Examples: C and C++, C#. efficient. Examples: Perl, Python and MATLAB. 12 Let’s Start!!! Python Python was created by Guido van Rossum in the Netherlands in 1990 and was named after the popular British comedy troupe Monty Python’s Flying Circus. Van Rossum developed Python as a hobby, and Python has become a popular programming language widely used in industry and academia due to its simple, concise, and intuitive syntax and extensive library. Python is a general-purpose programming language. That means you can use Python to write code for any programming task. Python is now used in the Google search engine, in mission-critical projects at NASA, and in transaction processing at the New York Stock Exchange. Primary factors Python is objected-oriented Structure supports such concept as polymorphism, operation overloading and multiple inheritance. Indentation Indentation is one of the greatest future in python It’s free(open source) Downloading and installing python is free and easy souuce code is easily accessible. Installing Python 16 Installing Python… 17 Installing Python… 18 Installing Python… 19 Python’s Development Environment This is the main control of the python development environment It is an interactive editor window The results of computations are displayed here Other editor windows may be launched from here IDLE is available in most desktop versions of Python 20 Using the IDLE window The Python command prompt (or interactive window) has a prompt sign >>> which indicates it is waiting for input To write and run code in the interactive window: 1. Simply type the code 2. Press the key 3. Observe the result(s) 21 Special Characters in Python Python programs are case sensitive. It would be wrong, for example, to replace print in the program with Print. 22 Print command The simplest program in most languages is to print a message to the screen In Python: >>> print("Hello, World!“) The print is a command word built into Python that means: display what follows to the screen The message in quotes Hello, World! is then displayed to the screen 23 Variables A variable is a location in a computer programs memory that is able to record and hold (called store) a value of data. Once a value has been stored in a variable it will remain there unchanged until it is updated. Each variable can only hold one item of data at a time To avoid the programmer having to remember where in memory the data may be positioned in the memory Basic allows the location to be referenced by a name. E.g. wifesBirthday is easier to remember that say memory 24 Variable naming rules To name a variable it must begin with a letter of the alphabet or underscore,Optionally followed by more letters of the alphabet, digits or underscore. It is always advisable to use meaningful variables names such as date_of_birth, noOfDwarves or car01. The name is not allowed any spaces in it, (a space in a word makes it two words), use underscores to join Names that are commands in Python (class, def, print, etc.) are not allowed to be used as variable names. Note: the name itself means nothing it merely has to be unique enough to identify it from other things 25 Assignment of values To set the value of a variable the equals symbol is used, the syntax is as follows = e.g. aNumber = 1234 _text = “Below is constant times a variable” theSum = 14.36 * aNumber Setting the value is called an assignment 26 Working with variables As well as changing the value in a variable in an assignment, We can update the value in a variable by using it on both sides of an assignment sum = 12 #initialise a value in the variable sum = sum + 1 # update the value print “answer is”, sum What answer would we expect to see for sum? In addition when a variable holds a string we can use the variable to pull the string apart or stick them together 27 Python and Types Python determines the data types in a program automatically. “Dynamic Typing” But Python’s not casual about types, it enforces them after it figures them out. “Strong Typing” So, for example, you can’t just append an integer to a string. You must first convert the integer to a string itself. Python Data Types ◼ Numbers: my_float = 10.73; my_integer = 42 ◼ Strings: my_str = "Dude, why are you using java?" ◼ Lists: my_list = ["foo", 24, "blah", "go away"] ◼ Tuples: my_tup = (1, 4, 32, "yoyo", ['ha', 'moog']) ◼ Dictionaries: my_hash = {'a':24.5, 'mo':'fo', 42:'answer'} ◼ Objects: my_inst = MyClass('bar'); my_inst.method() ◼ Modules: import myfile Look forward for more…!!!

Use Quizgecko on...
Browser
Browser