Arithmetic Operation in Python
Qus. What are operators? What is their function? Give examples of some unary and binary operators.
Ans: “Operators are those symbols used with operands, which tells compiler which operation is to be done on operands.‖ in other words – ―operators are tokens that trigger some computation/action when applied to variables and other objects in an expression.‖
Operators are of following types:
- Unary operators like (+) Unary Plus, (-) Unary Minus, not etc.
- Binary Operators like (+) addition, (*) multiplication, and etc.
Qus. What is block/code block/suit in Python?
Ans: Sometimes a group of statements is part of another statement of function. Such a group of one or more statements is called block or code-block or suit in python. e.g.
Qus. What is the role of indentation in Python?
Ans: Indentation plays a very important role in Python. Python uses indentation to create blocks of code. Statements at same indentation level are part of same block/suit. You cannot unnecessarily indent a statement; python will raise an error for that.
Qus. How many types of strings are supported by Python?
Ans: Python supports two types of strings:
(i) Single-line string That terminates in single line.
(ii) Multi-line String That stores multiple lines of text.
Qus. What will be the sizes of following constants?
(a) "\a‟ (b) “\a” (c) “Kumar\‟s” (d) "\‟ (e) “it‟s”
Ans: (a) 50 (b) 50 (c) 56 (d) 50 (e) 53
This screenshot is the output of the above question.
Qus. How can you create multi-line strings in Python?
Ans: We can create multi-line string by putting a backslash (\) at the end of line which allows you to continue typing in next line in same string.
Qus. Which of the following are syntactically correct strings? State reason.
(a) ”Python is nice Language”
(b) „He called me “Friend!” when he came‟
(c) “Very Good‟
(d) „This is a good book‟
(f) “I liked „Harry Potter‟ very much”
Ans: (a) Correct (b) Correct (c) Incorrect (d) Correct (e) Incorrect (f) Correct
Qus. What is the error in following Python program with one statement?
print(“My name is : “, name)
suggest a solution
Ans: Error is : ―name 'name' is not defined‖. And the solution is to declare the variable-name before this statement.
Qus. Predict the output of the following:
Ans: Output: 17 5
Write a Program to obtain temperature in Celsius and convert it into Fahrenheit using formula –
C X 9/5 + 32 = F
WAP to read todays date (only date Part) from user. Then display how many days are left in the current month.
WAP to print the area of circle when radius of the circle is given by user.
WAP to print the volume of a cylinder when radius and height of the cylinder is given by user.
WAP that asks your height in centimeters and converts it into foot and inches.
WAP to accept 3 side of triangle and find area of a triangle.
WAP to input principle amount,rate time and calculate simple interest.
WAP to read a number in n and prints n^2, n^3, n^4
WAP to calculate compound simple interest after taking the principle, rate and time.
WAP to take two numbers and check that the first number is fully divisible by second number or not.
WAP to take value of x,y,z from the user and calculate the equation
WAP to take the temperatures of all 7 days of the week and displays the average temperature of that week.