Chapter 7: More on Python
Exercises (Pgs. 127-129)
A. Tick (✓) the correct answers.
1. b
2. a
3. b
4. c
5. c
B. Fill in the blanks.
1. float( )
2. Boolean
3. True
4. precedence
5. equal
C. Write T for True and F for False.
1. T
2. F
3. T
4. F
5. T
D. Answer the following questions.
Q.1 What is the purpose of the input() function
Ans:- The `input()` function in Python lets users enter data during program execution. It displays a prompt, waits for user input, and returns the entered value as a string, making programs interactive and dynamic.
Ans:- In Python, you can convert a string input into an integer or float using the built-in functions int() and float().
You can use the int() function to convert a string that represents a whole number into an integer.
string_input = “123”
integer_value = int(string_input)
print(integer_value) # Output: 123
You can use the float() function to convert a string that represents a number with decimals into a float.
string_input = “123.45”
float_value = float(string_input)
print(float_value) # Output: 123.45
Q.3 What are operators in Python ?
Ans:- Operator in Python:
An operator is a symbol used to perform operations on values or variables.
Types of operators in Python:
There are 7 types of operators:
-
Arithmetic
-
Relational (Comparison)
-
Logical
-
Assignment
-
Bitwise
-
Membership
-
Identity
Q.4 Explain About string in Python ?
Ans:- In Python, a string is a data type used to store a sequence of characters. Strings are written inside single quotes (' '), double quotes (" "), or triple quotes (''' ''' or """ """). They are immutable, meaning their values cannot be changed after creation.
Q.5 What is BODMAS and PEDMAS in Python ?
Ans:- BODMAS:- BODMAS rule explains the correct order of operations in mathematics: Brackets, Orders, Division, Multiplication, Addition, and Subtraction. Following this order from left to right ensures accurate calculations, prevents mistakes, and produces correct and consistent results in coding and mathematics.
PEDMAS :- PEDMAS rule explains the order of operations in mathematics: Parentheses first, then Exponents, followed by Division and Multiplication, and finally Addition, ensuring expressions are evaluated correctly and consistently.
No comments:
Write CommentsPlease ask any question about gk related