Python Daily Question - 123
Step-by-Step Explanation:
1. Initialization:
a = "Hii"
b = "mani"
c = 6
a is a string "Hii".
b is a string "mani".
c is initialized to 6.
2. Outer Loop:
for i in a:
This loop iterates over each character in the string a.
The characters of a are 'H', 'i', and 'i'.
3. Inner Loop:
for j in b:
This loop iterates over each character in the string b.
The characters of b are 'm', 'a', 'n', and 'i'.
4. Condition and Increment:
if i != j:
c = c + 2
This statement checks if the characters i from a and j from b are not equal. If they are not equal, c is incremented by 2.
Detailed Iteration:
First iteration (i = 'H'):
j = 'm': H != m, so c = c + 2 → c = 6 + 2 = 8
j = 'a': H != a, so c = c + 2 → c = 8 + 2 = 10
j = 'n': H != n, so c = c + 2 → c = 10 + 2 = 12
j = 'i': H != i, so c = c + 2 → c = 12 + 2 = 14
Second iteration (i = 'i'):
j = 'm': i != m, so c = c + 2 → c = 14 + 2 = 16
j = 'a': i != a, so c = c + 2 → c = 16 + 2 = 18
j = 'n': i != n, so c = c + 2 → c = 18 + 2 = 20
j = 'i': i == i, so c remains 20
Third iteration (i = 'i'):
j = 'm': i != m, so c = c + 2 → c = 20 + 2 = 22
j = 'a': i != a, so c = c + 2 → c = 22 + 2 = 24
j = 'n': i != n, so c = c + 2 → c = 24 + 2 = 26
j = 'i': i == i, so c remains 26
Final Value of c:
After all the iterations, the value of c is 26.
Final Output: 26
So, the final value of c is 26.
#coding_with_mani #python #code #viral #youtubeshorts #shorts #short #youtube #code #india #code #viral #youtubeshorts #shorts #short #youtube #code #india
#pythonquestions #python #coding #youtube #pythonprogramming #code #programminglanguage #pythonprogramming
#shorts #python #code #viral #trending #youtubeshorts #sql #sqlserver #data #database #daily #dailyshorts #dailyquestions #dailyseries