blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
a50782f91ff41b6f3dd08e0591ccffae445e2967 | deepakduggirala/leetcode-30-day-challenge-2020 | /May/week-02-day-03-Find-the-Town-Judge.py | 1,203 | 3.625 | 4 | '''
In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
The town judge trusts nobody.
Everybody (except for the town judge) trusts the town judge.
There is exactly one person that satisfies properties 1 and 2.
You a... |
5527796d0c3a3fb979a361b12a89a68179760980 | deepakduggirala/leetcode-30-day-challenge-2020 | /September/09-compare-version-numbers.py | 690 | 3.828125 | 4 | '''
https://leetcode.com/explore/featured/card/september-leetcoding-challenge/555/week-2-september-8th-september-14th/3454/
'''
class Solution:
def compareVersion(self, version1: str, version2: str) -> int:
convert_version_to_list = lambda ver: [int(x) for x in ver.split('.')]
v1 = convert_version_to_... |
ba6abf4ea878921a5546fa4383f5bdc27a57639f | deepakduggirala/leetcode-30-day-challenge-2020 | /May/week-02-day-05-Single-Element-in-a-Sorted-Array.py | 950 | 3.78125 | 4 | '''
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.
Example 1:
Input: [1,1,2,3,3,4,4,8,8]
Output: 2
Example 2:
Input: [3,3,7,7,10,11,11]
Output: 10
Note: Your ... |
695d9747b3a747b6447402225960cfd457ba041b | deepakduggirala/leetcode-30-day-challenge-2020 | /May/week-03-day-01-Maximum-Sum-Circular-Subarray.py | 1,473 | 3.5 | 4 | '''
Maximum Sum Circular Subarray
Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C.
Here, a circular array means the end of the array connects to the beginning of the array. (Formally, C[i] = A[i] when 0 <= i < A.length, and C[i+A.length] = C[i] when i ... |
d508f0c5332895576ff54b9e30611649e8ec76cd | deepakduggirala/leetcode-30-day-challenge-2020 | /April/week-04-day-06-Maximal-Square.py | 1,174 | 3.671875 | 4 | '''
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Example:
Input:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Output: 4
'''
class Solution:
def maximalSquare(self, matrix):
R = len(matrix)
if R == 0:
return 0
... |
3fb0cc805ce0745e9b7200122eda456d8e63e266 | deepakduggirala/leetcode-30-day-challenge-2020 | /April/week-01-day-03-Maximum-Subarray.py | 727 | 4.15625 | 4 | '''
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Example:
Input: [-2,1,-3,4,-1,2,1,-5,4],
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Follow up:
If you have figured out the O(n) solution, try coding another sol... |
eebcae5621cc1d84d6a36bbbba5a16606be9fc84 | uprestel/ODE-Solver | /src/newtonssc.py | 4,122 | 3.578125 | 4 | """
Implementations of Newton methods using different strategies to achieve globalization and efficiency
_________________________________________________________________________________________________
Sources used: http://www.mathsim.eu/~gkanscha/notes/ode.pdf |
htt... |
02a32a6efd61bf0957d0af6d5e3e058218b01062 | keen-s/p | /x.py | 865 | 4.1875 | 4 |
def name():
print
try :
user_age = int(input("Please input your age : "))
if 0 <= user_age <= 3 :
print("Your a toddler!")
elif 4 <= user_age <= 12 :
print("You are a kid!!")
elif 13 <= user_age <= 19 :
print("You are a teenager!"... |
72082fb836db1b7dec35b93187dea4188e9c0fb7 | baranmcl/Project_Euler | /03_Largest_Prime_Factor.py | 612 | 3.6875 | 4 | #The prime factors of 13195 are 5, 7, 13 and 29.
#What is the largest prime factor of the number 600851475143 ?
import math
def isPrime(n):
if n == 2:
return True
if n%2 == 0 or n <= 1:
return False
sqr = int(math.sqrt(n)) + 1
for divisor in range(3, sqr, 2):
if n%divisor == 0:
... |
920b554c784c00874030de4b9ec72a85d58eb4ec | baranmcl/Project_Euler | /17_number_letter_counts.py | 1,453 | 3.765625 | 4 | #If the numbers 1 to 5 are written out in words: one, two, three, four, five,
#then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
#If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words,
#how many letters would be used?
#NOTE: Do not count spaces or hyphens. For example, 342 (t... |
a5fd28c914c904cdcf77fd9cb0b2ec7c36f5c8d4 | kimkw88/CS331_Project | /HW1/hw1.py | 9,366 | 3.65625 | 4 | # Author: Kwanghyuk Kim
# Hojun Shin
# Due: April 19 2021
# CS 331
# Programming Assignment #1
import sys
import copy
import Queue
LEFT = 0
RIGHT = 1
CHICKEN = 0
WOLVES = 1
BOAT = 2
class Node:
def __init__(self, node, method, state):
self.par_node = node
# If boat is at left side
... |
829daf16f6002677fca0cc44c5200fba466f8c96 | timqsh/advent2019 | /d4/d4.py | 353 | 3.515625 | 4 | import itertools as it
start = 146810
end = 612564
def has_2_in_row(s: str) -> bool:
return 2 in [len([*group]) for _, group in it.groupby(s)]
# return any(s[i] == s[i + 1] for i in range(len(s) - 1))
total = 0
for i in range(start, end + 1):
s = str(i)
if has_2_in_row(s) and sorted(s) == list(s):
... |
a829348efb02a455f54329dc03c62004a0a5c1b8 | need4spd/eulerproject | /need4spd/euler_44.py | 435 | 3.78125 | 4 | import math
def is_pentagonal(n):
n = abs(n)
p = ( math.sqrt(1 + 24*n) + 1 ) / 6
return p==int(p)
pent_list = [1]
i = 0
not_found = True
while not_found:
i+=1
pent_list.append(int(i * (3*i - 1)/2))
for j in range(2, len(pent_list) - 1):
if is_pentagonal(pent_list[i] - pent_list[j]) and is_pent... |
3bb4166d145f7b18f5365727588bbaf388d8846c | need4spd/eulerproject | /simsims/euler_6.py | 99 | 3.640625 | 4 | import math
a = 0
b = 0
for x in range(1,101):
a += math.pow(x,2)
b += x
print(math.pow(b,2)-a) |
910bccb0220a488b659080536f954c6d416166ae | need4spd/eulerproject | /need4spd/euler_22.py | 1,134 | 3.5 | 4 | #generate alphabet score
#alphaList=map(chr, range(ord('A'), ord('Z')))
alphaList = [chr(c) for c in range(ord('A'), ord('Z')+1)]
print (alphaList)
def getNameAndIndex(dataList):
for index in range(0, len(dataList)):
name = dataList[index]
print("name={0}, index={1}".format(na... |
5e5246f7d251455cd3c8937673cf86586ccf6dce | need4spd/eulerproject | /sun22/euler_3.py | 329 | 3.6875 | 4 | def prime(num) :
j=2
isPrime = False
while(j <= num) :
if(j!=num and num%j==0) :
isPrime = False
break
else :
isPrime = True
j=j+1
return isPrime
list=[]
a=600851475143
b=2
max=0
while(b <= a) :
if(a%b == 0 and prime(b) == True) :
a = a/b
list.append(b)
if(max < b) : max=b
else : b=b+1
p... |
8190f74f4aaff9ecbba6ea76d60a8466b84909d4 | need4spd/eulerproject | /need4spd/euler_45.py | 648 | 3.6875 | 4 | """
import math
def is_pentagonal(n):
n = abs(n)
p = ( math.sqrt(1 + 24*n) + 1 ) / 6
return p==int(p)
def is_hexagonal(n):
n = abs(n)
p = ( math.sqrt(8*n + 1) + 1) /4
return p == int(p)
def is_triangular(n):
n = abs(n)
p = (math.sqrt(8*n+1) - 1) / 2
return p == int(p)
n = 40756
while True:
... |
3b8384db029178844e1a7a45860ea9e233ecbe48 | BingQZhou/Grocery_Sales | /methods.py | 393 | 4.25 | 4 | import numpy as np
import pandas as pd
import methods as mt
import datetime
def convert_date(str):
"""
This method is used to convert a string into datetime.
"""
arr = str.split("-")
year = int(arr[0])
month = int(arr[1])
str = arr[2]
arr = str.split()
day = int(arr[0])
date = ... |
c8fa4084a31f015b44d321d25766f8ef9c9262ae | hackingmath/Neural-Net | /neuralnetwork.py | 5,618 | 3.578125 | 4 | '''Make your own Neural Network
Tariq Rashid
May 30, 2017'''
import numpy as np
#import matplotlib.pyplot as plt
from math import exp
#import scipy.special
class NeuralNetwork(object):
#initialize the neural network
def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
... |
c8dfe3a424f5a5768e111c6c31fabc360ab2d8a1 | skyhigh8591/VocationalTraining_LearningCode | /Program_Python_code/16.py | 164 | 3.65625 | 4 | #!/usr/bin/python
# -*- coding: UTF-8 -*-
num = 10
if num < 0 or num > 10: # 判断值是否在小于0或大于10
print 'hello'
else:
print 'undefine'
|
b7814940d67f81fb073377267ccf3d788ab64071 | skyhigh8591/VocationalTraining_LearningCode | /Program_Python_code/25-2.py | 1,145 | 3.828125 | 4 | #!/usr/bin/python
#coding=utf-8
#字典創建 while開關 字典添加 字典尋找
dictionary = {}
flag = 'a'
pape = 'a'
off = 'a'
while flag == 'a' or 'c' :
flag = raw_input("添加或查找单词 ?(a/c)")
if flag == "a" : #開啟
word = raw_input("輸入單詞(key):")
defintion = raw_input("輸入定義值(value):")
dic... |
385bebb9afa93dc3dadd2d72d68a5d8bcf15ea23 | skyhigh8591/VocationalTraining_LearningCode | /Program_Python_code/25-1.py | 353 | 3.84375 | 4 | #! /usr/bin/python
#coding=utf-8
#10~20質數
while(True):
num = input("enter your number:")
#num = int(num)
i=2
while(i<num):
if (num%i==0):
j=num/i
print '%d 等於 %d * %d' %(num,i,j)
print '不是質數'
break
i=i+1
else:
print num, '是... |
077ca7f1f8584d71805bda26c74acf4af890d692 | DBarthe/wikigraph | /wikigraph/models/graph.py | 2,265 | 4.15625 | 4 | import itertools
class Graph:
""" A basic graph class. """
def __init__(self):
""" A matrix vertice x edges. """
self.vertices = []
""" Gets the number of vertices. """
def order(self):
return len(self.vertices)
""" Gets the number of edges. """
def size(self):
return sum((len(edges... |
d4b0c2e9b7964b13c442a7c1e0471779480a99b3 | pixelkind/advent-of-code-2020 | /09/09_01.py | 498 | 3.546875 | 4 | file = open('./input.txt', 'r')
string = file.read()
numbers = list(map(lambda x: int(x), string.split('\n')))
preamble = 25
def calculate(numbers, number):
while len(numbers) > 0:
valueA = numbers.pop(0)
for valueB in numbers:
r = valueA + valueB
if r == number:
return True
return Fal... |
1ea5baabc6113eb51bf838ed9c8cd0f8ec663a1e | pixelkind/advent-of-code-2020 | /05/05_01.py | 797 | 3.734375 | 4 | file = open('./input.txt', 'r')
string = file.read()
lines = string.split('\n')
# first 7 characters will either be F or B
# Each letter tells you which half of a region the given seat is in
# F = front, B = back
def calculacte(start, row_string):
result = 0
row = start
for char in row_string:
row /= 2
... |
913b597dc825a10e7d0be27a4640a1cea7363f5e | ovenbakedgoods/GuessANumber | /NumberGame2.py | 1,147 | 4.125 | 4 | import random
number_of_guesses = 0
name = input('Are you feeling lucky? Step right up and guess a number! First what is your name?')
print(name + ', help me set some limits on this number')
x = int(input('Whats the smallest number to be included?'))
y = int(input('Whats the largest number to be included? '))
numb... |
a019a0585ef950b41721e2e6c3b798620c992cea | avikay/data-frame-I | /Pandas - Data Frames - I.py | 2,368 | 4.21875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[2]:
import pandas as pd
import numpy as np
from numpy.random import randn
# In[3]:
#random seed value is provided to get same random number(random numbers generator type i. seed ii. linear congurential etc.)
np.random.seed(101)
# In[7]:
#data frame is created using ... |
d319dc33fc73614d50a1dc258e65bf77549caab3 | Yanl05/LeetCode | /one_hundred_eight.py | 2,873 | 3.796875 | 4 | # -*- coding: UTF-8 -*-
"""
# @Time : 2019-07-17 08:55
# @Author : yanlei
# @FileName: one_hundred_eight.py
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。
本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。
示例:
给定有序数组: [-10,-3,0,5,9],
一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树:
0
/ \
-3 9
/ /
-10 5
来... |
3e9f955a5d9053d9bec47aa7a5905173591d1e13 | Yanl05/LeetCode | /twenty-one.py | 1,580 | 3.875 | 4 | # Definition for singly-linked list.
'''
将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
示例:
输入:1->2->4, 1->3->4
输出:1->1->2->3->4->4
'''
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
l1 = ListNode(1)
l1.next = ListNode(2)
l1.next.next = ListNode(4)
l2 = ListNode(1)
l2.next = ... |
be7cfc0af5644839bcb1b78f9bc9e6b685e642ee | Yanl05/LeetCode | /three.py | 735 | 3.515625 | 4 | class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
if not s:
return 0
longestlenth = 1 # 非空子串的长度最小为1
substr = ''
for item in s:
if item not in substr:
substr += item
... |
c086de9a4804a9fe9e5e2d24e75922253e229da4 | Yanl05/LeetCode | /forty-nine.py | 532 | 3.6875 | 4 | class Solution:
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
strs_map = {}
result = []
for i in strs:
string = ''.join(sorted(i))
if string not in strs_map:
strs_map[string] = len(... |
cf6b54a7486d6eb9c26a40d486d76f3dd66e652f | Yanl05/LeetCode | /one_hundred_one.py | 2,725 | 3.90625 | 4 | # -*- coding: UTF-8 -*-
"""
# @Time : 2019-07-12 09:31
# @Author : yanlei
# @FileName: one_hundred_one.py
给定一个二叉树,检查它是否是镜像对称的。
例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
1
/ \
2 2
/ \ / \
3 4 4 3
但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
1
/ \
2 2
\ \
3 3
来源:力扣(LeetCode)
链接:https://leetcode-... |
488c1a45036d087275bb1aaee84a6b9897e42416 | Yanl05/LeetCode | /one_thousand_twenty_five.py | 985 | 3.671875 | 4 | # -*- coding: UTF-8 -*-
"""
# @Time : 2019-06-25 22:53
# @Author : yanlei
# @FileName: one_thousand_twenty_five.py
爱丽丝和鲍勃一起玩游戏,他们轮流行动。爱丽丝先手开局。
最初,黑板上有一个数字 N 。在每个玩家的回合,玩家需要执行以下操作:
选出任一 x,满足 0 < x < N 且 N % x == 0 。
用 N - x 替换黑板上的数字 N 。
"""
class Solution(object):
def divisorGame(self, N):
"""
... |
9c5e15583f9938cb3177a4d0a69bcea59cb97340 | Yanl05/LeetCode | /one_hundred_ten.py | 3,582 | 3.65625 | 4 | # -*- coding: UTF-8 -*-
"""
# @Time : 2019-07-17 10:12
# @Author : yanlei
# @FileName: one_hundred_ten.py
给定一个二叉树,判断它是否是高度平衡的二叉树。
本题中,一棵高度平衡二叉树定义为:
一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1。
示例 1:
给定二叉树 [3,9,20,null,null,15,7]
3
/ \
9 20
/ \
15 7
返回 true 。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/... |
8d2d93dd2500d294c02c563525272e342d7dab27 | abhikpal86/Python_programs_practice | /binarysearch.py | 478 | 3.53125 | 4 | m = 0
def found(list, n):
l = 0
u = len(list)
while l <= u:
mid = (l + u) // 2
if list[mid] == n:
globals()['m'] = mid
return True
else:
if list[mid] < n:
l = mid + 1
else:
u = mid - 1
else:
r... |
deb3d37a744bbfaf86feac6a55905c8ab2fd3e6b | abhikpal86/Python_programs_practice | /linearsearch.py | 240 | 3.796875 | 4 | def search(lst,m):
for i in range(len(lst)):
if lst[i] == m:
print("The item found in position: ", i + 1)
break
else:
print("The item not found.")
list = [5,8,4,6,9,2,1]
n = 9
search(list,n)
|
7377669650fdd9a44481b6761f94e211a014f70f | abhikpal86/Python_programs_practice | /demo1.py | 237 | 4.15625 | 4 | print("Enter the number range.");
a=int(input("Enter the starting number: "));
b=int(input("Enter the last number: "));
i=a;
while i<=b:
if (i%3==0 or i%5==0):
print(end=(""))
else:
print(i ,end=(" "))
i=i+1
|
bff79099a481b4ebcf4a5bb04cb3a3044e892ae5 | SichYuriy/ParallelProgramming_KPI | /Lab6/SquareMatrix.py | 1,878 | 3.546875 | 4 | from Vector import Vector
class SquareMatrix:
def __init__(self, size):
self.size = size;
self.matrix = [[0 for j in range(size)] for i in range(size)];
def getSize(self):
return self.size
def get(self, i, j):
return self.matrix[i][j]
def set(self, i, j, val):
self.matrix[i... |
e090b0a80a05bbcc87738f47d31993e92720458f | kaiserasif/HackerRank | /Artificial Intelligence/Statistics and Machine Learning/Basic_Statistics_Warmup.py | 911 | 3.875 | 4 | # Enter your code here. Read input from STDIN. Print output to STDOUT
if '__main__' == __name__:
# define some functions
mean = lambda x: sum(x) / len(x)
cov = lambda x, y: mean([a*b for a,b in zip(x,y)]) - mean(x) * mean(y)
N = int(input())
nums = [int(i) for i in input().split()]
nums = sor... |
ad55c2106aa2d01bacbdca876a26a38669b67b0f | bobpaw/adv-coding | /TurtleFun.py | 1,164 | 3.984375 | 4 | ##
## Making some patterns with python turtles. Run in python 3.
## Author: Jason Kolbly <jason@rscheme.org>
##
import turtle
turtle.mode("logo")
screen = turtle.Screen()
screen.tracer(0,0)
joe = turtle.Turtle()
joe.shape("turtle")
joe.speed(10)
steve = joe.clone()
fred = joe.clone()
bob = joe.clone()
joe.sethea... |
88430912dc0b32fa154028dc0f9028a591396de2 | akmadan/pythoncourse | /break_pass_continue.py | 210 | 3.75 | 4 | # i = 1
# while(i<=10):
# if(i==5):
# break
# print(i)
# i=i+1
# for i in range(1,11):
# if(i==5):
# continue
# print(i)
# for i in range(1,10):
# pass
|
c4c956035e670b0a52d121bd36c6e2c75cdd3a8a | MohamedAtef321/Starks | /Tasks/1- Python Tricks/1- HackerRank/3- sWAP cASE/3- sWAP cASE.py | 294 | 4.03125 | 4 | def swap_case(s):
#swapped = s.swapcase()
swapped = ''
for letter in s:
if letter==' ': swapped += ' '
elif letter==letter.upper(): swapped += letter.lower()
elif letter==letter.lower(): swapped += letter.upper()
return swapped
|
289ef2dfc0850c2a9797bc3168e173fe16a9992c | Gaurav-Jain-0781/Unit-Testing | /test_functions.py | 1,220 | 3.8125 | 4 | from unittest import TestCase
from functions import divide, multiply
class unit_testing(TestCase):
def test_result(self):
result = 5.08
return self.assertAlmostEqual(divide(15, 3), result, delta=1.08)
def test_result_zero(self):
result = 0
return self.assertEqual(divide(0, 5),... |
8a10d35e9d87c76db36a36dfcba23e242814a4a6 | lukowar/study | /HW_1_1.py | 198 | 3.984375 | 4 | num_1 = int(input("input a = "))
num_2 = int(input("input b = "))
print("a + b = ", num_1 + num_2)
print("a - b = ", num_1 - num_2)
print("a * b = ", num_1 * num_2)
print("a / b = ", num_1 / num_2)
|
ed1350213d0c7126166dbae40f94cf835d3bcad4 | lukowar/study | /CW_2.py | 1,958 | 4.15625 | 4 | #Class work
#Task 1
num_1 = int(input("input first number "))
num_2 = int(input("input second number "))
if num_1 > num_2:
print ("{} is bigger than {}".format(num_1,num_2))
elif num_1 < num_2:
print ("{} is bigger than {}".format(num_2,num_1))
else:
print ("You have input equal values")
#Task 2
num_1 = ... |
9abea0382151c1439334666f307baae4cb381d15 | lukowar/study | /HW_3_3.py | 178 | 4.03125 | 4 | def greet(name):
if name == "Johnny":
return "Hello, my love!"
return "Hello, {}!".format(name)
name_1 = input ("Please input your name ")
print (greet(name_1))
|
17e333a044e23c6434aa3275e81e446afb61cac7 | lukowar/study | /HW_8_2.py | 398 | 3.546875 | 4 | def sorter(textbooks):
return sorted(textbooks,key=str.lower)
print (sorter(['Algebra', 'History', 'Geometry', 'English']), ['Algebra', 'English', 'Geometry', 'History'])
print (sorter(['Algebra', 'history', 'Geometry', 'english']), ['Algebra', 'english', 'Geometry', 'history'])
print (sorter(['Alg#bra', '$istory'... |
3172d21e3db58feab8b5d0cb9b7f65a66fde8660 | abhinas90/blackjack-trial | /status_line_chart.py | 818 | 3.5 | 4 | import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.animation import FuncAnimation
sns.set_style('white')
frame_len = 100000
fig = plt.figure(figsize=(9,6))
def animate(i):
data = pd.read_csv('status.csv')
y1 = data['win']
y2 = data['draw']
y3 = data['loss']
... |
24a4c256a9e1bfe01cc5698408875bf1f99c7b8e | HafsaParker/Encryption-Decryption-program | /encryptdecfile.py | 2,809 | 3.578125 | 4 | class code:
def __init__(self):
self.codes={'a':'z','b':'x','c':'y','d':'s','e':'u','f':'a','g':'e','h':'c','i':'k','j':'r','k':'n','l':'g','m':'d','n':'l','o':'m','p':'t','q':'f','r':'i','s':'h','t':'o','u':'j','v':'p','w':'v','x':'b','y':'w','z':'q'}
self.first=[]
self.enc=[]
... |
4aeb0d37ac28b6e26ea0524558b4624bf525a789 | sathish-selvan/python-turtle- | /playing with dots.py | 686 | 3.578125 | 4 | import turtle
sat = turtle.Turtle()
s = turtle.Screen()
s.bgcolor("white")
sat.penup()
sat.goto(0,0)
sat.pendown()
sat.speed(0)
n = 10
for k in range(1,37):
for i in range(5):
sat.penup()
sat.forward(50)
sat.pendown()
sat.dot(5*i)
sat.penup()
sat.goto(0,0)
sat.p... |
9b221b2e47649830928aa5df4889077afb64b5b9 | sathish-selvan/python-turtle- | /spirograph.py | 282 | 3.78125 | 4 | import turtle
turtle.bgcolor("black")
turtle.pensize(2)
turtle.speed(0)
for i in range(6):
for colours in ["Violet","cyan","green","yellow","orange","red","blue","purple","white"]:
turtle.color(colours)
turtle.circle(100)
turtle.left(10)
turtle.done() |
7b2b0dac137f73db4c97de0259ab678620bdcbf1 | rskidmore1/NumberGuess | /guessnumber.py | 916 | 3.71875 | 4 | import random
import numpy
def guess():
endRange = raw_input("Please select an end range:")
endRange = float(endRange)
guess = raw_input("Please guess a number:")
guess = int(guess)
rand = random.random()
randfloat = rand * endRange
randint = int(randfloat)
if guess == randint:
print "Great j... |
cf53fea3ac88cca586aba4e16c12a8c4510ee2e3 | DevTotti/ISBN | /app.py | 382 | 3.765625 | 4 | user = int(input("Enter number here: "))
def one(user):
number = user
if number % 4 == 0:
two(number)
else:
five(number)
def two(number):
num = number
if num % 100 == 0:
three(num)
else:
four(num)
def three(num):
year = num
if year % 400 == 0:
four(year)
else:
five(year)
def four(year):... |
7e1e9f6f3905dbf2b4b6319554686fd024241b10 | Yzdesarrollo/PythonCesde | /pythonFazt/string.py | 762 | 4.375 | 4 | myStr = 'Hello world'
# print(dir(myStr)) # Directorio de metodos de python
print(myStr.upper())
print(myStr.lower())
print(myStr.swapcase())
print(myStr.capitalize())
print(myStr.replace('Hello', 'Fazt').upper())
print(myStr.count('l'))
print(myStr.startswith('Hello')) # Si empieza con...
print(myStr.endswith('d')) ... |
a8e0c4c66d67a018acb27a3fdfe29adc02979909 | Yzdesarrollo/PythonCesde | /POO/Polimorfismo.py | 1,090 | 4.09375 | 4 | """Metodo construtor"""
print('----------Metodo Constructor-------------')
class Perro():
def __init__(self, color, raza):
self.color = color
self.raza = raza
Tobby = Perro('Negro', 'Bull Terry')
print('Tobby es un perro de raza {} y es de color {}'.format(Tobby.raza, Tobby.color))
"""Metodo str... |
2e90cfa4e5276bc8f6876e359c9e9a4ae579bd90 | Yzdesarrollo/PythonCesde | /pythonFazt/functions.py | 424 | 4.0625 | 4 | print('-----------FUNCION-----------------------------')
def hello(name='Persona'):
print(f'Hello {name}')
hello('Fazt')
hello('Ryan')
hello()
print('-----------FUNCION CON RETURN-----------------')
def add(num1, num2):
return num1 + num2
print(add(10, 20))
print(add(600, 20))
print('-----------FUNCION LAMB... |
b4771aed71974816fd4a542fe7e71b2ba1a0c634 | SongJialiJiali/test | /leetcode_657.py | 698 | 3.640625 | 4 | #leetcode 657. 判断路线成圈
class Solution(object):
def judgeCircle(self, moves):
"""
:type moves: str
:rtype: bool
"""
List_R, List_L, List_U, List_D = [], [], [], []
for i in range(len(moves)):
if moves[i] == 'R':
List_R.append(i)
... |
20999bf91d1574f1f63fc787cc2dd35790deb7ef | SongJialiJiali/test | /leetcode_744.py | 905 | 3.546875 | 4 | # leetcode 744. 寻找比目标字母大的最小字母
class Solution(object):
def nextGreatestLetter(self, letters, target):
"""
:type letters: List[str]
:type target: str
:rtype: str
"""
letters_sort = sorted(set(letters))
if target in letters_sort and letters_sort.index(target) <... |
cff78a70995d420cf1cae20f6da5f094287689b6 | SongJialiJiali/test | /leetcode_125.py | 538 | 3.703125 | 4 | #leetcode 125. 验证回文串
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
if len(s) == 0:
return True
set_num = set('0123456789')
set_str = set('abcdefghijklmnopqrstuvwxyz')
List = []
for i in range(... |
11a36aeabd1999743c9f398f5004808401f3f7b6 | SongJialiJiali/test | /leetcode_832.py | 462 | 3.5625 | 4 | #leetcode 832. 翻转图像
class Solution(object):
def flipAndInvertImage(self, A):
"""
:type A: List[List[int]]
:rtype: List[List[int]]
"""
for i in range(len(A)):
A[i] = A[i][::-1]
for m in range(len(A)):
for n in range(len(A[0])):
... |
8de4c908f7e778939b4a6b0c22bdc795d2dbcda8 | SongJialiJiali/test | /leetcode_258.py | 524 | 3.609375 | 4 | #leetcode 258. 各位相加
class Solution(object):
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
def addNum(n):
Sum = 0
while n > 0:
Sum = Sum + (n % 10)
n = n // 10
return Sum
if n... |
32530ca83f539ac126f3a917c76eb6b1c317e41d | SongJialiJiali/test | /leetcode_557.py | 465 | 3.609375 | 4 | # leetcode 557. 反转字符串中的单词 III
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
List_s = s.split(' ')
List_raw = []
for i in range(len(List_s)):
List_raw.append(List_s[i][::-1])
Str =''
for j in r... |
6eba31cfab8b248ae3df3f14b45096626acd6446 | yunussevin/Python | /Kare alma.py | 149 | 3.59375 | 4 | print("*********Girilen Sayının Karesi*********")
Sayı = input("Sayıyı Giriniz:")
intsayi = int(Sayı)
print("Sayının Karesi:", intsayi ** 2)
|
71679fcf91e8f825b2e055c377d9cfa846e42b2e | zhangli709/Scrapy | /reptile_study/day8/practice.py | 289 | 3.65625 | 4 | def trim(s):
s = trim(s)
return s
def main():
list1 = ['菜鸟教程', 'www.runoob.com']
list2 = ['百度', 'www.baidu.com']
print("学习网站:{0[0]}, 地址{0[1]}, 搜索网站;{1[0]}, 地址{1[1]}".format(list1,list2))
if __name__ == '__main__':
main()
|
8f28fb6961d1738c536015af0b45163645794cb1 | phoenix1911/firstPythonProjects | /demo_10_列表.py | 1,101 | 4.03125 | 4 | """
Python 的元组与列表类似,不同之处在于元组的元素不能修改。
元组使用小括号
列表使用方括号
"""
list1 = ["google", "baidu", 1, 2]
'''访问列表'''
print(list1)
print(list1[0])
print(list1[1:4]) # [a:b] 左开右闭原则 a<=x<b
print("-" * 100)
'''修改列表,列表不允许修改 但可以连接组合'''
lista = ["a", "b", "c"]
lista[1] = 10
print(lista)
print("-" * 100)
'''不允许删除元素 但可以删除整个列表'''
list0 = [... |
a4c6d07792f48525c9c196a1e1a0d55680163f25 | ijoosong/codechallenges | /python_test/sort.py | 1,335 | 3.5 | 4 | #!/usr/bin/python
import sys, getopt
# Store input and output file names
ifile=''
ofile=''
# Read command line args
myopts, args = getopt.getopt(sys.argv[1:], "i:o:")
##########################
# o == option
# a = argument passed to o
##########################
for o, a in myopts:
if o == '-i':
ifile = a... |
69e55c773ce37a0b393899988242557b7195a583 | liangdp1984/seqtools | /Python/seqtools/utilities/__init__.py | 237 | 3.75 | 4 | from progressbar import ProgressBar
def sliding_window(sequence, n=3):
"""Returns a sliding window (of width n) over a character sequence"""
total = len(sequence) - n + 1
for i in range(total):
yield sequence[i:i+n]
|
b0e0d14d2e835174bdeb38c70420627aa5ece777 | liangdp1984/seqtools | /Python/seqtools/sequence/kmer.py | 215 | 3.5 | 4 | from collections import Counter
from seqtools.utilities import sliding_window
def frequency(sequence, k=3):
freq = Counter()
for kmer in sliding_window(sequence, k):
freq[kmer] += 1
return freq
|
797c2a1b1826ad43ccd1ca42e185cc98e0b9ca37 | drewblik/Learn | /Book Calculator.py | 473 | 3.796875 | 4 | import math
#typecasting is converting a string to an int
name = input("Enter book name: ")
pages = int(input("Enter number of pages:"))
words = int(input("Enter number of words on one page: "))
hh_finish = round((pages*words/270/60)*2)
print("You will finish this book in " + str(hh_finish)+ " days!")
file1 = open(... |
cdac8817d25c3b77d1d8d8cc4f0e3a5e0a6c96b1 | sinipelto/popl-exercises | /examples/roman-numerals/tree_generation.py | 3,791 | 3.921875 | 4 | #!/usr/bin/env python3
# ----------------------------------------------------------------------
''' SuperSimple (and useless) unicodeLanguage. Numbers are roman numerals.
push 1 to stack, push 2 to stack, add them, print top of stack:
I⇑⍽II⇑⍽⊕⍽ψ⍽↵
push 1 to stack, push 11 to stack, swap 1. and 2. item in stack, minus... |
976a7abf8c7f578212ce1dc8f238b686df1f7bd1 | helloworldC2/VirtualRobot | /Config.py | 1,187 | 3.703125 | 4 | """File used to load in config info to be used in the program
"""
"""Variables to be saved and loaded
"""
config = {"email":"",
"receiveEmail":"",
"difficulty":"",
"numAI":"",
"name":"",
}
"""Loads the config file and stores the data in config(dict)
@Params:
None
@Ret... |
c50242551fbbeef4081837eee0873855bf1a7523 | evierkim/Battleship | /ComputerPlayer.py | 9,803 | 3.5625 | 4 | from Player import Player
import random
class ComputerPlayer(Player):
def __init__(self):
super().__init__()
self.oHit = False
self.shotHit = False # tells us if the current shot just made was a hit
self.direction = 0 # 0 = below, 1 = left, 2 = above, 3 = right
self.r = 0
... |
5c246d963efdd6cb828941bc0065875af1512d8e | ayush-09/Data_Structure_Python | /Sorting/Insertion Sort.py | 373 | 4.09375 | 4 | """
Created on Tue Sep 29 20:46:21 2020
@author: Ayush Varshney
"""
def insertionSort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i-1
while j >=0 and key < arr[j]:
arr[j+1] = arr[j]
j -= 1
arr[j+1] = key
arr = [3,7,5,8,4,9]
insertionSort(arr)
print ("The sorted a... |
f987e4d47ac6177952e11c1ab2c6379d8f35a66f | dhzhd1/LeetCode | /LongestStr.py | 754 | 3.578125 | 4 | def lengthOfLongestSubstring(s):
"""
:param s:
:return: int
"""
max_length = 0
start_index = 0
end_index = -1
if len(s) == 0:
return max_length
while start_index < len(s) and end_index < len(s)-1:
try:
match_index = str(s[start_index: end_index + 1]).inde... |
e71d29742ccff521e22bda06261040cbd25fc862 | dhzhd1/LeetCode | /Binary_Number_with_Alternating_Bits.py | 624 | 4.28125 | 4 | # coding=utf-8
"""
Given a positive integer, check whether it has alternating bits:
namely, if two adjacent bits will always have different values.
"""
def hasAlternatingBits(n):
"""
:type n: int
:rtype: bool
"""
result = True
if n != 0:
last_bit = 1 & n
n = n >> 1
whi... |
568169688e68a0c278dbf82a2afc8785b25d3a88 | dhzhd1/LeetCode | /Merge_Sorted_Array.py | 521 | 4.03125 | 4 | def merge(nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: void Do not return anything, modify nums1 in-place instead.
"""
for i in xrange(n):
nums1[m + i] = nums2[i]
nums1.sort()
if __name__ == "__main__":
# nums1... |
82d5fd32f26e91540797114701fa9442efdf12ab | cbass2404/codeWars | /python/printer_errors.py | 358 | 3.546875 | 4 | # def printer_error(s):
# total = 0
# for l in s:
# if ord(l) not in range(97, 110):
# total += 1
# return f'{total}/{len(s)}'
def printer_error(s):
return "{}/{}".format(len([x for x in s if ord(x) not in range(97, 110)]), len(s))
print(printer_error("aaaaaaaaaaaaaaaabbbbbbbbbbbb... |
0e403ae52fed6ea03a25f080629c8495420a1929 | James-Whitney/leetcode_solutions | /solutions/medium/solution_lengthOfLongestSubstring/test_solution.py | 1,308 | 3.546875 | 4 | import unittest
from solution import Solution
class TestSolution(unittest.TestCase):
def __init__(self, methodName: str = ...) -> None:
super().__init__(methodName=methodName)
self.solution = Solution()
def test_one(self):
input = "abcabcbb"
output = 3
actual = self.s... |
f5d93176e6003273eaf197f345e74cb3551e1b13 | kinsze032/python---zadania | /zad19.py | 11,103 | 3.890625 | 4 | from datetime import datetime
import sys
class Osoba(object):
def __init__(self, first_name, last_name, pesel, plec, data_wydania, data_waznosci, id_number):
self.first_name = first_name
self.last_name = last_name
self.pesel = pesel
self.plec = plec
self.data_wydan... |
7330a73c02761587287192e3af1f48d738bc0040 | kinsze032/python---zadania | /zad20.py | 2,735 | 3.578125 | 4 | class Konto():
# constructor or initializer
def __init__(self, name, money, pin):
self.name = name
self.balance = money # saldo
self.pin = pin
def pincheck(self):
if self.pin == pin2:
return True
else:
print("Błąd. Wprowadź ponownie PI... |
3f2177140798a610580a04c2ad82e6a478c1cf0a | Groff11/Tutoring | /divide_numbers.py | 183 | 3.890625 | 4 | print('give me a numerator')
numerator = input()
print('give me a denominator')
denominator = input()
result = int(numerator) / int(denominator)
print('result is: {}'.format(result))
|
d1988c958169833884f452f235c250492b4c08c6 | Groff11/Tutoring | /listcomprehension.py | 484 | 4.3125 | 4 | # - assign a word (string)
words = "tacocat"
# - use list comprehennsion to compare first and last letter
if words[0] == words[-1]:
# - if true:
# - use list comprehension to exclude the first and last letter
# - observe that a new string is created from the old string, excluding first and last
print(words[1:-1... |
7ebb33a3b25e33eb1852193ab4e701281ff03dd7 | lfcten/Leetcode | /Binary Search/find-kth/__init__.py | 832 | 3.765625 | 4 | def median_of_medians(A, i):
# divide A into sublists of len 5
sublists = [A[j:j + 5] for j in range(0, len(A), 5)]
medians = [sorted(sublist)[len(sublist) // 2] for sublist in sublists]
if len(medians) <= 5:
pivot = sorted(medians)[len(medians) // 2]
else:
# the pivot is the medi... |
60c41d41e7d0d016c86f7c28bcd24ef10e6da3de | lfcten/Leetcode | /Binary Search/Two Sum 2/Solution.py | 527 | 3.671875 | 4 | # two pointer
class Solution:
def twoSum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
:rtype: List[int]
"""
i = 1
j = len(numbers)
while 1:
ans = numbers[i - 1] + numbers[j - 1]
if ans > target:
... |
b0a4bf5758eddbaf569cfd82014d8be99dc8c917 | lgalicki/Fun-with-Python | /tic-tac-toe.py | 5,525 | 4.125 | 4 | from os import system #for screen cleaning
def print_pat1(list_pat1):
'''
Receives a list with the charactes that are part of a variable line in the board and prints it as a string;
INPUT: list of characters.
OUTPUT: none. It prints the line by itself.
'''
str_pat1 = str()
for char in list_... |
315a835bebd1160cce8ac5df8b7769ab0a0fd084 | lgalicki/Fun-with-Python | /send_gmail.py | 2,256 | 3.671875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 31 07:51:29 2020
@author: Luciano Galicki
This script will send simple text e-mails through Gmail accounts. In order for
it to work, there are a couple of steps that must be taken:
- the Gmail account must have less secure apps access activated;
-... |
320c19acacf15804c4ff8a9bb3bceb6e17708fe2 | micronoyau/Cryptography | /affine/affine.py | 1,277 | 3.546875 | 4 | def eucl (a, b):
"""
Retourne un couple (u,v) tq au+bv = pgcd(a,b).
Peut être prouvé par récurrence sur n, où pour tout n, aun + bvn = rn.
"""
u0, v0, u1, v1 = 1, 0, 0, 1
while b!=0:
q = a/b
a, b, u0, v0, u1, v1 = b, a%b, u1, v1, u0 - q*u1, v0 - q*v1
return (u0, v0)
def invM... |
ead7bc52af2e9a09a0b028389980ba14629ce16b | cbohara/data_visualization | /cali_highs_lows.py | 1,658 | 3.625 | 4 | import csv
from datetime import datetime
from matplotlib import pyplot as plt
filename = 'chapter_16/death_valley_2014.csv'
# open the file and store the resulting file object in f
with open(filename) as f:
# call csv.reader() and pass it the file object as an argument to create a
# reader object associated wi... |
a212b2f6acaa049f058876f68a90b0bb73f75405 | Hodvidar-Achille/MyProjectTest | /string_methods.py | 728 | 3.90625 | 4 | prenom = "Paul"
nom = "Dupont"
age = 21
print(
"Je m'appelle {0} {1} ({3} {0} pour l'administration) et j'ai {2} "
"ans.".format(prenom, nom, age, nom.upper()))
date = "Dimanche 24 juillet 2011"
heure = "17:00"
print("Cela s'est produit le {}, à {}.".format(date, heure))
# formatage d'une adresse
adresse = ""... |
87a5cc9a447efc16ab69945df6c51ac5c9b9da09 | physics91si/gatctg-lab10 | /sets.py | 1,879 | 4.28125 | 4 | import math
class Set:
def __init__(self):
'''initializes the set as the empty set'''
self.list = []
def contains(self, element):
'''Checks to see if an element is within the set; returns Boolean'''
for item in self.list:
if item == element:
return Tr... |
10b002bcf2ff1b79e1e4c1378690674c13c4579f | gamishilbha/python-assign-3 | /new list of comprehension.py | 143 | 3.671875 | 4 |
"""
list comprehension - updated
"""
given = [1, 2, 3]
matches = [1, 2, 3]
num=[]
print([(a, b) for a in given for b in matches])
|
dc325cf0aa6d471ca16d2ed80933c8f1f48bbcb5 | ddt99999/tst.quant-trading | /QuantTutorial/Financial/python_oop.py | 1,922 | 3.609375 | 4 |
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
c1 = complex(1,2)
c2 = complex(2,3)
type(c1)
c1 + c2
def discount_factor(r, t):
''' Function to calculate a discount factor
Parameters
==========
r : float
positive, constant short rate
t : float, array of ... |
3b0a37acdd3a9a0f9f3d4d2fa65c88a2ad7d4cf6 | chenp123123/ApiAutoTest | /day05/test_001.py | 2,191 | 3.578125 | 4 | '''
mock:
1.接口测试的测试场景较难模拟,要大量的工作才能做好
2.该接口的测试,依赖其他接口的模块,依赖的接口尚未开发完成
测试条件不充分时,怎么开展接口测试?
使用Mock模拟接口的返回值
'''
from unittest import mock
import requests
'''
支付接口:http://www.zhifu.com/
方法:post
参数:{"订单号":"12345","支付金额":20.56,"支付方式":"支付宝/微信/余额宝/银行卡"}
返回值:{"code":200, "msg":"支付成功"},{"code":201, "msg":"支付失败"}
接口尚未开发完成
'''
cl... |
9f84215826c948e909fe8822441704c0ad613eb5 | adam-weiler/GA-Reinforcing-Exercises-OOP | /todoList.py | 778 | 3.953125 | 4 | class TodoList():
def __init__(self):
self.task_list = []
def add_task(self, task):
self.task_list.append(task)
print(f'\'{task.description}\' added to list!')
return task
def show_list(self):
print('This is your To-Do list:')
for task in self.task_list:
... |
d0cad55e1415c5ca277bf4dd83ff5ed39d354ed6 | carlosedurf/py_tests | /src/baconwithegges.py | 526 | 4.25 | 4 | """
1 - Receive integer number
2 - Verify number is multiple 3 and 5:
return bacon with egges
3 - Verify number not is multiple 3 and 5:
return starves
4 - Verify number is multiple only 3:
return bacon
5 - Verify number is multiple only 5:
return egges
"""
def bacon_with_egges(n):
assert isinst... |
f3840870444a6f7b3f13aa96d2bf7588817d72ce | frdizon/CSC611M_Project | /DataUtils/dataMerger.py | 996 | 3.5 | 4 | import pandas as pd
# HELPERS: -------------------------------------------------------------
def tweetDuplicateChecker(tweetsdf, tweetStr):
t = tweetsdf[tweetsdf['Tweets'] == tweetStr]
return len(t) > 0
# ----------------------------------------------------------------------
# PARAMS SET:
outputFileName = "... |
0058d28bc8242ee7dd362856c7b24c5f969f72f8 | erikseyti/IteratorAndGeneratorExample | /ex2_iteration_patterns_with_generators.py | 767 | 4.03125 | 4 | # declaracao de um generator
def frange(start, stop, increment):
x = start
while x < stop:
yield x
x += increment
l = frange(100, 200, 1)
print(l)
# print(dir(limite))
# iterar um generator
for n in frange(0, 4, 0.5):
print(n)
# convertendo o generator em lista
limite = list(frange(0, 1,... |
2e47ebe90fb082a21e2ad0614a887567f437c706 | kreinberg/dsviz | /dsviz/iterators/queue_iter.py | 809 | 4 | 4 | '''Iterator class for queue data structures.'''
class QueueIter(object):
'''An iterator for all queue data structure.'''
def __init__(self, iterable):
'''Constructor for a queue iterator.
Args:
iterable: The queue to be iterated.
'''
self._iterable = iterable
... |
61f95b9f549e774e39ceab097f17bedec02fae90 | kreinberg/dsviz | /dsviz/iterators/heap_iter.py | 771 | 3.890625 | 4 | '''Iterator class for the binary heap data structure.'''
class HeapIter(object):
'''An iterator for the binary heap data structure.'''
def __init__(self, iterable):
'''Constructor for a queue iterator.
Args:
itera
'''
self._iterable = iterable
self._iterat... |
6fa38520ea8f5ae398a10ed58c9304b284bb1267 | robinson-1985/mentoria_exercises | /lista_ex3.py/exercicio8.py | 554 | 4.09375 | 4 | ''' 8. Elaborar um algoritmo que efetue a apresentação do valor da conversão em real
(R$) de um valor lido em dólar (US$). O algoritmo deverá solicitar o valor da cotação
do dólar e também a quantidade de dólares disponíveis com o usuário.'''
cotacao_dolar = float(input('Declare a cotação do dólar: $ '))
quantidade_... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.