Introduction to Programming with Python

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
Python November 14, Unit 7. Python Hello world, in class.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Data Types Integer 15 StringHelloThere! Float/Real BooleanYes / No CharP.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Type Conversions Implicit Conversion Explicit Conversion.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
1. Understand how to catch errors in a program 2. Know how to filter user input to stop incorrect data.
Introduction to Computer Programming
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Variables, Types, Expressions Intro2CS – week 1b 1.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
More Python Proglan Python Session 2. Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are.
AOIT Introduction to Programming Unit 2, Lesson 6 Arithmetic Operators and Operator Precedence Copyright © 2009–2012 National Academy Foundation. All rights.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Few More Math Operators
Lecture2.
Topics Designing a Program Input, Processing, and Output
Topic: Python’s building blocks -> Statements
Design & Technology Grade 7 Python
Variables, Expressions, and IO
Handling errors try except
පාඨමාලා මාතෘකා Microsoft SQL Server Databases සැකසීම
Algebra Algebra.
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Customizing Views Views Customize කර ගැනීම
ETI Base Code ETI මුලධර්මයන් හදුනාගනිමු
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
මුහම්මද් සල්ලල්ලාහු අලෙයිහි වසල්ලම්
Basics of MVC MVC වල මුලික කොටස්
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Creating and Configuring Models Models create කිරීම සහ config කර ගැනීම
වී පොහොර සහනාධාර මුදල් ප්‍රදාන වැඩසටහන 2017/18 මහ කන්නය
Customizing Controllers Controllers Customizing කර ගැනීම
Reading Input from the Keyboard
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Introduction to Programming with Python
Introduction to Programming with Python
Topics Designing a Program Input, Processing, and Output
Python Basics with Jupyter Notebook
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Topics Designing a Program Input, Processing, and Output
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Introduction to Python
Python Creating a calculator.
Presentation transcript:

Introduction to Programming with Python සංඛ්‍යා සමඟ වැඩ කිරීම Dileepa Rajapaksa | http://www.windowsgeek.lk @dsrajapaksa Microsoft Virtual Academy

කලින් Video එකේ අපි කතා කලේ මොනවාද? User කෙනෙක් ගෙන් input එකක් ලබා ගන්න අයුරු විචල්‍යයන් නැතහොත් variables ගැන Variable එකකට අගයක් ගබඩා කරන හැටි සහ එය නැවත භාවිත කරන අයුරු Variables අවශ්‍ය අකාරයට හසුරවන ආකාරය String functions භාවිතා කරන අයුරු Microsoft Virtual Academy

Demo කලින් Video එකේ අභියෝගයට පිළිතුරු Microsoft Virtual Academy

සංඛ්‍යා සමඟ වැඩ කිරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

අපිට ගොඩක් ප්‍රශ්ණ ගණිතය භාවිතාකරගෙන විසඳන්න පුළුවන්. උකස් සඳහා කොපමණ මුදලක් අපි මාසිකව ගෙවියයුතුද? බදු සහිතව යම් කිසි භාණ්ඩයක මිල කොපමණද? ආහාර වට්ටෝරුවක මෙන් දෙගුණයක් ආහාර සෑදීමට කොපමණ ද්‍රව්‍ය අවශ්‍යද? Microsoft Virtual Academy

String වගේම අංකත් ගබඩාකිරීමට සහ හැසිරවීමට හැකියාව තිබීම වැදගත්. age = 42 print(age)  Microsoft Virtual Academy

ඔබට ගණිතකර්ම කිරීම සඳහා අංක හෝ අංක ඇතුලත් variable භාවිතාකරන්න පුළුවන්. width = 20 height = 5 area = width * height perimeter = 2*width + 2*height perimeter = 2*(width+height) Microsoft Virtual Academy

මේවා තමයි සුලබම ගණිතකර්ම. Symbol Operation Example + Addition 5+2 = 7 - Subtraction 5-2 = 3 * Multiplication 5*2 = 10 / Division 5/2 = 2.5 ** Exponent 5**2 = 25 % Modulo 5%2 = 1 Microsoft Virtual Academy

පාසලේදී කල ගණිත නීති ඒ විදිහමයි. ගණිතකර්ම කිරීමේ ප්‍රමුඛතා අනුපිළිවල. ( ) parentheses ** exponent (e.g. **2 squared **3 cubed) */ multiplication and division + - addition and subtraction Microsoft Virtual Academy

Demo පරිගණකය භාවිතාකර ගණිත ගෙදර වැඩ කීරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

Formatting numbers Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

සමහර වෙලාවලදී Userට අංක පෙන්වීමට පෙර ඒවා Format එකකට හදන්න වෙනවා. Syntax Output print('I have %d cats' % 6) I have 6 cats print('I have %3d cats' % 6) I have 6 cats print('I have %03d cats' % 6) I have 006 cats print('I have %f cats' % 6) I have 6.000000 cats print('I have %.2f cats' % 6) I have 6.00 cats Microsoft Virtual Academy

අංක Format එකකට හදන්න Format method භාවිතාකරන්නත් පුළුවන්. Syntax Output print("I have {0:d} cats".format(6)) I have 6 cats print("I have {0:3d} cats".format(6)) I have 6 cats print("I have {0:03d} cats".format(6)) I have 006 cats print("I have {0:f} cats".format(6)) I have 6.000000 cats print("I have {0:.2f} cats".format(6)) I have 6.00 cats Microsoft Virtual Academy

Demo Numeric values format කරන අයුරු Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

Geek Tip! සමහරවිට Command එකේ දිග එක පේලියක් ඉක්මවන්න ඉඩතියෙනවා. total = 5 + 6 + 8 \      + 6 + 2 Microsoft Virtual Academy

Demo Numeric values format කරන අයුරු Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

අංක ඇතුලත්කිරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

වැටුප හා බෝනස් ඇතුලත් කළවිට එහි එකතුව ලබාගමු… salary = input("Please enter your salary: ") bonus = input("Please enter your bonus: ") payCheck = salary + bonus print(payCheck) Microsoft Virtual Academy

Demo User ගෙන් සංඛ්‍යාවන් ලබාගැනීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

User බෝනස් හා වැටුප ඇතුලත් කළවිට අපිට වැරදි පිළිතුරක් ලැබෙන්නේ ඇයි. salary = input("Please enter your salary: ") bonus = input("Please enter your bonus: ") payCheck = salary + bonus print(payCheck) What went wrong? Microsoft Virtual Academy

ඉඟිය: Input statement එකෙන් return කරන්නේ string අගයක් salary = '5000' bonus = '500' payCheck = salary + bonus print(payCheck) Microsoft Virtual Academy

Program එක හිතන්නේ salary හා bonus කියන්නේ string අගයන් කියලා ඒනිසා ඒවා එකතුකරනවා වෙනුවට concatenate කරනවා. salary = 5000 bonus = 500 payCheck = salary + bonus print(payCheck) Microsoft Virtual Academy

String වෙනුවට සංඛ්‍යා ලෙස සලකන ලෙස පයිතන් වෙත දැනුම්දීමට අපිට ක්‍රමයක් අවශ්‍යයි. Microsoft Virtual Academy

Datatype එකක් තවත් Datatype එකකට හැරවීමට functions තියෙනවා. int(value) converts to an integer long(value) converts to a long integer float(value) converts to a floating number (i.e. දශම සහිත අංක සඳහා) str(value) converts to a string මොන function එකද අපි අපේ code එක විසඳන්න භාවිතාකරන්නේ. Microsoft Virtual Academy

අපි string අගයන් float බවට පරිවර්තනය කලොත් බලාපොරොත්තුවන ප්‍රතිඵලය ලබාගන්න පුළුවන්. salary = input("Please enter your salary: ") bonus = input("Please enter your bonus: ") payCheck = salary + bonus payCheck = float(salary) + float(bonus) print(payCheck) මොකක් වේවි කියලද හිතන්නේ Salary එක “BOB”කියලා දුන්නොත් ? String අගයන් අංක බවට පරිවර්තනය කරන්න බැරි නිසා code එක crash වෙනවා. අපි Error handle කරන හැටි පසුව කතාකරනවා ! Microsoft Virtual Academy

Demo Datatype එක පරිවර්තනය කිරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

ඔබේ අභියෝගය - Loan Calculator එකක් නිර්මාණය කරන්න. ණය ප්‍රමාණය , පොළිය හා ණය ලබාගත් අවුරුදු ප්‍රමාණය ලබාදෙන්න. පහත සමීකරණය භාවිතයෙන් මාසිකව ගෙවියයුතු අගය ගණනයකරන්න. M = L[i(1+i)n] / [(1+i)n-1] M = මාසිකව ගෙවියයුතු අගය L = ණය ප්‍රමාණය i = (පොළී ප්‍රතිශතය )interest rate (for an interest rate of 5%, i = 0.05) n = වාරික ගණන Microsoft Virtual Academy

සුභ පැතුම් ඔබට දැන් ගණිත ගැටලු විසඳන්නත් පුළුවන්… ඔබට දැන් ගණිත ගැටලු විසඳන්නත් පුළුවන්… Microsoft Virtual Academy

සාරාංශය… පරිශීලකයාගෙන් සංඛ්‍යාවක් ආදානය ලෙස ලබා ගන්නා අයුරු Variable තුල සංඛ්‍යා ගබඩා කිරීම Variable තුල ඇති සංඛ්‍යා නැවත භාවිත කර ගණිත කර්ම … සුලභ භාවිත වන ගණිත කර්ම ගණිතකර්ම කිරීමේ ප්‍රමුඛතා අනුපිළිවල. Datatype එකක් තවත් Datatype එකකට හැරවීම Microsoft Virtual Academy