Introduction to Programming with Python Code Dileepa S




































- Slides: 36
Introduction to Programming with Python Code මගන තරණ ග නම Dileepa S. Rajapaksa | http: //www. windowsgeek. lk @dsrajapaksa Microsoft Virtual Academy
Demo කලන Microsoft Virtual Academy Video එක අභය ගයට පළතර
Code මගන If statement Microsoft Virtual Academy ත රණ ග නම
If statement එක න පළවන code එකක වශ ෂ condition එකක ත පත ව නව නම පමණක execute ව නන සලසවනන . answer=input("Would you like express shipping? ") if answer == "yes" : print("That will be an extra $10") ම ම == සලකණ ත රම ම කකද ?
ව නස == != < > <= >= is is is conditions පරකෂ කරමට symbols භ වත කරනන පළවන equal to not equal to less than greater than less than or equal to greater than or equal to if if if answer == "yes" : answer != "no" : total < 100 : total > 100 : total <= 100 : total >= 100 : .
If statement එක න පළවන code එකක වශ ෂ condition එකක ත පත ව නව නම පමණක execute ව නන සලසවනන. answer=input("Would you like express shipping? ") if answer == "yes" : print("That will be an extra $10") print("Have a nice day") Print statement එක indent වම ප රශණයක ඔව - indentව code එක execute ව නන සත ය ව න ව ල වට පමණය. තය නව ද condition එක ?
Demo If statement Microsoft Virtual Academy
ස බ ල කය If statements Microsoft Virtual Academy
අපට string එකක uppercase වල ස ට lowercase වලට පරවරතනය කරනන ක රමයක තය නව ද ? answer=input("Would you like express shipping? ") if answer. lower() == "yes" : print("That will be an extra $10") print("Have a nice day") ඉඟ ය: අප Strings සමඟ ව ඩකරම Video එක ම functions පළබඳ ඔබව ත ඉදරපත කළ lower() upper()
Demo ස ඛ ය සහ if statement සමග ව ඩ කරම Microsoft Virtual Academy
Handling user inputs Microsoft Virtual Academy
Demo If statement එකක භ වතය ලබ ග නම Microsoft Virtual Academy සඳහ අ කයක Userග න
Deposit කරන මදල userට input කරමට ලබ ද නන ක හ මද? deposit=input("How much would you like to deposit? ") if deposit > 100 : print("You get a free toaster!") print("Have a nice day") අප code එක crash ව නන ඇය ? ක හ මද ම ක හද ගනන ?
අපට ව නව input function එකකන ල බ න string අගය අ ක බවට පරවරතනය කරනන. deposit=input("How much would you like to deposit? ") if int(deposit) > 100 : print("You get a free toaster!") print("Have a nice day") ම නන ඒ සඳහ තවත වදහක deposit=int(input("How much would you like to deposit? ")) if deposit > 100 : print("You get a free toaster!") print("Have a nice day")
Branching Microsoft Virtual Academy
$100 ට ව ඩනම න මල Toaster එකකද $100ට අඩනම න මල Mug එකක ල බ නම deposit=input("How much would you like to deposit? ") if float(deposit) > 100 : print("You get a free toaster!") else: print("Enjoy your mug!") print("Have a nice day") Else statement එක තය න code එක execute ව නන condition එක සත ය න වන ත පමණය. 150 , 100 , 50කයන ඒව ඇතලත ප නවනන කමක ද? කලවට Screen එක
Demo Else ක ටස එකත කරම Microsoft Virtual Academy
If condition එක නව රද ද යනන මතකය ගබඩ කර තබ ග නමට Boolean variable භ වත කරගනන පළවන. deposit= input("how much would you like to deposit? ") if float(deposit) > 100 : #Set the boolean variable free. Toaster to True free. Toaster=True #if the variable free. Toaster is True #the print statement will execute if free. Toaster : print("enjoy your toaster") If statement එක සත ය වන ම සහ If statement එක ව රද වන ම ම න වග ද වල ව වද කයල බලනන.
Demo Boolean Variable භ වතය බ ලම Microsoft Virtual Academy සහ සයළම ක රම අවසථ
අප ත නපත අගය 50 ඇතලත code එක crash ව නන ඇය ? කල වට deposit= input("how much would you like to deposit? ") if float(deposit) > 100 : #Set the boolean variable free. Toaster to True free. Toaster=True #if the variable free. Toaster is True #the print statement will execute if free. Toaster : print("enjoy your toaster") error message එක බලනන : Name ‘free. Toaster’ is not defined.
Variable initialize කර තබම පරදදක #Initialize හ ඳ the variable to fix the error free. Toaster=False deposit= input("how much would you like to deposit? ") if float(deposit) > 100 : #Set the boolean variable free. Toaster to True free. Toaster=True #if the variable free. Toaster is True #the print statement will execute if free. Toaster : print("enjoy your toaster")
ද න අපට තවත Type කරම සදව නන පළවන deposit=input("How much would you like to deposit? ") if float(deposit) > 100 print("You get a free toaster!") free. Toaster=true else: print("Enjoy your mug!") print("Have a nice day") deposit=input("How much would you like to deposit? ") if float(deposit) > 100 : print("You get a free toaster!") free. Toaster=True else: print("Enjoy your mug!") print("Have a nice day") අතව රද
ස ර ශය… • If condition භ වතය න • Coding ලවම ද තරණ ග නම indentation ත බම • If Conditions භ වතය න ස ඛ ය ස සනඳනය • Else conditions භ වතය • Boolean Variables භ වත ය දම Microsoft Virtual Academy කර ඒව If conditions සමඟ
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.