2. Quick summary
• A - In how many types, programming languages can be classified? And
what are the types?
• S - Comment on the scenarios where which type is the best?
• A- Explain the difference between the 2 types of programming
languages.
• S – Which types of language has faster execution and which has less
memory requirement.
• A – Which types of language is Python?
3. • S - Which of the following are valid variable names?
• Time1
• 3time1
• Time-1
• Time_1
• A - Which python inbuilt function is used to take input from user from
command prompt?
• S – What is a source code?
4. Running python from file
• 2 ways to run python source code from file:
• 1. Install an IDE e.g pycharm, spyder, thonny
• Check whether you have right version of python.
• Type in the python code
• Run the file by “Run” button.
• Alternatively, outside IDE
• Create a new “.py” file.
• Activate python virtual environment.
• Enter the source code in python file.
• GO on therminal
• Type the following command:
• python <filename.py>
5. Write the code for following program in
python file and run it.
• Write a program to take 3 sides of a triangle as input and output the
perimeter of a triangle.
• Hint(Perimeter of triangle is sum of all sides)
• Input –
• Enter 1st side of triangle
• Enter 2nd side of triangle
• Enter 3rd side of triangle
• Output
• Perimeter of triangle is <your answer>
7. Setting the Data Type
• In python you don’t need to set data type explicitly. Python does it for
you when you declare the variable.
• The data type is set when you assign a value to a variable:
• x = “python class“ Data type = string
• x = 20.5 Data type = float.
• X = 4 Data type = integer
• X = True Data type = boolean
8. Checking the data type in python
• Get the data type of any variable by using the type() function.
• Example
• A = “I love python”
• type(A)
9. Convert from one data type to another
• Python has inbuilt functions to convert from one data type to another
• str(): converts any variable to string.
• int(): converts any valid integer from other data type to integer.
• float() : converts any valid integer form other data type to float.
• bool() : converts to boolean
11. Examples
• Open python shell
• Write code for 52
• Code for getting remainder from division of 625 and 19
• Write code for square root of 81
• Code for integer division 30 and 7
12. Get practical
• Easy - Write a program to convert kilometres to miles.
• Take kilometres as input
• Conversion factor = 0.621371
• Multiply kilometres by conversion factor.
• Hard –
• Python Program to Calculate the Area of a Triangle