Computer Science, asked by Harikesh51200, 11 months ago

Write a simple python function to increase the value of any number by a constant "C=5" and write another simple function to update the value of "C" to any other value like 6,7,8, etc.

Answers

Answered by poojan
1

Program of python functions which updates a constant and increments a value.

Language used : Python Programming

Program :

c=5

def increasevalue(n):

  n=n+c

  return n

val=int(input("Enter a value to be incremented: "))

print("Before updation, the incremented value is : ",increasevalue(val))

def changeconstvalue(m):

  global c

  c=m

  return c

c=changeconstvalue(int(input("Enter the constant updation value: ")))

print("After updation, the incremented value is : ", increasevalue(val))

Input :

Enter a value to be incremented: 10

Enter the constant updation value: 100

Output :

Before updation, the incremented value is : 15

After updation, the incremented value is : 110

Explanation :

  • Intialize a variable with 5, and write a function that takes a value and increments it by 5.

  • The value need to be given by the user.

  • Next, take another user input about changing the constant value.

  • Then pass it through a function that has the capability of changing the constant using global keyword, so that the constant value changes dynamically.

  • And then, pass the same variable through incrementing function and this time, the value should be incremented by the updated increment value.

Learn more :

  • Advantages of Programming in python

       brainly.in/question/11007952

  • Indentation is must in python. Know more about it at :

       brainly.in/question/17731168

Similar questions