Showing posts with label Python Quiz. Show all posts
Showing posts with label Python Quiz. Show all posts

Sunday, 16 November 2025

Python Coding Challenge - Question with Answer (01171125)

 


Explanation:

Assign a value to num
num = 5

We set num = 5.
We will use this value for checking divisibility.

Create the list a
a = [5, 10, 11, 13]

This list contains four numbers:
5, 10, 11, 13

Initialize sum variable
s = 0

We create s to store the total of selected numbers.
Starting value = 0

Start loop — go through each value in list
for v in a:

The loop takes each value v from the list:

First: v = 5

Then: v = 10

Then: v = 11

Then: v = 13

Check divisibility using IF + continue
    if v % num == 0:
        continue

We check:
If v is divisible by num (5), skip it.
Check each:

v v % 5 Divisible? Action
5 0             Yes         Skip
10 0             Yes         Skip
11 1              No         Add
13 3              No         Add

continue means: skip the rest of the loop and go to the next number.

Add the non-skipped values
    s += v

Only numbers NOT divisible by 5 get added:

s = 11 + 13 = 24

Print the final answer
print(s)

So the output is:

24

100 Python Projects — From Beginner to Expert


Python Coding Challenge - Question with Answer (01161125)

 Explanation:

List Initialization
a = [1, 4, 7, 10]

You create a list a that contains four numbers:
1, 4, 7, 10


Variable Initialization
s = 0

You create a variable s to store the sum.
Initially, sum = 0.

Loop Through Each Value
for v in a:

This loop will pick each value from list a, one by one.
So v becomes:
1 → 4 → 7 → 10

Check Condition
if v % 3 == 1:

You check if the number leaves remainder 1 when divided by 3.

Let’s check each:

v v % 3 Remainder Condition v%3==1?
1 1             Yes             ✔ Add
4 1             Yes             ✔ Add
7 1             Yes             ✔ Add
10 1             Yes             ✔ Add

All numbers satisfy the condition.

Add to Sum
s += v

Add all numbers that passed the condition.

s = 1 + 4 + 7 + 10 = 22

Print the Final Sum
print(s)

This prints:

22

Final Output: 22

Python Interview Preparation for Students & Professionals

Friday, 14 November 2025

Python Coding Challenge - Question with Answer (01151125)


Explanation:

Line 1: Initialization
count = 0

A variable count is created and initialized to 0.

This variable will act as the loop counter.

Line 2: Start of While Loop
while count < 5:

The loop will continue as long as count is less than 5.

The condition is checked before each iteration.

Line 3: Increment Counter
count += 1

In each iteration, count is increased by 1.

Equivalent to count = count + 1.

So count will take values: 1, 2, 3, 4, 5 during the iterations.

Line 4: Continue Condition
if count == 4:
    continue

If count equals 4, the continue statement executes.

continue means: skip the rest of this iteration and move to the next iteration.

Here, print(count) will be skipped when count == 4.

Line 5: Print Statement
print(count, end=" ")

If count is not 4, it will be printed.

end=" " ensures that the output is printed on the same line separated by a space.

Execution Flow
Iteration count value if count==4? Action Output so far
1             1                     No         print 1         1
2             2                     No         print 2         1 2
3             3                     No         print 3 1 2 3
4             4                     Yes continue (skip) 1 2 3
5             5                     No print 5 1 2 3 5

Final Output
1 2 3 5

HANDS-ON STATISTICS FOR DATA ANALYSIS IN PYTHON

Thursday, 13 November 2025

Python Coding Challenge - Question with Answer (01141125)

 

Explanation:

1. Class Declaration
class Counter:

This line defines a class named Counter.

2. Class Variable (Shared Across All Calls)
    x = 1

This is a class variable, not tied to any object.

Its value is shared every time the method is called.

Initial value: 1

3. Method Without self
    def nxt():
        Counter.x *= 2
        return Counter.x
Explanation:
def nxt(): → This method does not use self because we are not creating objects.

Counter.x *= 2 → Every time the method is called, the value of x is doubled.

return Counter.x → The updated value is returned.

4. Loop That Calls the Method Several Times
for _ in range(4):

This loop runs 4 times.

5. Printing the Result Each Time
    print(Counter.nxt(), end=" ")

Each loop iteration calls Counter.nxt()

The returned value is printed

end=" " keeps everything on one line with spaces

Final Output
2 4 8 16

Python Interview Preparation for Students & Professionals



Wednesday, 12 November 2025

Python Coding Challenge - Question with Answer (01131125)

 


Explanation:

Create a List
nums = [2, 4, 6]

A list named nums is created with three integer elements: 2, 4, and 6.

This will be used to calculate the average of its elements later.

Initialize Loop Control Variables
i = 0
s = 0

i → Acts as a loop counter, starting from 0.

s → A sum accumulator initialized to 0.
It will store the running total of the numbers in the list.

Start the While Loop
while i < len(nums):

The loop runs as long as i is less than the length of the list nums.

Since len(nums) is 3, this means the loop will run while i = 0, 1, 2.

This ensures every element in the list is processed once.

Add the Current Element to the Sum
    s += nums[i]

At each loop iteration:

The element at index i is accessed: nums[i].

It is added to the sum s.

Example of how s changes:

When i=0: s = 0 + 2 = 2

When i=1: s = 2 + 4 = 6

When i=2: s = 6 + 6 = 12

Increment the Loop Counter
    i += 1

After processing one element, i increases by 1.

This moves to the next element of the list in the next iteration.

Print the Final Result
print(s // len(nums))

Once the loop ends, the total sum s is 12.

The expression s // len(nums) performs integer division:

12 // 3 = 4

Hence, it prints the average (integer form) of the list elements.

Final Output

4

Probability and Statistics using Python


Tuesday, 11 November 2025

Python Coding Challenge - Question with Answer (01121125)


 Explanation:

1. Defining the Class
class Test:

This line defines a class named Test.

A class in Python is a blueprint for creating objects (instances).

2. Defining a Method Inside the Class
def square(self, n):
    return n * n

This defines a method named square inside the class Test.

self refers to the object that will call this method.

n is a parameter (the number whose square we will calculate).

return n * n computes the square of n and returns it.

3. Creating an Object of the Class
t = Test()

Here, an object t is created from the class Test.

Now, t can access all the methods of the class, including square().

4. For Loop Iteration
for i in range(1, 4):

The range(1, 4) generates the sequence 1, 2, 3.

So the loop will run 3 times with i = 1, then 2, then 3.

5. Calling the Method Inside the Loop
print(t.square(i), end=" ")

On each loop iteration, the method square() is called with the current value of i.

The method returns the square of i.

The print(..., end=" ") prints each result on the same line separated by spaces.

Let’s see what happens in each iteration:

Iteration Value of i t.square(i) Printed Output
1 1 1×1 = 1 1
2 2 2×2 = 4 1 4
3 3 3×3 = 9 1 4 9

Final Output
1 4 9 

Medical Research with Python Tools

Monday, 10 November 2025

Python Coding Challenge - Question with Answer (01111125)

 


Explanation:

1. Class Definition
class Test:
    x = 5

Explanation:

Test is a class with a class variable x initialized to 5.

Class variables are shared across all instances unless overridden in an instance.

2. Creating Instances
t1 = Test()
t2 = Test()

Explanation:

t1 and t2 are instances of the Test class.

Initially, neither instance has its own x, so they both refer to the class variable Test.x, which is 5.

3. Overriding Instance Variable
t1.x = 10

Explanation:

Here, we assign 10 to t1.x.

Python now creates an instance variable x inside t1 that shadows the class variable x.

t2.x still refers to the class variable Test.x.

Test.x remains unchanged (5).

4. Printing Values
print(t1.x, t2.x, Test.x)

Step-by-step Output:

t1.x → 10 (instance variable of t1)

t2.x → 5 (still refers to class variable Test.x)

Test.x → 5 (class variable remains unchanged)

Final Output:

10 5 5

AUTOMATING EXCEL WITH PYTHON

Python Coding Challenge - Question with Answer (01101125)

 


Explanation:

 Creating a list of pairs
pairs = [(1,2),(3,4),(5,6)]

pairs is a list containing three tuples.

Each tuple has two numbers: (x, y).

Initializing sum
s = 0

A variable s is created to store the running total.

Starts at 0.

 Loop starts
for x, y in pairs:

The loop iterates over each tuple in pairs.

On each iteration:

x receives the first value.

y receives the second value.

Iterations:

(1, 2)

(3, 4)

(5, 6)


Modify x inside loop
x += y

Adds y to x.

This does not change the original tuple (tuples are immutable).

This only changes the local variable x.

Step-by-step:

x = 1 + 2 = 3

x = 3 + 4 = 7

x = 5 + 6 = 11


Add new x to sum
s += x

Adds the updated value of x into s.

Running total:

s = 0 + 3 = 3

s = 3 + 7 = 10

s = 10 + 11 = 21


Line 6 — Final output
print(s)

Displays the total sum.

Final Output:
21

AUTOMATING EXCEL WITH PYTHON

Sunday, 9 November 2025

Python Coding Challenge - Question with Answer (01091125)


Explanation:

1. List Initialization
nums = [5, 2, 8, 1]

A list named nums is created.

It contains four elements: 5, 2, 8, 1.

2. Initialize Result Variable
r = 0

A variable r is created to store the running total.

It is initially set to 0.

3. Start of the Loop
for i in range(len(nums)):

len(nums) = 4, so range(4) gives: 0, 1, 2, 3.

This loop runs once for each index in the list.

i represents the current index.

4. Update the Result
    r += nums[i] - i

For each index i:

Take the value at that index → nums[i]

Subtract the index → nums[i] - i

Add that result to r

5. Step-By-Step Calculation
i = 0

nums[0] = 5

5 − 0 = 5

r = 0 + 5 = 5

i = 1

nums[1] = 2

2 − 1 = 1

r = 5 + 1 = 6

i = 2

nums[2] = 8

8 − 2 = 6

r = 6 + 6 = 12

i = 3

nums[3] = 1

1 − 3 = −2

r = 12 − 2 = 10

6. Print Final Output
print(r)

Prints the final result.

Output:
10

 600 Days Python Coding Challenges with Explanation

Friday, 7 November 2025

Python Coding Challenge - Question with Answer (01081125)

 


Step-by-Step Explanation

  1. Dictionary

    d = {"a":2, "b":4, "c":6}

    This dictionary has keys (a, b, c) and values (2, 4, 6).

  2. Initialize a variable

    x = 1

    We start x with 1 because we are going to multiply values.

  3. Loop through the values of dictionary

    for v in d.values(): x *= v
    • On each loop, v takes one value from the dictionary.

    • x *= v means x = x * v.

    Let's see how x changes:

    • First value v = 2: x = 1 * 2 = 2

    • Next value v = 4: x = 2 * 4 = 8

    • Next value v = 6: x = 8 * 6 = 48

  4. Print Result

    print(x)

    Output will be:

    48

Final Output

48

100 Python Projects — From Beginner to Expert

Thursday, 6 November 2025

Python Coding Challenge - Question with Answer (01071125)

 


Step-by-Step Explanation

StepValue of iCondition i > 4Action TakenValue of x
11Nox = x + 11
23Nox = x + 34
35Yes (5>4)continue → Skip adding4
46Yes (6>4)continue → Skip adding4

What is happening?

  • The loop goes through each number in the list a.

  • If a number is greater than 4, the continue statement skips adding it.

  • Only numbers less than or equal to 4 are added to x.

So:

x = 1 + 3 = 4

Final Output

4

PYTHON INTERVIEW QUESTIONS AND ANSWERS

Wednesday, 5 November 2025

Python Coding Challenge - Question with Answer (01061125)

 


Step-by-Step Execution

Loop Stepi ValueExpression (i + value)New value CalculationUpdated value
Start2
1st loop11 + 2 = 32 + 35
2nd loop22 + 5 = 75 + 712
3rd loop33 + 12 = 1512 + 1527

✅ Final Output

27

Why this happens?

Each loop uses the updated value to calculate the next addition.
So the value grows faster (this is an example of cumulative feedback in loops).

PYTHON FOR MEDICAL SCIENCE

Tuesday, 4 November 2025

Python Coding Challenge - Question with Answer (01051125)

 


Step 1:

count = 0
We start with a variable count and set it to 0.

Step 2:

for i in range(1, 5):
  • range(1,5) means numbers from 1 to 4
    (remember, Python stops 1 number before 5)

So the loop runs with:

i = 1 i = 2 i = 3
i = 4

Step 3:

count += i means:

count = count + i

So step-by-step:

icount (before)count = count + icount (after)
100 + 11
211 + 23
333 + 36
466 + 410

Step 4:

print(count) prints 10


Final Output:

Monday, 3 November 2025

Python Coding Challenge - Question with Answer (01041125)

 


Step-by-step explanation:

  1. range(3) → gives numbers 0, 1, 2.

  2. The loop runs three times — once for each i.

  3. Inside the loop:

    • The first statement is continue.

    • continue immediately skips the rest of the loop for that iteration.

    • So print(i) is never reached or executed.

 Output:

(no output)

๐Ÿ’ก Key point:

When Python hits continue, it jumps straight to the next iteration of the loop — skipping all remaining code below it for that cycle.

So even though the loop runs 3 times, print(i) never runs at all.

Application of Python Libraries in Astrophysics and Astronomy

Sunday, 2 November 2025

Python Coding Challenge - Question with Answer (01031125)

 


Step-by-step explanation:

  1. Dictionary d → {1:10, 2:20, 3:30}

    • Keys → 1, 2, 3

    • Values → 10, 20, 30

  2. .items()
    • Returns key-value pairs as tuples:
      (1, 10), (2, 20), (3, 30)

  3. Loop:

    • First iteration → k=1, v=10 → print(1+10) → 11

    • Second iteration → k=2, v=20 → print(2+20) → 22

    • Third iteration → k=3, v=30 → print(3+30) → 33

  4. end=' '
    • Keeps output on one line separated by spaces.

Output:

11 22 33

 Concept Used:
Looping through a dictionary using .items() gives both key and value, allowing arithmetic or logic to be performed on them together.

Python for Stock Market Analysis


Saturday, 1 November 2025

Python Coding Challenge - Question with Answer (01011125)

 


 Step-by-step explanation:

  1. arr = [5, 10, 15]
    → A list (array) with three elements.

  2. range(0, len(arr), 2)
    → This generates a sequence of numbers starting from 0 up to len(arr)-1 (which is 2),
    → but it skips every 2nd number.

    So the output of range(0, len(arr), 2) is:
    ๐Ÿ‘‰ [0, 2]

  3. Loop runs like this:

    • When i = 0 → arr[i] = arr[0] = 5

    • When i = 2 → arr[i] = arr[2] = 15

  4. print(arr[i], end=' ')
    → Prints the selected elements on the same line (because of end=' ').

Output:

5 15

๐Ÿ‘‰ The code prints elements at even indices (0 and 2) from the list.

Python Projects for Real-World Applications

Thursday, 30 October 2025

Python Coding Challenge - Question with Answer (01311025)

 


Step 1: The list data

data is a list of lists:

[ [1, 2], [3, 4]
]

So, it has two elements:

  • First element → [1, 2]

  • Second element → [3, 4]


๐Ÿ”ธ Step 2: The for loop

for x, y in data:

This line unpacks each inner list into two variables x and y.

  • On first iteration → x = 1, y = 2

  • On second iteration → x = 3, y = 4


๐Ÿ”ธ Step 3: Inside the loop

print(x + y, end=' ')
  • First iteration → x + y = 1 + 2 = 3

  • Second iteration → x + y = 3 + 4 = 7

end=' ' keeps the output on the same line.


Final Output:

3 7

๐Ÿ’ก Quick Tip:

This is called sequence unpacking — it works when each element in the list (like [1, 2]) contains exactly two items to assign to x and y.

Mathematics with Python Solving Problems and Visualizing Concepts

Wednesday, 29 October 2025

Python Coding Challenge - Question with Answer (01301025)

 


Step-by-Step Execution

  1. range(3) → means the loop will normally run for i = 0, 1, 2.


  1. First iteration:

      i = 0
    • print(i) → prints 0

    • if i == 1: → condition False, so it continues.


  1. Second iteration:

      i = 1
    • print(i) → prints 1

    • if i == 1: → condition True

    • Executes break → this stops the loop immediately.


  1. Because the loop is terminated using break,
    the else block is skipped.


Output

0
1

Key Concept

In Python,
for...else and while...else blocks work like this:

  • The else part runs only if the loop completes normally (no break).

  • If a break statement is used, the else block will not execute.


Try Changing It

If you remove the break, like this:

for i in range(3): print(i) else:
print('Finished')

Then output will be:

Python Coding Challenge - Question with Answer (01291025)

 


Explanation:

Import the NumPy Library
import numpy as np

This line imports the NumPy library and gives it a short alias name np.

NumPy provides functions for creating and manipulating arrays efficiently.

Create a NumPy Array
a = np.arange(1,10).reshape(3,3)

np.arange(1,10) → creates a 1D array from 1 to 9 (end is exclusive of 10).
Result: [1, 2, 3, 4, 5, 6, 7, 8, 9]
.reshape(3,3) → converts it into a 3x3 matrix (2D array).
So now:
a =
[[1 2 3]
 [4 5 6]
 [7 8 9]]

Initialize a Variable
total = 0

total will store the running sum of some elements from the array.

Starts at 0.

Loop Through Each Row
for i in range(3):
range(3) → generates numbers 0, 1, 2

These are the row indices of the array a.

So the loop runs 3 times:

1st iteration → i = 0

2nd iteration → i = 1

3rd iteration → i = 2

Access and Add Last Column Element
total += a[i, 2]

a[i, 2] means:

Row = i

Column = 2 (the third column, since index starts at 0)

Now let’s see each iteration:

i a[i,2] total (after addition)
0 3 0 + 3 = 3
1 6 3 + 6 = 9
2 9 9 + 9 = 18

Print the Result
print(total)


Output:

18

APPLICATION OF PYTHON IN FINANCE

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (180) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (27) Azure (8) BI (10) Books (261) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (299) Cybersecurity (29) Data Analysis (25) Data Analytics (16) data management (15) Data Science (242) Data Strucures (15) Deep Learning (98) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (18) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (51) Git (9) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (219) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (12) PHP (20) Projects (32) Python (1238) Python Coding Challenge (964) Python Mistakes (27) Python Quiz (393) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)