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 |
|---|---|---|---|---|---|---|
a1425e25f1877c25124a21e4aeb3023b7a05f8a6 | Hinen/SSU_PythonBasics | /Week1/Week1Main.py | 564 | 3.703125 | 4 | print("택배 배송을 위한 정보를 입력하세요.")
name = input("1) 받는 분 이름: ")
phoneNumber = input("2) 받는 분 연락처: ")
address = input("3) 받는 분 주소: ")
message = input("4) 배송 메시지: ")
print("\n아래 정보로 배송하겠습니다.")
print("==============================================")
print("- 받는 분 이름 : ", name)
print("- 받는 분 연락처 : ", phoneNumber)
print("- 받는... |
c22ce0eb08072e70c5fecc5e95c49041377f3285 | jkzilla/skills-sqlalchemy | /query.py | 1,575 | 3.703125 | 4 | # Note: this file will not run. It is only for recording answers.
# Part 2: Write queries
# Get the brand with the **id** of 8.
brandid = Brand.query.get(8)
# Get all models with the **name** Corvette and the **brand_name** Chevrolet.
model_cor_chev = Model.query.filter_by(name='Corvette', brand_name='Chevrolet')
# G... |
6941db9342043265b23f83e7ace4234d38750122 | Wild855/Pydash | /main.py | 19,167 | 3.578125 | 4 | # filename: main.py
# author: Yonah Aviv
# date created: 2020-11-10 6:21 p.m.
# last modified: 2020-11-18
# Pydash: Similar to Geometry Dash, a rhythm based platform game, but programmed using the pygame library in Python
"""CONTROLS
Anywhere -> ESC: exit
Main menu -> 1: go to previous level. 2: go to next level... |
1343ede15a9e068769c96204d08550e4684f881c | LIGHT1213/PythonStudy | /6/异常高级用法.py | 750 | 3.65625 | 4 | '''
try:
2/0 #引发除0异常
except:
print('出错了')
x=[1,2,3]
try:
print(x[3]) #引发下标超出范围异常
except:
print('出错了')
def dosome(): #定义函数
try:
print(5/0) #引发除0异常
except:
print("出错了") #发生异常时执行
finally:
print("finally部分已经执行") #不管异常都会执行
print('over') #正常执行
d... |
146dbc8dff0477dfa30bd954be1afc36a6a1697b | LIGHT1213/PythonStudy | /NUMBER.py | 443 | 3.625 | 4 | for i in range(1,10):
print(" "*(15-i),end="")
n=i
while n>=1:
if n==1:
print(' ',end="")
elif n==2:
print(' ',end="")
else:
print(n,end="")
n-=1
n+=1
while n<i:
n+=1
if n==1:
print(' ',... |
e276335f123bdaa535950a0c6c7c25988c26a254 | LIGHT1213/PythonStudy | /6/readline.py | 364 | 3.703125 | 4 | f = open("test.txt") #打开文件,返回一个文件对象
while True: #循环读取
chunk = f.readline() #每次读取一行
if not chunk: #如果没有读取到内容,则退出循环
break
print(chunk) #打印chunk
f.close() #关闭文件
|
f90587bd5e4eea7437053b9a3b21a69011d3ca91 | LIGHT1213/PythonStudy | /第十二章/历史股市分析.py | 1,557 | 3.5 | 4 | ###利用NumPy进行历史股价分析
import sys
import numpy as np
#读入文件
c,v=np.loadtxt('data.csv', delimiter=',', usecols=(6,7), unpack=True)
#计算成交量加权平均价格
vwap = np.average(c, weights=v)
print("VWAP =", vwap)
#算术平均值函数
print("mean =", np.mean(c))
#时间加权平均价格
t = np.arange(len(c))
print("twap =", np.average(c, weights=t))
#寻找最大值和最小值
h,... |
f13c66924fee7c81d224cfadbac62600414f7ac1 | tpraks/python-2.7 | /coins.py | 1,120 | 3.875 | 4 | def change_possibilities_bottom_up(amount, denominations):
ways_of_doing_n_cents = [0] * (amount + 1)
print "Printing Array after initialization..."
print ways_of_doing_n_cents
ways_of_doing_n_cents[0] = 1
for coin in denominations:
print("For coin in : %d" % coin)
for higher_amount in xrange(coin, a... |
b055b063788ed86998846bca08015b2634982ebe | tpraks/python-2.7 | /myanagram.py | 448 | 3.78125 | 4 | def anagram(mystr):
if len(mystr) == 0:
return []
elif len(mystr) == 1:
return mystr
else:
tmp_str = []
for i in range(len(mystr)):
substri = mystr[i]
rest_of_str = mystr[:i] + mystr[i+1:]
for anagram_substr in anagram(rest_of_str):
print [substri]
print anagram_s... |
2f4d5d2c4a37041f53c26f8bb0cce084028b4183 | tpraks/python-2.7 | /recur_reverse.py | 223 | 4.21875 | 4 | def reverse(str):
if len(str)==1:
return str
else:
return reverse(str[1::]) + str[0]
def main():
str1 = raw_input("Enter String: ")
print str1
print reverse(str1)
if __name__ == '__main__':
main()
|
f4359d28204880660125d87c180ba40f4ef2b532 | tpraks/python-2.7 | /righ_justify.py | 1,413 | 4.03125 | 4 | """
str="this is a lot of text. It goes on and on."
justify(str, 18)
--- output ---
this is a lot of
text. It goes on
and on.
justify(str, 10)
this is a
lot of
text. It
goes on
and on.
' ' * 5 == ' '
"""
def justify_line(line, columns):
num_words = len(line.split())
new_line=None
coun... |
69575a0e8f80950f4e15ce1b7beba0d283f8edc8 | tpraks/python-2.7 | /fibo_recur.py | 192 | 3.890625 | 4 | def fibo(n):
if ( n == 0 or n == 1 ) :
return n
return fibo(n - 2) + fibo(n - 1)
num = input("Enter number of series for fibo:")
for fiboof in range(num):
print fibo(fiboof)
|
5c2eaa9822ad40ea4eb3e7ecbae8210af1e2b3f0 | J-Klass/eight-queens-genetic-algorithm | /eight_queens/genetic_algorithm/genetic_algorithm.py | 6,583 | 3.640625 | 4 | import json
import operator
import random
import numpy as np
import pandas as pd
from eight_queens.genetic_algorithm.fitness import Fitness
from eight_queens.genetic_algorithm.queen import Queen
from eight_queens.plot.plot import plot
with open("eight_queens/configurations.json") as json_file:
data = json.load(js... |
8005800ec372a02c0dd7c31fb5b5b23ba96ef4a0 | HafizAhmadHassan/Comparing-Genes-Proteins-and-Genomes-Bioinformatics-III- | /amino.py | 794 | 3.71875 | 4 | import bio
mass = input("Enter your value: ")
coins = input("Enter your value: ")
mass = int(mass)
coins = [int(c) for c in coins.split(',')]
print(mass, coins)
def calc_combinations(mass, coins):
print("mass", mass, "coins", coins)
if mass==0:
return 1
useful_coins = [coin for coin ... |
d0b6984d19a4ea974b3398840d2d9f8b8bf98ccd | andytanghr/WhiteboardingChallenges | /wk02challenges.py | 1,661 | 3.984375 | 4 | # 1 demonstrate Collatz conjecture
def showCollatz():
n = int(input('Enter a number.. '))
while n != 1:
if n % 2 == 0:
n = n / 2
print(n)
else:
n = n * 3 + 1
print(n)
# showCollatz()
# 2 find largest palindrome that is a product of two three-digit integers
def findLargestPalindrome(... |
c573b99a5e457228815ba1704432c82457c67fa6 | Aliciawyse/intro-programming-nanodegree | /stage-3/Lesson3/entertainment_center.py | 1,754 | 3.59375 | 4 | # Assignment: Create instances of the class Movie
import fresh_tomatoes
import media
#Create a new instance the class movie. This calss is called toy story
toy_story = media.Movie('Toy Story', 'Story about a boy and his toys', 'https://upload.wikimedia.org/wikipedia/en/thumb/1/13/Toy_Story.jpg/220px-Toy_Story.jpg', ... |
952bfd584a33832f8aade8832a05e99c3ad03af5 | Wh1sky666/laba4 | /povish.py | 245 | 3.65625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
if __name__ == '__main__':
S = input("Введите ваш текст: ")
f = max(S.split(), key=len)
print("Самое длинное слово в предложении: ", f) |
255a630ce8ac960c214b6758e771233d36f0a6bc | Mo-Shakib/DSA | /Data-Structures/Array/right_rotate.py | 565 | 4.53125 | 5 | # Python program to right rotate a list by n
# Returns the rotated list
def rightRotate(lists, num):
output_list = []
# Will add values from n to the new list
for item in range(len(lists) - num, len(lists)):
output_list.append(lists[item])
# Will add the values before
# n to... |
3c75def2887a1846d1d2599db73158ef74420898 | love-adela/algorithm-wiki | /snippets/sorting/radix_sort/radix_lsd.py | 874 | 3.953125 | 4 | # Time Complexity : O(kn)
# Where k is a constant representing the maximum number of digits for any given number in the data.
# 요소 값을 명시적으로 비교하지 않아도 정렬할 수 있다.
# stable algorithm -> 자리수의 위치가 바뀌면 안된다. 14와 41은 서로 다른 수이기 때문에.
def radix_lsd(input_list):
position = 1
while True:
empty_lists = [list() for _... |
4026c43bdbcf6e425be60d5144684325f8125a60 | love-adela/algorithm-wiki | /snippets/Graph/topological_sorting.py | 569 | 3.796875 | 4 | def gvhnie(graph):
counts = [0] * (len(graph))
for v in range(len(graph)):
for u in graph[v]:
if u == -1: continue
counts[u] += 1
for v in range(len(graph)):
if graph[v] == [-1]: continue
if counts[v] == 0:
counts[v] = -1
return v
r... |
e107a4cfeecb9d8cde050f01e96e503b868df553 | love-adela/algorithm-wiki | /snippets/sorting/all_sort.py | 662 | 4.03125 | 4 | input_numbers = [param for param in input().split()]
# Selection Sort
def selection_sort(unordered_numbers: list) -> list:
print(f"원래 배열은 {input_numbers}")
for i in range(len(unordered_numbers)):
print(f"i = {i}일 때===========================")
for j in range(len(unordered_numbers)):
... |
c39199a3adbd69df2a840bb910bf91b0c94512ec | love-adela/algorithm-wiki | /snippets/sorting/insertion_sort/insertion_sort.py | 2,847 | 3.859375 | 4 | numbers = [int(param) for param in input().split(' ')]
# insertion sort - 두 배열을 활용하는 방법 # 첫 번째
list = []
for i in range(len(numbers)):
is_inserted = False
for j in range(len(list)):
if numbers[i] < list[j]:
is_inserted = True
list.insert(j, numbers[i])
break
if n... |
b9302a9ad70abcdd83c7399bbc494348b6f1e8d1 | tomaszprzybysz1/Python_basic | /Zajecia5/3.py | 316 | 3.59375 | 4 | def moja(*args,glue=':'):
tab=[]
tab2=[]
print('Wpisz string:')
while True:
k = input()
if k:
tab.append(k)
else:
break
for item in tab:
if len(item)>3:
tab2.append(item)
print(glue.join(tab2))
moja()
|
2f45744b635a9736391f011eb87c10b4180552fc | mksk1999/guvi-problem | /p17.py | 88 | 3.515625 | 4 | n=int(input())
s=str(n)
a=0
for i in range(len(s)):
a+=(int(s[i])**len(s))
print(a)
|
332231c8217d3f37efd9032ac2207c2e929a2d60 | mksk1999/guvi-problem | /p7.py | 365 | 3.828125 | 4 | def palindrome(input):
length = len(input)
palindromes = []
for x in range(2,len(input)+1):
min = 0
while (min+x) < length+1:
if(input[min:(min+x)] == input[min:(min+x)][::-1]):
palindromes.append(input[min:(min+x)])
min = min+1
for i in palindrome... |
398ccdc869ba6e92b473e566d6c768e5fa3d3d7f | mksk1999/guvi-problem | /p21.py | 184 | 3.6875 | 4 | n=int(input())
if(n==2 or n==1):
print("0")
for i in range(2,n):
c=1
for j in range(2,n):
if(i%j==0):
c+=1
if(c==2):
print(i,end=" ")
|
8374acd0403643656aa361f0cf4cf74ca926f053 | YNCHacks/ProfIndex | /app/models/database_controller.py | 5,237 | 3.515625 | 4 | """
Database Controller module for Prof_Index
Author: Sean Saito
The Controller for the database, to be interfaced with the
controller component of the app.
"""
### Imports ###
from professor import Professor
import os, json
from global_vars import json_file_path
class DatabaseConnector:
"""
... |
f840f628039ae22dd9a11c1233bc3228088c888f | cicihou/LearningProject | /leetcode-py/leetcode680.py | 775 | 3.671875 | 4 | class Solution:
def validPalindrome(self, s: str) -> bool:
'''
classic two-pointers,双指针
双指针 l, r 判断字符串是否相等
碰到第一个不相等的字母,检查其是否是唯一一个令其不相等的字符
尝试删去 s[l] 或者删去 s[r] 看一下剩下的字符串是否是一个 palindrome
在纸上画一下,删去左边就是 s[l+1:r+1],删去右边就是 s[l:r]
time: O(n)
space: O(1)
... |
4ffad9e2ac3d8c958af266d9e32fa94457c36401 | cicihou/LearningProject | /leetcode-py/leetcode90.py | 684 | 3.5 | 4 | class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
'''
跟 78 一模一样,多了一步排序和去重(一定要排序 不然 tuple(1,2) 和 tuple(2,1) 不会被视为重复)
'''
res = set()
path = []
def backtrack(nums, path, start):
# 注意:其实 nums 这个参数不带也行,从头到尾我们也没修改过 nums
... |
335a3c16795cf9720e659b5187cee669e63ca71e | cicihou/LearningProject | /leetcode-py/leetcode106.py | 1,193 | 3.765625 | 4 | # Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
'''
跟 105 相同的思想
中序遍历:左根右
后序遍历:左右根
其实目前使用的这种方法效率并不好
比较理想的方式是传递节点位置,recursion 的时候不带列表,只带 index 参数
https://leetcode.com/problems/constru... |
2bf447d952b42c1e6494774b5894fd8c310d2c40 | cicihou/LearningProject | /leetcode-py/leetcode768.py | 1,589 | 3.71875 | 4 | '''
题解:https://github.com/azl397985856/leetcode/blob/master/problems/768.max-chunks-to-make-sorted-ii.md
方法一:计数分桶(参考 769)
方法二:单调栈
'''
class Solution:
def maxChunksToSorted(self, arr: List[int]) -> int:
'''
method 1 分桶计数
分桶计数核心:
如果两个数组的计数信息是一致的,那么两个数组排序后的结果也是一致的
因此我们用排序过的... |
317a6da75e5db777d8f73c6cf464d55cf702f0ef | cicihou/LearningProject | /leetcode-py/leetcode61.py | 3,391 | 4.03125 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def rotateRight(self, head: ListNode, k: int) -> ListNode:
'''
method 1
快慢指针法
https://leetcode-cn.com/problems/rotate-list/... |
4a7572ceafda2e1801a34fad8a3f88cef652dca7 | cicihou/LearningProject | /leetcode-py/leetcode287.py | 1,066 | 3.5625 | 4 | class Solution:
def findDuplicate(self, nums: List[int]) -> int:
'''
method 1: set
time O(n)
space O(n)
'''
dic = set()
for i in nums:
if i not in dic:
dic.add(i)
else:
return i
'''
metho... |
92979d422d7eee9c10016cb1d260d127cba85cd5 | cicihou/LearningProject | /leetcode-py/leetcode889.py | 1,061 | 3.5625 | 4 | # Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
'''
这一题跟 105/106 相似
pre 前序遍历:根左右
post 后序遍历:左右根
构建二叉树,实质上就是要确定左子树和右子树
pre[0] 和 post[-1] 就是二叉树的根
pre[1] 是左二叉树的根,pre[1] 在 post 的位置,就是左右二... |
877743d0c008d9d1f39187c0744ad5fc8874e6c5 | cicihou/LearningProject | /leetcode-py/leetcode447.py | 1,940 | 3.8125 | 4 | '''
这题题意有点难懂,一个 length 为 n 的二维数组,里面的元素表示坐标系上的点
随意选一个点固定,算出二维数组中有多少种组合方式,能挑出剩下两个点到本点的距离相等
ps: 按照题目的排练组合,同样的点换个顺序也是一种组合方式(这好像公考的排列组合 =-=)
for c in counter.values():
res += c * (c-1)
比如说,到本点距离为 3 的点有8个,8 * 7 = 56,也就是说会有 56 个 Boomerangs 的组合方式
'''
class Solution:
def numberOfBoomerangs(sel... |
0b5b4ef1b1d74ee739d79902ab2a818943a7777d | cicihou/LearningProject | /leetcode-py/leetcode100.py | 1,526 | 3.953125 | 4 | # Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
'''
method 1 recursion
time: O(N)
... |
415849944f47731130720d788ab6d345b076bc3b | cicihou/LearningProject | /leetcode-py/leetcode150.py | 2,230 | 3.609375 | 4 | import operator
class Solution:
''' 这题用栈来做
其实准确来说应该是 math.ceil,只是刚好 int(val) 也拥有了这样的特性
真正的算法不是不停用 testcase 去将涉及到的边界值的条件都覆盖到,elegant 的写法跟具体采用的思想相关
'''
def evalRPN(self, tokens) -> int:
ops = {"+": operator.add, "*": operator.mul, "-": operator.sub, "/": operator.truediv}
if l... |
1e51ccc45000527951feddac51e70ee8b3d14c1e | cicihou/LearningProject | /leetcode-py/leetcode143.py | 1,206 | 3.828125 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reorderList(self, head: ListNode) -> None:
"""
Do not return anything, modify head in-place instead.
[1,2,3,4,5,6,7]
... |
9e5f4746ea6b7f6fe63828e62beb9c9a83e67f2a | cicihou/LearningProject | /leetcode-py/leetcode62.py | 2,908 | 3.59375 | 4 | '''
由 1 <= m, n <= 100 可推出,最大时间复杂度为O(n^4),故本题不能使用 backtracking
good video: https://www.youtube.com/watch?v=t_f0nwwdg5o
从暴力优化到 dp
'''
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
'''
method 1
intuitive recursion, TLE
'''
def countPaths(i, j):
if ... |
1e82bfa335c93cfec710306daf6724b0ad7fcc24 | cicihou/LearningProject | /leetcode-py/leetcode120.py | 2,277 | 3.671875 | 4 | '''
Triangle
找到三角形中自顶而下,值最小的路径
经典 DP 入门题
'''
class Solution:
def minimumTotal(self, triangle: List[List[int]]) -> int:
'''
method 1
每一步只能移动到下一行「相邻的节点」上,因此想走到位置(i, j),上一步就只能在位置(i-1, j-1) 或者 (i-1, j)
dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]) + triangle[i][j]
注意当 j = 0 时,... |
ed11a6f5760b49187f6405b53c2cee7bdff5c195 | cicihou/LearningProject | /leetcode-py.cn/leetcode10.03.py | 1,681 | 3.515625 | 4 | '''
https://leetcode-cn.com/problems/search-rotate-array-lcci/
面试题 10.03. 搜索旋转数组
搜索旋转数组。给定一个排序后的数组,包含n个整数,但这个数组已被旋转过很多次了,次数不详。请编写代码找出数组中的某个元素,假设数组元素原先是按升序排列的。若有多个相同元素,返回索引值最小的一个。
示例1:
输入: arr = [15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14], target = 5
输出: 8(元素5在该数组中的索引)
示例2:
输入:arr = [15, 16, 19, 20, 25, 1, 3, 4,... |
9a2b05d5328ab6ac8db76a883b1792a549b8ad8e | cicihou/LearningProject | /leetcode-py/leetcode10.py | 1,749 | 3.953125 | 4 | '''
'.' Matches any single character.
'*' Matches zero or more of the preceding element
example 1
a.b
True: acb, aab, avb
False: ab, acby, cb
example 2
a*b
True: b, ab, aab, aaab
False: a, acb
example 3
a*b.*y
True: by, bly, ably, ablmy
False: ay, ab
i 代表 text
j 代表 pattern
DP[i][j] = ?
if text[i] == pattern[j... |
e52541252c1d2c901fe626d3cfa89c126272eb10 | cicihou/LearningProject | /leetcode-py/leetcode204.py | 731 | 3.640625 | 4 | class Solution:
def countPrimes(self, n: int) -> int:
'''
埃氏筛/素数筛
如果 x 是质数(prime),那么 2x, 3x, 4x, 一定不是质数
用 isPrime list 表示是否为质数
从 i*i 开始,因为 i*i 之前的数必定会被前面的质数给访问掉,比如 质数为 3 的时候,6 会被质数为 2 时的循环搞定,只需要从 3*3 开始考虑
'''
isPrime = [1] * n
res = 0
for i ... |
059ac798a945fdf2eeb56c9f39eff9ffbe497f79 | cicihou/LearningProject | /leetcode-py/leetcode153.py | 1,963 | 3.625 | 4 | class Solution:
def findMin(self, nums: List[int]) -> int:
'''
method 1
binary search
这个问题实质上就是要找有序数组的最小值
若 nums[l] < nums[r] 则表示一定就是有序数组,此时返回 nums[l]
其他的步骤都是为了收缩范围,逼近有序数组
当 nums[mid] > nums[r],说明有序数组在左侧,那么旋转过后的最小数组就一定在右侧,收缩左区间 l = mid + 1
... |
778e321cbd8754683e603704345d944d325c445f | cicihou/LearningProject | /leetcode-py/leetcode669.py | 1,284 | 3.703125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode:
'''
这是一棵 BST(Binary Sear... |
9d58938cc250a0d8cd9a33ddf1779954153ed650 | cicihou/LearningProject | /leetcode-py/leetcode111.py | 792 | 3.609375 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def minDepth(self, root: TreeNode) -> int:
'''
跟 lc 104 高度相似,改一改
注意:当 min(l, r) 为 0 ... |
2ed4dc8f888f9eeadffb1c289d313865e471a23f | cicihou/LearningProject | /leetcode-py/leetcode92.py | 2,989 | 3.890625 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
'''
1. 把 cur 拨到 left 所在位置节点
2. 保存 cur(start) 以及 cur.next(end)
3. 将 linked_list[left, right] 中的节点倒转
4. connect
很不错的白板教程讲解: https://www.youtube.com/watch?v=wk8-_M-2fzI
'''
cl... |
7471c5beb138b6a39583083b4ea4173fa98e65b6 | Misha-create/MK_MIPT_Python | /черепашка/12(1).py | 291 | 4.15625 | 4 | import turtle
turtle.shape('turtle')
def polygon (angle, l):
for i in range(angle//2):
turtle.forward(l)
turtle.right(360/angle)
big = int(input())
small = int(input())
n = int(input())
turtle.left(90)
for i in range(n):
polygon(big, 1)
polygon(small, 1)
|
0da7540ad224a95344ba37fc2ba91df50e9f042c | Misha-create/MK_MIPT_Python | /черепашка/task_5 (1).py | 345 | 4.03125 | 4 | import turtle
turtle.shape('turtle')
length = 10
square = 90
step = 30
def square(length):
for i in range(4):
turtle.forward(length)
turtle.left(90)
for i in range(10):
square(length)
turtle.penup()
turtle.right(90)
turtle.forward(step)
turtle.right(90)
turtle.forward(step)
turtle.right(180)
turtle.down()... |
5418bc0142092fe8ad643fd5cac7aec3e068db85 | yalcinkilic/Euler_Project | /test_math_library.py | 331 | 3.59375 | 4 | import math_library
import random
for i in range(20):
random_number = random.randint(1 , 1000)
str_random_number = str(random_number)
length = len(str_random_number)
n = random.randint(1 , length)
print("The first" , n , "digit of the" , random_number , "is" , math_library.get_first_n_digit(random_... |
12d75e95913bdf72f930465d5bbe68e68d600956 | yalcinkilic/Euler_Project | /Problem0011.py | 2,787 | 3.9375 | 4 | """
This program solves 11th problem of Euler Project
"""
def compute_largest_diagonal2_product(grid):
"""
Find largest diagonal product
"""
max_product = 0
for row in range(len(grid) - 1 , 2 , -1):
for column in range(len(grid) - 3):
current_product = 1
for j in rang... |
f9491a59f8e091a0eb4cd8ce546d92df8b99830a | yalcinkilic/Euler_Project | /Problem0003.py | 337 | 3.515625 | 4 | import math_library
"""
This program solves 3rd question of Euler Project
"""
divisor_list = math_library.factorize_integer(600851475143)
for i in range(len(divisor_list) - 1 , -1 , -1):
if math_library.is_prime(divisor_list[i]) == True:
print("The largest prime divisor of 600851475143 is" , divisor_list[i... |
1a6c44c477f213d1aea6142b44ab1522b71af3ff | ocervi/portfolioDS | /module_0/Проект 0. GitHub. Самый быстрый старт.py | 1,931 | 3.546875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[8]:
import numpy as np
count = 0 # счетчик попыток
number = np.random.randint(1,101) # загадали число
print ("Загадано число от 1 до 100")
def game_core_v3 (number):
count = 0
low = 0 #нижняя граница диапозона
high = 101 #верхняя г... |
be258d97fdef7e4352544a0bc40fa2ca1abd9593 | KlediHasa16/Personal-website | /src/dice_roller.py | 1,861 | 4.0625 | 4 | from random import randint
def dicer():
while True:
dicu = randint(1, 6)
dice2 = randint(1, 6)
win = 25
move = dicu + dice2
print(dicu)
print(dice2)
print("You moved " + str(move) + " squares.")
c = move
b = input("Press Enter to roll the ... |
124bbb8ba9da101c72ffae44f897a2b8d71a4261 | G00398792/pforcs-problem-sheet | /bmi.py | 674 | 4.5625 | 5 | # bmi.py
# This program calculates your Body Mass Index (BMI).
# author: Barry Gardiner
#User is prompted to enter height and weight as a float
# (real number i.e. 1.0) number. The users weight is divided
# by the height in metres to the power of 2. The output
# is printed to the screen. The code "{:.2f}'.format(BMI)... |
24f5ea36d78234496e058ad9f9a120e4d74a3337 | nirajandata/iwbootcamp-assignnments-2 | /6.py | 152 | 3.8125 | 4 | list1=["John","nirajan","navaraj","ashish"]
a=0
for i in list1:
if(i=="John"):
a=1
if(a==1):
print("found")
else:
print("not found") |
3db30dad48df9ff1fbf166e50e1bdd75f2025270 | nirajandata/iwbootcamp-assignnments-2 | /2.py | 178 | 4.09375 | 4 | x =int(input("what's the date "))
if (x%4==0 and x%100!=0 ):
print(x,"is a leap year")
elif (x%400==0):
print(x,"is a leap year")
else:
print(x,"is not a leap year") |
c79d66168171e627c2c17aba9866e191578b5d12 | prathameshbane/HW3-CNN | /HM3-CNN.py | 8,951 | 4 | 4 | #!/usr/bin/env python
# coding: utf-8
# # Home 3: Build a CNN for image recognition.
#
# ### Name: Prathamesh Dilip Bane (CWID 10457749)
#
# ## 0. You will do the following:
#
# 1. Read, complete, and run the code.
#
# 2. **Make substantial improvements** to maximize the accurcy.
#
# 3. Convert the .IPYNB fi... |
eff3331f93df9597e9644c25dacc8021048be496 | Storch9120/rpi-car-arrow-detection-using-cascade-classifier | /car.py | 1,990 | 3.609375 | 4 | import time
class Car:
def __init__(self, left_wheel, right_wheel, speed=0):
self.left_wheel = left_wheel
self.right_wheel = right_wheel
self.speed = speed
self.steer_speed = 40
@property
def speed(self):
return self.__speed
@speed.setter
def speed(... |
0d4560b7486d56276b79df338c2612c077b93889 | mowoka/Lath_oop | /bankaccount.py | 1,004 | 3.625 | 4 | class Person:
def __init__(self, name, age, profesi):
self.name = name
self.age = age
self.profesi = profesi
def print_status(self):
pass
class BankAccount(Person):
def __init__(self, name, age, profesi, id):
super().__init__(name, age, profesi)
self.id... |
613cc6baa8d5ed2157e10553636266ac9fc1663f | wangmonday/Mypython | /days01_0709/task4.py | 580 | 3.546875 | 4 | print("####################################################")
print(" 欢迎进入石头剪刀布游戏平台")
print(" 我们的游戏是人机大战")
print(" 系统会自动出招,不会作弊")
print(" 玩家需要根据系统提示,进行选择出招")
print(" 游戏的结果会以积分进行计算,平台初始积分10分")
print(" 输一局扣一分,赢一局加两分")
print(" 战胜人机会有丰厚的奖励")
print("#####################################################")
prin... |
d003552c2353d86baa91c232f67d50f2fa98b306 | otonnesen/battlesnake-python | /app/BFS.py | 700 | 3.578125 | 4 | def neighbors(coords):
return [[coords[0]-1,coords[1]], [coords[0]+1,coords[1]], [coords[0],coords[1]-1], [coords[0],coords[1]+1]]
def BFS(start, goal, board):
visited = [start]
q = [start]
path = []
findPath = {}
while q:
c = q.pop()
if(not board.spaceOK(c)):
contin... |
09f3e74aea6174cec413af3491be03d59aeeccd8 | dmcg89/Tweet-Generator | /rearrange.py | 767 | 3.53125 | 4 | # completed multiple ways without shuffle, now using fisher-yates
import random
import sys
import random
words = sys.argv[1:]
neworder = []
# randintlist = []
# while len(neworder) < len(words):
# num = random.randint(0,len(words)-1)
# if len(randintlist) == 0:
# neworder.append(words[num])
# ... |
2cb3b7543d85f8a4f556901f8f07ebc3cb948450 | Lazizkhan1/Foundation | /R/R2.py | 159 | 3.8125 | 4 | arr1= [1, 3, 5, 7, 9, 10], [2, 4, 6, 8]
list1 = []
list1.extend(arr1[0])
print(list1)
list1.remove(list1[-1])
print(list1)
list1.extend(arr1[1])
print(list1) |
8149eaca0fb75b0d92593977d33a6fbbdb4a1906 | Lazizkhan1/Foundation | /Login/main.py | 10,374 | 3.5 | 4 | import os
import json
import sys
import time
class User:
def __init__(self):
self.name = None
self.login = "khan"
self.password = None
self.age = None
self.file_name = "user.txt"
self.reg_or_login = ['1', '2']
self.all_users = []
self.password_min_le... |
61f176a0b02cd1a40bd79061be4827e3df7ee423 | Lazizkhan1/Foundation | /Dars/1.py | 98 | 3.671875 | 4 | numbers = [2, 1, -4, -9, 0, -5, 8, 3]
numbers = [i for i in numbers if i % 2 == 0]
print(numbers) |
9794d91c3a4240632b3fbeb7872a7c0e85e45c4f | Lazizkhan1/Foundation | /N/N15.py | 88 | 3.625 | 4 | soz = input("String kiriting: ")
s = input("Harf kiriting: ")
print(soz.replace(s, "")) |
43ae452455a238c45ec2b9628f170f8911bfefbc | Lazizkhan1/Foundation | /V/V18.py | 331 | 3.78125 | 4 | class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def get_perimeter(self):
return (self.width + self.height) * 2
def get_area(self):
return self.width * self.height
shape1 = Rectangle(12, 4)
shape2 = Rectangle(3, 7)
shape3 = Recta... |
f411899d3cdfc27022abd1ff439d222a16c29bcb | v123582/python-data-science-sample-code | /2-1.py | 454 | 3.53125 | 4 | # 编码宣告
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
# 第三方模块引用
import this
from keyword import kwlist
# 变数与赋值
keywords = kwlist
# 流程控制
if len(keywords):
pirnt(keywords)
# ['False', 'None', ...]
for keyword in keywords:
print(keyword)
# 'False'
# 'None'
# ...
input("Input S... |
46330741824c0e9b61200fe7b8ec6e46b6a400b3 | ankurtiwari74/database_operations | /helper/database.py | 1,538 | 3.53125 | 4 | from abc import ABC, abstractmethod
class Database(ABC):
@abstractmethod
def create_schema(self, host, username, password, schema_name):
pass
@abstractmethod
def drop_schema(self, host, username, password, schema_name):
pass
@abstractmethod
def create_table(self, host, userna... |
f70c9a371369cb3ec1cd1f484c877704fa30b799 | mre9798/Python | /lab 9.1.py | 233 | 4.3125 | 4 | # lab 9.1
# Write a recursive function to find factorial of a number.
def fact(n):
if n==1:
return 1
else:
return n*fact(n-1)
n=int(input("Enter the nnumber : "))
print("Factorial is ",fact(n)) |
bbf9d4057f9597f6ac61b337fb350b0df1420def | mre9798/Python | /lab 6.1.py | 342 | 3.765625 | 4 | # lab 6.1
# Generate the pattern
# *
# * *
# * * *
# * * * *
# * * * * *
# * * * *
# * * *
# * *
# *
n=1
for i in range(1,10):
if i<=5:
for j in range(i):
print('*',end=' ')
else:
for j in range(i-n*2):
print('*', end=' ')
... |
5895b0e172e379e6a0aeb560d259a9736405df5e | mre9798/Python | /lab 6.4.py | 285 | 3.765625 | 4 | # lab 6.4
# Accept a list of integers from user. For all values above
# 100 store the string ‘Over’ in the specific position.
l=input("Enter list of numbers : ")
l=[int(n) for n in l.split()]
j=0
for i in l:
if i>100:
l[j]='Over'
j+=1
print(l) |
3593b2541570ac47285a3901615dbdfdc699735d | varshachary/PurePython | /SnowFlakeProgram.py | 317 | 3.609375 | 4 | from turtle import Turtle
t= Turtle()
t.speed(0)
#a=180
b=180
for c in range (5):
a=9*c
for i in range (100):
t.circle(i,a)
t.right(b)
t.circle(i,a)
t.right(b)
t.circle(i, a)
t.right(b)
t.circle(i,a)
input("Press any key to continue")
|
8bc9d38cfdb2897d5a33ab5f2f18cf7c07aba736 | Hryb-Yaroslav/Python_Starter | /lesson2_Task1.py | 70 | 3.609375 | 4 | a = input("First word: ")
b = input("Second word: ")
print(a, ", ", b) |
5f497caae6c6b608984f9ae454ebcaf4e91af95b | Hryb-Yaroslav/Python_Starter | /lesson3_Task1.py | 67 | 3.6875 | 4 | a = input("Enter your name: ")
if a == "Yaroslav":
print("Yes") |
b396cc3a50a9efb40323eb3efc337e0eeff06810 | iiSagarii/Python-for-Everybody-assignment-solutions | /py4e_assignment_9_4.py | 955 | 3.734375 | 4 | # Write a program to read through the mbox-short.txt and figure out who has the sent the greatest number of mail messages.
# The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail.
# The program creates a Python dictionary that maps the sender's mail address to a... |
369508143febe659bfd77fd2f77b295c3bf823ca | Ham1dul/Learning-Python | /Learning_Function_Syntax/Even_Odd_Function_Test.py | 560 | 3.953125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Wed Mar 8 09:18:31 2017
TESTING FUNCTION SYNTAX
odd or even
@author: Hamidul
"""
def is_even(x):
"""
takes an integer input
outputs true if int is even
else outputs false
"""
return x%2==0
def is_odd(x):
"""
... |
aa5902082dd53a8e35de51ee85c0be1cfc39703c | bajram-a/Basic-Programing-Examples | /For-While Loops/Exercise3.1.py | 490 | 3.90625 | 4 | """Write a program that takes a whole number n as a parameter, the program
then prints True if its a rime number, and False if its not.
*A prime number (or a prime) is a natural number greater than 1 that
cannot be formed by multiplying two smaller natural numbers."""
n = int(input())
prime = True
divisions = 0
for... |
65abd6e3940706315542de8ba291bdd93b2c1dab | bajram-a/Basic-Programing-Examples | /Conditionals/Exercise2.4.py | 505 | 4.25 | 4 | """Write a program that requires from the user to input coordinates x and y for the circle center
and the radius of that circle, then another set of coordinates for point A.
The program then calculates whether A is within the circle"""
from math import sqrt
Cir_x = float(input())
Cir_y = float(input())
r = float(inp... |
eaca1babef2a2beff87d776c20cc662a1bf4a697 | Kishwar/ML_UoW_Coursera | /Hadoop_Spark_MapReduce/Spark/movieCount_Spark.py | 1,889 | 3.703125 | 4 | #!/usr/bin/env python
# ----------------------------------------
# Creator: Kishwar KUMAR
# Course: Coursera UC San Diego
# Date: 04/01/2016
# Assignment: Week5.2
# ---------------------------------------
def split_show_views(line):
line = line.split(",")
return line[0], line[1]
def split_show_channel(line... |
0ad7777eec05969e43836ede24204feb8df42de6 | Kishwar/ML_UoW_Coursera | /modue2_scikit/week1/assignment/Regression/SimpleLinearRegression.py | 5,481 | 3.828125 | 4 | # These are my assignment project codes developed in python.
# Anyone can use these codes without any permission
#
# Contact info: Kishwar Kumar [kumar.kishwar@gmail.com]
# Country: France
#
# imports
import pandas as pd
import numpy as np
__author__ = 'kishwarkumar'
__date__ = '6/1/16' '9:15 PM'
# Function reads CS... |
3d89b9a4fe6550b32e5c8cea47ba5992e1bf440d | Viola8905/lab12 | /task1.12.py | 2,603 | 3.875 | 4 | import math
class TPTriangle:
def __init__(self, katet_1, katet_2):
self.katet_1 = katet_1
self.katet_2 = katet_2
def enter(self, katet_1, katet_2):
if katet_1 >=0:
self.katet_1 = katet_1
else:
raise Exception("Value<0")
if katet_... |
deec4c412899e90500cf607e569e14fde74ef711 | myouds/utils | /countdown.py | 2,765 | 3.890625 | 4 | #!/usr/bin/env python3
import sys
import itertools
import enum
class operator(enum.Enum):
ADD = "+"
SUBTRACT = "-"
MULTIPLY = "*"
DIVIDE = "/"
def __init__(self, val):
if val == "+":
operate = lambda a, b : a + b
elif val == "-":
operate = lambda a, b : a - b
elif val == "*":
operate = lamb... |
30e5e981f8574267328107cc521c72f5ff6ff97b | yangtao0304/hands-on-programming-exercise | /interview/031.py | 887 | 3.5625 | 4 | class Solution:
def nextPermutation(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
def reverse(nums, start):
end = len(nums) - 1
while start < end:
nums[start], nums[end] = nums[end], nums[start]
... |
f0a524cdbde9c59fc122e076979a6cb9a0bfd478 | yangtao0304/hands-on-programming-exercise | /data_structure/queues_and_stacks/200_num_islands.py | 4,030 | 3.6875 | 4 | from collections import deque
class Solution(object):
'''本题如何应用BFS?
我们可以把每一个陆地点当作树根,用 BFS 搜索四周的陆地并沉没它,那么这一整块的陆地都被沉没了
下次我们再遇到陆地点的时候就说明发现新大陆了'''
def num_islands_bfs(self, grid):
"""
:type grid: List[List[str]]
:rtype: int
"""
queue = deque()
visited = set... |
325ec763969e6a3cb44310a8e485650e8365d845 | yangtao0304/hands-on-programming-exercise | /jianzhi-offer/07.py | 670 | 3.84375 | 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 buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:
if not preorder:
return None
val ... |
9299e880b7fd62c9636021bfae8ed18adba8e09f | yangtao0304/hands-on-programming-exercise | /HOT_100/102.py | 1,791 | 3.703125 | 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 levelOrder(self, root: TreeNode) -> List[List[int]]:
res = []
if not root:
return res
queue = ... |
069048f0347f74a7073089b2ff8f91776e469d13 | yangtao0304/hands-on-programming-exercise | /interview/035_combination_sum.py | 3,135 | 3.734375 | 4 | '''
给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
candidates 中的数字可以无限制重复被选取。
说明:
所有数字(包括 target)都是正整数。
解集不能包含重复的组合。
示例 1:
输入: candidates = [2,3,6,7], target = 7,
所求解集为:
[
[7],
[2,2,3]
]
示例 2:
输入: candidates = [2,3,5], target = 8,
所求解集为:
[
[2,2,2,2],
[2,3,3],
[3,5]
]
'''
# ... |
8eaadcd5fb35be0be88548ecbe21ebd15beca755 | yangtao0304/hands-on-programming-exercise | /HOT_100/079.py | 2,474 | 3.578125 | 4 | '''
给定一个二维网格和一个单词,找出该单词是否存在于网格中。
单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。
'''
class Solution:
# 回溯
# 涉及 DFS,状态重置
directions = [(0, -1), (0, 1), (1, 0), (-1, 0)]
def exist(self, board: List[List[str]], word: str) -> bool:
m = len(board)
if m == 0:
... |
161a00ee3f6dc1afbfd351d28dd78d62cccd36a9 | yangtao0304/hands-on-programming-exercise | /HOT_100/032.py | 2,039 | 3.6875 | 4 | # 给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。
class Solution:
# 暴力, O(n^2) 会超时
def longestValidParentheses(self, s: str) -> int:
def is_valid(s):
bal = 0
for i in s:
if i == '(':
bal += 1
else:
bal -= 1
... |
30c75547fa22f45abe9af5dbfaee912706922819 | yangtao0304/hands-on-programming-exercise | /jianzhi-offer/22.py | 522 | 3.609375 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getKthFromEnd(self, head: ListNode, k: int) -> ListNode:
if not head or k < 1:
return
nxt = head
pre = head
for i in... |
2a8524c30cf9fbcc1c4e2e06bad78358ff8f6837 | yangtao0304/hands-on-programming-exercise | /HOT_100/017.py | 2,028 | 3.6875 | 4 | # 递归的方法相当于深度遍历,队列的方法相当于广度遍历
# 这个分析比较好理解:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/solution/tong-su-yi-dong-dong-hua-yan-shi-17-dian-hua-hao-m/
class Solution:
# 回溯
'''
回溯是一种通过穷举所有可能情况来找到所有解的算法
如果一个候选解最后被发现并不是可行解,回溯算法会舍弃它,并在前面的一些步骤做出一些修改,并重新尝试找到可行解
'''
# 循环 + 递归
... |
86ff918f77d0815a2068279beac1fefd2116ac79 | yangtao0304/hands-on-programming-exercise | /one-problem-per-day/10.01.py | 575 | 3.671875 | 4 | class Solution:
def merge(self, A: List[int], m: int, B: List[int], n: int) -> None:
"""
Do not return anything, modify A in-place instead.
"""
pos = m+n-1
a = m-1
b = n-1
while pos >= 0:
if a < 0:
A[pos] = B[b]
b -=... |
c5ff2f18e9728e2e015be69bf7389b11c54f55ba | fantods/python-design-patterns | /creational/builder.py | 1,258 | 4.4375 | 4 | # decouples creation of a complex object and its representation
# helpful for abstractions
# Pros:
# code is more maintainable
# object creation is less error-prone
# increases robustness of application
# Cons:
# verbose and requires a lot of code duplication
# Abstract Building
class Building(object):
def __in... |
3659eb3355c1a826c969b8c816e48eb8a8e21976 | fantods/python-design-patterns | /structural/composite.py | 1,254 | 3.765625 | 4 | # Describes a group of objects that are treated as a single instance
# Pros:
# works with complex tree structures more efficiently
# uses polymorphism and recursion to your advantage
# open/closed principle
# Cons:
# might be difficult to provide a common interface for classes with differing functionality
class ... |
77f8837147e6516faa44883791fc94cfe6f4e02b | BloodiestChapel/Personal-Projects | /Python/HelloWorld.py | 461 | 4.1875 | 4 | # This is a standard HelloWorld program.
# It is meant for practice.
import datetime
print('Hello World!')
print('What is your name?')
myName = input()
myNameLen = len(myName)
print('It is good to meet you, ' + myName)
print('Your name is ' + str(myNameLen) + ' characters long.')
print('What is your age?')
date ... |
2237b73bb6a5488bbe4e11f42f70b825087f4808 | polakaro/python_bootcamp | /zadanie_5.py | 232 | 3.546875 | 4 |
liczba = int(input('Podaj liczbę: '))
g = 1
s = liczba - 1
while s >= 0:
for i in range(0, s):
print(' ', end = '')
for i in range(0, g):
print('*', end = '')
print('\n')
s = s - 1
g = g + 2
|
1e7a6b647c55f0350499df1d90d44e333538be4c | nestauk/beis-indicators | /ds/beis_indicators/defra/defra_processing.py | 1,283 | 3.640625 | 4 | import geopandas as gpd
import os
import pyproj
def coordinates_to_points(df, x_coord_name, y_coord_name):
'''coordinates_to_points
Take a DataFrame with coordinate columns and returns a GeoDataFrame with
a single Point geometry column.
Args:
df (pandas.DataFrame): A DataFrame with spati... |
dca249e1bd96f8ba042691e6b717b388774621c6 | kinecosystem/burgerkin-board | /burgerkin-board/board.py | 2,334 | 3.65625 | 4 | from random import randint
class Board:
def __init__(self, x, y):
self.x = x
self.y = y
# self.board = [[1,2,3,4],[1,2,3,4],[5,6,7,0],[5,6,7,0]]
self.scores = {
1: 0,
2: 0
}
self.generate_board(x,y)
def generate_board(self,x,y):
#... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.