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
fe96e8e143cb8c13f7c3b1a1b5bba7db45616a20
frozen007/algo-study
/Challenge/lcof/lcof-09.py
893
3.765625
4
""" 剑指 Offer(第 2 版) https://leetcode-cn.com/problemset/lcof/ 剑指 Offer 09. 用两个栈实现队列 https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/ """ class CQueue(object): def __init__(self): self.s_a = [] self.s_b = [] def appendTail(self, value): """ :type value:...
4c5a3bf5c8cf889ef2924bbabc3b2f82db2cdf69
deepa045/python-programming
/Beginner/armstrong number.py
159
3.703125
4
n=int(raw_input()) temp=n sum=0 count=len(str(n)) while(n>0): digit=n%10 sum=sum+digit**count n=n/10 if (temp==sum): print "yes" else: print "no"
8867080790ebf240d493c7b823674338cac18375
deepa045/python-programming
/Beginner/mul two no and print even or odd.py
103
3.953125
4
num1,num2=raw_input().split() mul=int(num1)*int(num2) if(mul%2==0): print "even" else: print "odd"
c5e876dbf5400077e16a65c96937a8757d9b74a8
jamieHH/roguelike
/class_inventory.py
9,970
3.703125
4
from class_items import * # list.index(X). Returns the index in the list of the first item whose value... # ...is x. It is an error if there is no such item. # list.count(X). Returns the number of times x appears in the list. class Container: """Class for physical containers or character inventories""" TYPE...
ac95fb927af7eced3d6b06329a917df59a23573d
WillianPessoa/LIpE-Resolution-of-Exercises
/A01E06_salario-horas.py
189
3.9375
4
#!/usr/bin/python3 nome = input("Insira o nome do funcionário: ") salario = float( input("Insira o salário dele: ")) print("O salário do funcionário %s é R$ %.2f" % (nome, salario))
84edb47b87f494f5a6a0c1a679f7578eb597b7b4
WillianPessoa/LIpE-Resolution-of-Exercises
/A01E21_imc.py
763
4.03125
4
#!/usr/bin/python3 print("[CALCULANDO O ÍNDICE DE MASSA CORPORAL (IMC)]\n") print("Classificações para cada faixa de IMC:\n") print("\tAbaixo de 18,5 Abaixo do peso;") print("\tEntre 18,5 e 25 Peso normal;") print("\tEntre 25 e 30 Acima do peso;") print("\tAcima de 30 obeso.\n") altura = float( input("Insira a altur...
74d20b8caf905bd6457d8e185acc130715929305
WillianPessoa/LIpE-Resolution-of-Exercises
/A01E04_area-circulo.py
472
4.46875
4
#!/usr/bin/python3 # A única vez que nomeamos uma variável com suas letras maiúsculas é quando # sabemos que essa variável não vai mudar de valor (CONSTANTE) PI = 3.14159 # int() é utilizado para converter o texto inserido em número inteiro. raio = int( input("Insira o valor do raio em cm: ") ) # Calculando a ar...
bc761c7ec8d822a87e84934670bc7f5fb9b7267b
mukasama/portfolio
/Python Codes/Different Solutions.py
2,425
3.546875
4
print range(-5, 10, 2) print range(0,17, 3) print range(5, -6,-2) def mye(k): ''' Computes e up to k terms of the series ''' import math e = 0 for i in range(k): e = e + 1./math.factorial(i) print e def ss(): ''' Generates a restricted random ss ...
390550c4d3366ddf60bff4c13887d803c0f9a77c
mukasama/portfolio
/Python Codes/Proj 10/proj10.py
10,862
4.0625
4
# Martin Mukasa # CSE 231 - 009 # 11/ 28/ 2012 import math import turtle import time # This project uses turtle graphics to draw two snow people I have defined at least # 7 classes and. Also I do the minimum required (# 6) as said in the project description # At a minimum, a snow person should include three...
a2b2dd7fe076d007f6fac4de31341cc1324b5453
mukasama/portfolio
/Python Codes/lab 10.py
1,659
4.25
4
class Clock(object): def __init__(self,hours=0,minutes=0,seconds=0): h = hours m = minutes s = seconds ''' hours is the number of hours minutes is the number of minutes seconds is the number of seconds ''' self.hours = hours ...
18ec819f813fcf78e6826e270edcc39b9385e4b2
montreal91/workshop
/ap/leetcode/pyleet/lc0283.py
1,005
3.5625
4
# # Author: montreal91 # Time: 0:26 # Failed attempts: 0 # class Solution: def moveZeroes(self, nums): """ Do not return anything, modify nums in-place instead. """ for i, _ in enumerate(nums): z = i + 1 while z < len(nums) and nums[z] == 0: ...
e5c759fa996e94fefa98c7717ac08723301b80c2
montreal91/workshop
/tutorials/sicp/1.2/primality1.py
410
3.90625
4
def find_divisor(n, test_divisor): if test_divisor ** 2 > n: return n elif n % test_divisor == 0: return test_divisor return find_divisor(n, test_divisor + 1) def smallest_divisor(n): return find_divisor(n, 2) def is_prime(n): return n == smallest_divisor(n) if __name__ == ...
4293b712eb1912db21fbd5186117030ae959f6a8
montreal91/workshop
/tutorials/sicp/1.2/gcd.py
234
3.90625
4
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) if __name__ == '__main__': import sys if len(sys.argv) < 3: print("Not enough arguments.") print(gcd(int(sys.argv[1]), int(sys.argv[2])))
5e1c6afb2d76ada51187a51de74f8931f7c9b90b
montreal91/workshop
/ap/leetcode/pyleet/lc0125.py
731
3.5
4
# # Author: montreal91 # Time: 0:10 # Failed attempts: 0 # class Solution: def isPalindrome(self, s): processed = [] for ch in s: if ch.isalnum(): processed.append(ch.lower()) if len(processed) == 0: return True N = len(processed) fo...
7d66d9b4215a1d8a04da413d2431becfe1f260b9
montreal91/workshop
/educational/algorithms-cpp/exam/num_gen.py
230
3.609375
4
import sys from random import randint def GenerateBigNum(length): res = "" for i in range(length): res += str(randint(0, 9)) return res if __name__ == '__main__': print(GenerateBigNum(int(sys.argv[1])))
05469b06c1b3ea5544bd8506018e7d5cbea7eec6
montreal91/workshop
/forgery/complex-tennis/python/name.py
462
3.5625
4
class MyName( object ): def __init__( self, first_name="Random", last_name="Dude" ): super( MyName, self ).__init__() self.__first_name = first_name self.__last_name = last_name @property def first_name( self ): return self.__first_name @property def last_name...
91553b29b1d59c7cdd89d04cca081123a2354906
schwenzfeier/python_workshop
/json_converter.py
1,518
4
4
##################################################### ### Converting streamed JSON tweets into a CSV file ##################################################### import json ## Package for parsing JSON into a python dictionary import csv ## Package for writing CSVs ## What you want the resulting CSV file to be called O...
31913e1021a9238f221eba1fe966941f9501f1fa
DragonZ2013/Sem1_FP
/Seminar8/Raum.py
387
3.5625
4
class Raum(): def __init__(self, name, nr): self.__name = name self.__nr = nr def __eq__(self, other): if self.__name == other.__name: return True return False def __str__(self): return self.__name+" "+str(self.__nr) @property def name(self): ret...
c4bcbf7255318281d31092554982806cb11609c0
ronzionp/MersennePrimeNumbers
/src/PM1_S.py
835
3.65625
4
import sys import Prime_Tester import random ''' PM1_S: This module should find list of random prime number In order to start operation one should send the size of list ''' if (len(sys.argv) < 2): raise NameError("oops, you didn't give 1 argument.") list_size = int(sys.argv[1]) prime_list = [0] * list_size p...
3be4b3b4da244586baa07363a7ec27559c9ad41e
nandadao/Python_note
/note/download_note/first_month/day03/demo02.py
789
4.5
4
""" 选择语句 选择性的执行语句 if 条件: 满足条件执行的代码 else: 不满足条件执行的代码 if 条件1: 满足条件1执行的代码 elif 条件2: 满足条件3执行的代码 else: 以上条件都不满足执行的代码 练习:exercise01~06 """ sex = input("请输入性别:") if sex == "男": print("您好,先生!") # 否则如果 elif s...
94fa1fc4a7d36f2421d9798531308f15c2bf4955
nandadao/Python_note
/note/download_note/first_month/day08/day07_exercise/exercise04.py
316
4
4
# 6. 定义函数,在列表中查找最大值。 def get_max(list_target): max_value = list_target[0] for i in range(1, len(list_target)): if max_value < list_target[i]: max_value = list_target[i] return max_value list01 = [5, 4, 657, 89, 56] result = get_max(list01) print(result)
a03f14911cbfb93f24b7830fbcbbdcbc8682253a
nandadao/Python_note
/note/my_note/first_month/day05/exercise06.py
660
4.1875
4
""" 练习:根据月日,计算是这一年的第几天 3月5日 31 + 28 + 5 """ # month = int(input("请输入月份:")) # day = int(input("请输入日子:")) # # days_of_month = (31,28, 31,30, 31,30, 31,31,30, 31,30,31) # # day_of_today = day # # sum求和 # day_of_today = sum(days_of_month[:month-1]) + day # # # 传统思想,其他语言也可以使用这种思想 # # for i in range(month-1): # ...
060bd89960c488bfb4b58686cd5490306591533c
nandadao/Python_note
/note/download_note/first_month/day02/demo03.py
666
3.703125
4
""" 数据类型 """ # 1. None 空对象 # -- 占位 name = None age = 18 # -- 解除与对象的绑定关系 age = None # 2. 整数int # -- 十进制(逢十进一)0 1 2 3 4 .. 9 10 number01 = 10 # -- 二进制(逢二进一)0 1 10 number01 =0b10 # -- 八进制(逢八进一)0 1 .. 7 10 number01 = 0o10 # -- 十六进制(逢十六进一)0 1 ..9 a(10) ..f(15) number01 = 0x10 # 3. 浮点数 float number02 = 0.0 print(t...
a5ea2bb36e8d96006cd023a84cf84f1dc0909c24
nandadao/Python_note
/note/my_note/second_month/exercise_day01/file_fenli.py
874
3.71875
4
""" 2.文件分离练习 ​ 一个文件,文件名"talk.txt",再文件中保存一些对话信息,格式如下: ​ 老王:吃了么 ​ 老李:没呢,您呢? ​ 老张:您二位干什么呢? ​ 老李:溜弯啊,刚买菜会啊里啊 ​ 老张:是啊 通过程序,将该文件进行分离,每个人物的说话内容,重新写入一个新的文件中,文件以这个人的名字命名. """ f = open("talk.txt", "r") print(f) count = 0 for item in f: # item = "老李:溜弯啊,刚买菜会啊里啊" for i in item: # i = "老" item.split(":")[0] if ...
38d1cb2856f7ac35470fcb02c9546eebb34c7a6b
nandadao/Python_note
/note/my_note/first_month/day18/demo01.py
290
4.0625
4
""" lambda匿名函数: 价值:作为实参传递给函数 lambda 参数:函数体 """ # 有参数,有返回值 # def fun01(a): # return a == "ok" # # re = fun01("ok") # print(re) fun01 = lambda a:a == "ok" re = fun01("ok") print(re)
f6ce2c1fa7043ac6a78b4e57556687c70e75f788
nandadao/Python_note
/note/my_note/first_month/day09/day09/exercise02.py
448
3.78125
4
""" 定义函数,判断二维数字列表中是否存在某个数字 输入:二维列表、11 输出:True/False """ map = [ [2, 0, 2, 0], [2, 4, 0, 2], [0, 0, 2, 0], [2, 4, 4, 11], ] # print(2 in map)# False def if_exist(list_two_weidu, num): for i in list_two_weidu: for j in i: if j == num: return True r...
e2b112d234add91f30b186d31c325b237fcc9516
nandadao/Python_note
/note/my_note/first_month/day04/demo06.py
866
4.25
4
""" 通用操作 """ # name = "八戒" # print(id(name)) # name += "唐僧" # print(id(name)) # print(name) # # name02 = "唐僧" # name02 *= 2 # print(name02) # 比较:依次比较两个容器中元素大小,一旦不同则返回比较结果 # print("孙悟空" > "唐僧") # print(ord("孙"), ord("唐")) # # # # 成员比较 # print("大圣" in "我是齐天大圣") # 索引 # 0 1 2 3 。。。 len(s)-1 # -len(s) ...
fd511b1cc1b60ae3aa45677419090379594d3a1e
nandadao/Python_note
/note/download_note/first_month/day08/exercise01.py
211
3.59375
4
# 画出内存图 def fun03(p1,p2,p3): p1 = "孙悟空" p2 = [200] p3[:] = [300] g01 = "悟空" g02 = [100] g03 = [500] # 11:30 fun03(g01,g02,g03) print(g01)# ? 100 print(g02)# ? print(g03)# ?
9388c68d99efc86a53a16b8ad293d0e605d03779
nandadao/Python_note
/note/my_note/first_month/day17/exercise05.py
432
4.15625
4
""" 练习:获取list01中所有大于10的整数 """ list01 = [11, 2, "a", True, 33] # 生成器函数(写完后,给别人用) def get_bigger_than_10(): for item in list01: if type(item) is int and item > 10: yield item for item in get_bigger_than_10(): print(item) # 生成器表达式 for item in (item for item in list01 if type(item) is...
0197ea9bd9928de07d277b6026e23e71079ff060
nandadao/Python_note
/note/download_note/first_month/day11/day10_exercise/exercise01.py
1,747
3.921875
4
""" 4. 创建敌人类 -- 数据:名称,血量,攻击力,防御力 -- 行为:打印个人信息 -- 创建敌人列表 -- 在敌人列表中查找"灭霸"对象 -- 在敌人列表中查找所有死人 -- 在敌人列表中查找攻击力最大的敌人 -- 根据防御力,对敌人列表进行降序排列. """ class Enemy: """ 抽象的敌人 """ def __init__(self, name, hp, atk=0, defense=0): self.name = name self.hp = hp self...
7f923366cb0c052e665115911e37d35fbb5afdbe
nandadao/Python_note
/note/my_note/first_month/day07/exercise09.py
472
3.875
4
"" """ # 练习:古代的称,1斤是16量 # 在终端中获取两,计算几斤零几量. # 35 2 3 int_weight = int(input("请输入量:")) jin = int_weight // 16 liang = int_weight % 16 print(str(jin) + "斤零" + str(liang) + "量") """ def calculate_weight(total_weight): return (total_weight // 16, total_weight % 16) # -------------------...
da27b87aa9b5a99e5ed7daa6003cd2d162686d3a
nandadao/Python_note
/note/download_note/first_month/day05/exercise06.py
287
3.921875
4
# 练习:在终端中循环录入字符串,如果录入空,则打印所有内容。 list_result = [] while True: str_input = input("请输入内容:") if str_input == "": break list_result.append(str_input) str_result = "".join(list_result) print(str_result)
2d4e81c3d15b00b8e78c378bfea511ffa0103997
nandadao/Python_note
/note/my_note/first_month/day07/exercist06.py
323
3.6875
4
""" 练习: 把打印矩形定义成函数 """ def print_juxing(h, l, char): """ 打印矩形 :param h: int :param l: int :return: """ for r in range(h): for c in range(l): print(char, end=" ") print() print_juxing(4, 5, "$")
bcccbc389b28388e5a6ff16606e0206c23620c89
nandadao/Python_note
/note/download_note/first_month/day13/demo02.py
613
3.984375
4
""" 继承 -- 数据 练习:exercise02 """ class Person: def __init__(self,name=""): self.name = name """ # 子类如果没有构造函数,使用父类构造函数。 class Student(Person): pass s01 = Student("悟空") print(s01.name) """ # 如果子类有构造函数,会覆盖父类构造函数。 # 必须调用父类构造函数 class Student(Person): def __init__(self, name="", score=0): ...
ef235c31d2c659cef1eb31235962bfb14aab29de
nandadao/Python_note
/note/my_note/first_month/day06/demo03.py
1,113
3.890625
4
"""""" """ 字典推导式 """ # 需求:range(1, 11 ) key:1--10 value :键的平方 # dict01 = {item: item**2 for item in range(1, 11)} # print(dict01) # 需求:range(1, 11 ) key:1--10 value :键的平方 # 需求2.奇数拿出来 # dict01 = {item : item**2 for item in range(1, 11) if item%10 != 0} # print(dict01) # 练习1.将一个列表,转换为一个字典 # ["张无忌","赵敏","小昭"] # {"...
f3cd44058852ebc18b152740957b8dafb2b04b08
nandadao/Python_note
/note/download_note/second_month/day04/find_word.py
859
3.609375
4
""" 提供查找单词服务 使用udp编程完成 从客户端循环输入单词,获得单词的解释 服务端负责提供这个解释 """ from socket import * # 查单词函数 def select_word(word): f = open('dict.txt') # 文本方式打开 # 每次获取一行 for line in f: w = line.split(' ')[0] if w > word: f.close() return "没有该单词" elif word == w: # ...
ec269b0b75181455e4c50b55a81661fd4a042fbf
nandadao/Python_note
/note/my_note/second_month/day05/homework_day05.py
1,043
3.890625
4
""" 质数又被称为素数,是指一个大于1的自然数, 除了1和它自身外,不能被其它自然数整除, 且其个数是无穷的,具有许多独特的性质,现如今多被用于密码学上。 求100000以内的质数之和 """ # 自己的想法 # 做一个生成器,需要一个加一个 import time # def prime(): # # 求质数 # # for item in range(2, 1000): # 5 # if item == 2: # yield item # for i in range(2, item): # (2, 5) # if item % i == 0: # break # # y...
d2e88a5bf1e1069e8491f6285e0877c14c0aca69
nandadao/Python_note
/note/download_note/first_month/day17/demo01.py
1,423
4.25
4
""" yield 练习:exercise01 """ class MyRange: """ 可迭代对象 """ def __init__(self, stop): self.__stop = stop # 程序执行过程: # 调用不执行 # 调用__next__才执行 # 到yield暂时离开 # 再次调用__next__继续执行 # ... # 程序执行原理: "你看见的代码,实际不是这个样子" # 将yield关键字以前的代码定义到next方法中 ...
ddcf39629a53d084b67c591f7f2e3301b1c9b6c2
nandadao/Python_note
/note/download_note/first_month/day06/exercise02.py
701
3.984375
4
""" 练习:在终端中录入商品信息(名称/价格) 如果名称是空字符,则停止。 -- 将所有商品名称与价格打印出来(一行一个) -- 如果录入了"游戏机",则单独打印其价格. -- 要求:重复的商品,不能重复录入。 """ dict_commodity = {} while True: name = input("请输入商品名称:") if name == "": break price = float(input("请输入商品价格:")) if name not in dict_commodity: ...
1938f0077ee371bc07e2e90cc6ed2e90d4b48c32
nandadao/Python_note
/note/download_note/first_month/day05/review.py
1,138
3.53125
4
""" 复习 容器 通用操作:+ × == != in 索引 切片 字符串str:存储字符编码,不可变,序列 列表:存储变量,可变,序列 """ # 创建 list01 = [1, 2, 34, 45, 56, 6] list02 = list("我爱编程") # 添加 list01.append("end") list01.insert(2, "ok") # 修改 # --索引 list01[0] = "a" # --切片 # 遍历右边数据,依次赋值给左边 # list01[1:4] = "bcd" # list01[1:...
e67c555edb24bc2e0a5088ef84d09890fdf73081
nandadao/Python_note
/note/my_note/second_month/day07/prime.py
2,964
3.890625
4
""" 求100000以内质数之和 分别使用4个进程和10个进程做这件事, 并且分别统计执行时间,进行对比 提示: 1---25000 25001--5000 1--10000 10001--20000 """ from multiprocessing import Process import time import os # 装饰器 def timeis(f): def wrapper(*args, **kwargs): start_time = time.time() res = f(*a...
41c1d34a84f7cd9aa166a2a850d03377cec8e145
nandadao/Python_note
/note/download_note/first_month/day15/exercise02.py
400
3.734375
4
# 练习:定义函数,根据年月日计算星期(星期一、星期二、) import time def get_week(year, month, day): tuple_time = time.strptime("%d-%d-%d" % (year, month, day), "%Y-%m-%d") list_weeks = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] index = tuple_time[6] return list_weeks[index] print(get_week(2019, 11, 19))
00206c6b41b2b83f821e42d387791317e2b90392
nandadao/Python_note
/note/my_note/second_month/day16/mysql.py
629
3.5
4
""" mysql.py pymysql 数据库操作 """ import pymysql # 连接数据库 db = pymysql.connect(host="localhost", port=3306, user="root", password="123456", database="stu", charset="utf8") # 生成游标对象 (操作数据库执行sql语句获取结果的对象) cur = ...
3abdc382259d793e87f427d1081d64286de268fe
nandadao/Python_note
/note/my_note/first_month/day05/exercise04.py
236
3.59375
4
""" 练习:How are you 将上面英文语句,按照单词反转 最后还是字符串 """ str_01 = "How are you" list_02 = [] list_01 = str_01.split(" ") # ***** message = " ".join(list_01[::-1]) print(message)
d9f2421540ac37e26435a0d452ab6c74f4854008
nandadao/Python_note
/note/download_note/first_month/day09/answer_exercise/exercise03.py
695
4.03125
4
""" 定义函数,返回字符串中第一个不重复的字符。 输入:ABCACDBEFD 输出:E """ def get_repeating_info(target): dict_repeat_info = {} for char in target: dict_repeat_info[char] = target.count(char) # if char not in dict_repeat_info: # dict_repeat_info[char] = 1 # else: # dict_repeat_info[char] +=...
b634843400d1a08c30389b03bbd41aa02aaa204a
nandadao/Python_note
/note/my_note/first_month/day10/exercise04.py
257
3.890625
4
# 升序排列 list_01 = [1, 2, 22, 1, 2, 3] for r in range(len(list_01)-1): for c in range(r+1, len(list_01)): if list_01[r] > list_01[c]: list_01[r], list_01[c] = list_01[c], list_01[r] print(list_01)
7eb6d36f35cc7112c9bd0baa4e679d8b9bb23e38
nandadao/Python_note
/note/download_note/first_month/day03/exercise08.py
414
3.9375
4
# 练习:循环将季度转换为月份,如果输入q则退出. while True: season = input("请输入季度:") if season == "春天": print("1月2月3月") elif season == "夏天": print(" 4月5月6月") elif season == "秋天": print("7月8月9月") elif season == "冬天": print("10月11月12月") if input("请输入q退出") == "q": break
6e1af1637eaa743468a0e3056317e406323a6287
nandadao/Python_note
/note/download_note/first_month/day18/exercise01.py
2,733
3.984375
4
""" 需求: 1. 定义函数,在老婆列表中查找所有老婆的姓名 2. 定义函数,在老婆列表中查找所有老婆的姓名和身高 需求: 1. 定义函数,在老婆列表中累加所有老婆的总身高 2. 定义函数,在老婆列表中累加所有老婆的总体重 步骤: 1. 将需求完整实现到函数中。 2. 将变化点单独定义到函数中。 3. 将通用代码定义到函数中。 4. 用参数隔离变化点。 5. 将通用代码移动到IterableHelper类中 6. 测试调用IterableHelper...
db6df8f1eef87c39c7191c7bb4c74cb5f10ebe7b
nandadao/Python_note
/note/download_note/first_month/day03/exercise07.py
779
3.78125
4
# 练习1:在终端种录入一个整数,如果是奇数为变量state # 赋值为"奇数",否则赋值为偶数. number = int(input("请输入整数:")) # if number % 2 ==1: # state = "奇数" # else: # state = "偶数" # if number % 2: # state = "奇数" # else: # state = "偶数" state = "奇数" if number % 2 else "偶数" print(state) # 练习2:在终端种录入一个年份,如果是润年为变量day # 赋值为29,否则赋值为28. ...
f534fab1e15ecc73e6b0f3cde156980e90347841
nandadao/Python_note
/note/download_note/first_month/day17/exercise01.py
849
4.09375
4
""" 将迭代器版本的员工管理器,改为yield版本 day16/exercise04 调试,体会过程. """ class EmployeeManager: def __init__(self): self.__list_employees = [] def add_employee(self, skill): self.__list_employees.append(skill) def __iter__(self): # yield "悟空" # yield "八戒" # yield "唐僧" ...
f262be6a1baaca368304396d1b3be983469477e7
nandadao/Python_note
/note/my_note/first_month/day04/homework_day04.py
1,435
4.125
4
# 3.(扩展) # 循环 # 一个小球从100米落下,每次弹回原高度一半, # 请计算: # 一:总共弹起多少次(最小弹起的高度0 # .01 # m) # 二:整个过程,经过多少米 # count = 0 # jump = 0 # height = 100 # while height/2 > 0.01: # height /= 2 # jump += height*2 # count += 1 # # print(height) # # print(jump) # print("总共弹了" + str(count) + "次。") # print("整个过程,经过...
94744e23d635c8e599bad4893cc600dacbf8fc33
nandadao/Python_note
/note/download_note/first_month/day15/review.py
3,603
4
4
""" 10:30 面向对象 概述 面向过程:关心解决问题的步骤(实现细节) 面向对象:关心解决问题的人 类和对象: 类:类别,模板 对象:个体,实例 类和类区别:行为不同 对象与对象:数据不同 抽象:剔除个性的、非本质,抽离共性、本质特征的过程。 语法: class 类名: def __init__(self,参数): ...
72136b5c889d3986ac88156eebf186d5d37984b5
nandadao/Python_note
/note/download_note/first_month/day04/demo07.py
752
4.21875
4
""" 列表 list """ # 1. 创建 # -- 创建空列表 list01 = [] list02 = list() # -- list01 = [100,"悟空",True] # list(可迭代对象) list02 = list("我是齐天大圣") # 2. 添加 # -- 追加 list01.append("八戒") # -- 插入 list01.insert(1,"唐僧") print(list01) # 3. 修改 # 将唐三藏地址,赋值给列表第二个元素 list01[1] = "唐三藏" # 遍历[10,20],将每个元素赋值给切片位置的元素 list01[-2:] = [10,20] list01[...
3ab01d02e08aeb1e504eb021477500f78d0105f3
nandadao/Python_note
/note/my_note/first_month/训练营笔记/day03/example.py
6,848
3.875
4
# 计算总共的秒数 # hour = int(input('请输入小时数:')) # minute = int(input('请输入分钟数:')) # second = int(input('请输入秒数:')) # # result = hour * 3600 + minute * 60 + second # print("总秒数是:"+str(result)) # total_second = int(input("请输入总秒数:")) # hour = total_second // 60 // 60 # second = total_second % 60 # minute = total_second // 60 % 60...
ff3f00389d5bf9cea8a70f14e539a6702b148bcf
nandadao/Python_note
/note/download_note/first_month/day13/demo05.py
476
4.15625
4
""" 反向运算符(特别不重要) 作用:当前类对象与其他类对象做算数运算 """ class Vector1: def __init__(self, x=0): self.x = x def __str__(self): return "向量的分量是:" + str(self.x) def __add__(self, other): return Vector1(self.x + other) def __radd__(self, other): return Vector1(self.x + other) ...
aceaac25e51ceff859ba5bfa5b94ca9c27f41d79
nandadao/Python_note
/note/my_note/second_month/day11/regex1.py
620
3.671875
4
""" regex1 正则表达式 """ import re s = "今年是2019年12月10日,2019年初的目标实现了吗" \ "保持95斤的愿望还记得吗" pattern = r"\d+" # 获取匹配内容的迭代器 result = re.finditer(pattern, s) # for i in result: # 迭代得到每处匹配内容的match对象 # < _sre.SRE_Match object; span = (3, 7), match = '2019' > # print(i.group()) # 2019 ... # 完全匹配 # obj = re.f...
51d5f25cb5f42b7f490134d0c754f1c82336a398
nandadao/Python_note
/note/download_note/first_month/day07/exercise09.py
221
3.890625
4
# 练习:将下列代码,定义到函数中. def each_unit_sum(str_number): sum_value = 0 for item in str_number: sum_value += int(item) return sum_value re = each_unit_sum("1231234234") print(re)
ba740f93917a3481227bcd8a39abab404243a4d3
nandadao/Python_note
/note/my_note/first_month/day17/exercise04.py
921
4.28125
4
""" 练习:定义函数:my_enumerate函数,实现下列效果 """ list01 = [1, 2, 55, 3] dict01 = {"a":1, "b":2, "c":3} def my_enumerate(iterable): my_index = 0 for item in iterable: yield (my_index,item) my_index += 1 # for index, item in my_enumerate(list01): # print(index, item) # print("-----------------") ...
9355b32a5516f3857b35be5d74781167bb9e0f3b
bobby-palko/100-days-of-python
/07/main.py
1,568
4.3125
4
from art import logo # Alphabet list to use for our cipher alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] # Sweet ASCII art print(logo) is_finished = False def caesar(text, shift, direction): # Cut down large shift ...
cf408c572a8853f7c56f4cf2f6e284d410908a1c
bobby-palko/100-days-of-python
/30/main.py
2,354
3.546875
4
from tkinter import * import pandas from random import choice BACKGROUND_COLOR = "#B1DDC6" LANGUAGE_FONT = ("Arial", 40, "italic") WORD_FONT = ("Arial", 60, "bold") timer = None next_word_pair = {} # -------------------- DATA SETUP -------------------- # try: data = pandas.read_csv("data/words_to_learn.csv") e...
32bf5473060c794b71de30c3d96e9d76d82af0b3
monty8800/PythonDemo
/base/42.IO编程-序列化.py
2,801
4.15625
4
# 1.序列化 - pickling ,使用pickle模块来实现 import pickle d = dict(name='mwu', age=10, score=88) print(pickle.dumps(d)) # pickle.dumps()方法把任意对象序列化成一个bytes,然后,就可以把这个bytes写入文件。 # 1.1序列化 # 或者用另一个方法pickle.dump()直接把对象序列化后写入一个file-like Object: # f = open('./demo/files/dump.txt','wb') # pickle.dump(d,f) # f.close() # 1.2反序列化 f = op...
47496831eb874ccad1a30d98aa88d2ddd07e9af4
monty8800/PythonDemo
/base/15.迭代器.py
2,023
4.15625
4
# 迭代器 from collections.abc import Iterable, Iterator print(isinstance([],Iterable)) # True print(isinstance({},Iterable)) # True print(isinstance('',Iterable)) # True print(isinstance((x for x in range(1,11)),Iterable)) # True print(isinstance(100,Iterable)) # False # 迭代对象(Iterable)和迭代器(Iterator) # 以上几种为True的都是迭代对象,但...
711991ea38eb5526374a935c5dbc8ed13e54dd64
AyebakuroOruwori/Python-Kids-Projects
/Comparing Dataset Entries-Storing Data in Variables.py
2,145
4.28125
4
#We would be using our knowledge abount booleans and comparison to compare the data of two students from a collection of grade submissions. #We'll kick it off by saving the id, average grade, and recent test score in variables for each of the two student entries. #Let's start saving the data for the first student ent...
14dab5ca1511484bd14b89a827965e1c6a1fe106
yaozezhen/python-challenges
/removeNums.py
236
3.640625
4
# function descriptor: removeNums(s) # removes numbers from a given string # s - a string that only contains alphanumeric characters # return type: string # example: s - "Hel1o" => return "Helo" def removeNums(s): # fill-in code here
c7078b035861d2a372f5e730ef0baa65801c1eab
tsilva19/ProjetoPython
/aula2cont.py
778
4.0625
4
#Interação com o usuario a = int(input("Entre com o primeiro valor: ")) b = int(input("Entre com o segundo valor: ")) soma = a + b sub = a - b mult = a * b div = a / b resto = a % b print(type(soma)) #convertendo inteiro soma = str(soma) print('soma: ' + soma) #comando format resultado =('soma: {soma}. \nsubtração: {s...
eaa8950260018da4e7ab6fdad1d2ce412617df6c
sandr12234/DMI
/PYTHON/sin_caur_summu_ver2.py
544
3.515625
4
#!/usr/bin/python from math import sin #a0, a1, a2, a3 #S0, S1, S2, S3 -> S x=1. * input("Lietotaj, ludzu, ievadi x argumentu: ") y=sin(x) print "sin(%.2f) = %.2f"%(x,y) a0 = (-1)**0*x**1/(1) #S0=a0 S=a0 print "a0 = %6.2f S0 = %6.2f"%(a0,S) a1 = (-1)**1*x**3/(1*2*3) #S1=(a0)+a1 #S1=S0+a1 S=S+a1 print "a1 = %6.2f S1 ...
378e56e1f5a1a42fa977a6a8fd9d6f8f3cca832a
IsHYuhi/Introduction_of_Python3
/chapter5/standardLibrary.py
4,262
3.90625
4
print('setdefault()とdefaultdict()による存在しないキーの処理') periodic_table = {'Hydrogen': 1, 'Helium': 2} print(periodic_table) ''' 存在しないキーで辞書にアクセスしようとすると、例外が発生する。 辞書のget()関数を使って、キーが存在しない場合はデフォルト値を返すようにすることができる。 setdefault()はキーがなければさらに辞書を追加することができる ''' carbon = periodic_table.setdefault('Carbon', 12) print(carbon) print(periodic...
388b3f00e037128135b1d9a563a357ce645bbe1a
IsHYuhi/Introduction_of_Python3
/chapter6/nametuple.py
1,492
3.875
4
''' 名前付きタプルはタプルのサブクラスでオフセット[offset]だけでなく名前(.name)でも値にアクセスできる namedtuple関数には 名前 空白区切のフィールド名の文字列 の引数を渡す ''' from collections import namedtuple Duck = namedtuple('Duck', 'bill tail') duck = Duck('wide orange', 'long') print(duck) print(duck.bill) print(duck.tail) print('\n名前付きタプルは辞書からも作れる') parts = {'bill': 'wide orange...
e9cd0a70a1fd8d694a59377a57f0dab0f9ca53cf
mirzatuzovic/ORS-PA-18-Homework05
/task4.py
666
4.25
4
""" =================== TASK 4 ==================== * Name: Can String Be Float * * Write a script that will take integer number as * user input and return the product of digits. * The script should be able to handle incorrect * input, as well as the negative integer numbers. * * Note: Please describe in details p...
fa2186ba87410db2f1118d1e79ea83414dac7c63
NBakalov19/SoftUni_Python_Fundamentals
/01.Python_Intro_Functions_And_Debugging/draw_filled_square.py
504
4.09375
4
def print_top_or_bottom_of_dashes(n): print(''.join('-' * (2 * n))) def print_filling(n): print(''.join('\\/' * (n - 1)), end='') def print_body(n): for row in range(1, n - 1): print('-', end='') print_filling(n) print('-', end='') print() def print_squa...
6e2e8ce4f2f76c4b6e380a15967205e53d658618
NBakalov19/SoftUni_Python_Fundamentals
/01.Python_Intro_Functions_And_Debugging/exam_preparation.py
735
3.765625
4
count_of_bad_grades = int(input()) bad_grades = 0 average_grades = 0 task_count = 0 last_task = '' output = '' while True: command = input() if command == 'Enough': average_grades /= task_count output = f'Average score: {average_grades:.2f}\n' \ f'Number of problems: {...
ab21a6d84cc536d07561d835c50458a397170b08
NBakalov19/SoftUni_Python_Fundamentals
/03.Dictionaries/lab/wardrobe.py
900
3.71875
4
if __name__ == '__main__': lines = int(input()) wardrobe_dict = {} for line in range(lines): dict_info = input().split(' -> ') color = dict_info[0] clothes = dict_info[1].split(',') if color not in wardrobe_dict.keys(): wardrobe_dict[color] = {} ...
93de2b7e854598a22174755961eb94bcf1ec0eae
NBakalov19/SoftUni_Python_Fundamentals
/04.Objects_and_Classes/distance_beetwen_two_points.py
628
3.96875
4
import math def calculate_distance(first_point, second_point): side_a = math.fabs(first_point.x - second_point.x) side_b = math.fabs(first_point.y - second_point.y) return math.sqrt(side_a ** 2 + side_b ** 2) if __name__ == '__main__': class Point: def __init__(self, x, y): ...
68344863671faf93697198f046907b790fde669e
NBakalov19/SoftUni_Python_Fundamentals
/01.Python_Intro_Functions_And_Debugging/graduation.py
258
3.984375
4
name = input() year = 1 average_grade = 0 while year <= 12: grade = float(input()) if grade >= 4: year += 1 average_grade += grade average_grade /= 12 print(f'{name} graduated. Average grade: {average_grade:.2f}')
c9766569112f0b53a489370cdf81b03bfc9a5faa
NBakalov19/SoftUni_Python_Fundamentals
/02.Lists/lab/square_nums.py
200
3.625
4
import math nums = list(map(int, input().split(' '))) nums = list(filter(lambda num: math.sqrt(num) == int(math.sqrt(num)), nums)) nums.sort() nums.reverse() print(' '.join(map(str, nums)))
fb713e764b44c44aa5d91bd92d99c079ba4de8e2
NBakalov19/SoftUni_Python_Fundamentals
/01.Python_Intro_Functions_And_Debugging/newHome.py
1,233
4.1875
4
import math flowers_type = input() flowers_count = int(input()) budget = int(input()) flowers = { "Roses": 5, "Dahlias": 3.8, "Tulips": 2.8, "Narcissus": 3, "Gladiolus": 2.5 } money_needed = flowers_count * flowers[flowers_type] discount = 0 if flowers_type == 'Roses' and flow...
7abd93fcc16530ac2cc8b30854d77341d1c879a5
camhanson/DSCI-402-F2019
/bf_test.py
2,213
3.5625
4
#One way to import/ use modules import basic_functions as bf print(bf.add_2(4,5)) #Another way to import/use modules #import basic_functions #print(basic_functions.add_2(10,12)) #Another way #from basic_functions import * #print(add_2(31,33)) #Another way #from basic_functions import add_2 #print(add_2(29,44)) #Tes...
b97b6ffef891affb6f1124bcf1d15b622e01ff0d
nimitsingh7/SWP-OP
/InsertionSort/Insertion/Sort.py
386
3.890625
4
''' Created on 08.01.2019 @author: Nimit ''' def insertionSort(A): for i in range(1, len(A)): h = A[i] j = i-1 while j >=0 and A[j] > h: A[j+1] = A[j] j = j - 1 A[j+1] = h A = [12, 11, 13, 5, 6] insertionSort(...
1941b1af8db88e5c6dbee5e345bec594920380a3
dhrumil-shah/leetcode-python
/108-ConvertSortedArraytoBinarySearchTree.py
862
3.78125
4
""" 108. Convert Sorted Array to Binary Search Tree """ # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def sortedArrayToBST(self, nums: List[int]) -> TreeNode: length = len(num...
7e90c44565604f4636311241e7a2b45f86279c6f
dhrumil-shah/leetcode-python
/35-SearchInsertPosition.py
802
3.765625
4
# -*- coding: utf-8 -*- """ Created on Sun Aug 25 19:11:38 2019 @author: dhrumil-shah """ class Solution: def searchInsert(self, nums: List[int], target: int) -> int: length = len(nums) for i in range(length): if (target <= nums[i]): return i if (i == length-1):...
01936223cfa3aa3e0b38f66b3a456a7557baf00b
GuilhermeFerreira08/Git
/tubbing.py
1,314
3.765625
4
##tubbing.py - pesquisa de videos no youtube ##coding:utf-8 import requests,bs4,select,webbrowser,sys #download da pagina def openPages(links): numOpen = min(5,len(links)) #as cinco primeiras referencias da palavra-chave for i in range(numOpen):#Abre uma aba do navegador para cada resultado webbrowser...
a97dc05d5a11b498771b33471a599296cd03d1e0
Georgiy0/cryptography
/1/BasicCrypto/TranspositionCipher.py
1,374
3.546875
4
from random import randint from BlockCipher import BlockCipher """ Implements transposition cipher with the blocks of provided length (by default blockSize is 8 byte). If the data cannot be devided in final number of length the last incomplete block won't be encrypted. """ class TranspositionCipher(BlockCipher): def ...
67e42a270b82a807bc20108cc09a6414f1db0c82
darusdc/ujian_jcds
/soal_3.py
1,047
4.03125
4
def Sort_odd_even(x=list): odd=list(sorted(filter(lambda a: a%2==0 ,x),reverse=True)) even=list(sorted(filter(lambda a: a%2!=0 ,x))) even_list=[i for i in range(1,len(x)+1,2) if i>3] odd_list=[i for i in range(0,len(x)+1,2) if i>2] result=[] for i in range(len(x)): if i==0 or i==1: ...
9b1c92c12d3f913aef5271f7796ae89e769cad39
KairoWageh/PythonTasks
/Assignments/Assignment 1/vowels.py
304
3.765625
4
def vowels(name): vowels = ['a','e','i','o','u','A','E','I','O','U'] i = 0 while i < len(name): x = name[i] if x in vowels: name = name.replace(x,"") #cotinue ==> stops script #name += x i+=1 return(name) print(vowels("python"))
9495fbd8481f1608b5a97f435d023ac6225a40cb
umangbhatia786/PythonPractise
/General/APIProject.py
1,152
3.640625
4
from pyfiglet import figlet_format from termcolor import colored from random import choice import requests def print_message(msg, input_color): '''The function to print a message with user-defind color''' valid_colors = ('red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') if input_color not in ...
3366b1aa278766d24fd285173d621674bcd78c57
umangbhatia786/PythonPractise
/GeeksForGeeks/Strings/replace_occurences.py
248
4.28125
4
#Python Program to replace all occurrences of string with another def replace_occurrences(input_str, word, replace_with): return input_str.replace(word, replace_with) my_str = 'geeksforgeeks' print(replace_occurrences(my_str,'geeks','abcd'))
d66b170ea6e47a766be002dc60fe46ed2f45871c
umangbhatia786/PythonPractise
/CSV/reader.py
265
3.546875
4
from csv import reader file_path = r'C:\Users\Umang Bhatia\Documents\Udemy\Python3\CSV\address.csv' with open(file_path) as file: csv_reader = reader(file) csv_rows = list(csv_reader) '''for row in csv_reader: print(row)''' print(csv_rows)
2a874cf2f2f1af992ad26896c9433d56a9a02bb0
umangbhatia786/PythonPractise
/Practise/find_the_duplicate.py
671
3.921875
4
''' find_the_duplicate([1,2,1,4,3,12]) # 1 find_the_duplicate([6,1,9,5,3,4,9]) # 9 find_the_duplicate([2,1,3,4]) # None ''' '''def find_the_duplicate(input_list): unique_list = list(set(input_list)) if len(input_list) == len(unique_list): return None else: num = 0 for val in unique...
39bfcad28fc2da53c90e9b3ae748400ce0d4c526
umangbhatia786/PythonPractise
/GeeksForGeeks/Strings/get_uncommon_words.py
486
4.46875
4
#Python Code get list of uncommon words from 2 different strings def get_uncommon_words(input_str1, input_str2): '''Function that uses List Comprehension to get uncommon words out of two strings''' word_list_1 = input_str1.split(' ') word_list_2 = input_str2.split(' ') return [word for word in word_li...
73ed260447b9c669febd0c9bf8d20d885c06f76a
umangbhatia786/PythonPractise
/General/ASCII_Art.py
568
3.8125
4
from pyfiglet import figlet_format from termcolor import colored def print_message(msg, input_color): '''The function to print a message with user-defind color''' if input_color not in valid_colors: input_color = 'magenta' ascii_art = figlet_format(msg) colored_ascii_art = colored(ascii_art,...
5be3752dea353fecf96a4342ab92621de0a5af06
umangbhatia786/PythonPractise
/File_IO/readFile.py
363
3.640625
4
file = open(r'C:\Users\Umang Bhatia\Documents\Udemy\Python3\File_IO\sample.txt','r') #Printing The Content after reading the file print(file.read()) #Reading again will print nothing as Cursor is set to last print(file.read()) #We will set the cursor to original position using seek method file.seek(0) #Now reading ...
977be7873ecfb430347dd0502e047f728b692e8c
umangbhatia786/PythonPractise
/GeeksForGeeks/List/second_largest.py
250
4.125
4
#Python Program to find 2nd Largest num input_list = [1,5,3,6,8,7,10] def get_second_largest(int_list): sorted_list = sorted(int_list) return sorted_list[-2] print(f'Second largest number in given list is {get_second_largest(input_list)}')
827dc12b9a54c24b763ef7a38c3b284efe48cce8
umangbhatia786/PythonPractise
/OOPS/DeckCards/human.py
553
3.921875
4
class Human: def __init__(self, first, last, age): self.first = first self.last = last self._age = age #Alternate way of getter and setter i.e by making properties @property def age(self): return self._age @age.setter def age(self, new_age): if new_age >=0: self._age = new_age else: raise Val...
e7e09e72227e2aa8b496af46e1e02440c0cc8eed
umangbhatia786/PythonPractise
/General/FormatString.py
224
4.3125
4
#Method from python 2 --> 3.5 str1 = 'My name is {} and age is {}'.format('Umang', 26) print(str1) #Method from python 3.5+ # f strings name = 'Cheems' age = 26 str2 = f'My name is {name} and age is {age}' print(str2)
a037828ad15874ee1ba066ebefd3f62dbd233fa7
umangbhatia786/PythonPractise
/CSV/dict_writer.py
704
4.03125
4
from csv import reader,DictWriter import csv file_path = r'C:\Users\Umang Bhatia\Documents\Udemy\Python3\CSV\details.csv' print('***************** CSV Before Writing Data ***************') with open(file_path) as file: csv_reader = reader(file) for row in csv_reader: print(row) with open(file_path,...
e60053e7c10f506946a209209ee65e378d030089
umangbhatia786/PythonPractise
/Python+SQL/select_data.py
369
3.953125
4
import sqlite3 as sql from csv import reader #creating or connecting to DB conn = sql.connect('my_friends.db') #Create a cursor object c = conn.cursor() #Executing a command c.execute("SELECT * FROM Friends WHERE fname IS 'Pri'") '''for result in c: print(result)''' print(c.fetchall()) #commiting the changes c...
0706983aa5be1423b926944536e78f49b16d1d51
elleech/python_4fun
/battleship-game.py
3,463
3.9375
4
import random def print_board(board): for row in board: print(' '.join(row)) def rand_place(): x = random.randrange(len(board)) y = random.randrange(len(board)) d = random.choice(['+x', '+y']) return(x, y, d) def ship_type(): # {'Shipname': [quantity, size]} ships = ...
8038c7618f323f8a5dd8f47e0228e4eabea1dd20
xettrisomeman/pythonsurvival
/generatorspy/theproblem.py
1,346
4.6875
5
#lets focus on generators #generator is special functions which yields one value at a time #generator gives iterator #we need syntax that generates one item at a time , then #"yiels" a value , and waits to be called again, saving #state information #this is called generators a special case of iterator, #We need a wa...
d72c60c547025346f483a3b17ba2a18c2917aeed
xettrisomeman/pythonsurvival
/listcompre/usingcompre.py
552
4.59375
5
#now using list comprehension #list comprehension is shortcut #it consists of two pats within brackets []. #the first part is the value to be produced ,for example ,i. #second part of list comprehension is the for statement header. # syntax : [value for_statement_header] #example old_list = [1,2,3] #take each eleme...
0e01b546e12c054ee20ba01c551a751a23ce21e7
MurphDirt879/cs-module-project-hash-tables
/applications/notes.py
2,373
3.6875
4
cache = {} ​ def fib(n): if n <= 1: return n ​ if n not in cache: # if n is not a key in the cache cache[n] = fib(n-1) + fib(n-2) ​ return cache[n] ​ for i in range(95): print(f'{i:3} {fib(i)}') def expensive_function(x, y): key = (x, y) if key not in cache: # if n is ...