Python Lecture 0 Problem Set 0: Basic
Topic • Installation • Hello World • Input/ Output • Variable (+Naming Convention) • Data Type • Type Casting • Built in Function • Problem Set 0: Basic (6)
Create First Python Program File • Python IDLE • File -> New File -> Save (/Save As) -> Hello.py • Write Python Program • Run -> Run Module (F5)
Write First Python Program print("Hello World")
Comment • # Single Line Comment • """ Multi Line Comment """
First Python Program Modified # First Python Program # Program Name: Hello World # Author Name: Mun Al Mamun # A Program to Print a text print("Hello World")
Input/ Output 1 # input a String name = input() print(name)
Input/ Output 1 (Con.)[Display Message 1] #input a String print("Input Your Name") name = input() print(name)
Input/ Output 1 (Con.)[Display Message 2] #input a String name = input("Input Your Name: ") print(name)
Input/ Output 1 (Con.)[Data Type] #input a String name = input("Input Your Name: ") print(name) print(type(name))
Input Your Name # input a String #print("Input Your Name") name = input("Input Your Name: ") #name = input() print(name) #print(type(name))
Variable (+ Naming Convention) The Rules • https://www.python.org/dev/peps/pep-0008/#naming-conventions • lowercase_underscore for functions, methods, attributes, variables • lowercase_underscore or ALL_CAPS for constants • PascalCase for classes • camelCase only to conform to pre-existing conventions • _underscore for non-public methods and instance variables
Input an Integer Number age = input() print(age)
Input an Integer Number [2] age = input() print(age) print(type(age)) • All Input is String in Python • We have to Type Cast to convert String into Integer.
Input an Integer Number [3 (no way)] age = input() print(type(age)) print(age) age = int(age) print(age) print(type(age))
Input an Integer Number [3] [Final] age = int(input()) print(type(age)) print(age) print(type(age))
Input an Float Number cgpa = input() print(cgpa) print(type(cgpa))
Input an Float Number [1 (no way)] cgpa = input() print(type(cgpa)) cgpa = float(cgpa) print(cgpa) print(type(cgpa))
Input an Float Number [2] [Final] cgpa = float(input()) print(type(cgpa)) print(cgpa) print(type(cgpa))
Are you a liar? [1] you = True print(you) print(type(you))
Are you a liar? [2] you = False print(you) print(type(you))
Formatted I/O #Input Name with Formatted Output name = input("What is Your Name: ") print("Hello, ",name) #Input Age with Formatted Output age = int(input("What is Your Age: ")) print("Your age is: ",age) #Input CGPA with Formatted Output cgpa = float(input("What is Your CGPA: ")) print("Your CGPA is ",cgpa)
Formatted I/O #Input Name with Formatted Output name = input("What is Your Name: ") print("Hello, ",name) print("Hello, ",name, "nHow are You?") print("Hello, {}".format(name)) print(f"Hello, {name}")
Data Type • str (String) • int (Integer) • float (Float) • bool (Boolean) • None (NoneType)
Built-in Function • print() • input() • type() • int() • float() • https://docs.python.org/3.6/library/functions.html
Problem Set 0: Basic (6) • Hello World. • IO Your Name. • IO your Age. • IO your CGPA. • Are you a liar? (Boolean) • Formatted I/O. (String + Numeric) [for Problem 2,3,4]
Online Resourse • python.org -> Docs -> Tutorial • YouTube • Python Tutorials -> Corey Schafer • Python Beginners Tutorials -> Mahmud Ahsan : Thinkdiff • Learn Python Programming -> Clever Programmer • Python 3.5 Basic (Bangla) -> Vubon Roy • Python Tutorials for Absolute Beginners by CS Dojo -> CS Dojo
Any Question?
Prepared by Mun Al Mamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b

Lecture 0 python basic (ewurc)

  • 2.
  • 3.
    Topic • Installation • HelloWorld • Input/ Output • Variable (+Naming Convention) • Data Type • Type Casting • Built in Function • Problem Set 0: Basic (6)
  • 5.
    Create First PythonProgram File • Python IDLE • File -> New File -> Save (/Save As) -> Hello.py • Write Python Program • Run -> Run Module (F5)
  • 6.
    Write First PythonProgram print("Hello World")
  • 7.
    Comment • # SingleLine Comment • """ Multi Line Comment """
  • 8.
    First Python ProgramModified # First Python Program # Program Name: Hello World # Author Name: Mun Al Mamun # A Program to Print a text print("Hello World")
  • 9.
    Input/ Output 1 #input a String name = input() print(name)
  • 10.
    Input/ Output 1(Con.)[Display Message 1] #input a String print("Input Your Name") name = input() print(name)
  • 11.
    Input/ Output 1(Con.)[Display Message 2] #input a String name = input("Input Your Name: ") print(name)
  • 12.
    Input/ Output 1(Con.)[Data Type] #input a String name = input("Input Your Name: ") print(name) print(type(name))
  • 13.
    Input Your Name #input a String #print("Input Your Name") name = input("Input Your Name: ") #name = input() print(name) #print(type(name))
  • 14.
    Variable (+ NamingConvention) The Rules • https://www.python.org/dev/peps/pep-0008/#naming-conventions • lowercase_underscore for functions, methods, attributes, variables • lowercase_underscore or ALL_CAPS for constants • PascalCase for classes • camelCase only to conform to pre-existing conventions • _underscore for non-public methods and instance variables
  • 15.
    Input an IntegerNumber age = input() print(age)
  • 16.
    Input an IntegerNumber [2] age = input() print(age) print(type(age)) • All Input is String in Python • We have to Type Cast to convert String into Integer.
  • 17.
    Input an IntegerNumber [3 (no way)] age = input() print(type(age)) print(age) age = int(age) print(age) print(type(age))
  • 18.
    Input an IntegerNumber [3] [Final] age = int(input()) print(type(age)) print(age) print(type(age))
  • 19.
    Input an FloatNumber cgpa = input() print(cgpa) print(type(cgpa))
  • 20.
    Input an FloatNumber [1 (no way)] cgpa = input() print(type(cgpa)) cgpa = float(cgpa) print(cgpa) print(type(cgpa))
  • 21.
    Input an FloatNumber [2] [Final] cgpa = float(input()) print(type(cgpa)) print(cgpa) print(type(cgpa))
  • 22.
    Are you aliar? [1] you = True print(you) print(type(you))
  • 23.
    Are you aliar? [2] you = False print(you) print(type(you))
  • 24.
    Formatted I/O #Input Namewith Formatted Output name = input("What is Your Name: ") print("Hello, ",name) #Input Age with Formatted Output age = int(input("What is Your Age: ")) print("Your age is: ",age) #Input CGPA with Formatted Output cgpa = float(input("What is Your CGPA: ")) print("Your CGPA is ",cgpa)
  • 25.
    Formatted I/O #Input Namewith Formatted Output name = input("What is Your Name: ") print("Hello, ",name) print("Hello, ",name, "nHow are You?") print("Hello, {}".format(name)) print(f"Hello, {name}")
  • 26.
    Data Type • str(String) • int (Integer) • float (Float) • bool (Boolean) • None (NoneType)
  • 27.
    Built-in Function • print() •input() • type() • int() • float() • https://docs.python.org/3.6/library/functions.html
  • 28.
    Problem Set 0:Basic (6) • Hello World. • IO Your Name. • IO your Age. • IO your CGPA. • Are you a liar? (Boolean) • Formatted I/O. (String + Numeric) [for Problem 2,3,4]
  • 29.
    Online Resourse • python.org-> Docs -> Tutorial • YouTube • Python Tutorials -> Corey Schafer • Python Beginners Tutorials -> Mahmud Ahsan : Thinkdiff • Learn Python Programming -> Clever Programmer • Python 3.5 Basic (Bangla) -> Vubon Roy • Python Tutorials for Absolute Beginners by CS Dojo -> CS Dojo
  • 30.
  • 31.
    Prepared by Mun AlMamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b