Skip to content

Instantly share code, notes, and snippets.

💭
Towards Singularity

Robofied Robofied

💭
Towards Singularity
Block or report user

Report or block Robofied

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View basic_python_Input_Marks.py
## Inputting subjects marks
sub_1 = 40
sub_2 = 50
## Calculating avergare of both subjects
avg_marks = (sub_1+sub_2)/2
View basic_python_ifelse.py
## 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
View basic_python_if.py
## Checking condition if marks>80 then student is good.
if avg_marks >= 80:
print("Student is very good with marks %d" %avg_marks)
View basic_python_function_without_parameter.py
#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
View basic_python_function_with_usecase.py
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))
View basic_python_mutiple_students.py
## 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)
View basic_python_global_local1.py
## 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()
View basic_python_global_local2.py
## 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.
View basic_python_global_local3.py
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)
View basic_python_installing_modules1.py
## 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
You can’t perform that action at this time.