Skip to content

Instantly share code, notes, and snippets.

@Robofied
Robofied / basic_python_Input_Marks.py
Created February 2, 2019 12:35
Machine Learning Codes
## Inputting subjects marks
sub_1 = 40
sub_2 = 50
## Calculating avergare of both subjects
avg_marks = (sub_1+sub_2)/2
@Robofied
Robofied / basic_python_ifelse.py
Created February 2, 2019 12:39
Machine Learning Codes
## 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
## Checking condition if marks>80 then student is good.
if avg_marks >= 80:
print("Student is very good with marks %d" %avg_marks)
#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
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))
## 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)
## 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()
## 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.
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)
## 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