ADVANCED PROGRAMMING CONCEPTS - Python
Subject : ADVANCED PROGRAMMING CONCEPTS - Python (TY A and B Mechanical)
- 10 minutes before
Python Programs:
# Recursion
# Python also accepts function recursion,
# which means a defined function can call itself.
# Recursion is a common mathematical and programming concept.
# It means that a function calls itself.
# This has the benefit of meaning that
# we can loop through data to reach a result.
# The developer should be very careful with recursion as
# it can be quite easy to slip into writing a function
# which never terminates, or one that uses excess amounts of memory
# or processor power.
# However, when written correctly recursion can be
# a very efficient and mathematically-elegant approach to programming.
# import sys
# sys.setrecursionlimit(2000)
# print(sys.getrecursionlimit())
count=0
def greeting():
global count
count+=1
print("Hello",count)
greeting()
greeting()
Output:
Hello 1
.
.
.
Hello 995
Hello 996
Traceback (most recent call last):
File "C:/Users/Hp/PycharmProjects/python_function/12.py", line 26, in <module>
greeting()
File "C:/Users/Hp/PycharmProjects/python_function/12.py", line 24, in greeting
greeting()
File "C:/Users/Hp/PycharmProjects/python_function/12.py", line 24, in greeting
greeting()
File "C:/Users/Hp/PycharmProjects/python_function/12.py", line 24, in greeting
greeting()
[Previous line repeated 993 more times]
File "C:/Users/Hp/PycharmProjects/python_function/12.py", line 23, in greeting
print("Hello",count)
RecursionError: maximum recursion depth exceeded while calling a Python object
# Example of recursion
# finding factorial value of 5
# 0!=1
def fact(n):
if n==0:
return 1
return n * fact(n-1)
result=fact(5)
print("Factorial value=",result)
Output:
Factorial value= 120
#Python Main Function
# Python offers other conventions to define the execution point.
# One of them is using the main() function and the __name__ property of a python file.
# What is __name__ in Python?
# The __name__ variable is a special builtin Python variable
# that shows the name of the current module.
# __name__
#
# __main__
#__name__=23
#print(__name__)
#print(__name__)
#__name__=34
#print(__name__)
# Main function is like the entry point of a program.
# However, Python interpreter runs the code right from the first line.
# The execution of the code starts from the starting line and goes line by line.
# It does not matter where the main function is present or it is present or not.
#print("Welcome")
#__name__=34
def main():
print("Hello World")
#
#main()
if __name__=="__main__":
main()
# Since there is no main() function in Python,
# when the command to run a Python program is given to the interpreter,
# the code that is at level 0 indentation is to be executed.
# However, before doing that, it will define a few special variables.
# __name__ is one such special variable.
# If the source file is executed as the main program,
# the interpreter sets the __name__ variable to have a value __main__.
# If this file is being imported from another module,
# __name__ will be set to the module’s name.
# __name__ is a built-in variable which evaluates to the name of the current module.
Output:
Hello World
#Python Main Function
# Python offers other conventions to define the execution point.
# One of them is using the main() function and the __name__ property of a python file.
# What is __name__ in Python?
# The __name__ variable is a special builtin Python variable
# that shows the name of the current module.
# __name__
#
# __main__
#__name__=23
#print(__name__)
#print(__name__)
#__name__=34
#print(__name__)
# Main function is like the entry point of a program.
# However, Python interpreter runs the code right from the first line.
# The execution of the code starts from the starting line and goes line by line.
# It does not matter where the main function is present or it is present or not.
#print("Welcome")
__name__=34
def main():
print("Hello World")
#
#main()
if __name__=="__main__":
main()
# Since there is no main() function in Python,
# when the command to run a Python program is given to the interpreter,
# the code that is at level 0 indentation is to be executed.
# However, before doing that, it will define a few special variables.
# __name__ is one such special variable.
# If the source file is executed as the main program,
# the interpreter sets the __name__ variable to have a value __main__.
# If this file is being imported from another module,
# __name__ will be set to the module’s name.
# __name__ is a built-in variable which evaluates to the name of the current module.
Output:
#print("File1 __name__ = %s" % __name__)
print("File1 __name__ =", __name__)
if __name__ == "__main__":
print("File1 is being run directly")
else:
print("File1 is being imported")
Output:
File1 __name__ = __main__
File1 is being run directly
import file1
print("File2 __name__ =",__name__)
if __name__ == "__main__":
print("File2 is being run directly")
else:
print("File2 is being imported")
Output:
File1 __name__ = file1
File1 is being imported
File2 __name__ = __main__
File2 is being run directly
import file1
import file2
print("File3 __name__ =",__name__)
if __name__ == "__main__":
print("File3 is being run directly")
else:
print("File3 is being imported")
Output:
File1 __name__ = file1
File1 is being imported
File2 __name__ = file2
File2 is being imported
File3 __name__ = __main__
File3 is being run directly
Google Meet Video Recording:
Present Roll Numbers:
TYA_02 Shradhha Gajakosh
TYA_03 Gayatri Joshi
TYA_04 Vaishnavi Lakheri
TYA_05 Saleha Mirjkar
TYA_06 Madhuri Parchandrao
TYA_08 Deepjyoti Sathe
TYA_09 Rutuja Tarapurkar
TYA_10 Dhananjay Admane
TYA_11 Amol Sul
TYA_12 Dnyaneshwar Bansode
TYA_13 Atish Jadhav
TYA_15 Samarth Chavan
TYA_16 Saurabh Chavan
TYA_17 Shreeyash Chavan
TYA_18 Yogesh chavan
TYA_22 Onkar deokar
TYA_25 Yash Gadekar
TYA_29 Yuvraj Shelar
TYA_35 Parchandrao Chandragupta Vinayak
TYA_37 Atharv Joshi
TYA_38 Saurabh Kadasare
TYA_39 ayush Kale
TYA_41 Prathmesh Kirgat
TYA_42 Sachin Kshirsagar
TYA_44 Mangesh Misal
TYA_45 Suraj More
TYA_48BHUSHAN NARUTE
TYA_49 Sachin Waghmare
TYA_50 Pranay Disale
TYA_53 Nihal Mujawar
TYA_55 Prajwal Musale
TYA_57 PRITAM Padage
TYA_58 Paras Mule
TYA_59 Shailesh Pawar
TYA_62 Sunil Sadul
TYA_63 Aazam Shaikh
TYA_64 Sohel Shikalgar
TYA_65 Pravin Somadale
TYA_66 Shashikant Thorat
TYA_68 Chaitan Wadekar
TYA_73 Ashley A Thomas
TYA_76 Ashutosh vardole
TYB_01 Samruddhi Deshpande
TYB_02 Prerana Ekatpure
TYB_04 Snehal Mane
TYB_05 Vaishali More
TYB_06Dhanashree Sonawane
TYB_09 Adesh Bankar
TYB_10 Aniket Bansode
TYB_11 Vinayak Bapat
TYB_12 Hritik Bhosale
TYB_13 Vaibhav Bhosale
TYB_14 Pratik Deshmukh
TYB_16 Manthan Dixit
TYB_18 Suraj Gavali
TYB_20 Dhondiram Waghmode
TYB_21 Nilesh Kadam
TYB_22 Abhijit Khote
TYB_26 AMOL MALI
TYB_28 Om Metkari
TYB_31 JAYDEV NANAWARE
TYB_32 Saurabh Nikam
TYB_33 Ridham Parmar
TYB_34 Madan Patil
TYB_35 Santosh Patil
TYB_36 Yogesh Patil
TYB_37 Omkar Pawar
TYB_38 Shubham Pawar
TYB_41 Yasar Khatik
TYB_44 Aftab Shaikh
TYB_46 Dipak Shinde
TYB_49 Dnyaneshwar Shitole
TYB_50 Harshvardhan Ubale
TYB_51 Mohit Taur
TYB_52 Sachin Kengar
TYB_54 Rohit Vidhate
TYB_55 Saurabh Wadekar
TYB_58 SANDIP BAGUL
TYB_59 Pranav Bhandare
TYB_60 Avinash Dhabade
TYB_61 Rupesh Dhere
TYB_62 Nitin Eakamalli
TYB_63 Saurabh Gaikwad
TYB_66 Omkar Jagtap
TYB_70 Akash Mane
TYB_71 Onkar Kale
TYB_73 vaibhav Jagtap
TYB_75 Hrushikesh Walujkar
TYB_77 Sumit Patwari
TYB_78 Harshada Patil
No comments:
Post a Comment