Subscribe this Blog

Wikipedia

Search results

Notifications and New Posts!

Tuesday, November 24, 2020

YouTube Premiered Lecture - November 25, 2020, 11:00 AM - ADVANCED PROGRAMMING CONCEPTS - Python (TY A and B)

   ADVANCED PROGRAMMING CONCEPTS - Python

Due to internet/network connectivity issue, 

I will be conducting lecture on YouTube. 
Lecture will start at sharp 11:00 AM.
Please attend it. And if you have any questions then
please ask in Comment box below the video.

Topics which will be covered in this session are: 1. Python Module 2. Python - Try, Except, Finally block

Due to Internet connectivity issue making premiered video can be great tool 
where without any kind of interruption students can watch lecture video.

YouTube Session
ADVANCED PROGRAMMING CONCEPTS - Python (TY A and B)
Punyashlok Ahilyadevi Holkar Solapur University.
TY Mechanical Engineering Students.
Ref.: https://www.w3schools.com/python/
For more clarity please watch YouTube video with 360p or 480p Quality. 
Please click on the three vertical dots on video then select Quality option.
Then select resolution as 360p or 480p.

Please write you Name and Roll Number in Live Chat Box/Comment Box (below Video in YouTube) to capture your attendance.
YouTube Video Lecture: 
This video is premiered it will start at sharp 11:00 AM.
To ask questions in Chat Box/Comment Box :





Facebook Event Registration : Click here

Python Programs:

mymodule.py file

# What is a Module?
# Consider a module to be the same as a code library.
# A file containing a set of functions you want to include in your application.

def greeting(name):
  print("Hello, " + name)




person1 = {
  "name": "Ram",
  "age": 36,
  "country": "India"
}

import mymodule

mymodule.greeting("Rahul")

#When using a function from a module, use the
# syntax: module_name.function_name

Output:
Hello, Rahul

import mymodule

a = mymodule.person1["age"]
n=mymodule.person1["name"]
c=mymodule.person1["country"]
print("Age of Ram:",a)
print("Name of person:",n)
print("Country: ",c)
Output:
Age of Ram: 36
Name of person: Ram
Country:  India

# Re-naming a Module
# You can create an alias when you import a module, by using the "as" keyword:


import mymodule as mm

a = mm.person1["age"]
n=mm.person1["name"]
c=mm.person1["country"]
print(a)
print(n)
print(c)
Output:
36
Ram
India

# Built-in Modules
# There are several built-in modules in Python,
# which you can import whenever you like.

# Example
# Import and use the platform module:

import platform

x = platform.system()
print(x)
Output:
Windows

# Using the dir() Function
# There is a built-in function to list all the function names (or variable names)
# in a module. The dir() function:


import platform
import mymodule
x = dir(platform)
print(x)

y=dir(mymodule)
print(y)

Output:
['_WIN32_CLIENT_RELEASES', '_WIN32_SERVER_RELEASES', '__builtins__', '__cached__', '__copyright__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', '_comparable_version', '_component_re', '_default_architecture', '_follow_symlinks', '_ironpython26_sys_version_parser', '_ironpython_sys_version_parser', '_java_getprop', '_libc_search', '_mac_ver_xml', '_node', '_norm_version', '_platform', '_platform_cache', '_pypy_sys_version_parser', '_sys_version', '_sys_version_cache', '_sys_version_parser', '_syscmd_file', '_syscmd_uname', '_syscmd_ver', '_uname_cache', '_ver_output', '_ver_stages', 'architecture', 'collections', 'java_ver', 'libc_ver', 'mac_ver', 'machine', 'node', 'os', 'platform', 'processor', 'python_branch', 'python_build', 'python_compiler', 'python_implementation', 'python_revision', 'python_version', 'python_version_tuple', 're', 'release', 'sys', 'system', 'system_alias', 'uname', 'uname_result', 'version', 'win32_edition', 'win32_is_iot', 'win32_ver']
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'greeting', 'person1']

# Import only the person1 dictionary from the module:

from mymodule import person1

print ("Age:",person1["age"])
print("Name:",person1["name"])
print("Country:",person1["country"])

# Note: When importing using the from keyword,
# do not use the module name when referring to elements in the module.
# Example:
# person1["age"],
# not mymodule.person1["age"]
Output:
Age: 36
Name: Ram
Country: India



# Python Try Except

# The try block lets you test a block of code for errors.
# The except block lets you handle the error.
# The finally block lets you execute code,
# regardless of the result of the try- and except blocks.

# Exception Handling
# When an error occurs, or exception as we call it,
# Python will normally stop and generate an error message.
#
# These exceptions can be handled using the try statement:

#x=5

#print(x)        #it gives error

#x=5
try:
  print("Value of x:",x)
except:
  print("An exception occurred!!!")
  print("Welcome")
Output:
An exception occurred!!!
Welcome

# Many Exceptions
# You can define as many exception blocks as you want,
# e.g. if you want to execute a special block of code for a special kind of error.

# Example
# Print one message if the try block raises a NameError and another for other errors.

#The try block will generate a NameError, because x is not defined:

#x=20
#print("Value of x from main python script",x)

# try:
#   print("Value of x in try block",x)
# except NameError:
#   print("Variable x is not defined")
# except SyntaxError:
#   print("Something else went wrong")



#x=20
try:
  print(x)
except NameError:
  print("Variable x is not defined")
except SyntaxError:
  print("Something else went wrong")

Output:
Variable x is not defined

# Else
# You can use the else keyword to define
# a block of code to be executed if no errors were raised:

# Example
# In this example, the try block does not generate any error:


try:
  x=20
  print(x)
except SyntaxError:
  print("Something went wrong")
except NameError:
  print("x is not defined.")
else:
  print("Nothing went wrong")
Output:
20
Nothing went wrong

# Else
# You can use the else keyword to define
# a block of code to be executed if no errors were raised:

# Example
# In this example, the try block does not generate any error:

try:
  pass
  #print("Hello")
except:
  print("Something went wrong")
else:
  print("Nothing went wrong")
Output:
Nothing went wrong

# Finally
# The finally block, if specified,
# will be executed regardless if the try block raises an error or not.

# Example
try:
  x=20
  print(x)
except:
  print("Something went wrong")
finally:
  print("The 'try except' is finished")
Output:
20
The 'try except' is finished

# Raise an exception
# As a Python developer you can choose to throw an exception if a condition occurs.
#
# To throw (or raise) an exception, use the raise keyword.
#
# Example
# Raise an error and stop the program if x is lower than 0:

x = -1

if x < 0:
  raise Exception("Sorry, x is negative")
Output:
Traceback (most recent call last):
  File "C:/Users/Hp/PycharmProjects/Python_Try_Except ion_Handling/6.py", line 12, in <module>
    raise Exception("Sorry, x is negative")
Exception: Sorry, x is negative

# The raise keyword is used to raise an exception.
#
# You can define what kind of error to raise, and the text to print to the user.
#
# Example
# Raise a TypeError if x is not an integer:

#x = "hello"
#print(type(x))
x=20
if not type(x) is int:
  raise TypeError("Only integers are allowed")
else:
  print("Value of x is integer!!!")
  print("Exception is not raised!!!")
Output:
Value of x is integer!!!
Exception is not raised!!!

Present Students:
SAMARTH CHAVAN​TA15
Dhanashree Sonawane ​TYB06
Akshay Pansare ​TA43
TYB_44 Aftab Shaikh ​TYB_44
Hritik Bhosale ​TB 12
Akash Ajgar ​TY B 56
Mohit Taur ​TYB_51
ADESH BANKAR ​TYB_09
Om Metkari ​TB-28
TYB_41 Yasar Khatik ​TYB_41
Nilesh Kadam ​TYB - 21
TYA_44 Mangesh Misal ​TYA_44
Vijay Mali ​TYB_26 AMOL MALI
Rohit Chatage ​TYB_40
Prathmesh Kirgat ​TYA_41
Prajwal Musale ​TYA_55
Omkar Jagtap ​TYB_66
ABHI KHOTE ​TYB_22
SALIM SHAIKH ​TYB_45
Nikhil Mundhe ​TYA47
TYB_33 Ridham Parmar ​TYB_33
Jaydev nanaware ​TYB_31
Pravin Somdale ​TYA_65 
TYA_13 Atish Jadhav ​TYA_13
8D SOUL Official 
Namrata Parvat ​TYA07
Pranay Disale ​Pranay Disale TYA_50
deepjyoti sathe ​TA08
Deepak Shinde ​TYB 46
Milind Jagadale ​TA34
Samarth Mane-Deshmukh ​TYA_51
Onkar Phalake ​TY A 60
manthan dixit ​TYB16
Irfan Mulani ​TYA_54
TYB_71_Onkar Kale ​TY_B_71
Omkar Patil ​TA_70
Ganesh Todkar ​TA24
OMKAR PAWAR ​TYB_37
saurabh chavan ​TYA_16
Harshvardhan Ubale ​TYB_50
Yash Gadekar ​TYA_25
TYB_34 Madan Patil ​TYB_34
Saleha Mirjkar ​TYA-05
Akash Mane ​TYB_70
sumit Patwari ​TYB_77
TYB_48 Vishwajit Shinde ​TB 48
TYA_29 Yuvraj Shelar ​TYA-29
TYB_17 Abhinay Gaikwad ​TB17
TYA_35 Parchandrao Chandragupta Vinayak
Sachin Waghmare ​TA49
TYB_41 Yasar Khatik ​TB 41
TYB_03 Arati Lale ​TB 03
Sushant Jadhav ​TYB_65
Shashikant Thorat ​TYA_66
TYA_73 Ashley Thomas ​TYA_73
Snehal Mane ​TYB_04
TYB_55 Saurabh Wadekar ​TYB 55
TYA_64 Sohel Shikalgar ​TY A 64
shailesh pawar ​TYA_59
TYB_54 Rohit Vidhate ​TYB_54
AMIT YELE ​TYB-76
TYB_53 Krishna Langote ​TYB_53
TYB_17 Abhinay Gaikwad ​​TB17
Atharv Joshi ​TYA_37
TYA_56 Mr.R.R Nagargoje ​TYA~56
Suraj More ​TYA 45
TYA_57 PRITAM Padage ​TYA57
Dnyaneshwar Bansode ​TA_12
Shreeyash Chavan ​TYA 17
Shubham Deokar ​TB72
TYA_57 PRITAM Padage ​TYA57
Aditya Motewar ​TYA46
Madhuri Parchandrao ​TYA_06
Rutik Godse ​TYA_31
Its_Pranav_ Show ​TYB 59
PrerAna Ekatpure ​TYB02
Kiran Kasulwar ​TY -A 20
Rohit Salgar ​TYB 74
TYB_41 Yasar Khatik ​TYB_41
VINAYAK Gawali ​TYA_72
Santosh Patil ​TYB_35
SUNIL Sadul. ​TY-A_62
TYB_58 SANDIP BAGUL ​TYB-58
Shraddha gajakosh ​TY_A_02
Yogesh patil ​TYB_36
Gayatri Joshi ​TYA_03
Om Metkari ​TYB-28
TYA_44 Mangesh Misal ​TYA_44
Kashiling Sarak ​TYB_42
ADESH BANKAR ​TYB_09
Vaibhav Bhosale ​TB 13
TYB_17 Abhinay Gaikwad ​​TB17
TYB_75 Hrushikesh Walujkar ​TYB_75
sumit Patwari ​TYB_77
TYB_41 Yasar Khatik ​TYB_41
Vaishnavi Lakheri ​TYA_04
Samruddhi Deshpande ​TYB_01
TYB_20 Dhondiram Waghmode ​TB20
bharat burungale ​TA14


No comments:

Post a Comment