Python mid 1 answers Module - 1
1) Describe about different features of python programming language. Explain the applications of Python.
Python is a dynamic, high level, free open source and interpreted programming language. It supports object-oriented programming as well as procedural oriented programming.In Python, we don’t need to declare the type of variable because it is a dynamically typed language.For example, x = 10 Here, x can be anything such as String, int, etc.Features in Python There are many features in Python, some of which are discussed below –
1. Easy to code:
Python is a high-level programming language. Python is very easy to learn the language as compared to other languages like C, C#, Javascript, Java, etc. It is very easy to code in python language and anybody can learn python basics in a few hours or days. It is also a developer-friendly language.
2. Free and Open Source:
Python language is freely available at the official website and you can download it from the given download link below click on the Download Python keyword.Download Python Since it is open-source, this means that source code is also available to the public. So you can download it as, use it as well as share it.
3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming. Python supports object-oriented language and concepts of classes, objects encapsulation, etc.
4. GUI Programming Support:
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk in python.PyQt5 is the most popular option for creating graphical apps with Python.
5. High-Level Language:
Python is a high-level language. When we write programs in python, we do not need to remember the system architecture, nor do we need to manage the memory.
6. Extensible feature:
Python is a Extensible language. We can write us some Python code into C or C++ language and also we can compile that code in C/C++ language.
7. Python is Portable language:
Python language is also a portable language. For example, if we have python code for windows and if we want to run this code on other platforms such as Linux, Unix, and Mac then we do not need to change it, we can run this code on any platform.
8. Python is Integrated language:
Python is also an Integrated language because we can easily integrated python with other languages like c, c++, etc.
9. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time. like other languages C, C++, Java, etc. there is no need to compile python code this makes it easier to debug our code. The source code of python is converted into an immediate form called bytecode.
- Large Standard Library
Python has a large standard library which provides a rich set of module and functions so you do not have to write your own code for every single thing.There are many libraries present in python for such as regular expressions, unit-testing, web browsers, etc.
11. Dynamically Typed Language:
Python is a dynamically-typed language. That means the type (for example- int, double, long, etc.) for a variable is decided at run time not in advance because of this feature we don’t need to specify the type of variable.
2) Demonstrate a python program to read student details and print. Write a python program to read two numbers & print sum of those numbers.i) #student information
name = input("Enter your name:")
roll = input("Enter your roll number:")
age = input("Enter your age:")
branch = input("Enter your branch:")
section = input("Enter your section:")
print("Name of the student is:")
print(name)
print("Rollnumber of student is:")
print(roll)
print("Age of student is:")
print(age)
print("Branch of student is:")
print(branch)
print("Section of student is:")
print(section) ii) #addition of 2 numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1+num2
print("The sum of 2 numbers is:")
print(sum)
3)Explain different operators in python programming.Write a program to demonstrate arithmetic, relational operators.
i) 1
Arithmetic operators: Arithmetic operators are used to perform
mathematical operations like addition, subtraction, multiplication and division.Operator Description Syntax
+ Addition: adds two operands x + y
- Subtraction: subtracts two operands x - y
* Multiplication: multiplies two operands x * y
/ Division (float): divides the first operand by the second x / y
%
Modulus: returns the remainder when first operand is
divided by the second x % y 2
Relational Operators: Relational operators compares the values. It either
returns True or False according to the condition.Operator Description Syntax
> Greater than: True if left operand is greater than the right x > y
< Less than: True if left operand is less than the right x < y
== Equal to: True if both operands are equal
x == y != Not equal to - True if operands are not equal x != y >=
Greater than or equal to: True if left operand is greater
than or equal to the right x >= y <=
Less than or equal to: True if left operand is less than or
equal to the right x <= y 3
Logical operators: Logical operators perform Logical AND, Logical
OR and Logical NOT operations.
Operator Description Syntax
and Logical AND: True if both the operands are true x and y
or Logical OR: True if either of the operands is true x or y
not Logical NOT: True if operand is false not x
4