For Quiz Preparation for TGES ,Go to General Knowledge Section

Tuesday, November 4

Chapter 7( More on Python ) Class -7th

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:- In Python, the input() function is an essential tool for making your programs interactive. It allows you to ask the user for information and receive their response. This makes your program dynamic, as it can change based on the data entered by the user. When you use the input() function, Python will display a prompt (a message) on the screen and wait for the user to type something. Once the user presses Enter key, the program returns the input as a string.

2. 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

3. In Python, relational operators (also known as comparison operators) are used to compare two values or expressions. They help determine the relationship between the values, such as whether one value is equal to, greater than, or less than another. These operators return a Boolean value: True or False.

Here are the common relational operators in Python:

== (Equal to)

Compares if two values are equal.

python

Copy

x = 5

y = 5

print(x == y) # Output: True

!= (Not equal to)

Compares if two values are not equal.

python

Copy

x = 5

y = 3

print(x != y) # Output: True

> (Greater than)

Compares if the value on the left is greater than the value on the right.

python

Copy

x = 5

y = 3

print(x > y) # Output: True

< (Less than)

Compares if the value on the left is less than the value on the right.

python

Copy

x = 5

y = 10

print(x < y) # Output: True

>= (Greater than or equal to)

Compares if the value on the left is greater than or equal to the value on the right.

python

Copy

x = 5

y = 5

print(x >= y) # Output: True

<= (Less than or equal to)

Compares if the value on the left is less than or equal to the value on the right.

python

Copy

x = 3

y = 5

print(x <= y) # Output: True

4. In Python, when an expression contains more than one operator, the interpreter needs to decide which operator to evaluate first. This decision is based on two main concepts: precedence and associativity.

Precedence refers to the order in which operators are evaluated. Operators with higher precedence are evaluated before those with lower precedence. For example, multiplication (*) has higher precedence than addition (+), so in an expression like 2 + 3 * 4, the multiplication will be performed first, followed by addition.

5. BODMAS stands for:

B: Brackets (Parenthesis, Square Brackets, Curly Brackets)

O: Of (or Powers/Exponents)

D: Division

M: Multiplication

A: Addition

S: Subtraction

The BODMAS rule dictates the order of operations when solving a mathematical expression. According to BODMAS, the steps should be followed in the exact order, from left to right. Understanding and applying this rule ensures that calculations yield the expected results, helps avoid errors, and allows for clearer and more effective coding.

No comments:
Write Comments

Please ask any question about gk related

Total Pageviews

Popular Posts

© 2014 SSC GK.in . Designed by Bloggertheme9 | Distributed By Gooyaabi Templates
Powered by Blogger.