50% found this document useful (2 votes)
1K views3 pages

Python Operators and Presence Check

1. The document provides 3 questions to solve using Python operators. The first question relates numbers 399, 543 and 12345 using the equation 22*y + z, where x = 12345, y = 543, z = 399. The second justifies the results of integer and float division when dividing positive and negative numbers. 2. The second question sets variables a=5, b=3, c=10 and uses a/=b and c*=5 to divide and multiply them, outputting the results. 3. The third question checks for the presence of "s" in the string "Data Science" using a membership operator, and obtains 64 using numbers 4 and 3 with the power operator.

Uploaded by

Kamlesh Nikam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
1K views3 pages

Python Operators and Presence Check

1. The document provides 3 questions to solve using Python operators. The first question relates numbers 399, 543 and 12345 using the equation 22*y + z, where x = 12345, y = 543, z = 399. The second justifies the results of integer and float division when dividing positive and negative numbers. 2. The second question sets variables a=5, b=3, c=10 and uses a/=b and c*=5 to divide and multiply them, outputting the results. 3. The third question checks for the presence of "s" in the string "Data Science" using a membership operator, and obtains 64 using numbers 4 and 3 with the power operator.

Uploaded by

Kamlesh Nikam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • MODULE-2 OPERATORE Tasks

MODULE-2 OPERATORES

Please implement by using Python

1. A. Write an equation which relates 399, 543 and 12345


B. “When I divide 5 with 3, I got 1. But when I divide -5 with 3, I got -2”—How would you justify
it.

2. a=5,b=3,c=10.. What will be the output of the following:

A. a/=b

B. c*=5

3. A. How to check the presence of an alphabet ‘s’ in word “Data Science” .

B. How can you obtain 64 by using numbers 4 and 3 .

########### Assignments Module 2_Operators #############

## Que.1 (A) ##

#Write an equation which relates 399, 543 and 12345

x = 12345

y = 543

z = 399

equation = 22*y + z

if equation == x:

print('it is a valid relation')

## Que.1 (B)
#“When I divide 5 with 3, I got 1. But when I divide -5 with 3, I got -2”—How would you justify it.

a=5

b=3

a/b

a//b

a = -5

b=3

a/b

a//b

## Que. 2 ##

#a=5,b=3,c=10.. What will be the output of the following:A. a/=b

a=5

b=3

c = 10

a/=b

print(a)
c*=5

print(c)

## Que. 3 ##

#A. How to check the presence of an alphabet ‘s’ in word “Data Science” .

# By using membership operators

"s" in "Data Science"

#B. How can you obtain 64 by using numbers 4 and 3 .

a=4

b=3

a**b

Common questions

Powered by AI

Correctly interpreting division results is crucial since different operators provide different types of division, which directly affect program logic and outcomes. For instance, the use of '//' gives integer division, cutting off the decimal and potentially leading to unexpected results or logical errors, especially with negative numbers where Python's rounding strategy might differ from expectations. Precise interpretation ensures accurate calculations and can prevent costly errors in more complex systems .

The equation represents a valid mathematical relation because when substituting the values for variables x, y, and z as mentioned, it balances correctly. Specifically, 12345 is equal to 22 times 543 plus 399, thereby satisfying the equation x = 22 * y + z when checked programmatically .

The output of the expression a/=b when a=5 and b=3 is 1.6666666666666667. This operation performs division and then assigns the result back to the variable a, effectively updating its value to the division's result .

You can check for the presence of a character in a string through the use of membership operators such as 'in'. For example, to verify if the letter 's' is in the string "Data Science", you would use '"s" in "Data Science"', which evaluates to True .

Python's floor division might be preferred when working with integer calculations where fractional parts are irrelevant, such as indexing, loop counters, or scenarios needing a flooring effect to ensure conservative results. It's particularly useful in performance-sensitive tasks where integer arithmetic is faster, or simpler control structures are beneficial, such as defining grid layouts or chunk sizes in algorithms .

Integer division in Python, performed using the '//' operator, differs from regular division '/' by rounding down to the nearest whole number. This is particularly evident with negative numbers. For example, 5 divided by 3 results in 1.666..., and the integer division 5 // 3 gives 1. However, with -5 // 3, it results in -2 rather than the -1.666... outcome from regular division. Python rounds towards negative infinity in the case of integer division with negatives, which explains the -2 result .

The exponential operator '**' in Python is used to raise a number to the power of another number. To calculate 64 using numbers 4 and 3, you would use 4**3, meaning 4 raised to the power of 3. This expression evaluates to 64, effectively using exponentiation to derive the desired result .

The equation 22*y + z = 12345 demonstrates the use of arithmetic operations to ascertain relationships between constants via coefficients and added terms. Here, the logic entails multiplying a coefficient (22) by a variable (y=543) and adding another variable (z=399) to achieve the target (12345). This exemplifies a basic linear equation where the variables and coefficients operate to verify or derive a specific value, highlighting practical applications of linear arithmetic within a program .

The multiplication assignment operator '*=' in Python multiplies a variable by a specific value and assigns the product back to the variable. For example, in the document, if c=10 and you execute c*=5, the value of c becomes 50. This operation simplifies and condenses the code by combining multiplication and assignment into a single step .

Membership operators in Python allow for efficient and straightforward checking of a character's presence or absence within a string. They enhance string manipulation by providing simple logic: using 'in' and 'not in', users can write cleaner and more readable code, facilitating operations such as substring searches, validations, and conditional operations based on string content. This enhances both efficiency and functionality in textual data processing .

MODULE-2 OPERATORES
Please implement by using Python
1.
A. Write an equation which relates 399, 543 and 12345 
B.  “When I di
#“When I divide 5 with 3, I got 1. But when I divide -5 with 3, I got -2”—How would you justify it.
a = 5
b = 3
a/b 
a//b
a =
c*=5
print(c)
## Que. 3 ##
#A. How to check the presence of an alphabet ‘s’ in word “Data Science” .
# By using membership op

You might also like