Introduction to Programming with Python

Slides:



Advertisements
Similar presentations
Modules and Objects Introduction to Computing Science and Programming I.
Advertisements

CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 4: "Difference Between Dates" and data abstraction.
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
The fourth programming assignment J.-F. Pâris Fall 2014.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
A revision guide for programming with python. 1.A program is a set of instructions that tells a computer what to do. 2.The role of a programmer is to.
Introduction to Computational Linguistics Programming I.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
Date Variables Visual Basic for Applications 5. Objectives n In this tutorial, you will learn how to: n Reserve a Date variable n Use an assignment statement.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Xin Liu Feb 4, * Use midterm questions for previous 231/217 midterms for practices * ams
Introduction to Computing Using Python for loop / def- ining a new function  Execution control structures ( if, for, function call)  def -ining a new.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
PYTHON PROGRAMMING Week 3 - Tuesday. STARTER Hour of Code Video.
Chapter 9 - Formatted Input/Output
Introduction to Computing Science and Programming I
14 Shipping Time App Using Dates and Timers
Tutorial 14 – Shipping Time Application Using DateTimes and Timers
Lesson 06: Functions Class Participation: Class Chat:
Enjoying Maths In Year 1.
Python – Dates and Times
SQL – Data types.
Java String and Date ISYS 350.
Design & Technology Grade 7 Python
Variables, Expressions, and IO
JavaScript Arrays Date
SQL – Dates and Times.
SQL DATE/TIME FUNCTIONS
Functions CIS 40 – Introduction to Programming in Python
Servlet Date Operations
Java Date ISYS 350.
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Functions, Procedures, and Abstraction
Introduction to Programming with Python
Introduction to Programming with Python
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Chapter 9 - Formatted Input/Output
Date Functions Farrokh Alemi, Ph.D.
Defining a Database Schema
How much revision will you do today?
Unit 2. Day 7..
Java Date ISYS 350.
Libraries of Code Notes from Wilson, Software Design and Development Preliminary Course pp
Classes.
Python 19 Mr. Husch.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Introduction to Value-Returning Functions: Generating Random Numbers
Announcements Nate’s office hours Card key problems?
Introduction to Programming with Python
Python Basics with Jupyter Notebook
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Governing Board Meeting Schedule
Kirkwood Center for Continuing Education
Java Date ISYS 350.
Lesson 02: Introduction to Python
Find your new seat for today.
Python 19 Mr. Husch.
The Web Wizard’s Guide To JavaScript
Trainer: Bach Ngoc Toan– TEDU Website:
Functions, Procedures, and Abstraction
Java Date ISYS 350.
Ballot Comment Resolution
Python Creating a calculator.
Temporal Data Part V.
Working with dates and times
Presentation transcript:

Introduction to Programming with Python Date and Time සමඟ වැඩකරන හැටි Dileepa Rajapaksa | http://www.windowsgeek.lk @dsrajapaksa Microsoft Virtual Academy

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

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

දින සහ වේලාවන් සමග වැඩ කිරීම DateTime Last part Practice your language Microsoft Virtual Academy

අපි ගොඩක් වෙලාව ගතකරනවා deadline හා schedule ගැන හිතමින් මගේ උපන්දිනයට දින කීයද? මගේ Project එක බාරදෙන්න ඕනේ කවදාද? දින දෙකකින් appointment එකක් දාන්න ඕනෙ, ඒ දවස කවදා වේවිද? Microsoft Virtual Academy

මේ වගේ ගැටළු විසඳීමේදී අපිට දින සහ වේලාවන් ගබඩා කිරීම සහ හැසිරවීම ගැන ඉගෙනගන්න වෙනවා. Microsoft Virtual Academy

තමන්ගේ උපන්දිනයට ඇති දින ගණන සොයාගැනීමට අවශ්‍යනම් මුලින්ම අද දිනය දැනගතයුතුයි. datetime කියන class එක මගින් අපිට අද දිනය ලබාගන්න පුළුවන්. #The import statement gives us access to  #the functionality of the datetime class import datetime #today is a function that returns today's date print (datetime.date.today()) Microsoft Virtual Academy

දිනයන් variable වල ගබඩාකරන්න පුළුවන්. import datetime #store the value in a variable called currentDate currentDate = datetime.date.today() print (currentDate) Microsoft Virtual Academy

Demo දැන් වේලාව හා දිනය පෙන්වීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

දිනයෙහි ඇති වෙනස් කොටස් ඔබට භාවිතාකරන්න පුළුවන්. import datetime currentDate = datetime.date.today() print (currentDate) print (currentDate.year) print (currentDate.month) print (currentDate.day) Microsoft Virtual Academy

Demo දිනයෙහි කොටස් භාවිතය සඳහා date functions එක භාවිතාකිරීම Last part Practice your language Microsoft Virtual Academy

Date formats Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

2/5/2014 මගින් පෙන්වන්නේ මොන දවසද? Microsoft Virtual Academy

වෙනත් format එකකට දිනය පෙන්වන්න ඕනෙනම් මොකද කරන්නේ ? විවිධ රටවල විවිධ පරිශීලකයින් විවිධ date format භාවිතාකරනවා, default ක්‍රමය ඔබට අවශ්‍ය විදිහ නොවෙන්න පුළුවන්. මේ දේවල් වලටත් විසඳුම් තියෙනවා, ඒත් ටිකක් වෙලාව යනවා ඒ වගේම වැඩිපුර code ලියන්න වෙනවා. default format එක YYYY-MM-DD Microsoft Virtual Academy

Python වලදී strftime භාවිතාකරලා date format එක වෙනස්කරන්න පුළුවන්. import datetime currentDate = datetime.date.today() #strftime allows you to specify the date format print (currentDate.strftime('%d %b,%Y')) Microsoft Virtual Academy

මොනවද මේ %d %b සහ %Y? %d කියන්නේ දිනය %b මාසය හා කෙටි යෙදුම (eg : Jan , Feb ) %Y අංක 4 කින් යුත් අවුරුද්ද Microsoft Virtual Academy

තවත් අවශ්‍යවෙන්න පුළුවන් දේවල් %b මාසයේ කෙටිනම %B මාසයේ සම්පූර්ණ නම %y අංක 2කින් අවුරුද්ද දැක්වීමට %a දවස කෙටියෙන් දැක්වීමට %A දවස සම්පූර්ණයෙන් දැක්වීමට Strftime සම්පූර්ණ ලැයිස්තුව සඳහා strftime.org යන්න. Microsoft Virtual Academy

Demo Formatting dates Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

Wedding Invitation එකක් print කරන්න පුළුවන්ද? “Please attend our event Sunday, July 20 in the year 1997” import datetime currentDate = datetime.date.today() #strftime allows you to specify the date format print (currentDate.strftime ('Please attend our event %A, %B %d in the year %Y')) Microsoft Virtual Academy

ඉංග්‍රීසි වෙනුවට සිංහල වගේ වෙනත් භාෂාවක්…. Localization කියලයි ඒකට කියන්නෙ සාමාන්‍යයෙන් Program එක භාවිතාකරන්නේ පරිගණකය භාවිතාකරණ භාෂාව. ඒත් අපිට පරිගණකයේ Settings වලින් හැම විටම බලාපොරොත්තු වෙන්න බැහැ. අපිට පුළුවන් Python වලට කියන්න එක් භාෂාවක් පමණක් භාවිතාකරන්න කියලා. ඒකට තවත් code සහ වෙලාව වැයවෙනවා.ඒවා ගැන දැන්ම කතාකරන්නේ නැහැ.හොයලාබලන්න ඕනෙනම් මෙතනට යන්න babel Python library http://babel.pocoo.org/ Microsoft Virtual Academy

උපන්දිනයට ඇති දින ගණන ගනිමු,ඒ සඳහා මට User ගෙන් birthday එක අහන්න වෙනවා. birthday = input ("What is your birthday? ") print ("Your birthday is " + birthday) birthday එකේ datatype එක මොකක්ද? string අපට එය දිනයක් වශයෙන් සැලකියයුතුනම් ( උදා: අපි datetime function එක භාවිතා කරලා format එක වෙනස් කරලා print කලා වගේ ) අප විසින් එය දිනයක් බවට පරිවර්ථනය කරන්න වෙනවා. Microsoft Virtual Academy

strptime function එක මගින් ඔබට පුළුවන් string එකක් දිනයක් බවට පරිවර්තනය කරන්න import datetime birthday = input ("What is your birthday? ") birthdate =  datetime.datetime.strptime(birthday,"%m/%d/%Y").date() #why did we list datetime twice?  #because we are calling the strptime function #which is part of the datetime class #which is in the datetime module print ("Your birth month is " + birthdate.strftime('%B')) Microsoft Virtual Academy

Demo User ගෙන් date value එකක් ලබාගැනීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

User විසින් අපි strptime function එකේ දක්වලා තියෙන විදිහට වඩා වෙනස් විදිහකට දිනය ඇතුලත්කලොත්… birthdate = datetime.datetime.strptime(birthday,"%m/%d/%Y") Program එක crash වෙනවා අපට අවශ්‍ය date format එක userට කියන්න සිදුවෙනවා. birthday = input ("What is your birthday? (mm/dd/yyyy)") මෙවැනි ගැටලු හසුරවන අයුරු අප පසුවට සාකච්ඡාකරනවා Microsoft Virtual Academy

Dates ටිකක් අවුල් වගේද. , ඒක වටිනවද Dates ටිකක් අවුල් වගේද? , ඒක වටිනවද? ඇයි නැත්තෙ ඒවා string විදිහට store කරන්න. ඔයාලට ලොකු උත්සවයකට හෝ නිවාඩුවකට ඇති දින ගණන පෙන්වීමට countdown එකක් හදන්න පුළුවන් nextBirthday = \ datetime.datetime.strptime(‘02/04/2016','%m/%d/%Y').date() currentDate = datetime.date.today() #If you subtract two dates you get back the number of days #between those dates difference = nextBirthday - currentDate print (difference.days) Microsoft Virtual Academy

Dates ටිකක් අවුල් වගේද. , ඒක වටිනවද Dates ටිකක් අවුල් වගේද? , ඒක වටිනවද? ඇයි නැත්තෙ ඒවා string විදිහට store කරන්න. ශීතකරණයේ තියෙන ද්‍රව්‍යවල කල් ඉකුත්වන දිනයපෙන්වීම currentDate = datetime.date.today() #timedelta allows you to specify the time  #to add or subtract from a date print (currentDate + datetime.timedelta(days=15)) print (currentDate + datetime.timedelta(hours=15)) Microsoft Virtual Academy

ඔබට Dates සමඟ තවත් වැඩ සිදු කරන්න වෙනවද? ඔබට අවශ්‍යදේ datetime වල නැත්නම් dateutil library එක බලන්න (උදා: දින දෙකක් අතර ඇති පරතරය අවුරුදු වලින් ලබාගැනීමට අවශ්‍යනම් ) Dateutil library : http://labix.org/python-dateutil Microsoft Virtual Academy

වේලාව සමග වැඩකිරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

වෙලාව ගැන මොකද? Datetime කියන එකේ අපිට වෙලාවත් store කරන්න පුළුවන්. import datetime currentTime = datetime.datetime.now() print (currentTime) print (currentTime.hour) print (currentTime.minute) print (currentTime.second) Microsoft Virtual Academy

dates වගේම time format කරන්නත් strftime() භාවිතාකරන්න පුළුවන්. import datetime currentTime = datetime.datetime.now() print (datetime.datetime.strftime(currentTime,'%H:%M')) %H පැය ( පැය 24 වෙලාවෙන් ) %I පැය ( පැය 12 වෙලාවෙන් ) %p AM හෝ PM %m මිනිත්තු %S තත්පර Microsoft Virtual Academy

Demo වේලාවන් සමග වැඩකිරීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

ඔබේ අභියොගය Project එකක අවසාන දිනය user ගෙන් ලබාගන්න. පිළිතුර සති, දින හා පැය වල එකතුවක් ලෙස ලබාදෙන්න. ඉඟිය: ඔබට numeric value video එකේ සාකච්ඡාකල math functions අවශ්‍ය වේවි. Microsoft Virtual Academy

සුභ පැතුම් ! දැන් ඔබට Date Time සමඟ වැඩකරන Program එකක් ලියන්න හැකියාව තියෙනවා Microsoft Virtual Academy

සාරාංශය… datetime class එක import කරන හැටි Dates format කරන හැටි Strftime function එක භාවිතා කරන අයුරු Strptime function එක භාවිතා කරන අයුරු Times සමඟ වැඩකරන අයුරු Microsoft Virtual Academy