Skip to content

Commit 0381585

Browse files
committed
adding my python files
0 parents  commit 0381585

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1548
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
venv
2+
.idea
3+
__pycache__
4+
*.yaml

2D lists .py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 2D lists = a list of lsit
2+
3+
4+
drinks = ['coffee','Soda','tea']
5+
dinner = ['Pizza','Humburger','Hot dog']
6+
dessert = ['cake','icecreame']
7+
8+
food = [drinks,dinner,dessert]
9+
10+
for i in food:
11+
print(i[0])

AstractClasse.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Prevents a user from creating an object of that class
2+
# + comples a user to override abstract methods in a child class
3+
4+
# abstract class = A class which contains one or more abstract methods
5+
# abstract method = a method that has a declaration but does not have an implementation.fr
6+
7+
8+
from abc import ABC, abstractmethod
9+
class Vehicle(ABC):
10+
@abstractmethod
11+
def go(self):
12+
pass
13+
@abstractmethod
14+
def stop(self):
15+
pass
16+
class Bike(Vehicle):
17+
def go(self):
18+
print("You ride the bike .")
19+
def stop(self):
20+
print("this Bike is stopped")
21+
22+
class Car(Vehicle):
23+
def go(self):
24+
print("You drive the car")
25+
def stop(self):
26+
print('this car is stopped')
27+
28+
29+
car = Car()
30+
bike = Bike()
31+
# truck = Truck()
32+
33+
car.go()
34+
bike.go()
35+
36+
bike.stop()
37+
car.stop()

Dict.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dictionary = A changeable, unOrdered collections of unique key:value pairs
2+
# fast because they use hashing, allow us to access a value quickly
3+
4+
# capitals = {
5+
# "USA":'washington DC',
6+
# "INDIA":'newdelhi',
7+
# 'Russia':'bejings'
8+
# }
9+
#
10+
# capitals.update({'Geramny':"Berlin"})
11+
# capitals.update({'USA':'Las Vegas'})
12+
# capitals.pop('USA')
13+
# # capitals.clear()
14+
15+
# print(capitals['Russia'])
16+
# print(capitals.get('Germany'))
17+
# print(capitals.keys())
18+
# print(capitals.values())
19+
# print(capitals.items())
20+
# print(capitals)
21+
#
22+
# for key,value in capitals.items():
23+
# print(key ,value,end=',')
24+
25+
26+
# nested Dict
27+
28+
29+
test_dict = {'GFG': {'rate': 4, 'since': 2012}}
30+
test_dict['GFG']['rank'] = 1
31+
32+
rate = test_dict['GFG']
33+
print(rate)
34+
print(test_dict)

DictCompreHension.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Dictionary Comprehension = create dictionaries using an expression can replace for loops
2+
# and certain lambda fucntion
3+
4+
5+
# dictionary = {key: expression for (key,value) in iterable}
6+
# dictionary = {key: expression for (key,value) in iterable if conditional }
7+
# dictionary = {key: (if/else) for (key,value) in iterable }
8+
# dictionary = {key: function(value) for (key,value) in iterable }
9+
10+
# cities_temperture = {'Bhubaneswar':34,'Bhadrak':36,'Cuttack':30,'Anugul':23}
11+
# print(cities_temperture)
12+
# print('-' * 50)
13+
# cities_temperture_in_F = {key: round((value -32) * (5/9)) for (key,value) in cities_temperture.items()}
14+
# print(cities_temperture_in_F)
15+
# print('-' * 50)
16+
17+
# -----------------------------------------------------------------
18+
# weather = {'Bhubaneswar':'cloudy','Bhadrak':'snowing','Cuttack':'rain','Anugul':'cloudy'}
19+
#
20+
# rainy_cities = {key: value for key,value in weather.items() if value == 'rain'}
21+
# cloudy_cities = {key: value for key,value in weather.items() if value == 'cloudy'}
22+
# snowing_cities = {key:value for key,value in weather.items() if value == 'snowing'}
23+
#
24+
#
25+
# print(snowing_cities)
26+
# print(cloudy_cities)
27+
# print(rainy_cities)
28+
# ---------------------------------------------------------
29+
# cities_temp = {'Bhubaneswar':34,'Bhadrak':24,'Cuttack':45,'Anugul':40}
30+
#
31+
# Helthy_weather = {key: ('Good'if value <= 30 else 'bad' ) for (key,value) in cities_temp.items()}
32+
# print(Helthy_weather)
33+
#
34+
# warm_cold = {key:('cold' if value <= 30 else 'warm') for (key,value) in cities_temp.items()}
35+
# print(warm_cold)
36+
# ------------------------------------------------
37+
cities_temp = {'Bhubaneswar':34,'Bhadrak':24,'Cuttack':45,'Anugul':40}
38+
39+
40+
41+
def add(temp):
42+
if temp >= 30:
43+
temp = temp - 5
44+
else:
45+
temp += 2
46+
return temp
47+
48+
add_temp = {key: add(value) for (key,value) in cities_temp.items()}
49+
50+
51+
print(add_temp)
52+
print(cities_temp)
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+

DuckTyping.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Duck typing = concept where the class of an object is less important than the methods
2+
# class type is not checked if minimum methods/attributes are present
3+
# "If it was like a duck, and it quacks like a duck", then it must be a duck.
4+
5+
6+
class duck:
7+
def walk(self):
8+
print('it walk like a duck')
9+
def talk(self):
10+
print('its talk like duck.')
11+
12+
class chicken:
13+
def walk(self):
14+
print('its walk like a chicken.')
15+
def talk(self):
16+
print('its talk like a chicken')
17+
18+
class person:
19+
def catch(self,duck):
20+
duck.walk()
21+
duck.talk()
22+
23+
24+
25+
duck1 = duck()
26+
chicken1 = chicken()
27+
person1 = person()
28+
29+
person1.catch(chicken1)

Filter().py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# filter() = creates a collection of elements from an iterable
2+
# for which a function returns
3+
4+
# filter(function,iterables)
5+
6+
# nums = ['Anil','Ankita','Ashish','Lenka','Biswaprakash']
7+
# func = lambda words: len(words) >= 5
8+
# filter = list(filter(func,nums))
9+
#
10+
# print(filter)
11+
12+
# ------------------------------------------
13+
14+
details = [
15+
('Anil',21),
16+
('Ankita',34),
17+
('Sunil',9),
18+
('GUdu',12),
19+
('Sayani',23),
20+
('Sipra',12),
21+
]
22+
23+
func = lambda age:age[1] >= 18
24+
25+
filter = list(filter(func,details))
26+
27+
# print(filter)
28+
29+
for i in filter:print(i[0] +':'+ str(i[1]))
30+

ForLoop.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
# for loop = a statement that will excute it`s a block of code
3+
# code a limited amount of times.
4+
5+
6+
# while Loop = unlimited
7+
# for loop = limited
8+
9+
#
10+
# for i in range(1,10):
11+
# print(i + 1)
12+
# ---------------------------------
13+
# for i in range(50,100,2):
14+
# print(i)
15+
16+
# ------------------------------
17+
# for i in "Anil kumar nayak":
18+
# print(i)
19+
# -----------------------------------
20+
for i in range(10, 0, -1):
21+
print(i)
22+
time.sleep(1)
23+
print("happy new year")
24+
25+
26+
27+

Function .py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# function = a block of code which is excuted only when it is called
2+
3+
4+
def Hello(f_name,lname,age):
5+
print(f'hello everyone my name is {f_name} {lname}')
6+
print(f"my age is {age}")
7+
print('have a nice day')
8+
9+
10+
Hello("Anil",'nayak',21)

Higher Order fucntion.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Higher Order Function = a function that either:
2+
# 1.accepts a function as an arguments
3+
# or
4+
# 2. returns a function
5+
# (In python , Function are also treated as a object)
6+
7+
# def loud(text):
8+
# return text.upper()
9+
#
10+
# def quit(text):
11+
# return text.lower()
12+
#
13+
#
14+
# def Hello(func):
15+
# text = func("HELLO")
16+
# print(text)
17+
#
18+
#
19+
# Hello(quit)
20+
21+
#-------------------------------------- Example -2
22+
23+
def divisor(x):
24+
def dividend(y):
25+
return y / x
26+
return dividend
27+
28+
divide = divisor(2)
29+
print(divide(12))

IndexOperator.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# index operator []= gives access to a sequence`s element (str,list,tuples
2+
3+
4+
name = "anil kumar nayak!"
5+
6+
# if(name[0].islower()):
7+
# name = name[0].upper() + name[1:]
8+
9+
10+
firstname = name[0:4].upper()
11+
lastname = name[5:].lower()
12+
lastchaar = name[-1]
13+
14+
print(lastchaar)
15+
print(firstname)
16+
print(lastname)
17+
print(name)
18+

KeywordArguments.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# keyword Arguments = arguments preceded by an identifier when we pass them to a function
2+
# the order of the arguments doesnt matter, unlike positional arguments
3+
# python known the names of the arguments that our function receives
4+
5+
def hello(fname,middlename,lname):
6+
print(f"hello {fname} {middlename} {lname}")
7+
8+
hello(fname="Anil",lname='nayak',middlename='kumar')

List.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# list = used to store multiple items in a single variable
2+
3+
food = ['pizza', 'humburger', 'hotdog']
4+
num = [1,34,5,67,8,]
5+
food[0] = 'sushi'
6+
7+
# food.append('icecream')
8+
# food.remove('hotdog')
9+
# food.pop()
10+
# food.insert(3,'Cake')
11+
# num.sort()
12+
# food.clear()
13+
print(food)
14+
15+
#
16+
# for i in food:
17+
# print(i[::-1],end='+')
18+
19+
20+
Number = ["a",'b',2,'c',3]
21+
str = [item for item in Number if type(item) == str]
22+
int = [item for item in Number if type(item) == int]
23+
print(f"Number : {str}" )
24+
print(f"List : {int}")
25+
26+

Loop Control Statement .py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Loop Control Statements =change a loops excution from its normal sequence
2+
3+
# break = used to terminating the loop
4+
# continue = skips to the next iteration of the loop
5+
# pass = does nothing , aacts as a placeholder
6+
7+
# **Break-----------------
8+
# while True:
9+
# name = input("nter ur name :")
10+
# if name != "":
11+
# break
12+
# print(f"{name} tu mgya ete alsua name lekhibaku tote kia gandimaruchhi ")
13+
14+
# --------------------------continue
15+
16+
phoneNumber = '760-9830-371'
17+
18+
# for i in phoneNumber:
19+
# if i == "-":
20+
# continue
21+
# print(i, end='')
22+
23+
# pass-------------------------------
24+
25+
for i in range(1, 20):
26+
if i == 13:
27+
pass
28+
print(i)
29+
30+

0 commit comments

Comments
 (0)