DEV Community

Sanjay Sugumar
Sanjay Sugumar

Posted on

python RESTART #4

sep in Python means separator. It is used inside using sep=. For example, print("A","B",sep="-") gives output A-B.


What is Function?
A function is a block of code that performs a specific task. It helps reuse code again and again without writing it multiple times.


Arguments?
A function is a block of code that performs a specific task. It helps reuse code again and again without writing it multiple times.

`def add(a, b):
print(a + b)

add(5, 3)`

In This Code "add (5,3)" is a Arguments


Polymorphism:
print(len("Python")) # string
print(len([1,2,3])) # list


Method Overloading:
Method Overloading means using the same function name to do different tasks with different arguments.
`
def add(a, b=0):
print(a + b)

add(5)
add(5, 3)`

*Here, the same add() function works with one argument and two arguments.
*Same Function name with different number of arguments or with different type of arguments.


Addition of first n numbers:
THE STORY { The famous story of Carl Friedrich Gauss adding numbers tells of a clever 10-year-old boy who outsmarted his teacher by instantly finding the sum of all integers from 1 to 100. Instead of adding them one by one, he discovered a brilliant pattern that revolutionized arithmetic }

n * (n+1)

2

10 * 11

2


HERE THE GIRL WAS ASKINNG THE PARENT TO GIVE ME DAILY GIVE ME ONE RUPEE

bag = 0
day = 1
while day<=10:
bag = bag + day
day = day + 1
print(bag)


Addition of First n Numbers:

total = 0 #
no = 1
while no<=10:
total = total + no
no = no + 1
print(total)


Additive Identity
5 + 0 = 5
12 + 0 = 12


Multiplicative Identity

5 * 1 = 5
12 * 1 = 12


Multiplication of First n Numbers:

total = 1 #
no = 1
while no<=5:
total = total * no
no = no + 1
print(total)


FACTORIAL

factorial = 1 #
no = 1
while no<=5:
factorial = factorial * no
no = no + 1
print(factorial)

5! --> 5 * 4 * 3 * 2 * 1


factorial = 1 #
no = 5
while no>=1:
factorial = factorial * no
no = no - 1

print(factorial)

feet = 50
up = 2
day = 1
feet = feet - up
day = day + 1
feet = feet - up
day = day + 1
feet = feet - up
day = day + 1
feet = feet - up
day = day + 1


FROG STORY:
ONE FROG WAS INSIDE THE 50 FEET WELL DAILY TWO STEP UP AND DAILY ONE STEP DOWN ******

feet = 50
up = 2
down = 1.25
day = 0
while feet>0:
feet = feet - up + down
day = day + 1
print(day)


Top comments (0)