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
3cb40ae342951bd1fae39773ada08d117f3ceb14
morningstars/python_base
/day08/code01.py
513
4.03125
4
""" 面向对象 类 对象 """ class Wife: def __init__(self, name, age): self.name = name self.age = age def cooking(self): print("做饭") w01 = Wife("hello", 12) w01.cooking() class Student: def __init__(self, name, age): self.name = name self.age = age def study(self...
b6ebc660395a4ddb63ae81aa92aabbc2ffdce812
morningstars/python_base
/day06/code03.py
449
3.84375
4
""" for for """ for c in range(2): for i in range(3): print("*****", end="") print() """ 函数 """ def attack(): print('----------') attack() def tr(count): for index in range(count): for j in range(index + 1): print("#", end="") print() tr(5) def add(n...
1139140d687738c6ec72fda75816ee7127d8ac98
fpelliccioni/RGSPL
/arraymodel.py
8,064
4.28125
4
""" Module to define the array model for APL. """ import math class APLArray: """Class to hold APL arrays. All arrays have a shape of type list and a list with the data. The length of the data attribute is always the product of all elements in the shape list, even for scalars (the product of an e...
809ae6c744eee68f86c23fda386312b859c12178
brendanv7/VanAllen-GameDesign
/gdp1/Labs/gdp1/lab5/klacik_crazy_shapes.py
3,305
4.28125
4
""" Pygame base template for opening a window Sample Python/Pygame Programs Simpson College Computer Science http://programarcadegames.com/ http://simpson.edu/computer-science/ Explanation video: http://youtu.be/vRB_983kUMc """ import pygame import random # Define some colors BLACK = (0, 0,...
e01785e691dd59ddc10c7ca6ebe33360f88133e9
brendanv7/VanAllen-GameDesign
/gdp1/EscapeFromTheProgrammingLab/src/escape_the_programming_lab.py
5,574
3.671875
4
import pygame from Player import Player from Level import SplashScreen, Level01, Level02, Level03, EndScreen import constants """ Escape From the Programming Lab Author: Brendan Van Allen Version: 0.3 (beta) How to Play: - Move the player using the arrow keys - Interact with items by getting close to them...
8a70a572452ff4a39385a4bd12a1b4c3309197ef
HuiOng/turtle-crossing-game
/player.py
482
3.734375
4
from turtle import Turtle STARTING_POSITION = (0, -280) MOVE_DISTANCE = 10 FINISH_LINE_Y = 280 class Player(Turtle): def __init__(self): super().__init__() self.penup() self.color("black") self.shape("turtle") self.setheading(90) self.goto((0,-280))...
b916d4922475b263d0140d752de73eae17ae256b
dreamatn/workspaces
/pyProjcct/src/test02/test02.py
467
3.921875
4
import types def displayNumType(num): print num, 'is', if type(num) is types.IntType: print 'an integer' elif type(num) is types.FloatType: print 'an float' elif type(num) is types.LongType: print 'an long' elif type(num) is types.ComplexType: print 'an complex' e...
32a0df21e425724055b2f149a2ac8517edb15b15
SabitDeepto/BoringStuff
/chapter4_lists/basic.py
1,402
3.78125
4
# try except try: spam = ['cat', 'bat', 'rat', 'elephant'] x = spam[23] print(x) except IndexError: print("An exception occurred") """ প্রথম ইনডেক্স > শো করে লিস্টের কোন ইনডেক্সে আমি এক্সেস নিবো , দ্বিতীয় ইনডেক্স > কত তম ইনডেক্সের ভ্যালু চাই সেইটার জন্য দায়ী । spam[1][2] --> [1] দ্বিতীয় লিস্ট [২] দুই নাম্ব...
322be9bbf093725a12f82482cd5b9d0ffdf98dcc
bgschiller/thinkcomplexity
/Count.py
1,966
4.15625
4
def count_maker(digitgen, first_is_zero=True): '''Given an iterator which yields the str(digits) of a number system and counts using it. first_is_zero reflects the truth of the statement "this number system begins at zero" It should only be turned off for something like a label system.''' def counter(n): ...
a8f2158fe199c282b8bdc33f257f393eb70e6685
iamaro80/arabcoders
/Mad Libs Generator/06_word_transformer.py
737
4.21875
4
# Write code for the function word_transformer, which takes in a string word as input. # If word is equal to "NOUN", return a random noun, if word is equal to "VERB", # return a random verb, else return the first character of word. from random import randint def random_verb(): random_num = randint(0, 1) if ra...
87b195740a95cb69236d2897c0c2d161f4996a6d
Numa52/CIS2348
/Homework 3/11.18.py
380
4.09375
4
#Ryan Nguyen PSID: 1805277 #taking input from user num_values = input() #splitting numbers through spaces list_values = [int(num) for num in num_values.split() if int(num) > 0] #Apply the sort() function over list of values to sort #the values in ascending order. list_values.sort() #displaying result without negati...
7c017d73da7b2e702aecf6fa81114580389afe09
Numa52/CIS2348
/Homework1/3.18.py
862
4.25
4
#Ryan Nguyen PSID: 180527 #getting wall dimensions from user wall_height = int(input("Enter wall height (feet):\n")) wall_width = int(input("Enter wall width (feet):\n")) wall_area = wall_width * wall_height print("Wall area:", wall_area, "square feet") #calculating gallons of paint needed #1 gallon of paint covers 3...
6046d63bb06564aee4fa9c061c051e818ee16940
Lirianer/pygame-stelio
/api/Circle.py
334
3.703125
4
class Circle(): def __init__(self, x, y, radius): self.x = x self.y = y self.radius = radius def setX(self, x): self.x = x def setY(self, y): self.y = y def setRadius(self, radius): self.radius = radius def getX(self): return self.x def getY(self): return self.y def getRadius(self): retu...
d97b935112aea0d133246d823dbbe70e22c32632
Lirianer/pygame-stelio
/api/Rectangle.py
625
3.84375
4
class Rectangle(): def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height def setX(self, x): self.x = x def setY(self, y): self.y = y def getX(self): return self.x def getY(self): return self.y def setWidth(self, width): self.width = width ...
e3248aeeb6072fdaa11424a1c5cd8dffa2a47a18
amckinlay27/Python
/Final/Final.py
6,850
3.65625
4
#PART 01: Implement UML for each subclass class Employee: def __init__(self, first_name, last_name, SIN, managedBy): self.__first_name = first_name self.__last_name = last_name self.__SIN = SIN self.__managedBy = managedBy def getFirstName(self): return self.__f...
ec4ae8308b6937fa489cc12eff05eb3b8f874281
mohankris24/Python-Training
/project1.py
4,274
3.671875
4
# Problem Generator, ignore this code block. import random import string random.seed(9) class Problem: def __init__(self): self._EXTENSION_LIST = ["txt", "zip", "pdf", "docx", "jpeg", "png", "xlsx", "html"] self._RANDOM_CASES = self.cases() self._CORNER_CASES = self.corner_cases() ...
016eaba971c98475e426f34dbefdf0f91a32ea0d
DavidNester/SoftwareEngineeringFA17
/Project2/A/calculations.py
1,185
3.71875
4
""" Author: David Nester Date: 10.6.17 Module with functions useful to robot package pickup simulation. """ def distance_between_points(x, y): """ Euclidean distance between two points, x and y :param x: point 1 :param y: point 2 :return: Euclidean distance """ return ((float(x[0]) - float(y...
f5540eb90b304d519809c8c010add05fc11e491f
sindhumudireddy16/Python
/Lab 2/Source/sortalpha.py
296
4.375
4
#User input! t=input("Enter the words separated by commas: ") #splitting words separated by commas which are automatically stored as a list. w=t.split(",") #sorting the list. w1=sorted(w) #iterating through sorted list and printing output. for k in w1[:-1]: print(k+",",end='') print(w1[-1])
4a2c8343a75a26cf215bb33e8ef0df6437494f77
sqccathy/Leetcode-1
/101. Symmetric Tree.py
737
3.953125
4
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if not roo...
bafa1ba20495921843657c4bcff18feb755d9516
sqccathy/Leetcode-1
/112. Path Sum.py
2,125
3.828125
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 __init__(self): self.stack = Stack() self.count = 0 def hasPathSum(self, root, sum): """ :type ro...
d59c18f3a97b6f98e89a391b3c97e0fc58f951e1
sqccathy/Leetcode-1
/34. Search for a Range.py
1,945
3.515625
4
class Solution: def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ def binSearch(nums, target): if len(nums) == 1 and nums[0] == target: return [0,0] elif len(n...
6d3890bb89bfcda0d2a731c987dae91bd3d437c2
SobuleacCatalina/Instructiunea-IF
/problema_8_IF.py
553
3.921875
4
""" Să se afişeze cel mai mare număr par dintre doua numere introduse în calculator. Exemple : Date de intrare 23 45 Date de ieşire nu exista numar par ; Date de intrare 28 14 Date de ieşire 28 ; Date de intrare 77 4 Date de ieşire 4. """ a=int(input("primului numar")) b=int(input("al doilea numar")) if((a%2...
b262e5361d6f767772dce01b226ddbfc7449e299
demo112/1807
/PythonNet/day07/code/thread2.py
492
3.546875
4
from threading import Thread, currentThread from time import sleep # import os def fun(sec): print("线程属性测试") sleep(sec) # 线程对象的getName()属性 print("%s线程结束" % currentThread().getName()) thread = [] for i in range(3): t = Thread(target=fun, name="cooper%d" % i, args=(2,)) thread.append(t) t....
fdf7c7bf62062cec658eb4b058f32a5fba647f54
demo112/1807
/python/python017/code/attribute.py
904
3.90625
4
# attribute.py # 此示例示意为对象添加实例变量(实例属性)及访问实例变量(实例属性 class Dog: def eat(self, food): """此方法用来描述小狗吃东西的行为""" print(self.color, '的', self.kinds, '小狗正在吃', food) self.last_food = food def show_last_food(self): print(self.color, '的', self.kinds, '上次吃的是', self.last_food) dog1 = Dog() ...
74d01284b388d70ebcc4e64f40ac63034b401a19
demo112/1807
/python/Myself_Note/note/class_name.py
2,501
3.75
4
# 在班级所有人的名字中的名字中随机抽取一个人的名字且不可复现 import random as R def input_name(): lst = [] while True: try: name = input('请输入姓名') if name: lst.append(str(name)) else: raise ZeroDivisionError except TypeError: print('您输入的姓名有误请重新...
74bfe273e1b63481272d651df3368bb3d3b6d662
demo112/1807
/python/python015/teach_day15/code/test.py
157
3.71875
4
L = [1, 2, 3, 4, 5] def cc(): for x in L: yield x it = iter(L) print(next(it)) print(next(it)) print(next(it)) print(next(it)) print(next(it))
c3c78e3f1440cfe44a1b4ecd9594d94f50e081ea
demo112/1807
/python/python019/code/enclosure.py
540
3.9375
4
class A: def __init__(self): self.__p1 = 100 self.p2 = 200 def show_info(self): print(self.__p1, '此对象的实例方法可以访问和修改私有属性') a.__m() def __m(self): print("A类对象的__m方法被show_info调用") a = A() # print(a.__p1) # AttributeError: 'A' object has no attribute '__p1' print(a.p2...
1afdc21987b85b27ad782e5deaf8a85fd9858ab6
demo112/1807
/python/Myself_Note/Runoob/exercise/7.py
128
4.09375
4
# 将一个列表的数据复制到另一个列表中。 a = [1, 2, 3] b = a[:] print(b) a = [1, 2, 3] b = a.copy() print(b)
8774d41e2ebd4ab4df7e4e1104b505e4bd4f7376
demo112/1807
/python/python017/code/instance_method.py
721
3.71875
4
# instance_method.py class Dog: """创建一个Dog类, 此类用于描述一种小动物的行为和属性""" def eat(self, food): """此方法用来描述小狗吃东西的行为""" print('id 为', id(self), '小狗正在吃', food) def sleep(self, hour): """此方法用来描述小狗睡觉的行为""" print('小狗睡了', hour, '小时') def play(self, thing): """此方法用来描述小狗睡觉的行为""...
84d2b9ee3667b7aa55d4252cbeb05a1b2a28fda4
demo112/1807
/python/python015/self_day15/homework/myxrange.py
788
3.9375
4
# 写一个生成器函数myxrange([start, ], stop[, step]) 来生成一系列整数 # 要求: # myxrange功能与range功能相同(不允许调用range函数) # 用自己写的myxrange函数结合生成器表达式求1~10内奇数的平方和 def myrange(start, end=0, step=1): while True: start, end = end, start if start > end: yield end end += step start...
97ddc7d4b3e7f74b506b9826a47eb45742a2986b
demo112/1807
/PythonNet/day07/code/thread_lock.py
327
3.671875
4
import threading a = b = 0 def value(): while True: lock.acquire() if a != b: print("a = %s b = %s" % (a, b)) lock.release() t = threading.Thread(target=value) e = threading.Event() lock = threading.Lock() t.start() while True: with lock: a += 1 b += 1 t....
5b0777d57fb589e66533e64958db51372fb562fb
demo112/1807
/python/python015/self_day15/exercise/encode.py
154
3.5625
4
s = str(input('请输入一段字符串')) b = s.encode('utf-8') print(b) print(len(b)) print(len(s)) s2 = b.decode() print(s + '\n' + s2) print(s == s2)
79599691f5f02b41d96f51b85ffea651ecc54539
demo112/1807
/python/python014/self/code/try_finally2_test.py
239
3.65625
4
x = 100 y = 200 try: save_x = x save_y = y try: x = int(input("请输入x")) y = int(input("请输入y")) print("x=%d, y=%d" % (x, y)) finally: x = save_x y = save_y except: pass
12087ed6ec67279c3180d9df4da7206a75e9cc48
demo112/1807
/python/python018/code/inherit.py
642
3.609375
4
class Human: @staticmethod def say(what): print("说", what) @staticmethod def walk(distance): print('走了', distance, '公里') class Student(Human): @staticmethod def study(subject): print("今天学了", subject) class Teacher(Student): @staticmethod def teach(subject)...
c1d86be77a500afeff80ca8bf557962a3cf5bf9a
demo112/1807
/python/python019/homework/iterprime2.py
999
3.859375
4
class Prime: def __init__(self, b, n): self.begin = b self.count = n self.cur_count = 0 def __iter__(self): return self # iter 会自动调用self的next方法 def __next__(self): # 判断已提供的数据个数和要提供的数据个数是否相等 if self.cur_count >= self.count: raise StopItera...
a434ffcb5663f693cce9acbb015c4999afd59381
demo112/1807
/python/python017/code/zhang_li_class.py
742
3.796875
4
class Human: def __init__(self, name, age): self.name = name self.age = age self.skill = None self.money = 0 def teach(self, teacher, sth): self.skill = sth print(teacher.name, "教", self.name, sth) def works(self, money): self.money += money ...
5425fcb3366b0da6f194e7fa08ca903645d4426c
demo112/1807
/python/python013/self_day13/homework/nine_excel.py
420
3.515625
4
def hang(a): lst = [] for n in range(1, a + 1): lst += ['%02s *%02s =%03s' % (n, a, n * a)] return lst def each(a): lst = hang(a) for m in lst: print(m, end=' ') print() def main(n): for a in range(1, n + 1): each(a) main(9) # WAY2 for x in range(1, 10): ...
622e3118bbf2561c95f0767b2b935888fa5dfc0b
demo112/1807
/算法/排序算法/插入排序.py
647
3.640625
4
def insert(values): global P if len(values) == 1: return values for i in range(1, len(values)): t = values[i] for j in range(i - 1, -1, -1): # 从当前无序数据i的前一个开始 # 遍历到0为止 if values[j] > t: values[j + 1] = values[j] P =...
c53d64a388cf07718e2a41c63fe746b614ed004c
yangyana/PythonStudy
/class_0621_basic/sandashujuleixing_tuple.py
778
3.84375
4
#元组 关键字 tuple 标志() #t=() #空元组? #1 标志是() 关键字 tuple #2 元组里可以放任何类型的数据 元素与元素之间用逗号隔开 #3 元组里面的元素 也都有索引 是从0开始 跟字符串的索引方式是一致的 #4 元组取值方式:元组名[索引值], 正序 反序 #5 支持切片 元组名[m:n:k] 跟字符串是一样的 #返回的还是列表类型 t_1=(1,2,0,[1,2,3],(4,5,6)) s_7=[1,'hello',2.0,[1,2,3],(1,2,3)] s_7[-1]=666 print(s_7) #整个给替换掉 #输出...
eb9f3924a97d47ed5b2ab2a25553225438ab6f7f
glaurent96/HackerRankProblems
/Breaking_The_Records/script.py
1,185
3.828125
4
#!/bin/python3 # BREAKING THE RECORDS import math import os import random import re import sys # # Calculate the number of times a player broke their max and min record # # Sample input: # 9 <------------------------Number of games played # 10 5 20 20 4 5 2 25 1 <----Points scored per game # Sample o...
388031510ce94d6b683b7ea9710451233cd45be6
nika-kvr/UnilabPythonDevelopment
/Chapter1_Contribution/Guli Sakhvadze/test.py
1,267
3.71875
4
import spacy from spacy import displacy from spacy.lang.en.stop_words import STOP_WORDS nlp = spacy.load("en_core_web_sm") text = nlp('''Kraftwerk is a German band formed in Düsseldorf in 1970 by Ralf Hütter and Florian Schneider. Widely considered as innovators and pioneers of electronic music, they were among the fi...
0ee7fbef0394b11839a6d193995abed41b46cd22
nika-kvr/UnilabPythonDevelopment
/Chapter11_Structuring/projects/example/PortalProject/myproject/models.py
1,466
3.6875
4
class Student(db.Model): __tablename__ = "students" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) # One_to_one relationship # A student only has one teacher, thus uselist is False. # Strong assumption of 1 teacher per 1 student and vice versa. teacher = db.re...
4c8d65e2fa8233ac72b84e5618fd1c62d4486684
Rachine/confound_prediction
/confound_prediction/mutual_information.py
4,913
3.5625
4
'''Computation of mutual information''' import numpy as np from scipy.special import gamma,psi from scipy.linalg import det from numpy import pi from sklearn.neighbors import NearestNeighbors from scipy.stats.kde import gaussian_kde # __all__=['entropy', 'mutual_information', 'entropy_gaussian'] # # EPS = np.finfo(f...
051595540cbc36a1d14dc97f054fd8b9831a42b0
smpotdar/udacity_ai_in_robotics
/dynpro1.py
2,442
3.90625
4
# -*- coding: utf-8 -*- """ Created on Mon Nov 30 17:03:11 2015 @author: ShubhankarP """ # ---------- # User Instructions: # # Create a function compute_value which returns # a grid of values. The value of a cell is the minimum # number of moves required to get from the cell to the goal. # # If a cell...
53f32fd461a9653429e3cac6ff72e305fd9b71fa
catsymptote/NITOPython_Feb2019
/Graphical_Method_1.py
401
3.6875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Feb 24 12:27:06 2019 @author: catsymptote """ import numpy as np import matplotlib.pyplot as plt #%matplotlib notebook # Grafical methods works best with only 1 variable. x = np.arange(-4, 4, 0.01) f = x**2 + 3*x - np.exp(x) #print(x) plt.plot(x, f)...
c1e0429c6adb66db11643805be569a58896be755
sharingan3/Function-Grapher
/main.py
1,644
3.765625
4
import numpy as np import matplotlib.pyplot as plt class Graph: def __init__(self, x_coordinate, y_coordinate): "Initialize all x and y inputs" self.all_x_coordinate = x_coordinate self.all_y_coordinate = y_coordinate "Define axis scale" self.x_axis = np.linspace(-np.pi, n...
6df7ba22cf69a041c5605a9f55c86d0f0636af82
buinyi/Data-Wrangling-with-MongoDB
/code for project/P3_1_iterative_parsing.py
3,640
3.8125
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This is a modification of iterative parsing script used in Lesson 6. In this script I: - count the number of different tags and save to a csv file - count the number of second level tags stored in 'k' field of 'tag' and save them to a csv file - count the number of uniq...
9dc9baca84045fd017f07a4f69a8d9a1564ab5b2
kenny-designs/sworcery
/sworcery/game.py
5,350
3.703125
4
""" This holds the class 'Game'. The purpose is to give the main file 'sworcery' everything the game needs to run. In other words, this is the backbone of our game engine. """ # Make our imports import pygame from pygame.locals import* # For constant variables, values, etc... import constants # for our levels such as...
5b08438b761490d7ad4e8f229aede28e65e47eae
rohit-gorle/Trees-3
/Path_Sum.py
1,422
3.734375
4
// Time Complexity :O(N) // Space Complexity :O(N) // Did this code successfully run on Leetcode : yes // Any problem you faced while coding this : // Your code here along with comments explaining your approach: checking current sum and appending the array which is equal to the target # Definition for a binary tre...
087d5ec24ac8bcdf36858435bc3b979855686d8f
carlosyair22/python-challenge
/PyBank/main.py
1,663
3.84375
4
import csv import os #variables that will be used to gather the statistics months=0 PL=0 increases=0 greaterIncrease=0 greaterDecrease=0 file=os.path.join("budget_data.csv") with open(file,"r") as budget_data: budgetReader=csv.reader(budget_data,delimiter=",") # Remove header line header=next(budgetReader...
b25936f0ee4bfb41e990aea4d06ec1294294e632
rafael-agra/space-invaders-game
/main.py
1,687
3.78125
4
#Import list import turtle import os #Setting up the screen wn = turtle.Screen() wn.bgcolor("black") wn.title("Space Invaders") #Border drawing border_caneta = turtle.Turtle() border_caneta.speed(0) border_caneta.color("white") border_caneta.penup() border_caneta.setposition(-300,-300) border_caneta.pendown() border...
bf9ed382c2e5bb38cb4c12baafea9c712849a6ce
FlyLikeSoarin/2019-2-Track-Backend-E-Vihrev
/other-tasks/Caches.py
1,444
3.5
4
from collections import OrderedDict class LRUCache(): def __init__(self, capacity=10): self.capacity=capacity self.cache = OrderedDict() def get(self, key): if key in self.cache: self.cache.move_to_end(key, last=False) return self.cache[key] else: ...
11145a1e45cc2d8f6823b3b25ba0de60fb4f7179
jendakolda/Advent_of_Code
/Day3/Day3.py
548
3.75
4
def slope(left, down=1): coordinate = 0 tree = 0 step = 0 with open('Day3_input.txt', 'r', encoding='utf-8') as plan: for line in plan: line = line.strip() if step % down == 0: if line[coordinate] == '#': tree += 1 coord...
95d9f1a9b27804e48f37cbeddd335895bc755cbf
klsysmmns/learn-python-hardway
/ex5.py
636
4
4
name = 'Zed A. Shaw' age = 35 # not a lie height = 74 #inches weight = 180 # lbs eyes = 'Blue' teeth = 'White' hair = 'Brown' cmheight = height * 2.54 kgweight = weight * 0.453592 print 'Let\'s talk about {0}.'.format(name) print 'He\'s {0} inches tall.'.format(cmheight) print 'He\'s {0} pounds heavy.'.format(kgweight...
875368a8a7190c59b71e24c78e3fcbdb971e8de2
modestzhang/git_repository
/learn_python/chapter_7.py
495
3.921875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/8/23 22:27 # @Author : modestzhang # @project : learn_python # @File : chapter_7.py # @Copyright : Manjusaka # 用户输入 # name = input("Please enter your name:") # print(name) # # age = int(input()) # print(age) # current_number = 1 # while curr...
282d4bc6da4f25e342b5a27b7023ed41af6c2b13
modestzhang/git_repository
/learn_python/chapter_5.py
605
3.71875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/8/21 22:34 # @Author : modestzhang # @project : git_repository # @File : chapter_5.py # @Copyright : Manjusaka # for 循环 cars = ['bmw', 'audi', 'toyota', 'subaru'] for car in cars: if car == 'bmw': print(car.upper()) else: ...
f945172c0b5ad029e096f92e37d19b01c45f6c37
modestzhang/git_repository
/learn_python/chapter_10.py
1,530
3.5625
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/8/30 22:37 # @Author : modestzhang # @project : git_repository # @File : chapter_10.py # @Copyright : Manjusaka # with open('pi_digits.txt') as file_object: # # contents = file_object.read() # # print(contents.rstrip()) # for line...
b27842cd9b24c0d38e73b51e539ca0ec49b37b97
AIHackerTest/lijinyan89_Py101-004
/Chap0/project/guess_game.py
780
3.640625
4
import random correct_num = int(random.randint(0,20)) print ("这是一个猜数字游戏。") count = 0 while count < 10: guess_num = int(input("请随机输入一个20以内的数字:")) count += 1 if guess_num == correct_num: print ("恭喜您,猜对了!") break if guess_num < 0 or guess_num >= 20: print ("输入数字不符...
c6c60c4ab654bd864072e60a5f4bb64796ff4609
EzequielRomio/tienda_de_empanadas
/console_version/order_class.py
2,104
3.640625
4
class Order: def __init__(self, requested=None, oder_list=None, user=None, adress=None, phone=None): self.requested = requested self.order_list = oder_list self.user = user self.adress = adress self.phone = phone self.list_content() def list_content(self): ...
9791dc9cb5195fba0fd7b3237a6d8d39b089a20e
GreatHayat/Sorting_Data_Structures
/insertion_sort.py
382
4.28125
4
# Insertion Sort Algorithm def insertionSort(array): n = len(array) for i in range(1, n): key = array[i] j = i - 1 while j >= 0 and array[j] > key: array[j + 1] = array[j] j = j - 1 array[j + 1] = key # Calling the function array = [5,4,3,2,1] inserti...
e46ffbb6c5f7e39db537d08b288c5dad79e7d8db
akarshchincholi/Python-Challenge
/Code.py
10,754
4.15625
4
import urllib.request # Basic HTTP simplifying module to open URLs from urllib.request import urlopen import urllib.parse import re # re means Regular Expressions which is used for data manipulation in the HTML source code import sqlite3 ...
9768644a325db104cfb9d22dcd3708de05b2eb9a
C3-nou/prueba_tec
/ejercicio1.py
795
3.71875
4
arr = [] i = 0 while i < 4: var = input("Ingresa variable número {num}: ".format(num = (i+1))) if int(var) > 0: if i == 1 and int(var) > arr[0]: print("La segunda variable debe ser menor a la primera.") elif i == 2 and int(var) < arr[0]: print("La tercera variable no debe...
31f4808b13f6d9476fdd784ad49cfeb9049374c4
Yosh666/PythonMaison
/hello.py
251
3.96875
4
msg="Hello World" print (msg) bananes=5 bananemangees=2 bananes = bananes-bananemangees print (bananes) string="je suis une chaine" print(string) nom = input("Comment t'appelles tu?") print("Bonjour ",nom)#la concaténation se fait avec la virgule!
bc407ecfb1209c428ed0e3cbab881ede367f08ec
ols32/Sprint-3
/leikursp3.py
2,904
3.984375
4
import turtle import os wn=turtle.Screen() wn.bgcolor("red") wn.title("Grísaleikur") level = 1 totlevel = 4 #Búum til klasa fyrir leikmanninn, Class definition. class Player(turtle.Turtle): #self is a keyword. def __init__(self): #Initialize player turtle.Turtle.__init__(self) #Initialize turtle ...
6e0136934bd6c614c34cff0546d1b1e38a2b58f0
yyogeshkumar/python
/Binary Exponential.py
225
3.90625
4
print("Enter Base Value:") Base=int(input()) print("Enter Expo value:") Expo=int(input()) final_val=1 while Expo>0: if Expo%2!=0: final_val=final_val*Base Base=Base*Base Expo>>=1 print(final_val)
b109ef8f3a2c0aad41803763435e16813d5bf581
PetarDamyanov/Python
/week09/week09_03/task1/main.py
891
3.5
4
from interface import * def get_id(): return input("add id:") def get_user_info(): full_name = input('full_name:') email = input('email:') age = int(input('age:')) phone = input('phone:') additional_info = input('additional_info:') return full_name, email, age, phone, additional_info d...
350f4e317ca8540a3f4f0248c8d1643f23a3b8ab
PetarDamyanov/Python
/week02/week02_03/task02.py
301
3.796875
4
from fractions import Fraction def simplify_fraction(fraction): n = fraction[0] d = fraction[1] fractions = str(Fraction(n, d)) f1 = fractions.split("/")[0] f2 = fractions.split("/")[1] return (int(f1), int(f2)) def main(): pass if __name__ == '__main__': main()
fff7e20ca3a95256c91df7bd076deed22155ebd3
PetarDamyanov/Python
/week01/week01_01/task5.py
251
3.90625
4
def palindrome(n): return n == n[::-1] # if palindrome(121): # print("TRUE") # else: # print(FALSE) # if palindrome("kapak"): # print("TRUE") # else: # print("False") # if palindrome("baba"): # print("TRUE") # else: # print("FALSE")
6a5c661ae2e4bf0a01f5b091eea40ab503c566e0
letwant/python_learning
/learn_liaoxuefeng_python/高级特性/列表生成式.py
1,835
3.5625
4
# -*- coding: utf-8 -*- # 列表生成式即List Comprehensions,是Python内置的非常强大的可以用来创建list的生成式 # 如果想生成[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] value = list(range(1, 11)) # 但是如果想生成 [1*1, 2*2, 3*3, 4*4 ... 10* 10] 该怎么做? # 方法一:使用循环 L = [] for x in range(1, 11): L.append(x * x) print(L) # [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] # 方法二:使用列表...
b9cf4f68c2bcb975561600f6504248a832b565a2
letwant/python_learning
/learn_liaoxuefeng_python/函数式编程/高阶函数/高阶函数介绍.py
912
4.25
4
# -*- coding: utf-8 -*- # 高阶函数英文叫Higher-order function。什么是高阶函数?我们以实际代码为例子,一步一步深入概念。 print(abs(-10)) # 10 print(abs) # <built-in function abs> # abs(-10)是函数调用,而abs是函数本身 # 函数本身也可以赋值给变量,即:变量可以指向函数 # 如果一个变量指向了一个函数,那么,可以通过该变量来调用这个函数 f = abs value = f(-10) print(value) # 10 # 【函数名也是变量】 abs = 10 # abs(-10) # TypeError: ...
84291b0ab7923d42e0ead6e000c9dd634e5869eb
letwant/python_learning
/learn_liaoxuefeng_python/网络编程/UDP编程.py
1,918
3.703125
4
import socket # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # # 绑定端口: # s.bind(('127.0.0.1', 9999)) # # print('Bind UDP on 9999...') # while True: # # 接收数据: # data, addr = s.recvfrom(1024) # print('Received from %s:%s.' % (addr, data)) # s.sendto(b'Hello, %s!' % data, addr) # import sys # # ...
43c7fbe2648c5006e23f36b17c96f017901aa7ec
meera21-meet/meetyl1
/lab2.py
197
3.953125
4
list1=[1,2,3,4] list2=[2,4,6,8] list3=[] def lists(list1,list2): for i in list1: if i in list2: list3.append(i) return list3 print (lists(list1,list2)) lists(list1,list2) #def listen():
e7e296445cd59a6f695575dba64d77b4caba8b63
mindentropy/leetcode
/914.py
478
3.5
4
#!/usr/bin/env python from math import gcd class Solution(object): def hasGroupsSizeX(self, deck): deck_map = dict() for val in deck: deck_map[val] = deck_map.get(val, 0) + 1 a = 0 if len(deck_map.keys()) > 2: key, a = deck_map.popitem() for key, val in deck_map.items(): gcdval = gcd(a, val) ...
d18f39ebfa63663bc144745438ad849bd8aaacb9
mindentropy/leetcode
/557.py
646
3.734375
4
#!/usr/bin/env python class Solution(object): def reverseWords(self, s): strlen = len(s) if strlen == 0: return s s = list(s) startidx = 0 for idx in range(strlen): if s[idx] == ' ': endidx = idx - 1 while(startidx < endidx): s[startidx], s[endidx] = s[endidx], s[startidx] ...
998c6158468dfc0ea8782c1924db38554aad6a51
mindentropy/leetcode
/103.py
1,098
3.78125
4
#!/usr/bin/env python 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 bfs(self, root): lst = [root] numarr = [] numflip = 0 while len(lst) != 0: arr = [] lvlnode = [] while len(l...
fbef636eb1ef445be43131020ad2ac6ecd501d30
mindentropy/leetcode
/2160.py
309
3.6875
4
#!/usr/bin/env python class Solution(object): def minimumSum(self, num: int) -> int: arr = [] while num: arr.append(num%10) num = int(num / 10) arr.sort() return ((arr[0] * 10 + arr[2]) + (arr[1] * 10 + arr[3])) if __name__ == '__main__': sol = Solution() print(sol.minimumSum(4009))
e0629683a4739b8c9ca05cff3af417f8a0beb2d5
mindentropy/leetcode
/1161.py
999
3.5
4
#!/usr/bin/env python class TreeNode(object): def __init__(self, val = 0, left = None, right = None): self.val = val self.left = left self.right = right ##TODO: Solve iteratively. class Solution(object): def __init__(self): self.maxsum = -1000000 self.level = 0 def bfs(self, nodearr, maxsum, lvl): ...
89b0fd292459b63bd72c5a6d5297fbe1067b922f
mindentropy/leetcode
/1160.py
684
3.96875
4
#!/usr/bin/env python class Solution(object): def countCharacters(self, words, chars): final_word = "" char_hash = {} for char in chars: if char not in char_hash: char_hash[char] = 0 else: char_hash[char] += 1 for word in words: found = True hash_cmp = char_hash.copy() for ch in w...
afd2e014d2ada4ebcb7134f067461653c4cac9c4
mindentropy/leetcode
/844.py
534
3.765625
4
#!/usr/bin/env python class Solution(object): def backspaceCompare(self, S: str, T: str) -> bool: stk1 = list() stk2 = list() for idx in range(len(S)): if S[idx] != '#': stk1.append(S[idx]) else: if len(stk1): stk1.pop() for idx in range(len(T)): if T[idx] != '#': stk2.append(T[idx...
1b9e282c02b351dee852ce2dda1d75eff7f6eeaf
mindentropy/leetcode
/682.py
445
3.59375
4
#!/usr/bin/env python class Solution(object): def calPoints(self, ops): stk = [] total = 0 for op in ops: if op == 'D': stk.append(stk[-1] * 2) elif op == 'C': stk.pop() elif op == '+': stk.append(stk[-1] + stk[-2]) else: stk.append(int(op)) for val in stk: total += val ret...
76af9f3919b7eb9b347f6f2e7eead7f0bfe2f84d
mindentropy/leetcode
/657.py
492
3.703125
4
#!/usr/bin/env python class Solution(object): def judgeCircle(self, moves): """ :type moves: str :rtype: bool """ x = 0 y = 0 for idx in range(len(moves)): if moves[idx] == 'U': y += 1 elif moves[idx] == 'D': y -= 1 elif moves[idx] == 'L': x -= 1 elif moves[idx] == '...
ed1b0fe83478116f5fa35c8a61abe795fdbbf47c
mindentropy/leetcode
/35.py
421
3.890625
4
#!/usr/bin/env python class Solution(object): def searchInsert(self, nums, target): low = 0 high = len(nums) - 1 while low <= high: mid = (low + high) >> 1 if nums[mid] == target: return mid elif target > nums[mid]: low = mid + 1 elif target < nums[mid]: high = mid - 1 return hig...
09c182e6c16f034cbcf2d22ba31c83ab6cbaf90e
mindentropy/leetcode
/922.py
533
3.765625
4
#!/usr/bin/env python class Solution(object): def sortArrayByParityII(self, A): """ :type A: List[int] :rtype: List[int] """ parity_arr = [None] * len(A) count = 0 for idx, val in enumerate(A): if val & 1 == 0: parity_arr[count] = val count = count + 2 count = 1 for idx, val in enum...
a993dfe59e0f0a7da97771875b3403a0fcc9b808
mindentropy/leetcode
/169.py
891
3.5
4
#!/usr/bin/env python class Solution(object): def occurences_in_list(self, nums, x): cnt = 0 for val in nums: if val == x: cnt += 1 return cnt def majority_element(self, nums): n = len(nums) if n == 0: return (False, None, 0) elif n == 1: return (True, nums[0], 1) else: b = nums[...
937fc85f55de14bdc9bd196ba9cfb637b0943557
mindentropy/leetcode
/746.py
499
3.71875
4
#!/usr/bin/env python from typing import List class Solution(object): def minCostClimbingStairs(self, cost: List[int]) -> int: min_costs = [0] * (len(cost) + 1) #Min cost for steps 0 and 1 is 0. for i in range(2, len(cost) + 1): ## min(one step, two step) min_costs[i] = min(min_costs[i - 1] + cost[i ...
a481e7d6dc43ed7975a8ce34baee307dc3274889
mindentropy/leetcode
/654.py
888
3.75
4
#!/usr/bin/env python from typing import List from typing import Optional class TreeNode: def __init__(self, val = 0, left = None, right = None): self.val = val self.left = left self.right = right class Solution(object): def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]: if len(n...
d305e830fca4ea3a2b16bd26cc4bf0befbea2ac6
mindentropy/leetcode
/82.py
939
3.6875
4
#!/usr/bin/env python class ListNode: def __init__(self, val = 0, next = None): self.val = val self.next = next class Solution(object): def deleteDuplicates(self, head: ListNode) -> ListNode: node = head follower = None while node != None: runner = node.next while runner != None and runner.val == n...
4acb7890d02d8f121fbd1ade4fa4045f8332a43a
mindentropy/leetcode
/167.py
1,148
3.640625
4
#!/usr/bin/env python class Solution(object): # def binsearch(self, numbers, lo, hi, searchnum): # if lo > hi: # return -1 # else: # mid = (lo + hi)//2 # # if numbers[mid] == searchnum: # return mid # elif searchnum > numbers[mid]: # return self.binsearch(numbers, mid + 1, hi, searchnum) # elif sear...
b95b3a9dcd5f6b0904814343ebe3701eb17538fd
mindentropy/leetcode
/107.py
1,057
3.796875
4
#!/usr/bin/env python class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def bfs(self, root): lst = [] bott_up_nodes = [] if root == None: return bott_up_nodes lst.append(root) while len(lst) != 0: nodeval = [] lvlnode ...
69aff2121c14c25ad7d4240737ae5509f84b0651
mindentropy/leetcode
/237.py
515
3.75
4
#!/usr/bin/env python class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def deleteNode(self, node): prev = None while node.next: prev = node node.val = node.next.val node = node.next prev.next = None if __name__ == '__main__': node = ListNode...
2d2af8de9aaa209c3abde5db0588001c9426cdab
mindentropy/leetcode
/206.py
653
4.03125
4
#!/usr/bin/env python class ListNode(object): def __init__(self, x): self.val = x self.next = None class Solution(object): def reverseList(self, head): prev = None curr = head nxt = None if head == None: return None if head.next == None: return head while(curr): nxt = curr.next curr.n...
871a8fb33f1bf898fe2a224eb7d16e774ed13aab
mindentropy/leetcode
/1441.py
650
3.625
4
#!/usr/bin/env python from typing import List class Solution(object): def buildArray(self, target: List[int], n: int) -> List[str]: cnt = 1 op = [] i = 0 # while i < len(target): # if target[i] == cnt: # op.append("Push") # cnt += 1 # else: # while target[i] != cnt: # op.append("Push") # ...
1ed74a9a37430d937303bb784c070fa2df319e4e
mindentropy/leetcode
/561.py
346
3.65625
4
#!/usr/bin/env python class Solution(object): def arrayPairSum(self, nums): nums.sort() idx = 0 maxsum = 0 nums_len = len(nums) while idx < nums_len: maxsum += nums[idx] if nums[idx] < nums[idx+1] else nums[idx+1] idx += 2 return maxsum if __name__ == '__main__': sol = Solution() print sol.a...
402249dc1df10272d22c422e441dbf6d14ade917
mindentropy/leetcode
/965.py
783
3.859375
4
#!/usr/bin/env python from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.right = None self.left = None class Solution(object): def isUnivalTree(self, root): """ :type root: TreeNode :rtype: bool """ que = deque() que.appendleft(root) val = root.va...
e12089df900c7403f04ca86410374e93fa2e033b
mindentropy/leetcode
/700.py
790
3.921875
4
#!/usr/bin/env python class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): # def searchBST(self, root, val): # while root != None: # if val > root.val: # root = root.right # elif val < root.val: # root = root.left # elif val == root...
e4712d1c04f72f80fb9ab005d9b45daabcaae343
jaclu010/html-img
/src/html_img/render.py
1,009
3.53125
4
import os import webbrowser from pathlib import Path def img_to_html(img_path = "test.png", out_file = "index.html", open_out_file = True): """ Render a HTML file with an embedded image file All image formats that are supported by the <img> tag are valid. For reference, see https://developer.mozilla.org/en-US/...
5965d177b3496b31e534da222122bfbd0edc5eb8
zyks/python-wars
/components/tile_map.py
1,847
3.59375
4
from enum import Enum import random import game_config class TileMap(object): class Tile(Enum): EMPTY = 0 WALL = 1 class Spawn: def __init__(self, pos, dir): self.initial_position = pos self.initial_direction = dir def __init__(self): self....
5e23584733a57efccbf2c4e2d45efa1d9c2d74ea
zyks/python-wars
/components/position.py
392
3.578125
4
class Position(object): def __init__(self, x=0, y=0, rotation=0): self.x = x self.y = y self.rotation = rotation def set(self, position): self.x = position.x self.y = position.y self.rotation = position.rotation def move(self, motion, time): self.x ...
263387b1a516c9558c26c0d6fd2df142ff9edcc6
muondu/caculator
/try.py
528
4.40625
4
import re def caculate(): #Asks user to input operators = input( """ Please type in the math operation you will like to complete + for addition - for subtraction * for multiplication / for division """ ) #checks if the opertators match with input if not re.match("^[+,-,*,/]*$", operators)...
1edd3809d431ece230d5d70d15425bd2fa62e43a
jabhij/DAT208x_Python_DataScience
/FUNCTIONS-PACKAGES/LAB3/L1.py
445
4.3125
4
""" Instructions -- Import the math package. Now you can access the constant pi with math.pi. Calculate the circumference of the circle and store it in C. Calculate the area of the circle and store it in A. ------------------ """ # Definition of radius r = 0.43 # Import the math package import math # Calculate C C ...