blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 545k | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 545k |
|---|---|---|---|---|---|---|
0ce96b38ee72f345ea234bb397b6acc45233c7a0 | davtoh/advutils | /advutils/counters.py | 34,380 | 3.65625 | 4 | #!/usr/bin/env python
# -*- coding: latin-1 -*-
"""
This module defines counters useful to generate numbers simulating digital counters
"""
from __future__ import division
from __future__ import print_function
#from builtins import str
from builtins import range
from builtins import object
from numbers import Number
... |
b539b62442ce0f87853c3d7e35b7a381d50a34d7 | JasonWorger/QAC_Challenges | /string_gen.py | 191 | 3.5625 | 4 | import random
import string
def string_gen():
letters = string.ascii_lowercase
result = "".join(random.choice(letters)
for i in range(5))
return result
print(string_gen()) |
cb6649378c6fe71e046143947e630b64f89e73b3 | damienwmartin/MetaLearning2020 | /Rebel/games/othello.py | 15,048 | 4.125 | 4 | '''
Implementation of Othello.
Adapted from https://github.com/suragnair/alpha-zero-general/blob/master/othello
Game representation:
2 players, Black (id=0) and White (id=1). Black plays first.
Game board is represented by a square 2D np.array corresponding
to the rows and columns of... |
09cf7b81f7c617ef5dac40eafa6d710a44db0c0e | santoshdurgam/DataStructures | /bst.py | 1,768 | 4.09375 | 4 | class node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
class binary_search_tree:
def __init__(self):
self.root = None
def insert(self, value):
if self.root == None:
self.root = node(value)
else... |
780f79f1fca5c5d9e6cf5c9a34989daa1380d01f | Amad1704/lessson1 | /answers.py | 278 | 3.703125 | 4 | answers={"привет": "И тебе привет!", "как дела": "Лучше всех", "пока": "Увидимся"}
def get_answer(question, answer = answers):
question=question.lower()
print(answer[question])
question = input()
print(get_answer(question))
|
405b6a62bc0a4326c0201b5d4e795bb2c454711d | MrDrewShep/advent_of_code_2019 | /01/puzzle.py | 998 | 3.875 | 4 | # PART ONE
# What is the sum of the fuel requirements for all of the modules on your
# spacecraft?
with open("data.txt") as f:
data = f.readlines()
data = [i.strip("\n") for i in data]
def calc_fuel(module_mass):
"""Takes in mass of a module and returns the amount of fuel required
to launch it"""
... |
c4d61d1c2fee32068f4d37251ad68ea52004a95e | sedeeki/Numerical-Methods | /Bisection_Newton_QuasiNewton.py | 5,780 | 3.796875 | 4 |
import numpy as np
import math
#----------------------------------------------------
def bisection(f, x1, x2, tol=1e-14, itmax=200, SHOW=False):
""" find a solution of f(x)=0 on the interval [x1,x2] by the bisection method.
return the results in a tuple (x, k, f(x)),
where x ... |
290df5219a8f4a0ece597cb7a9d854e73f5a70f6 | icasarino/Rabbit | /BinaryMethods.py | 2,995 | 3.875 | 4 | def rightShift(value, offset):
"""
Realiza un ciclo en los bits
Diferencia con operador setea el primer bit con el valor del ultimo
EJ:
21 -> 10101
rightShift(21,1) ==> 26 -> 11010
21 >> 1 ==> 10 -> 01010
"""
numBits = value.bit_length() - 1
for i in range(0... |
fff0498b02beda34d7ba14d5d54e41a7e3a0a27f | FireFox5/FireMonkey- | /First Month/forth lesson 05.07.2021/lesson 4.1.py | 177 | 3.921875 | 4 | #for i in range(10):
# print("hello",i)
# for k in range(10):
# print("hello from USA",k)
for q in range(5):
name=input(f"you {q} in qoute")
print(name)
|
c9170c803dd94206f248af59fff8f268f766320d | FireFox5/FireMonkey- | /First Month/second lesson 28.06.2021/lesson 2.3.py | 227 | 3.734375 | 4 | age=float(input("your age "))+20.2
print(age)
print(type(age))
currency=84.5+0.228+1
print(currency)
print(currency)
print(int(float(str(currency))))
is_sunny=True
is_rainy=False
print(type(is_rainy))
print(type(is_sunny))
|
3edf18972bd8e0d4655a71b0bd87741e1ce00587 | FireFox5/FireMonkey- | /First Month/second lesson 28.06.2021/lesson 2.py | 118 | 3.546875 | 4 | name="sultan "
print(name)
years=20+1/(2*2)-1
years2="20"+"20"
years3="20"*4
print(years)
print(years2)
print(years3) |
49e2dc5e5c63205c941f9b8bef6147fb6d5f4586 | FireFox5/FireMonkey- | /First Month/second lesson 28.06.2021/lesson2.2.py | 182 | 3.5625 | 4 | name="abc"
name2=input()
age=input()+20
age2=99.2
print(name2)
print(type(name2))
print(name2)
print(age)
#print(type(age2))
#print(type(age))
#print(type(name))
#print(type(name2))
|
b140bc588000d49c057e4d954a9ff303997bd942 | cristiano-corrado/ipconverter | /ipconverter.py | 3,588 | 3.6875 | 4 | #!/usr/bin/python
import os
import sys
import re
import struct
import datetime
from socket import inet_aton
#define list where to add ip addresses.
listIP=[]
#identify a unique per day file. not great but no waste of time
today=datetime.datetime.today()
finalFile=str(today.date())+"-ipfile-sanitised.txt"
... |
cc704a0b6eac68caae0a3f42c9eeb416ddd87add | sgriffith3/python_basics_9-14-2020 | /larnin_funcs.py | 467 | 3.890625 | 4 | # Learning Functions
# printing x + 33
def func1():
print(33)
func1()
print("Let's do that again!")
func1()
def func2(x):
print(x + 33)
func2(99)
func2(1099)
def func3(y, z):
print(y * z)
func3(3, 4)
def func4(a, b, c):
print(a - (b + c))
return a - (b + c)
def main():
answer1 = ... |
5b9d02e8b3b62588d1de662ef4321b20097c8f10 | sgriffith3/python_basics_9-14-2020 | /pet_list_challenge.py | 843 | 4.125 | 4 | #Tuesday Morning Challenge:
#Start with this list of pets:
pets = ['fido', 'spot', 'fluffy']
#Use the input() function three times to gather names of three more pets.
pet1 = input("pet 1 name: ")
pet2 = input("pet 2 name: ")
pet3 = input("pet 3 name: ")
#Add each of these new pet names to the pets list.
pets.appen... |
f9cffb3f8d8587963a8c819e63bfccc4a152e639 | pinkfluffy855/pendulum | /section3.py | 2,730 | 3.71875 | 4 | """
A stationary damped pendulum
For fun.
"""
import numpy as np
import matplotlib.pyplot as plt
import pendulum
### Pendulum swings with amplitude smaller than $4 v_c$
#We assume a pendulum length of 20 m and a trolley speed of vc = 1 m/s. The load needs to be transported by 6 m, hence deltat= 3 s.
#The initial ... |
26afeab27e2cc0dc55d045b0179b17780ecea344 | randalong/PyTorchZeroToAll | /2_linear_model.py | 499 | 3.625 | 4 | import numpy as np
import matplotlib.pyplot as plt
x_data = [1.0, 2.0, 3.0]
y_data = [2.0, 4.0, 6.0]
w = 1
def forward(x):
return x * w
def loss(x,y):
y_pred = forward(x)
return (y_pred-y)**2
w_list = []
mse_list = []
for w in np.arange(0.0, 4.0, 0.1):
loss_sum = 0
for x_val, y_val in zip(x_d... |
ff0c5c38ca1e0d2b8cba59966bfea5cd7a743fc8 | PavlovAlx/repoGeekBrains | /dz5.py | 516 | 4.3125 | 4 | string1 = int(input("введите выручку"))
string2 = int(input("введите издержки"))
if string1 >= string2:
print ("вы работаете с прибылью:", string1-string2)
print ("рентабельность:", string1/string2)
string3 = int(input("численность сотрудников:"))
print ("прибыль на сотрудника:", (string1-string2)... |
72a42c7ff9a6b490b96b19147c2db1bedb99d542 | anon-cand/nexpreval | /operations/constant.py | 811 | 3.859375 | 4 | from operations.operation import Operation
class Constant(Operation):
"""
Class to represent a constant
"""
TAG = 'default'
__slots__ = 'value'
def __init__(self, value = None):
self.value = value
def __hash__(self):
return hash(self.value)
def __call__(self):
... |
e92f2e8ccb173792b7be00653675a745e6c62a64 | Mycodeiskuina/Among-Us-game-0.5 | /Segunda_parte.py | 10,402 | 3.890625 | 4 | """En mi codigo el algoritmo astar recorre una matriz de 0s y 1s,
donde los 1 representan obstaculos y retorna un camino,
por eso antes de poner la matriz como parametro de la funcion astar
convierto la matriz en una matriz de 0s y 1s"""
from math import sqrt
import random
#inicializamos la matriz
m = []
for i in r... |
78e6d0b1ce07844cbc88aab306267d882441b3df | Lt3kr/Liam_Turelid_TE19C | /Introkod_syntax/strings_uppg/Uppgift_5c.py | 1,123 | 3.859375 | 4 | fråga = input("kryptera eller dekryptera?: ")
alfabetet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_."
if fråga == "kryptera":
ROTLösen = input("ROT och ditt lösen: ")
seperation = ROTLösen.split(" ")
ROT = int(seperation[0])
Meddelande = seperation[1].upper()
resultat = ""
for letter in Meddelande:
... |
7ed442f350732cfdb2ef56f27542bf6fce0e1d0d | Lt3kr/Liam_Turelid_TE19C | /Introkod_syntax/Laxa2/uppg.3.py | 251 | 3.609375 | 4 | tal1 = float(input("Skriv ett tal så ska jag se ifall de är störst: "))
tal2 = float(input("Skriv ditt andra tal: "))
tal3 = float(input("Skriv ditt tredje tal: "))
tal4 = float(input("Skriv ditt fjärde tal: "))
print(max(tal1, tal2, tal3, tal4)) |
3b82e9fb01b53368c4ffbe7da95f51059072595d | Lt3kr/Liam_Turelid_TE19C | /Introkod_syntax/räkna_med_python/For läxor/For_uppg_5.py | 421 | 3.734375 | 4 | # uppgift 5a
for f in range (11):
print(f"{5*f}", end=" ")
print()
#uppgift 5b
k = int(input("ge mig ett tal! "))
for n in range(11):
print(f"{k*n}", end=" ")
print()
#uppgift 5c
for j in range(11): #gör vad som står under 10 ggr
for i in range(11): #gör samma här
print(f"{i*j}", end = " ") #tar... |
7ca9341e3ddc4149c16eb18561457ce179b0b348 | Lt3kr/Liam_Turelid_TE19C | /Introkod_syntax/FunktionsUppgifter/Uppgift2.py | 500 | 3.671875 | 4 | # gör en funk som beräknar s = 1 + 3 + 5 + 7 + 9 + ... + (2n +1)
Start = int(input("Skriv vad starten är: ")) - 1
n = int(input("Skriv vad du vill ha som den sista delen: "))
def Aritmetisk_summa(n):
Summan = 0
for x in range(Start, n+1):
Summan += (2*x + 1)
return Summan
print(f"den arit... |
d9bd61933eb23e69a2c083fd98bf18ced1e4b868 | Lt3kr/Liam_Turelid_TE19C | /Introkod_syntax/Labb/labb.2/uppgift2.py | 103 | 3.6875 | 4 | x=0
for i in range(100):
x += 1
if x % 5 != 0:
print(x)
else:
print("burr") |
a61fbb95a269c1ad6ed3920988024aefbb001853 | DavidLoi/DMOJ | /Uncategorized/Valentine's Day '19 J1 - Rainbow Rating.py | 580 | 3.5625 | 4 | users = int(input())
list = []
for i in range(users):
current = int(input())
if current < 1000:
list.append("Newbie")
elif current < 1200:
list.append("Amateur")
elif current < 1500:
list.append("Expert")
elif current < 1800:
list.append("Candidate Master... |
24c0cdb43ffda5810a383015e0cccf00b3a2d103 | DavidLoi/DMOJ | /Uncategorized/CPC '19 Contest 1 P1 - Distance.py | 325 | 3.5 | 4 | num = int(input())
path = []
if num%2 == 0:
for i in range((int(num/2))):
path.append(i+1)
path.append(num-i)
elif num % 2 == 1:
for i in range(int((num-1)/2)):
path.append(i+1)
path.append(num-i)
path.append(int(num/2) + 1)
print(" ".join(str(x) for x in p... |
427eb7b7767a36cf6565e6d703b786b4223f61cb | Senofjohan/breathe_and_build_cloud_infrastructure | /mouth_open_algorithm.py | 1,058 | 3.796875 | 4 | import math
def get_lip_height(lip):
sum=0
for i in [2,3,4]:
# distance between two near points up and down
distance = math.sqrt( (lip[i][0] - lip[12-i][0])**2 +
(lip[i][1] - lip[12-i][1])**2 )
sum += distance
return sum / 3
def get_mouth_... |
ccd5596008603cfa9d615b5485c6ced3b42782fc | wreyesus/Python-For-Beginners---2 | /0026. Automate Parsing and Renaming of Multiple Files.py | 2,449 | 3.5 | 4 | #Automate Parsing and Renaming of Multiple Files
import os
os.chdir('D:\Study\Hadoop\Python\Cory_Schafer youtube videos')
print(os.getcwd())
for f in os.listdir():
#print(f) #print all file/folders of file
#print(os.path.splitext(f)) #will split file name and ext
file_name , ... |
d503092c169f07e614859b581774ae27fc8c058c | wreyesus/Python-For-Beginners---2 | /0020. List Comprehensions.py | 2,760 | 4.15625 | 4 | #Comprehensions
nums = [1,2,3,4,5,6,7,8,9,10]
# I want 'n' for each 'n' in nums
my_list = []
for n in nums:
my_list.append(n)
print(my_list)
#Using List Comprihension
my_list_com = [n for n in nums]
print(my_list_com)
############
#I want 'n*n' for each 'n' in nums
my_list1 = []
for n in nums... |
900733030503c1011f0df3f2e5ee794499e422b0 | wreyesus/Python-For-Beginners---2 | /0025. File Objects - Reading and Writing to Files.py | 474 | 4.375 | 4 | #File Objects - Reading and Writing to Files
'''
Opening a file in reading / writing / append mode
'''
f = open('test.txt','r')
#f = open('test.txt','w') --write
#f = open('test.txt','r+') --read and write
#f = open('test.txt','a') --append
print(f.name) #will print file name
print(f.mode) #wi... |
41183f1363e0e0c40cc970c7f3a717250a83a872 | meg1988/PycharmProjects | /seleniumwd2/excercise/FindPrice.py | 576 | 3.625 | 4 | from selenium import webdriver
class FindPrice():
def findprice(self):
baseurl = "https://letskodeit.teachable.com/pages/practice"
driver = webdriver.Firefox()
driver.get(baseurl)
# price = driver.find_element_by_xpath("//table[@id='product']//tr//td[text()='Python Programming Lan... |
2c3cc02032b9864347776d0200de88183c07dc0d | meg1988/PycharmProjects | /Pyproject/classess/exceptionhandling.py | 437 | 4.09375 | 4 | def exceptionhandling():
try:
a="aa"
b=10
c=0
print(a/c)
except ZeroDivisionError:
print("this is wrong, cant divide by zero")
except TypeError:
print("cant add int to str")
raise Exception("this is an exception")
else:
print("there is no ... |
9fa70f4432995fc59d1ba1d674ff0047fd862b28 | meg1988/PycharmProjects | /Pyproject/classess/Car.py | 338 | 3.75 | 4 |
class Car(object):
wheels = 4
def __init__(self, make, model="Centra"):
self.make = make
self.model = model
def info(self):
print("Make of the car " + self.make)
print("Model of the car " + self.model)
c1 = Car("Nissan")
c2 = Car('bmw', 'i550')
c1.info()
c2.info()
prin... |
412ac494347bf94d8fc4b42b4775f4516795005d | bryanjulian/Programming-11 | /BryanJulianCoding/Operators and Stuff.py | 1,028 | 4.1875 | 4 | # MATH!
x = 10
print (x)
print ("x")
print ("x =",x)
x = 5
x = x + 1
print(x)
x = 5
x + 1
print (x)
# x + 1 = x Operators must be on the right side of the equation.
# Variables are CASE SENSITIVE.
x = 6
X = 5
print (x)
print (X)
# Use underscores to name variables!
# Addition (+) Subtraction (-) Multiplycation (... |
c1d10dd9049cd92ba07c427bae1ea2d33a66b786 | wangweihao/Python | /6/6-16-2.py | 498 | 3.6875 | 4 | #!/usr/bin/env python
#coding:UTF-8
matrix1 = [[1,2,3,4], [1,2,3,4],[1,2,3,4],[1,2,3,4]]
matrix2 = [[1,2,3,4], [1,2,3,4],[1,2,3,4],[1,2,3,4]]
def matrix_multi():
li = []
for i in range(len(matrix1)):
li_ = []
for j in range(len(matrix2[0])):
s = 0
for k in range(len(mat... |
8f5be80dca96d0cf478780563ad719ec814678a3 | wangweihao/Python | /6/6-8.py | 397 | 3.6875 | 4 | #!/usr/bin/env python
#coding:UTF-8
dict = {'0':'zero', '1':'one', '2':'two', '3':'three', '4':'four', '5':'five', '6':'six', \
'7':'seven', '8':'eight', '9':'night'}
str = raw_input('please input a number (0-1000):')
list = []
for i in range(len(str)):
list.append(str[i])
for j in range(len(list)):
... |
35e6049c09ecdc76a1d6c718168fc7429328865e | wangweihao/Python | /6/6-12.py | 363 | 3.921875 | 4 | #!/usr/bin/env python
#coding:UTF-8
def findchr(string, char):
print string, char
for i in range(len(string)):
if char == string[i]:
break
if i == len(string)-1:
return -1
else:
return i
if __name__ == '__main__':
str = 'abcdef'
c = 'a'
d = 'p'
print... |
776ad18ff91a475ded5a6dbef9769539767ce5a1 | wangweihao/Python | /13/13-8.py | 823 | 4 | 4 | #!/usr/bin/env python
#coding:UTF-8
class Stack(object):
stack = []
def __init__(self, obj):
self.stack = obj
def pop(self):
if 'pop' in dir(self.stack):
return self.stack.pop()
else:
index = len(self.stack)-1
ret = self.stack(index)
... |
740c59e9a65e7c68650c4883d8025eac5e5750cf | wangweihao/Python | /11/11-14.py | 222 | 3.90625 | 4 | #!/usr/bin/env python
#coding:UTF-8
def fiboni(n):
if n == 1 or n == 0:
return 1
else:
return fiboni(n-1) + fiboni(n-2)
if __name__ == '__main__':
for i in range(20):
print fiboni(i)
|
620286ed9767af19513f32fa39ca723595ce6adc | wangweihao/Python | /6/6-6.py | 349 | 3.765625 | 4 | #!/usr/bin/env python
#coding:UTF-8
str = raw_input('please input a string:')
list = []
for i in range(0, len(str)):
if str[i] != ' ':
list.append(i)
break
for i in range(i, len(str)):
if str[i] == ' ':
list.append(i)
break
if list[0] == 0:
print str
else:
ret = str[lis... |
5a48ed02fb8d1100abf955dea24498a1cb530a8a | wangweihao/Python | /7/7-7.py | 129 | 3.625 | 4 | #!/usr/bin/env python
#coding:UTF-8
dic = {1:'a', 2:'b', 3:'c'}
newdic = {}
for k in dic:
newdic[dic[k]] = k
print newdic
|
858a56861965e44d0d1b3161957ea9edd11720ef | wangweihao/Python | /2/2-15.py | 511 | 4.1875 | 4 | #!/usr/bin/env python
#coding:UTF-8
myTuple = []
for i in range(3):
temp = raw_input('input:')
myTuple.append(int(temp))
for i in range(3):
print myTuple[i]
if myTuple[0] > myTuple[1]:
temp = myTuple[0]
myTuple[0] = myTuple[1]
myTuple[1] = temp
if myTuple[0] > myTuple[2]:
temp = myTuple[0]
... |
0a9a79fb3fc07e714d2a87aa9127fd94c44d0d6b | wangweihao/Python | /15/match.py | 189 | 3.9375 | 4 | #!/usr/bin/env python
#coding:UTF-8
import re
Str = 'hello world'
m = re.match('hello', Str)
if m is not None:
print m.group()
print type(m.group())
else:
print 'not found'
|
8f49d9c6ecbbb0ad9a43b820a932a7d5ca7c6095 | wangweihao/Python | /6/6-3.py | 158 | 3.78125 | 4 | #!/usr/bin/env python
#coding:UTF-8
list = []
while 1:
x = input('please input number:')
if x == -1:
break
list.append(x)
list.sort()
|
7882e3aafa815e47e7898a012eb078f33cb3fb2d | MemoryReload/SimplePythonExamples | /Example/Example1_3.py | 726 | 3.734375 | 4 | class Rectangle(object):
def __init__(self, color='white', width=10, height=10):
super(Rectangle,self).__init__()
print 'create a %s\t%r,sized:%d\theight:%d' %(color,self,width,height)
class RoundedRectangle(Rectangle):
def __init__(self,*k,**kw):
k=(self,)+k
apply(Rectangle.__... |
3f6c0ac583ec489c61b0d812c8b3bdd37eddaf40 | Bmcentee148/PythonTheHardWay | /ex15.py | 273 | 3.8125 | 4 | from sys import argv
script, filename = argv
txt_file = open(filename)
print "Here's your file %r:" % filename
print txt_file.read()
print "Print the filename again:"
filename_again = raw_input('> ')
txt_file_again = open(filename_again)
print txt_file_again.read()
|
9d175894ced0e8687bb5724763722efdeb70741f | Bmcentee148/PythonTheHardWay | /ex_15_commented.py | 743 | 4.34375 | 4 | #import argv from the sys module so we can use it
from sys import argv
# unpack the args into appropriate variables
script, filename = argv
#open the file and stores returned file object in a var
txt_file = open(filename)
# Tells user what file they are about to view contents of
print "Here's your file %r:" % filena... |
dcc622587a5c864792d4ab073da0f5ad239907bf | Bmcentee148/PythonTheHardWay | /ex3.py | 825 | 4.375 | 4 | # begin counting chickens
print "I will now count my count my chickens"
#Hens is 25 + (30 / 6) = 30
print "Hens", 25 + 30.0 / 6
#Roosters is 100 - (25 * 3) % 4
print "Roosters", 100 - 25 * 3 % 4
#begin counting eggs
print "Now I will count my eggs"
#eggs is 3 + 2 + 1 - 5 + (4 % 2) - (1/4) + 6
print 3 + 2 + 1 - 5 + 4... |
f8c27ff7a12600945b1a2c24bd55f8326cf5c3c8 | Bmcentee148/PythonTheHardWay | /ex34.py | 309 | 4.09375 | 4 | # Learning to index elements contained in a list. Just like arrays in Java!
animals = ["bear", "tiger", "penguin", "zebra"]
bear = animals[0]
print bear
nums = range(1,11) # list of ints 1 to 10
my_num = nums[9] # The tenth element ie 10
his_num = nums[0] # The first element ie 1
print my_num, his_num
|
43b70b64ab6d1e25bf7ffdb497a07bfe72539e2f | Bmcentee148/PythonTheHardWay | /ex5_v2.py | 754 | 3.671875 | 4 | name = "Zed A. Shaw"
age = 35 # not a lie
print "Let's talk about %s." % name
height = 74 # inches
height_centimeters = height * 2.54
print height_centimeters
print "He's %d inches, or %d centimeters tall." % (height, round(height_centimeters))
weight = 180 # pounds
weight_kilograms = weight * 0.453592
print weight_k... |
c4d5cc928ee53ccfdd17c60938a7f9d0ee54e0ba | donnell794/Udemy | /Coding Interview Bootcamp/exercises/py/circular/index.py | 533 | 4.1875 | 4 | # --- Directions
# Given a linked list, return true if the list
# is circular, false if it is not.
# --- Examples
# const l = new List();
# const a = new Node('a');
# const b = new Node('b');
# const c = new Node('c');
# l.head = a;
# a.next = b;
# b.next = c;
# c.next = b;
# circular(l) # true
def c... |
c38d82526b9f5c557ede5a976cb2dcc9e7261842 | donnell794/Udemy | /Coding Interview Bootcamp/exercises/py/tree/index.py | 1,410 | 3.953125 | 4 | # --- Directions
# 1) Create a node class. The constructor
# should accept an argument that gets assigned
# to the data property and initialize an
# empty array for storing children. The node
# class should have methods 'add' and 'remove'.
# 2) Create a tree class. The tree constructor
# should initialize a 'root' pro... |
9f8bc1fa1200b78a9777b0dd40e408d0b2da2c96 | donnell794/Udemy | /Coding Interview Bootcamp/exercises/py/fromlast/index.py | 613 | 4.03125 | 4 | # --- Directions
# Given a linked list, return the element n spaces
# from the last node in the list. Do not call the 'size'
# method of the linked list. Assume that n will always
# be less than the length of the list.
# --- Examples
# const list = new List();
# list.insertLast('a');
# list.insertLast('b');
... |
669afade07619df314a48551e17ad102f28b249f | donnell794/Udemy | /Coding Interview Bootcamp/exercises/py/fib/index.py | 608 | 4.21875 | 4 | # --- Directions
# Print out the n-th entry in the fibonacci series.
# The fibonacci series is an ordering of numbers where
# each number is the sum of the preceeding two.
# For example, the sequence
# [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
# forms the first ten entries of the fibonacci series.
# Example:
# fib(4) === 3
... |
a161ecd3ad0cd0d746a85474f39b92b94f4469ee | muhang/daily-programmer | /7-15.py | 560 | 3.65625 | 4 | def problem(testStr, problemStr):
for probLetter in problemStr:
if probLetter in testStr:
testStr = testStr[testStr.index(probLetter)+1:len(testStr)]
else:
return False
return True
if __name__ == "__main__":
testA = problem("synchronized", "snond")
testB = proble... |
0b0b246f748dbf8c7bd314af8f2182c52e9de3d3 | breman27/CodeWars | /6 Kyu/Python/is_it_prime.py | 205 | 3.84375 | 4 | from math import sqrt; from itertools import count, islice
def is_prime(num):
if num is 0 or num is 1:
return False
return num > 1 and all(num%i for i in islice(count(2), int(sqrt(num)-1))) |
2fffc40faf0cfe6bc472e27ab951e8612fa94db4 | jhu97/baekjoon | /10870.py | 194 | 3.9375 | 4 | n = int(input())
numbers = [0,1]
if n == 0:
print(0)
elif n == 1:
print(1)
else:
while (len(numbers) - 1) < n:
numbers.append(numbers[-2]+numbers[-1])
print(numbers[-1]) |
14afd0cc9a60afbd927f997f141993c6cb54e1dc | jhu97/baekjoon | /2522.py | 193 | 3.625 | 4 | import sys
input = sys.stdin.readline
N = int(input())
for n in range(1, N + 1):
print("{0:>{1}}".format(n * '*', N))
for i in range(N - 1, 0, -1):
print("{0:>{1}}".format(i * '*', N))
|
ca845eb0d97de9a6b4abd397dbc95564e7ccf8bd | ES2Spring2019-ComputinginEngineering/project-one-grant-and-patrick | /simulation_code.py | 5,986 | 4.28125 | 4 | #Pendulum Simulation
# Simulation of a pendulum, graphs position, velocity, and acceleration vs. time using meters and seconds
# Created by: Grant Smith and Patrick Wright
#his will produce three graphs one with velocity vs. time another with position vs. time and a final of acceleration vs. time
#It will print t... |
1c422a54db9416f308eab05525bf3faea7ac9530 | vrastello/Game-Project | /FocusGame.py | 8,600 | 3.9375 | 4 | # Name: Vincent Rastello
# Date: 11-27-20
# Description: This is a program for creating a game of Domination. Follow this link to see a description:
# https://www.youtube.com/watch?v=DVRVQM9lo9E. My data structure will consist of three classes: Player, Board
# and FocusGame. Player and Board will not communicate with e... |
ab679c57ed329a89160ba09ff44e535602c7c4dc | MohamedAdel99/Parallel-HTTP-Proxy | /code.py | 10,887 | 3.625 | 4 | # Don't forget to change this file's name before submission.
import sys
import os
import enum
import socket,threading
class HttpRequestInfo(object):
"""
Represents a HTTP request information
Since you'll need to standardize all requests you get
as specified by the document, after you parse the
req... |
d417ee88b2aa638a18ff1bbb99cd42d2d96c062c | Gus98/IGL | /alphaEven.py | 1,659 | 3.578125 | 4 | import math
import matplotlib.pyplot as plt
import numpy as np
import random
def T(Z, alpha):
#this is the natural extension funtion with the input being a 2 element list
a = 0
b = 0
if Z[0] > 0:
e = 1
else:
e = -1
k = math.floor((1/abs(Z[0]) - alpha + 2)/2)
a = 1/abs(Z[0]) ... |
38a44d9ba0619c8a6f90ad1c82da64eaac4be212 | suruisunstat/leetcode_practice | /amazon/python/1. Two Sum.py | 674 | 3.546875 | 4 | class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
# h = {}
# for i, num in enumerate(nums):
# n = target - num
# if n not in h:
# h[num] = i
... |
fc29de0ee7e96ae3d39e183fe2ad9f1813258c2b | suruisunstat/leetcode_practice | /amazon/python/437. Path Sum III.py | 1,479 | 3.609375 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def pathSum(self, root, sum):
self.numOfPaths = 0
self.dfs(root,sum)
return self.numOfPaths
... |
327a97bcecde8a6f2d385709c0c0bada63674fe5 | suruisunstat/leetcode_practice | /amazon/python/24. Swap Nodes in Pairs.py | 860 | 3.84375 | 4 | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
dummy = ListNode(0)
... |
a2786e3a176fdaa4abd0eb5c778b314ce873ad6a | suruisunstat/leetcode_practice | /486. Predict the Winner.py | 987 | 3.5 | 4 | ## method1: recursion O(2^n) time
class Solution(object):
def PredictTheWinner(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return self.winner(nums, 0, len(nums) - 1, 1) >= 0
def winner(self, nums, s, e, turn):
if s == e:
return turn * nums... |
2451888fcd98edbc4ee7cf2923e0a560845008dd | suruisunstat/leetcode_practice | /amazon/python/104. Maximum Depth of Binary Tree.py | 1,285 | 3.765625 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
# def maxDepth(self, root):
# """
# :type root: TreeNode
# :rtype: int
# """
# if... |
b9b084f86706063e46c7bd0579a2758dc7de2553 | suruisunstat/leetcode_practice | /amazon/python/9. Palindrome Number.py | 482 | 3.578125 | 4 | class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
#return str(x) == str(x)[::-1]
if x < 0 or (x % 10 == 0 and x != 0):
return False
revert = 0
while x > revert:
revert = revert * 10 + x % 10
... |
f31db6e9ab43a04d97ad34853681a0c2a95823ff | suruisunstat/leetcode_practice | /amazon/python/208. Implement Trie (Prefix Tree).py | 2,703 | 3.890625 | 4 | # import collections
class Node(object):
def __init__(self):
self.children = collections.defaultdict(Node)
self.isword = False
def containsKey(self,ch):
if self.children.get(ch) == None:
return False
return True
def get(self,ch):
return self.ch... |
8fa85e0a0b64bcf6b2175da13c5414b6f4397e90 | cmattox4846/PythonPractice | /Pythonintro.py | 2,522 | 4.125 | 4 | # day_of_week = 'Monday'
# print(day_of_week)
# day_of_week = 'Friday'
# print(f"I can't wait until {day_of_week}!")
# animal_input = input('What is your favorite animal?')
# color_input = input('What is your favorite color?')
# print(f"I've never seen a {color_input} {animal_input}")
#**** time of day
# time_of_d... |
17cb8a6cac5b72b252aa421004f17affc7c06b7c | shellhome/mystrategy | /myshell/src/mypython.py | 3,513 | 3.828125 | 4 |
# -*- coding:utf-8 -*-
'''
Created on 2016年2月16日
@author: shellcom
'''
def hello(name):
'''
:param name:
'''
return "hello," + name + "!"
def story(**kwds):
return "once upon a time, there was a "\
"%(job)s called %(name)s" % kwds
def power(x, y, *others):
if others... |
97a1e6ed08a341e3635ff353181c98ee9f8466e4 | erikbrannstrom/advent-of-code-2017 | /day11.py | 722 | 3.75 | 4 | MOVEMENT = {
"nw": (-0.5, 0.5),
"n": (0, 1),
"ne": (0.5, 0.5),
"se": (0.5, -0.5),
"s": (0, -1),
"sw": (-0.5, -0.5)
}
def move(coords, step):
move = MOVEMENT[step]
return (coords[0] + move[0], coords[1] + move[1])
def distance(coords):
diagonal_steps = abs(coords[0]) * 2
straight_steps = abs(coords[1]) - dia... |
8144b865e19d4b533985d435d0be28c52223caf7 | 12DReflections/PythonWebScraping | /13_newsScrape/main.py | 761 | 3.625 | 4 | import gethtml
import articleText
# Scrapes a site's context
# Come up with keywords of that site
# Keywords compare to a list of regular words which are removed
def main():
url = "http://www.theage.com.au/world/us-election/donald-trump-talks-and-talks-and-beneath-the-verbal-deluge-themes-emerge-20160325-gnreo1.htm... |
f6ddfe6d2be79149d6a0b7c7fd373e8524990574 | Hadiyaqoobi/Python-Programming-A-Concise-Introduction | /week2/problem2_8.py | 1,206 | 4.53125 | 5 | '''
Problem 2_8:
The following list gives the hourly temperature during a 24 hour day. Please
write a function, that will take such a list and compute 3 things: average
temperature, high (maximum temperature), and low (minimum temperature) for the
day. I will test with a different set of temperatur... |
3c0f32642e1477fe148b57a56620a1ec54dff419 | Hadiyaqoobi/Python-Programming-A-Concise-Introduction | /week1/problem1_1.py | 363 | 3.8125 | 4 | '''Write a function problem1_1() that prints "Problem Set 1".
Tip: Be careful that your program outputs this exact phrase with no additional
characters. It will be graded automatically and must be precise. Here is the
run of my solved problem 1_1:
problem1_1()
Problem Set 1
'''
def problem1_1(... |
11bee85063a59abe16f76b399c84b46606c8a549 | jvastola/DiscreteMathematics | /DiscreteMath/OddEven/oddeven.py | 244 | 3.875 | 4 | arr = []
max = 0
while max < 10:
num = int(input('enter an int: '))
if num & 1:
arr.append(num)
max = max + 1
if len(arr) == 0:
print('No odd numbers were entered')
else:
oddArr = sorted(arr)
print(oddArr[-1])
|
794e49a348841f0b195054649039622bd8c6daea | arifemrecelik/Project-Euler | /10.py | 294 | 4.03125 | 4 | import math
result = 0
def isPrime(n):
if n % 2 == 0 and n > 2:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
limit = int(input("Enter the limit: "), 10)
for i in range(1,limit):
if isPrime(i):
result += i
print(result-1) |
aab8e731292be72366b9db81a0906ef40962f2f5 | pudal/FirstStep | /palindrome.py | 152 | 3.875 | 4 | word= input("단어를 입력해보세요")
result = True
for i in range(len(word)):
if word[i] != word[-1-i]:
result = False
break
print(result)
|
5413f9ffa55e90ddd4649be5a78c9366240818c3 | FE1979/weatherapp | /weatherapp.core/weatherapp/core/abstract/commands.py | 5,284 | 3.59375 | 4 | """ Application commands
ConfigureApp: set provider to show, caching time and way of app output
Configure: set Provider options
"""
from abstract.abstract import Command
import config.config as config
class ConfigureApp(Command):
""" Configures application
Options to configure:
- what pro... |
821b6ff69b1b5e95f2ef5080f1804d7ebf3709da | tHeMaskedMan981/coding_practice | /theory/algorithms/binary_search/Find_first_and_last_position_in_sorted_array.py | 1,301 | 3.5625 | 4 | import time
nums = [6,8,8,9]
target = 8
l,r = 0, len(nums)-1
found = False
# > and < conditions are same in both the cases (r = mid-1, l = mid+1)
# For leftmost index, when nums[mid]==target, close in from the right side. r = mid. this way we
# dont loose the target, and keep on moving towards the leftmost occurenc... |
c9696e77689ca80b0ec5c1a46f9e5a59857c3b57 | tHeMaskedMan981/coding_practice | /problems/dfs_tree/symmetric_tree/recursive.py | 995 | 4.21875 | 4 |
# A node structure
class Node:
# A utility function to create a new node
def __init__(self, key):
self.data = key
self.left = None
self.right = None
class Solution(object):
def isSymmetric(self, root):
if root is None:
return True
r... |
aab16a42ae6dc911edc2462b300b52a819a1c39b | tHeMaskedMan981/coding_practice | /theory/algorithms/binary_search/simple_binary_search.py | 495 | 3.859375 | 4 |
# Driver Code
arr = [ 2, 3, 4, 10, 40 ]
x = 3
l,r = 0, len(arr)-1
while l <= r:
# Use this to avoid overflow problems
mid = l + (r - l) // 2
# Check if x is present at mid
if arr[mid] == x:
print(mid)
break
# If x is greater, ignore left half
elif arr[mid] <... |
99dafa9ed15abd0e7e14a16ca3381c4c3e029abc | IshmaelDojaquez/Python | /First Game/Various_Games.py | 4,094 | 4.21875 | 4 | import random
from random import randint
print("Welcome to the Game Selector")
# Use of a dictionary
gameConversion = {
1: "Random Number Guesser",
2: "MadLib",
3: "Rock Paper Scissors"
}
# Use of methods
def gameMenu():
print("1. Random Number Guesser")
print("2. MadLib")
print("3. Rock... |
62e3168c128f1d16bef0ec4cc31afa2e05ae9cae | IshmaelDojaquez/Python | /Python101/Lists.py | 413 | 4.25 | 4 | names = ['John', 'Bob', 'Sarah', 'Mat', 'Kim']
print(names)
print(names[0]) # you can determine a specific positive or negative index
print(names[2:4]) # you can return names at a index to a given index. Does not include that secondary index
names[0] = 'Howard'
# Practice
numbers = [3, 6, 23, 8, 4, 10]
max =... |
5587f9e0340d5b7d6f83700bf182cb59eec60dce | IshmaelDojaquez/Python | /Pong/Pong.py | 5,154 | 3.953125 | 4 | # Pong game
import turtle
import os
window = turtle.Screen()
window.title("Pong")
window.bgcolor("black")
window.setup(width=800, height=600)
window.tracer(0) # forces a manual update rather then allowing the window to update on its own
# Score
score_player1 = 0 # player 1
score_player2 = 0 # player 2
# Paddle f... |
6354e5a260db818df5bc0cab5b56394aa79aaccd | IanJang/codewars | /junyeong/valid_parentheses.py | 850 | 3.6875 | 4 | from junyeong import Test
def valid_parentheses(string):
check = 0
for s in string:
if s == '(':
check += 1
if s == ')':
if check <= 0:
return False
check -= 1
return check == 0
def test_valid_parentheses():
Test.assert_equals(valid... |
23176d422e75876e000427cf8234b86747f35b45 | IanJang/codewars | /junyeong/integers_recreation_one.py | 1,875 | 3.515625 | 4 | import math
def list_squared(m, n):
ret = []
for num in range(m, n + 1):
sum_ = op_optimized_sum_square(num)
if math.sqrt(sum_) % 1 == 0:
ret.append([num, sum_])
return ret
sum_square_cache = {}
def op_optimized_sum_square(n):
if n in sum_square_cache:
return s... |
896d08e412e0081e9c9944932b87a513c054b447 | Arseniy-Popov/DataStructures | /heap/heap.py | 3,294 | 3.984375 | 4 | from collections.abc import Container, Sized
class Heap(Container, Sized):
"""
Priority queue implemented with the heap data structure.
Allows for retrieval of the smallest element and insertions
in O(logn) time, as well as constant time smallest element
access. Ordering of the elements can be cus... |
f3c146b6f76b4faa3744eac23b868b8274d893a6 | Arseniy-Popov/DataStructures | /heap/test_heap.py | 1,930 | 3.671875 | 4 | import random
import unittest
from heap import Heap
class TestHeap(unittest.TestCase):
def setUp(self):
self.heap = Heap()
self.items = random.choices(range(100), k=30)
def test_push_peek(self):
items = []
for i in self.items:
self.heap.push(i)
items.a... |
e725914c01baf97942a3c581c40e62565bc84b08 | ajitg9572/session2 | /fomatting.py | 151 | 4.53125 | 5 | name="ajit"
age= 23
# print("your name is {} your age is{}".format(name,age))python 3
# python 3.6 below
print(f"your name is {name} your age is{age}") |
cc58a433d0fa4283925a12288d958ab4ef4ec64d | ajitg9572/session2 | /elif.py | 225 | 4.03125 | 4 | age=int(input("enter your age"))
if 0<age<=3:
print("ticket is free")
elif 11<age<=20:
print("your ticket price is 200")
elif 21<age<=30:
print("your tiket price is 300")
else:
print("your ticke price is 250") |
e2ba3d2b834e092bd3675fbcf8dbe5c33a31f729 | ajitg9572/session2 | /hackerrank_prob.py | 206 | 4.28125 | 4 | #!/bin/python3
# declare and initialize a list
fruits = ["apple","mango","guava","grapes","pinapple"]
# pritning type of fruits
print (type(fruits))
# printing value
for fruit in fruits:
print(fruit) |
1ff664be7c0423695ad6b965d487c5fa57625bbc | ajitg9572/session2 | /empty_or_not.py | 110 | 3.9375 | 4 | name=input("enter your name")
if name:
print("your name is",name)
else:
print("you not type anything") |
6b0cf072761db21b90b5c474d20f42624eb2cd81 | ajitg9572/session2 | /test.py | 290 | 4.03125 | 4 | def odd_even(l):
odd_num =[]
even_num=[]
for i in l:
if i %2==0:
even_num.append(i)
else:
even_num.append(i)
output =[odd_num,even_num]
return output
num =[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
print(odd_even(num))
|
7272a47b347604d33c2e3bcca50099c1976da126 | gdof/Amadou_python_learning | /rock_paper_scissor/main.py | 1,345 | 4.34375 | 4 | import random
# We are going to create a rock paper scissor game
print("Do you want a rock, paper, scissor game?")
# create a variable call user_input and port the user a Yes a No
user_input = input("Yes or No? ")
# if the user select no print out "It is sorry to see you don't want to play"
if user_input == "no":
... |
1ca78e25659ec812a01a9020871e603f54dd405c | Mzaba014/Hackerrank-Solutions | /30 Days of Code/day20_sorting.py | 1,016 | 4.0625 | 4 | '''
Title : Sorting
Subdomain : 30 Days of Code
Domain : Python 3
Author : Manuel Zabala
Created : 2/19/2019
Problem : https://www.hackerrank.com/challenges/30-sorting/problem
'''
#!/bin/python3
def bubblesort(arr, n):
num_swaps = 0
# Lead pointer iterates over full length
for i in range(n)... |
dcbf099c9ded9c2242211aea078d54cf1230a5ab | Mzaba014/Hackerrank-Solutions | /30 Days of Code/day15_linkedlists.py | 1,204 | 3.890625 | 4 | '''
Title : Linked List
Subdomain : 30 Days of Code
Domain : Python 3
Author : Manuel Zabala
Created : 2/19/2019
Problem : https://www.hackerrank.com/challenges/30-linked-list/problem
'''
class Node:
def __init__(self, data):
self.data = data
self.next = None
class Solution:
de... |
ea48fc2694ba9ff520544deebc14917870cb20af | Mzaba014/Hackerrank-Solutions | /30 Days of Code/day5_loops.py | 425 | 3.5625 | 4 | '''
Title : Loops
Subdomain : 30 Days of Code
Domain : Python 3
Author : Manuel Zabala
Created : 2/19/2019
Problem : https://www.hackerrank.com/challenges/30-loops/problem
'''
#!/bin/python
import math
import os
import random
import re
import sys
def multiples(n):
for i in range(1, 11):
p... |
dba34595bddb596bc07dfbfb97971d24fc406586 | vikasb7/Data-Structures | /Shuffle String.py | 543 | 3.75 | 4 | '''
Vikas Bhat
Restored a Shuffled String
Time Complexity o(N)
'''
class Practice:
def restoreString(self, s, indices):
"""
:type s: str
:type indices: List[int]
:rtype: str
"""
lis = ["a"] * len(indices)
for i in range(len(s)):
lis[indices[i]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.