This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Inputting subjects marks | |
sub_1 = 40 | |
sub_2 = 50 | |
## Calculating avergare of both subjects | |
avg_marks = (sub_1+sub_2)/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Checking condition if marks>80 then student is good. | |
if avg_marks >= 80: | |
print("Student is very good with marks %d" %avg_marks) | |
## Checking condition if marks is in range(60,80) then student is average. | |
elif (avg_marks<80 and avg_marks> 60): | |
print("Student is average with marks %d" %avg_marks) | |
## Checking condition if marks is below 60 then needs improvement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Checking condition if marks>80 then student is good. | |
if avg_marks >= 80: | |
print("Student is very good with marks %d" %avg_marks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Functions without parameters | |
def functions_without_para(): | |
print("Hey! You know how to create functions") | |
functions_without_para() | |
#[Output]: | |
#Hey! You know how to create functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def student(name,sub1,sub2): | |
avg_marks = (sub1+sub2)/2 | |
if avg_marks >= 80: | |
print("%s is very good student with marks %d" %(name,avg_marks)) | |
## Checking condition if marks is in range(60,80) then student is average. elif (avg_marks<80 and avg_marks> 60): | |
print("%s is average student with marks %d" % (name,avg_marks)) | |
## Checking condition if marks is below 60 then needs improvement | |
else: | |
print("%s needs improvement %d" % (name,avg_marks)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## List of multiple students | |
l = [('Ram',80,90),('seeta',50,30),('Jerry',20,45),('Bellow',60,70),('Geeta',98,78)] | |
## For checking the marks ## iterating over list | |
## First unzipping each element as it is stored as a tuple. | |
## If you don't know this concept don't worry will cover this in intermediate python. | |
## Here just for your understanding how useful to define a function | |
for e in l: | |
student(*e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Creating a global variable | |
a = "Hello! Welcome to python tutorials." | |
def func(): | |
## It will automatically takes the value of global variable as we didn't define any other local variable "a" inside fubction. | |
print(a) | |
## Calling the function toc check what value of "a" will it print. | |
func() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Creating a global variable | |
a = "Hello! Welcome to python tutorials." | |
def func(): | |
## It is another local variable of function func() | |
a = "Hello! Everyone" | |
print(a) | |
## Here it will print the value of global variable "a" which is not changed even if the a's value | |
## in function func() is changed because func() is not accessing the global variable and then chnaging it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = "Hello! Welcome to python tutorials." | |
def func(): | |
## Now by using "global" keyword we are actually modifying the global variable a instead of creating a new local variable. | |
global a | |
## assigning a new value | |
a = "Hello!" | |
print(a) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Already existing standard library, comes already installed while installing Python package. | |
import os | |
## using list dir, listing the files and folders in that particular directory. | |
for e in os.listdir(r'C:\Users\Robofied\Documents\getting started with python'): | |
print(e) | |
#[Output]: | |
## These are the output files conyained in the directory. | |
.ipynb_checkpoints |
OlderNewer