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 |
|---|---|---|---|---|---|---|
165a6121c0cad87a2e9a8d466176ef4565a18c4c | xbum2008/python | /Lesson01_06.py | 327 | 3.796875 | 4 | a = int(input("Введите значение начального километража >>> "))
b = int(input("Введите значение целевого километража >>> "))
i = 1
while a < b :
i +=1
a = a * 1.1
print("Результат будет достигнут за", i, "дня/ей.") |
0620e323720417e9aafe800abe34ad097c772df4 | guyburg/atm | /prompts.py | 2,107 | 3.78125 | 4 | from user import User
class Prompt(object):
# Type that knows to display message and process user input
def __init__(self):
self.message = self._get_message()
def display_message(self, message=None):
if message:
print message
else:
print self.message
... |
24d017fde428687742f43c2e6899e982ad9a668f | Shimei-Py/fcpython | /work0304-001.py | 197 | 4 | 4 | total=0
for a in range(50,1,-2):
print(a)
total += a
print("偶數總和:",total)
total=0
for a in range(1,50,2):
print(a)
total += a
print("奇數總和:",total)
|
964b0266742b96b063ea220c8b3220945e7116f8 | rksin8/turtle | /cross_arrow.py | 213 | 3.53125 | 4 | import turtle
pen = turtle.Turtle()
pen.shape("arrow")
pen.color("red")
pen.penup()
pen.goto(0,-180)
pen.pendown()
pen.goto(0,180)
pen.penup()
pen.goto(-180,0)
pen.pendown()
pen.goto(180,0)
turtle.mainloop()
|
cdccd3f41e6c90ea7128ebd0c2a8cd5c1a92e569 | einekatze/gdp1-homework | /gdp1/assignment_5/collatz.py | 403 | 3.859375 | 4 | def collatz(n, acc=None):
if n <= 0:
raise ValueError("Collatz must be called with n > 0.")
if acc:
acc.append(n)
else:
acc = [n]
if acc[-3:] == [4, 2, 1]:
return acc
if n % 2 == 0:
new_n = n // 2
else:
new_n = 3 * n + 1
return collatz(new_... |
1b21896d30fcf091ec8a7a7cfab3b656ccae97e4 | einekatze/gdp1-homework | /gdp1/assignment_1/mean_calculator.py | 601 | 3.921875 | 4 | from gdp1.common.input_helpers import *
def main():
print("Application for calculating means of two real values")
print()
x = float_input("Please enter the first real value: ")
y = float_input("Please enter the second real value: ")
# The harmonic mean is defined as zero iff one or both of the v... |
9a144d98214ff7365662e754b5b2b0c71038a8a1 | 4n6strider/GoblinWordGenerator | /goblin.py | 941 | 3.796875 | 4 | import itertools
print('\n------------------\n\n G 0 B L ! N | WORDGENERATOR\n\n ~ by: UndeadSec\n\n------------------\n')
escala = input('Please provide a size scale(i.e: "1 to 5" = 1:5) : ')
inicial = int(escala.split(':')[0])
final = int(escala.split(':')[1])
chrs = 'abcdefghijklmnopqrstuvwxyz'
chrs_up = chr... |
73e121e4833473887aa0c9f894658aea38d911bb | Shyamala95/Digital-Alpha-Assignments | /apr_5 calculator.py | 1,140 | 3.90625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Apr 7 17:48:42 2018
@author: user
"""
def factorial(x):
if(x!=0):
return int(x)*int(factorial(int(x)-1))
else:
return 1
def LCM(a,b):
if a >b :
min1 = a
else:
min1=b
while 1:
if(min1%a==0 and min1... |
2dad1f4a5f8d26679e41bcf79df1c2f19afdb6a5 | Shyamala95/Digital-Alpha-Assignments | /list.py | 545 | 3.90625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Apr 17 18:04:51 2018
@author: user
"""
l=[]
te=int(input("Enter the no.of.terms"))
for i in range(te):
n=int(input("Enter the numbers:"))
l.append(n)
print("new list:",l)
length=len(l)
print(len(l))
l.sort()
# First Largest and Second Largest
pri... |
915b1159c097cdc51170b10ccd91c20d9b4a3713 | pjlinn/projectEuler | /74.digitFactorialChains/digitFactorialChains.py | 1,569 | 3.765625 | 4 | '''
Runs under a minute. Checks to see if I've already found
the chain for each calculated if number. If I have, I add
it to what I've found so far. If I haven't, I continue and
add once I have finished.
'''
import math
import time
# Doesn't work for numbers like 10, 100, 1000, etc.
# Shouldn't matter though
def fac... |
52d858d8b5687c3ca407a8ad87b800603702e42e | Vaild/python-learn | /teacher_cade/day11/9.异常传递.py | 458 | 3.84375 | 4 | #!/usr/bin/python3
# coding=utf-8
# def main():
# print(i)
#
#
# if __name__ == '__main__':
# i = 3
# main()
def demo1():
num = int(input("输入整数:"))
print(num)
return num
def demo2():
return demo1()
def main():
# 利用异常的传递性,在主程序捕获异常
try:
print(demo2())
except Exception... |
8b1e686d30901916278e2e312df1a880912a0cce | Vaild/python-learn | /homework/20200707/34_元组返回元素的个数.py | 81 | 3.765625 | 4 | #!/usr/bin/python3
# coding = UTF-8
tuple1 = (2,5,3,2,4)
print(tuple1.count(2)) |
66febda7544cf934bd1f122810b18906307d40de | Vaild/python-learn | /homework/20200707/30_将二维列表和二维元组转换成列表.py | 244 | 3.65625 | 4 | #!/usr/bin/python3
# coding = UTF-8
lista = [
['a', 1],
['b', 2]
]
tuplea = (
('x', 3),
('y', 4)
)
dicta = {}
dictb = {}
for i in lista:
dicta[i[0]] = i[1]
print(dicta)
for i in tuplea:
dictb[i[0]] = i[1]
print(dictb) |
3e8b56b106e9a5172de1592b9669bb35303af4a6 | Vaild/python-learn | /teacher_cade/day19/9.next和iter的迭代器.py | 1,004 | 4.21875 | 4 | #!/usr/bin/python3
# coding=utf-8
from collections.abc import Iterator
class MyIterator():
"""自定义的供上面可迭代对象使用的一个迭代器"""
def __init__(self):
self.mylist = []
# current用来记录当前访问到的位置
self.current = 0
def add(self, val):
self.mylist.append(val)
# 调用next方法时,其实就是执行__next__
... |
bcf0b8159bc0de4d402f65c7a5c0bf268aa46a93 | Vaild/python-learn | /homework/20200707/46_字符串大写小写与互换.py | 125 | 3.921875 | 4 | #!/usr/bin/python3
# coding = UTF-8
string = 'abCdEfg'
print(string.upper())
print(string.lower())
print(string.swapcase()) |
64282d65928a96978511d5978db8dea5d709f512 | Vaild/python-learn | /homework/20200709/植物大战僵尸.py | 1,488 | 3.515625 | 4 | #!/usr/bin/python3
# coding = UTF-8
# code by va1id
class SunFlower:
def __init__(self, life = None):
self.life = life
def ProductSun(self):
print('生产阳光')
def Wave(self):
print('摇晃')
class Shooter:
def __init__(self, life=None, bullet=None):
self.life = life
... |
c5cc75fe885f14f205e2b0db8255ef3c580f0684 | Vaild/python-learn | /teacher_cade/day19/7.对象可迭代的.py | 533 | 4.3125 | 4 | #!/usr/bin/python3
# coding=utf-8
class MyList(object):
def __init__(self):
self.container = []
def add(self, item):
self.container.append(item)
# 对象就是可迭代的
def __iter__(self):
return iter(self.container)
mylist = MyList()
mylist.add(1)
mylist.add(2)
mylist.add(3)
for num in ... |
a10ba30f65434ff98cb01015fec211b6e144373b | Vaild/python-learn | /homework/20200707/16_收尾元素对二维列表排序.py | 221 | 3.75 | 4 | #!/usr/bin/python3
# coding = UTF-8
lista = [
[6, 5],
[3, 7],
[2, 8]
]
# key = lambda 元素:元素【字段索引】
lista.sort(key=lambda y: y[0])
print(lista)
lista.sort(key=lambda y: y[1])
print(lista) |
270a46360e4813d5034426d7276c47e84b7f211f | Vaild/python-learn | /teacher_cade/day13/3.二叉树层次建树.py | 1,588 | 3.953125 | 4 | #!/usr/bin/python3
# coding=utf-8
from collections import deque
class Node(object):
"""节点类"""
def __init__(self, elem=-1, lchild=None, rchild=None):
self.elem = elem
self.lchild = lchild
self.rchild = rchild
class Tree:
"""树类"""
def __init__(self):
self.root = None
... |
95de4df0dd0312e1f7bfbaf8eb4a0e0ecb9b85af | Vaild/python-learn | /teacher_cade/day14/3.短路运算.py | 313 | 3.859375 | 4 | #!/usr/bin/python3
# coding=utf-8
import copy
# 短路运算
arr = [1, 2, 3, 4, 5, 6, 7]
print(0 and arr[4])
print(1 or arr[4])
# arr1 = copy.deepcopy(arr)
# print(arr is arr1)
# arr[0] = 10
# print(arr1[0])
arr1 = arr[0:7]
print(arr1)
arr1[0] = 100
print(arr)
for i in range(0):
print('I am handsome')
|
307cd2f8ccdcf9abd2e077ed313a81e7cd574989 | Yuanchao07/100day | /which_days.py | 561 | 4.34375 | 4 | def is_leap_year(year):
return year % 4 == 0 and year != 100 or year % 400 == 0
def which_day(year, month, day):
days_of_month = [
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
]
days = days_of_month[is_leap_year(year)]
total = 0
... |
02027e76d9563714bb9a1b67c7401c5553c73a77 | shortcolin/bushacks | /kdtree.py | 4,862 | 3.515625 | 4 |
# Algorithms "inspired by" wikipedia kd-tree page algorithms :-)
import math
import struct
class Node:
def __repr__(self):
return self.location.__str__()
def dump(self,maxdepth=1000,depth=0):
if depth == maxdepth: return
if self.leftChild:
self.leftChild.dump(maxdepth,depth+1)
print ... |
1e252b0287dd1146885882d9443fa506a41cdfc6 | chris-miklas/Python | /Lab01/reverse.py | 269 | 4.1875 | 4 | #!/usr/bin/env python3
"""
Print out arguments in reverse order.
"""
import sys
def reverse():
"""
Printing arguments in reverse order.
"""
for i in range(len(sys.argv)-1, 0, -1):
print(sys.argv[i])
if __name__ == "__main__":
reverse()
|
4a3a55e948fcc6b0eac6bbcef48b46a69910fe67 | chris-miklas/Python | /lab05/counter.py | 244 | 3.8125 | 4 | #!usr/bin/env python3
"""
Counts the number of individual words in a file.
"""
import sys
with open(sys.argv[1]) as f:
text = f.read().split()
dictionary = {w:0 for w in set(text)}
for w in text:
dictionary[w] += 1
print(dictionary)
|
5e9bc9fa1ab8e19203c8c1971e4147944beb8d95 | chris-miklas/Python | /lab05/just.py | 590 | 3.578125 | 4 | #!usr/bin/env python3
"""
Justify text to max number of chars.
"""
import sys
def just(file_name,width,output):
with open(file_name) as f:
text = f.readlines()
for i in range(len(text)):
if output == "None":
print(text[i].ljust(int(width)))
else:
file = open(out... |
2b2c801d2241b75c21ee65231020b4af8e4b4fec | raimundogabriel/desafio | /parte1/quest2.py | 498 | 3.828125 | 4 |
def strbalanceada(frase, bracket):
if len(frase) % 2 != 0:
print('desbalanceado 1')
return 0
else:
i = 0
j = -1
while i < (len(frase)/2): #do inicio ao meio
if frase[i] + frase[j] not in bracket:
print('desbalanceado 2')
re... |
b4dbf72dd1f6055d9e018dd8e03eb0e9558f9171 | Capeo/AIReproducibility | /ClusteringByFastSearchAndFindOfDensityPeaks/Code/Pre-Processing.py | 1,056 | 3.765625 | 4 | #Processes datasets
#The Input.txt is the dataset with n rows, where the first n-1 rows are coordinates.
#The Output.dat is the preprocessed version of the Input.txt. It contains three rows.
#The two first is the index (1 indexed) of the points in Input.txt and the third row is the distance between those points.
#
#Run... |
e99ae158f30500b5732d79cc6ed23a9bcf58c2af | nixman97/Pendulum | /Calculations.py | 202 | 3.640625 | 4 | from math import sin, radians
class Calculations:
def getAngle(self, lat, hours):
print(((sin(radians(lat)) * 360) / 24) * hours)
return (((sin(radians(lat)) * 360) / 24) * hours)
|
13d5bc85078894de27e0bc39acc5dd6c694822db | nz-mparkinson/pytheria | /main.py | 11,297 | 3.640625 | 4 | #!/usr/bin/python
#Import libraries
import pygame
from pygame.locals import *
from gui import *
from world import *
#Define a class for the Game
class Game:
SELECT_RANGE = 1 #How far away an object can be from the mouse and still be selected
#Define the constructor
def __init__(self, w... |
86ffb3138d8eb92b4fb9d7834b8411a9e77e1b57 | leoswaldo/acm.tju | /2968_Find-the-Diagonal/find_the_diagonal.py | 1,969 | 4.4375 | 4 | #!/python3/bin/python3
# A square matrix contains equal number of rows and columns. If the order of
# the matrix is known it can be calculated as in the following format:
# Order: 3
# 1 2 3
# 4 5 6
# 7 8 9
# Order: 5
# 1 2 3 4 5
# 6 7 8 9 10
# 11 12 13 ... |
88a65bb564a336d41301b6a65b4b3c428c5d6d53 | PikaKight/ICS4U-Classwork | /Coding_Practice/class/class_prep_2.py | 2,980 | 3.890625 | 4 | import datetime
from typing import List, Optional
class Classroom:
warnings: List[str] = []
def __init__(self, name: str):
self._subject = name
self._students: List[Student] = []
def set_name(self, name: str):
self._subject = name
def get_name(self):
return se... |
b8b6833c5bde9b110949f1a29245cefeab68a955 | PikaKight/ICS4U-Classwork | /Test/Tester.py | 894 | 4.03125 | 4 | # Student = dict() # creates an empty dictionary
# start = True
# while start:
# F_name = input("Student First Name: ")
# L_name = input ("Stuendt Last Name: ")
# Student[F_name] = L_name
# print (Student[F_name]) #returns the value
# ask = input("Do you want to continue (Y/N)")
# ... |
debe5e29b69748adea819fa371a96d6d76c1348f | PikaKight/ICS4U-Classwork | /Coding_Practice/class/class_test_practice.py | 3,987 | 3.75 | 4 | from typing import List
from datetime import date
class Person:
def __init__(self, first_name: str, last_name: str, DOB: date, email=None):
self._first_name = first_name
self._last_name = last_name
self._email = email
self._DOB = DOB
def set_first_name(self, first_name: str... |
a766a28ca3be316ce5d63ad1d806b4480693ebaa | PikaKight/ICS4U-Classwork | /Test/test_dict.py | 310 | 3.96875 | 4 | """
diction = {
"hello": 1,
"hi": 2,
"goodbye": 3,
"bye": 4
}
word = input()
try:
del diction[word]
except KeyError:
print("Key {} not found".format(word))
print (diction)
"""
new = {
"Name": {"Hello":"World", "form": "temperary"},
"Lie": {"Cake": "Is"}
}
print(new["Name"]) |
ddf0bda2265ee188fa3b0d5bc41d1a9d4de828f1 | KevinBruce2018/PAT_Basic_Level | /1009.py | 107 | 3.515625 | 4 | data = input().split()[::-1]
for i in range(len(data)-1):
print(data[i],end=' ')
print(data[len(data)-1]) |
14e07d88b88e3ce512dec202cb76efcdcf5f540a | geoabraham/crispy-garbanzo | /terminal-games/blackjack.py | 6,994 | 3.984375 | 4 | import random
class Card:
"""Card class
Returns:
_type_: _description_
"""
suits = ["clubs", "spades", "hearts", "diamonds"]
# this dictionary provides the value of face cards, for scoring purposes
faces = {"two": 2, "three": 3, "four": 4, "five": 5, "six": 6,
"seven": 7... |
68a7a56460b638888650a70501ceff0774aaf23e | geoabraham/crispy-garbanzo | /cracking_codes/transposition_columnar_cipher_hack.py | 1,624 | 3.78125 | 4 | import detect_english
import transposition_columnar_cipher
def main():
encrypted_text = """AaKoosoeDe5 b5sn ma reno ora'lhlrrceey e enlh na indeit n uhoretrm au ieu v er Ne2 gmanw,forwnlbsya apor tE.no euarisfatt e mealefedhsppmgAnlnoe(c -or)alat r lw o eb nglom,Ain one dtes ilhetcdba. t tg eturmudg,tfl1e1 v ... |
384b0518eb391d63a4454e4bd6f15a53211df1c5 | geoabraham/crispy-garbanzo | /hackerrank/sofi_preparation.py | 1,276 | 3.921875 | 4 | # -- recorrer matriz de forma alterna
# -- convertir de string a numero
# -- comprobar si es substring de otro string
# 1234
# 5678
# 9876
# 1234 8765 9876
# "1234" = 1234
# "12.5" = 12.5
# "asdfgh" "ads"
def matrix_alterna(matrix: list):
fila = 0
col = 0
while fila < len(matrix):
if fila % 2 ... |
3688e5ca4f0fe239be6f8c022ddb962eb0a50bc5 | geoabraham/crispy-garbanzo | /detect_string_pattern.py | 1,553 | 3.875 | 4 | # You are allowed to create new strings,
# but otherwise you are not allowed to construct
# extra data structures to solve this problem (no list, set, dictionary, etc).
# this function takes two parameters as strings to compare.
def detect_pattern(s1, s2):
# Keep in mind that this method should return the same val... |
977e69d8cda8f4ddd89529429fed239b3c19acb0 | leilin-research/Link-Travel-Time-prediction | /dataToGraph.py | 3,729 | 3.96875 | 4 | import math
def lineToPoint(line):
'''
Takes a line that looks like this
156;2014-02-01 00:00:00.739166+01;POINT(41.8836718276551 12.4877775603346)
and returns latitude and longitude value
'''
driverID, timeStamp, point = line.split(';')
#POINT(41.8836718276551 12.4877775603346)
latitud... |
89fbb49ff6824c1d770b5c813c9b71ac50f08442 | mmikolajczak/MultipleAgentsRL | /utils/others.py | 378 | 3.515625 | 4 | import re
import os
def natural_sort(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
return sorted(l, key=alphanum_key)
def get_path_to_file_last_in_numerical_order(dir_path):
return os.path.join(dir_... |
4fc4dc29b3ace7f52b17315120775d5d0532ac9d | lh20180514/python | /function.py | 1,506 | 3.859375 | 4 | #自定义函数,注意缩进
def function_converter(C):
fahrenheit = C * 9/5 + 32
return str(fahrenheit) + '°F'
C2F = function_converter(35)
print(C2F)
def g2kg_converter(g):
intg = g /1000
return str(intg) + "kg"
print(g2kg_converter(2101))
import math
def triangle_calc(a,b):
return math.sqrt(a*a + b*b)
print(t... |
acd88cf6d0cdf3bb123df1cb8b79d9075dc86333 | kenlens/sketch_5SOSkenlen | /sketch_5SOSkenlen.pyde | 722 | 3.53125 | 4 | , , xCoordinate = 50
yCoordinate = 50
speed = 5
anotherSpeed = 6.7
ellipseSize= 50
def setup():
size(400, 400)
def draw():
background(99, 56, 155)
global xCoordinate, speed, ellipseSize, yCoordinate, anotherSpeed
leftTopBoundary = ellipseSize / 2
rightBottomBoundary = 400 - ellipseSize / 2
... |
1302375f03be94986645f5fd1c9377a61cad2fe7 | awanish604/sharedResources | /Crypto/RSA Decrypt : As_q13.py | 4,612 | 4.03125 | 4 | '''
This code deals with breaking the RSA.
Here the assumption is n and e are given public key = [e,n]
n is very small number and can be factorized easily
here the user will factorize the n and will find p & q
as n = p*q
e.g : 18923 = 1, 127,149,18923
=> p*q = 127 * 149 (so this way calculat... |
8d9a29da852fc1d71591473a4c8008d7bfc33fd0 | johnarsakeio/uniprojects | /project9.py | 222 | 3.734375 | 4 | a=int(input ('give a nubmer'))
while True:
result=0
a=(a*3)+1
while a>0:
temp=a%10
result=result+temp
a=int(a/10)
a=result
if a<10:
break
print (a)
|
b2f6bcec8e5e285b00c0bf297b0392e26f894a77 | raymondyin/cs-foundation | /problems/20_Valid_Parentheses.py | 422 | 3.75 | 4 | class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
queue = []
dic = {')': '(', ']': '[', '}': '{'}
for char in s:
if char in "([{":
queue.append(char)
elif char in "]})":
if len(queu... |
0d83a380be06d2c363112e5ed5605bae7742d233 | daviswer/gpytorch | /gpytorch/random_variables/categorical_random_variable.py | 1,817 | 3.5 | 4 | import torch
from torch.autograd import Variable
from .random_variable import RandomVariable
class CategoricalRandomVariable(RandomVariable):
def __init__(self, mass_function):
"""
Constructs a categorical random variable
mass_function represents the weights of the distribution
Pa... |
259737fab79dba1c11ca9c4d878fbe1b277b106f | RanjaniMK/Python-DataScience_Essentials | /Multiple_if_else_statements_Demo.py | 181 | 3.953125 | 4 | if 5==7:
print('first statment is true.')
elif 2==4:
print('second statement is true.')
else:
print('last statement is true.')
#Output: last statement is true.
|
24d17e612bfc874dc12d9e3c03d8eb020bf9158a | RanjaniMK/Python-DataScience_Essentials | /creating_a_set_from_a_list.py | 250 | 4.34375 | 4 | # Trying to create a set from a list
# 1. create a list
# 2. create a set
my_list = [1,2,3,4,5]
my_set = set(my_list)
print(my_set)
#Note: The list has square brackets
# The output of a set has curly braces. Like below:
# {1, 2, 3, 4, 5}
|
ac10dad16ae99e31ee0775a3b742b9253e081f8d | RanjaniMK/Python-DataScience_Essentials | /loop_on_a_list_of_strings.py | 58 | 3.671875 | 4 | list=["Tom", "Dick", "Harry"]
for i in list:
print(i)
|
e2962dfb6e2a2c0f141a461eeecb158db7aa46eb | RanjaniMK/Python-DataScience_Essentials | /HelloWorld.py | 154 | 4.1875 | 4 | print("Hello World")
if(5>3):
print("5 is greater than 3")
if(5<3):
print("True")
else:
print("False")
x = 5
y = "Hello World"
print(x)
print(y)
|
27a6d441fadede3bad2319841d6ad8c951bb4d9e | nami-h/Interview | /max of binary tree.py | 797 | 3.515625 | 4 | class newNode:
def __init__(self, data):
self.data = data
self.left = self.right = None
def findMax(root):
# Base case
if (root == None):
return -999999999999
res = root.data
lres = findMax(root.left)
rres = findMax(root.right)
if (lres > res):... |
8a4a85f4c70304ab02b92e1f3247a07b8bb75fe3 | nami-h/Interview | /insertion sort.py | 281 | 3.890625 | 4 | def insertion(arr):
for i in range(1, len(arr)):
k=arr[i]
j=i-1
while j>=0 and k<=arr[j]:
arr[j+1]=arr[j]
j-=1
arr[j+1]=k
arr=[23,-7,9,12,4]
insertion(arr)
for i in range(len(arr)):
print(arr[i])
|
18f2d2e04171903faa0b35598dc8b698616a646f | nami-h/Interview | /all possible permutations of string.py | 275 | 3.890625 | 4 |
def permutations(string):
perm= []
if len(string) == 1:
return [string]
else:
for char in string:
[perm.append(char + a) for a in permutations(string.replace(char, ""))]
return perm
string = "ABC"
print(permutations(string))
|
7fd6ac6f09518d6bc290f329008c68ed236b3374 | benmaier/couzinswarm | /couzinswarm/simulation.py | 12,673 | 3.59375 | 4 | """
Simulation module
=================
Contains the `Swarm` class, which is used for simulation.
"""
import numpy as np
from couzinswarm.objects import Fish
from progressbar import ProgressBar as PB
class Swarm:
"""A class for a swarm simulation.
Attributes
----------
number_of_fish : int, def... |
588117a14e7494ca32d14c52c17c371e2c1659f7 | Kaushal1011/Automatic-CertificateDetail-Generator | /certificatemaker.py | 3,638 | 3.640625 | 4 | #!/usr/bin/env python3
"""Script to add text on certificates using data in csv file on a png"""
import csv
from PIL import Image, ImageDraw, ImageFont
def main() -> None:
"""
Reads names.csv and certi.png and adds names and project title in certificate
based on coordinates specified
"""
with open... |
5ae8dd109bab6defffbc5b2ab2570c75d255fdee | madhumitha998/Python-Computational-Thinking | /Q3/q3_main.py | 2,730 | 3.84375 | 4 | # q3_main.py
# do NOT submit this file. Run it to test your solution.
from q3 import *
# the following functions are used for answer checking
# test case functions return True (if successful) or False (if failed)
# ------------------------------------
# test case 1
def test_case1():
nums = [3, 0, 1, 0,... |
65755e12983bc94124f8eba9b62d109ff4d27797 | larryce/exerciciopybrasil-4 | /Quest39.py | 537 | 4.0625 | 4 | n=int(input("entre com o numero:"))
altura= eval(input("entre com a altura:"))
ma=altura
maNumero=n
menorAltura=altura
menorAlturaNumero=n
i=1
while i<3:
n= int(input("entre com o numero;"))
altura = input("entre com a altura:")
if altura>ma:
ma=altura
maNumero=n
if altura<menorAltura:
... |
7b7e33d2a997e5286766ca9e5f1be2a075f99031 | larryce/exerciciopybrasil-4 | /Quest37.py | 1,550 | 3.8125 | 4 | altura=eval(input("entre com sua altura:"))
peso=eval(input("entre com seu peso:"))
code=eval(input("entre com seu codigo:"))
saida=int(input("entre com 1 para continuar ou 0 para sair:"))
ma=altura
maCode=code
menorAltura=altura
menorAlturaCode=code
maiorPeso=peso
maiorPesoCode=code
menorPeso=peso
menorPesoCode=code
s... |
197a4f7a1f8298f8623eacdadfaaa3331c8f7dd2 | lauravoicu/Heroku-Streamlit-CNN | /app/streamlit_app.py | 975 | 3.59375 | 4 | import os
import keras
from keras.datasets import mnist # MNIST dataset is included in Keras
import numpy as np
import pandas as pd
import streamlit as st
import random
st.title("Written Digit Recognition App")
# load mnist dataset, test set
(_, _), (x_test, y_test) = mnist.load_data()
# load model from file
mo... |
8ce0121205e818f7af2e092002d1ebe7131a7cc3 | taog123/test1 | /1..py | 214 | 3.5 | 4 | # a=0
# b=1
# while b < 100:
# print(b)
# a,b=b,a+b
num=int(input(">>>"))
for i in range(3,101):
for j in range(2,i):
if i % j == 0:
break
else:
print(i)
|
5341dc0da722023aacb4a55c860b37fe3f822b17 | taog123/test1 | /lianxi.py | 812 | 3.578125 | 4 | # a=int(input(">>>"))
# b=a//2
# c=range(0,b+1)
# d=range(b-1,-1,-1)
# for i in c:
# e = str(' ' * (b-i) + '#' * (2 * i + 1))
# print(e)
# for i in d:
# f = str(' ' * (b-i) + '#' * (2 * i +1 ))
# print(f)
#
# for i in range(1, 10):
# for k in range(1, 10 - i):
# print(end=" ")
# fo... |
292a8806ef336025016fca31d35813ae96108581 | saucypasta/gobbletai | /gob.py | 7,034 | 3.71875 | 4 | import numpy as np
class board():
def __init__(self):
#player1 is 1, player 2 is -1
#4 is big, 1 is small
self.p1 = [[1,2,3,4],[1,2,3,4],[1,2,3,4]]
self.p2 = [[1,2,3,4],[1,2,3,4],[1,2,3,4]]
self.player = 1
self.current_board = self.init_board()
def init_board... |
5de374e70f94e367b47ba087c1b8aa3883c3ace3 | Savka-bot/-228- | /Critter.py | 1,534 | 3.703125 | 4 | class Critter:
...
@property
def mood(self):
unhappiness = self.hunger + self.boredom
if unhappiness < 5:
m = "прекрасно"
elif 5 <= unhappiness <= 10:
m = "неплохо"
elif 11 <= unhappiness <= 15:
m = "не сказать чтобы хорошо"
else:
... |
e0b47ac4e2bec863eaa16a0fa5e0f888b595d906 | John-Goya/Python-55-phonebook | /phonebook_main.py | 1,101 | 3.625 | 4 | # Python Ver: 3.6.1
#
# Author: John S. Goya
#
# Purpose: Phonebook demo MAIN
#
from tkinter import *
import tkinter as tk
#import other modules (separate files for gui & functions)
import phonebook_gui
import phonebook_function
# Frame is the Tkinter frame class
class ParentWindow(Frame):
def __ini... |
5c05985b4974bd8282c20678ff326cf61407b99e | VictorTruong93/dictionary_exercises_python | /dictionary_recap.py | 839 | 4.40625 | 4 |
# Dictionaries aka
# Hashes, HashMap, HashTables, Object, Map
# places = {
# 'farm burger': '1234 piedmont, atlanta',
# 'naan stop': '12345 piedmont, atlanta',
# }
# what is the address of farm burger?
# print(places['farm burger'])
friends = {
'Europe':{
'Paris': ['Frankie','Grace'],
... |
8a2e3bd56b7151fb854aada0561c1354f8d9f1e7 | BlackIcePenguin/ObjectOrientedPrograming | /oop.py | 3,500 | 4.03125 | 4 |
class Rocket:
def __init__(self, x, y):
self.x = x
self.y = y
def move_rocket(self, width, height):
self.x += width
self.y += height
def get_distance(self, rocket):
a = self.x - rocket.x
b = self.y - rocket.y
distance = (a ** 2 + b ** 2) ** (1/2)
... |
2976b57aa72ee494346fe8b492107516e5ac86bd | iawarner/HereWeGo | /scottishmoor.py | 3,450 | 3.9375 | 4 |
def standing_stones():
print "After walking a ways, you come into a mysitcal circle of standing stones."
print "They're creeping you out."
print "You feel a strange power."
print "Should you leave, or go approach the stones?"
circle = raw_input("> ")
if circle == "leave":
copse()
else:
dead("The stones got... |
4fa0ffc437b5b9dc47119b0229d1fc9967b9b45c | notruilin/LeetCode | /1008. Construct Binary Search Tree from Preorder Traversal/bstFromPreorder.py | 626 | 3.71875 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def bstFromPreorder(self, preorder: List[int]) -> TreeNode:
def dfs(lst):
if not len(lst): return None
... |
5d2a9c6a2d8682cc709caf9a4b6bdc6a24ea4c61 | notruilin/LeetCode | /990. Satisfiability of Equality Equations/equationsPossible.py | 1,199 | 3.5625 | 4 | class Solution(object):
def equationsPossible(self, equations):
"""
:type equations: List[str]
:rtype: bool
"""
parent = [x for x in range(27)]
rank = [0 for _ in range(27)]
def find(x):
if parent[x] == x:
return x... |
4e142875e10bcb9b2bda6db7f19915961175574d | benjaminch/numworks-scripts | /scripts/cutting_height.py | 2,172 | 3.625 | 4 | class Log:
def __init__(self, saw_blade_height_millimeters):
self.boards = []
self.saw_blade_height_millimeters = saw_blade_height_millimeters
def __str__(self):
output = ""
for i, board in enumerate(self.boards):
output += "| {0:>6} |".format(str(board))
... |
ec7c72e4d431e834c13ea5a1dc83f051720ad8cb | brabemi/codewars-python | /5-productFib.py | 309 | 3.546875 | 4 |
def productFib(prod):
F1 = 0
F2 = 1
while True:
if F1 * F2 == prod:
return [F1, F2, True]
if F1 * F2 > prod:
return [F1, F2, False]
F2 += F1
F1 = F2 - F1
print(productFib(4895)) # [55, 89, True]
print(productFib(5895)) # [89, 144, False]
|
e5714a82e6e65941162618edcace85956c6e6c80 | kristina-y/shopping-cart | /shopping_cart.py | 7,640 | 3.65625 | 4 | # shopping_cart.py
# This program allows the user to enter groceries by user id and then prints a receipt with the total price.
import os
products = [
{"id":1, "name": "Chocolate Sandwich Cookies", "department": "snacks", "aisle": "cookies cakes", "price": 3.50, "price_per": "item"},
{"id":2, "name": "All-Sea... |
c5c7e144661268cd69765869bf4ab38e8669b14b | kgrinev/Sea-Level-Prediction | /sea_level_predictor.py | 1,228 | 3.65625 | 4 | import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
def draw_plot():
# Read data from file
df = pd.read_csv("epa-sea-level.csv")
x = df["Year"]
y = df["CSIRO Adjusted Sea Level"]
# Create scatter plot
fig, ax = plt.subplots(figsize=(10, 10))
plt.scatter(x... |
ac4e24a89e65481c4367d12742c2cc4a60d116bb | andreztz/exercicios | /ListaDeExercicios-4/exercicio_4.py | 150 | 3.5 | 4 |
def maximo(a, b, c):
major = a
numbers = [a, b, c]
for num in numbers:
if major <= num:
major = num
return major
|
8aa61ece499276aa0d128b46e6e8c9df78f017a3 | andreztz/exercicios | /ListaDeExercicios-1/exercicio-3.py | 454 | 3.640625 | 4 | total_segs = int(input('Por favor, entre com o número de segundos que deseja converter: '))
dias = total_segs // 86400
temp_restante = total_segs % 86400
total_segs = temp_restante
horas = total_segs // 3600
segs_restantes = total_segs % 3600
minutos = segs_restantes // 60
segs_restantes_final = segs_restantes % 60... |
d2bd0ed8fd7c27dd1caf9e876984b125be5b6008 | zecookiez/30-Day-LeetCoding-Challenge | /Week4_Day28_First_Unique_Number.py | 1,284 | 3.890625 | 4 | from collections import deque
class FirstUnique(object):
def __init__(self, nums):
"""
:type nums: List[int]
"""
# O(1) Insertion
# Amortized O(1) query, worst case is O(N)
# Alternatively, you could use OrderedDict
self.seen = set()
... |
12eda20b8172afaa59df69a2b5060330036fc458 | zecookiez/30-Day-LeetCoding-Challenge | /Week5_Day29_Binary_Tree_Maximum_Path_Sum.py | 1,014 | 3.75 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def maxPathSum(self, root):
"""
:type root: TreeNode
:rtype: int
... |
e59bd8dc9ef679db3c1116a4a783368a210ae059 | zecookiez/30-Day-LeetCoding-Challenge | /Week1_Day07_Counting_Elements.py | 577 | 3.53125 | 4 | class Solution(object):
def countElements(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
# With O(N) memory, we can use a hashmap/dictionary to count the occurences of every element.
# O(N log N) solution, O(1) memory
# 12ms on Leetcode... |
af78671bf3d4fe081962c01a11310762b9a05a8d | tingleshao/leetcode | /remove_duplicates_from_sorted_listII/main2.py | 818 | 3.71875 | 4 | result=None
p0=head
p1=head
if (head.val !=(head.next).val):
result=head
while(p0.next!=None):
# the last two nodes
if (p0.next.next==None):
if (p0.val == p0.next.val):
if (p0!=p1):
p1.next =None
else:
... |
2ae428df27ac238807af6aa899352c3c4eff2969 | tingleshao/leetcode | /merge_k_sorted_lists/main.py | 1,289 | 3.671875 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @param a list of ListNode
# @return a ListNode
def mergeKLists(self, lists):
dummyNode = ListNode(0)
mn = float("Inf")
mnind = 0
empty =... |
c468be6bd8ae7287dbe0b6dc6a834b7a18b36248 | tingleshao/leetcode | /recover_binary_search_tree/main.py | 1,211 | 3.78125 | 4 | # Definition for a binary tree node
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
# @param root, a tree node
# @return a tree node
def recoverTree(self, root):
self.first = None
self.second = None
... |
30f444ba19805d82c04cc46fcc45d622ace2581b | tingleshao/leetcode | /regular_expression_matching/main2.py | 1,466 | 3.65625 | 4 | class Solution:
# @return a boolean
def isMatch(self,s, p):
#print "heres: " + s + "and " + str((s!= "") )
if p == "":
return s == ""
if (len(p) > 1 and p[1] != "*") or (len(p) == 1):
if s == "" or (not self.matchFirst(s[0],p[0])):
return False
return ... |
93dd6b5b0e8d20d59dd0af5164a474d91c40fe8c | tingleshao/leetcode | /binary_tree_zigzag_level_order_traversal/main.py | 1,838 | 3.75 | 4 | # Definition for a binary tree node
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
# @param root, a tree node
# @return a list of lists of integers
def zigzagLevelOrder(self, root):
res = []
leftQueue = []
... |
ee68a83acb8d9399ecaf14fb63c231be16d30219 | tingleshao/leetcode | /sqrt_x/main.py | 493 | 3.71875 | 4 | class Solution:
# @param x, an integer
# @return an integer
def sqrt(self, x):
left = 1
right = x
ans = x
while left <= right:
mid = left + (right-left) /2
if mid <= (x / mid):
left = mid + 1
ans = mid
else:
right = mi... |
aa6f5a62f11a5676138c487cc484fc645255d706 | tingleshao/leetcode | /valid_parentheses/main.py | 1,879 | 3.65625 | 4 | class Solution:
# @return a boolean
def isValid(self, s):
c1 = 0
c2 = 0
c3 = 0
stateStack = []
for x in s:
if x == "(":
stateStack.insert(0,1)
c1 += 1
# print "1"
elif x == "[":
stateStack.insert(0,2)
... |
752f34eb1a9f037a869f346311742e40f7987206 | tingleshao/leetcode | /insertion_sort_list/main.py | 834 | 3.921875 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param head, a ListNode
# @return a ListNode
def insertionSortList(self, head):
pre = cursor = dummyHead = ListNode(0)
dummyHead.next = head
... |
fc09140b5800f887bc5243234dbe472c4e32572a | tingleshao/leetcode | /remove_duplicates_from_sorted_listII/main.py | 1,471 | 3.6875 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @param head, a ListNode
# @return a ListNode
def deleteDuplicates(self, head):
vdict = []
ddict = []
if head == None:
return None
... |
b0d8df66be30db37bb83d94d9b74fecb3270ea1a | tingleshao/leetcode | /merge_k_sorted_lists/main2.py | 574 | 3.796875 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @param a list of ListNode
# @return a ListNode
def mergeKLists(self, lists):
if len(lists) == 0:
return None
dummy = ListNode(0)
tail ... |
79320e597beddc47d9f979c2d5bdc56d00f58d5b | tingleshao/leetcode | /binary_tree_maximum_path_sum/main.py | 1,164 | 3.734375 | 4 | # Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# @param root, a tree node
# @return an integer
def maxPathSum(self, root):
if root == None:
return 0
m... |
76def6900e1534088c6146645f8bd1e3fe6cd373 | tingleshao/leetcode | /add_two_numbers/main.py | 1,630 | 3.78125 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @return a ListNode
def addTwoNumbers(self, l1, l2):
if l1 == None:
return l2
if l2 == None:
return l1
curr1 = l1
... |
2124ae018076b8ed8a380ac613ded46ba9c50ed1 | tingleshao/leetcode | /interleaving_string/main.py | 1,200 | 3.765625 | 4 |
class Solution:
# @return a boolean
def isInterleave(self, s1, s2, s3):
# print len(s1)
# print len(s2)
#s print len(s3)
if len(s3) != (len(s1) + len(s2)):
return False
table = [[False for i in range(len(s2)+1)] for j in range(len(s1)+1)]
# print table
... |
30ca3f4e06164425e07c109444c59311c3a6f6a6 | tingleshao/leetcode | /valid_palindrome/main.py | 918 | 3.703125 | 4 | class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == "":
return True
i = 0
j = len(s) -1
while i < j:
if s[i].lower() in "abcdefghijklmnopqrstuvwxyz1234567890" and s[j].lower() in "abcdefghijklmnopqrstuvwxyz12345... |
6d1a0e5d586a678f6a3bb0956bf4aad71eb14108 | tingleshao/leetcode | /word_search/main.py | 1,250 | 3.53125 | 4 | class Solution:
# @param board, a list of lists of 1 length string
# @param word, a string
# @return a boolean
def exist(self, board, word):
for i in xrange(len(board)):
s = board[i]
for j in xrange(len(s)):
if board[i][j] == board[0]:
visited = [[False for m ... |
642988c0f36a1c7c4782c3f6af2af5f07bc19535 | NikitaWas/Python-Guide | /Python-Urok-2.py | 4,149 | 4.09375 | 4 | print('Урок 2')
print('Условия')
print('Введите любое число')
x = int(input())
if x>5:
print(x)
else:
print(5)
x = int(input())
if x < 0:
x = -x
print(-x)
x = int(input())
y = int(input())
if x > 0:
if y > 0: # x > 0, y > 0
print("Первая четверть")
else: # x... |
e85879074b6c9d9a5609bfc6e348caed73057499 | Vivekn741/poker-game | /poker-game.py | 6,081 | 3.921875 | 4 | import random
class Card(object):
"""A card"""
def __init__(self, suite, face):
self._suite = suite
self._face = face
@property
def face(self):
return self._face
@property
def suite(self):
return self._suite
def __str__(self):
if... |
d4811562351bd1a96b886a8c7405a772b697b0ed | dmoore1989/aoc2020 | /day_2-2.py | 589 | 3.59375 | 4 | import re
file1 = open('day_2_in.txt', 'r')
Lines = file1.readlines()
correct_passwords = 0
print(len(Lines))
for line in Lines:
line_breakdown = re.match(r'([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', line)
position_a = int(line_breakdown[1])
position_b = int(line_breakdown[2])
letter = line_breakdown[3]
... |
55931663bb9d3db62a67469ff9abf5d877d58f85 | maverick850/reddit-analysis | /graphdata.py | 283 | 3.671875 | 4 | # -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
"""
This module graphs the data
"""
def main(splitforgraph,keylist):
barlabels = list()
for week in splitforgraph:
barlabels.append(week[0])
print('barlabels', barlabels)
return
|
511a7d2674f3fffefe7c2b977eab1d97dfda5d6a | gsshohel1314/python_practice_one | /w3_variables.py | 1,464 | 3.734375 | 4 | # Variable holo akti container ja data store korar jonno use kora hoy.
# Python e variable er datatype bole dite hoy na.
x=5
y="Rokon"
print(x)
print(y)
# String variable er value single or double quotes diye declare kora jay.like,
first_name="Shohel"
last_name='rana'
print(first_name)
print(last_name)
# Variable nam... |
6c1263670785e8e238dcb098ee1ed2640b202e92 | Deepa-chaurasiya01/Quiz-game | /game.py | 5,935 | 4.125 | 4 | print("Hello, Welcom to !!!The Quiz Game!!!")
answer = input("Are you ready to play (yes/no):")
score = 0
total_q = 10
if answer.lower() == 'yes':
print("Okay! then Let's play !!!The Quiz Game!!! \n ")
answer = input("1.The Pir Panjal range is located in which of the following states? \n a. Arunachal ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.