Mayank Vikash

Day 4 of 100 Days of Python

 

Day 4 of 100 Days of Python

Today, I started Nested Loop. It is a for or while loop running inside another loop. It is mainly used for executing repetitive tasks, while another macro task is simultaneously being executed.  


# Write a program that inputs the number of rows and columns, then prints an alternating matrix of 1s and 0s where the element is 1 if the sum of its row and column indices is even, and 0 otherwise


r = int(input("Enter number of rows "))

c = int(input("Enter number of columns "))



for i in range(0,r):

        for j in range(0,c):

            s = i + j

            if s%2==0:

                print(1, end=" ")

            else:

                print(0, end=" ")

        print()

```The question for this program was to input the number of rows and columns into two different variables. And create a matrix, but at the position where the row value and column value add up to an even, a 1 should be placed there. And where they add up to an odd number, a 0 should be placed.

Day 3 of 100 Days of Python

Day 3 of 100 Days of Python

 

Today is June 22nd, the third day of the 100 Days of Python Coding challenge. I am doing some Number Manipulation questions in Python that use a while loop and digit extraction.The first program checks for an Armstrong Number. To solve it, I use a while loop and a counter variable to get the number of digits in the input number. Then, with another loop, I use the while loop again, but this time extract a digit, raise it to the power of its number of digits and then add their sum in a separate variable 's'.![image.png](https://raw.githubusercontent.com/mayankvikash/mayankvikash.github.io/main/assets/img/image-7.png)```python
# Armstrong Number. An Armstrong number (like 153 or 371) is a number equal to the sum of its own digits raised to the power of the number of digits
n = int(input("Enter a number to check for Armstrong Number"))
p = n
s=0
c = 0
while n>0:
    c=c+1
    n = n//10
n = p
while n>0:
    d = n%10
    print(f"Current digit: {d}")
    s = d**c + s
    print(f"Current sum: {s}")
    n = n//10
print(f"No. of digits: {c}")
print(f"Sum of digit raised to number of digit: {s}")
if s==p:
    print("It is Armstrong Number")
else:
    print("It is not")
```I learned that in Python, instead of Math.pow, we use double asterisk (**) to raise a number to a power. I also discovered another method for calculating the number of digits in an input number. It is that we can use this syntax, `len(str(num))` which converts the number into a string and calculates its length.

The second program is to check whether a number is Prime number or not. Like all the other previous programs, this one was also very easy. Interestingly, while solving this program, I got to know a little trick.If I use break in for loop after a if statement  and just after that if I put an else, then if the loop runs completely,  meaning if the break statement does not get the control out of the loop block, then the statement under else will be executed, as showin in the console output.```python
n = int(input("Enter a number to check for prime number "))

for i in range(2, n):
    if n%i==0:
        print(f"{n} is divisible by {i}")
        break
else:
    print(f"{n} is prime number"
```

Day 2 of 100 Days of Python

Today is Day 2 of my 100 Days of Python Challenge. Yesterday, I learned about the Conditional Statements like if, else and elif, which are used to execute a block of code if the required conditions are met. Using these, I solved two incredibly common coding questions that are asked in the exams.Today's goal is to solve some number manipulation questions in Python to brush up on my coding knowledge. The first program is very simple. It basically inputs (asks for a 3-digit number) a three-digit number. Then, using division and modulo operations to extract the digit into 3 different variables, without using loops. And finally, adds the digits, stores and prints the summation of its digits. While writing this program, I learned that using // means that only the integer division takes place (ex. 5//2 = 2 and 5/2 = 2.5).

SC1

```python
# number manipulation in python
# Digit Extraction and sum of digit of a 3-digit number
n = int(input("Enter a number of 3 digit"))
d1 = n //100
#  '//' for integer division, ex- 5//2 = 2 instead of 2.5
d2 = (n//10)%10
d3 = n%10

dsum = d1 +d2 +d3

print(f"The digits are: {d1}, {d2}, and {d3}")
print(f"Sum of 3 digits: {dsum}")
```The second program uses a while loop to reverse the input number. And checks for a palindrome number. When a reversed number is equal to the original number, it is called a palindrome number. I will focus more on these types of questions starting tomorrow. 


SC2

```python
# Take an integer input, reverse it mathematically, and determine if it's a palindrome
# palindrome is number equal to its reversed like 99 and 88 or 121
n = int(input("Enter a number to check for palindrome"))
og = n
rn = 0
while n>0:
    d = n%10
    rn = (rn*10) + d
    n = n//10
print(rn)
if og==rn:
    print("It is palindrome")
else:
    print("It is not")
```

Learned the while loop and how to reverse a number using a loop and an extra variable.```python
rn = (rn*10) + d
```The original value of rn is 0. During the first iteration, 0*10 + d = 0 + d = d. In the second iteration, rn = d*10 + d. Since the value of d changes to the last digit of the number after it is divided by 10, the final value of rn is the reverse of the original number.ex - 1451st loop: d = 5, rn = 0 + d = 5, n = 145//10 = 142nd loop: d = 4, rn = 5 * 10 + d = 54, n = 14//10 = 13rd loop: d = 1, rn = 54 * 10 + d = 541, n = 1//10 = 0After the third loop, the condition n>0 is not true. So the loop stops, and the final value of rn is 541, which is the reverse and palindrome of 145.

Day 1 of 100 Days of Python



Today is the first day of the coding challenge I took (although by the time I finish writing this post, it will be past 12 in the morning).




Yesterday, I played around with basic Python syntax, such as print, which lets us display text in the console. Today, my goal is to learn more about basic Python syntax and work through a few practice questions.














This was one problem that I solved yesterday. These kinds of questions are asked repeatedly in board exams, and I am very familiar with them. I will do more of these kinds of questions tomorrow.




#Electricity Bill question in Python

# An electricity board charges for electricity delivered to domestic consumers based on the number of units consumed.

# For the first 100 units: ₹4.00 per unit

# For the next 200 units: ₹6.00 per unit

# Beyond 300 units: ₹8.00 per unit

# A fixed meter charge of ₹200 is added to every bill.

# Given the units consumed, calculate the total bill.




units = int(input("Enter units consumed"))

fixc = 200

amt = 0.0

if units <=100:

amt = 4.00*units

elif units <= 300:

amt = (100*4.00) + ((units -100)*6.00)

else:

amt = (100*4.00) + (200*6.00) + ((units-300)*8.00)

tbill = amt + fixc

print(f"Total amount to be paid: {tbill}")

This is the second program:














It is also one of the most asked types of questions in the board exam.




Here is the code




# Input the basic salary of an employee. Compute the Gross Salary and Net Salary based on the following:

# HRA (House Rent Allowance) = 20% of Basic

# DA (Dearness Allowance) = 50% of Basic

# Gross Salary = Basic + HRA + DA

# Tax Deduction: If Gross Salary is over ₹1,00,000, deduct 10% of Gross as tax; otherwise, tax is 0.

# Net Salary = Gross Salary - Tax Deduction







bs = int(input("Enter basic salary"))

hra = 0.2 * bs

da = 0.5*bs

gross = bs + hra + da

tax = 0.0




if gross>100000:

tax = 0.1*gross

else:

tax = 0.0

net = gross - tax




print(f"Basic Salary: {bs}")

print(f"hra: {hra}")

print(f"da: {da}")

print(f"tax: {tax}")

print(f"net salary: {net}")

After practising these programs, I am familiar with the input syntax of Python as well as Conditional Statements. For Tomorrow, I plan to practise some number manipulation exercises.

100DaysofPython: Day 0

Python is one of the most popular programming languages. It is simple to understand and easy to learn for beginners. Although I am not exactly a beginner. I did spend 4 years in school (from grade 9 to 12) in school learning Java and practising problems like String Manipulation, Array Operations and recently Stacks and Queues.

I am starting college this year, and the syllabus includes Python. So, to get used to a completely new programming language and to brush up on my existing programming skills, I have decided to challenge myself with the 100 Days of Python Challenge.

As the name suggests, I will practise Python for the next 100 days and give my all to at least get to the intermediate level. I will also try some interesting Python projects to showcase on my GitHub profile.

I was supposed to post this, actually, yesterday, on 19th June, which I decided to call Day 0 (for getting to know basic Python commands like 'print' statements and variables). But, I started late at night, so I didn't get to finish writing (It's 9:20 am on 20th June at the time of writing this).


SC1

In the above screenshot, it can be seen that I was playing around with basic Python syntax and was able to get the hang of it. Now, instead of 'System.out.println', the simple 'print' seems more natural to me.


SC2


While playing around, I also learned a new thing: Python f-string. 

So basically, unlike Java, I cannot put both a String and an Integer variable in a single print statement. And normally, I would have had to convert the Integer datatype variable into a String to print it alongside the text. But the f-string formatting allows me to use curly braces for variable operations. This was a fun discovery, and I hope to get to know more about it as I proceed to Day 1 of the challenge. 

 Also, I tried a simple variable swapping program in Python. Here is the screenshot of it:

SC3

Here is everything I wrote on Day 0 of 100 Days of Python:

print("This is first line of code")

a = 5
b = 10
print(a+b)
# for printing the summation along with text and not getting an error, 
Use f-string along with curly braces for variables and their operations

print(f"Sum of a and b: {a+b}")

#another way, without using f-string

print("Sum of a and b in old way:" + str(a+b))

print(f"The value of a is {a} and b is {b}")

#swapping values using a third variable

c = a

a = b

b = c

print(f"The value of a: {a} and b: {b} are reversed")

#swapping values of two variables using Python

a, b = b, a

print(f"The value of a is now original {a} and b is original {b} ")

Today is 20th June, 2026. Starting Today, I will practise Python for the next 100 Days with my full effort!