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 |
|---|---|---|---|---|---|---|
d94bb919212af78508fc1a5f0ada3a9750184d23 | owaiskazi19/Practice-Problems | /Graph/flood_fil.py | 889 | 3.59375 | 4 | class Solution(object):
def dfs(self, image, i , j, color, newColor):
if i < 0 or i >= len(image) or j < 0 or j >= len(image[i]) or image[i][j] != color:
return
if image[i][j] == color:
image[i][j] = newColor
print i,j, image
self.dfs(image, i - 1, j, color, ... |
1992eb3e519121c50fc1250869007a68d43ac691 | raphey/euler-utilities | /my_utility_module.py | 3,155 | 3.578125 | 4 | __author__ = 'raphey'
# python 3
import time
import cProfile
from functools import update_wrapper, reduce
def read_2d_input(file_name, dtype=int, delimiter=','):
data = []
with open(file_name, "r") as f:
content = f.readlines()
for line in content:
data.append(list(map(dtype, lin... |
4b130db9066095299381ee5ba3baff79f4105dcc | jiankangliu/baseOfPython | /PycharmProjects/02_Python官方文档/一、Python初步介绍/02_Python核心对象、变量、输入和输出/2.4编程项目.py | 1,024 | 4.09375 | 4 | #1找零钱
strMoney=input("Enter amount of change:")
money=int(strMoney)
Quarters=money//25
money=money%25
Dimes=money//10
money=money%10
Nickels=money//5
money=money%5
Cents=money
print("Quarter: ",Quarters,"\t","Dimes: ",Dimes,"\n","Nickels: ",
Nickels,"\t","Cents: ",Cents,sep="")
#2汽车贷款
loan=float(in... |
05d8fe47e1dfa4cdacf7dfc4fed5673837e91589 | jiankangliu/baseOfPython | /PycharmProjects/函数/交换变量的值.py | 140 | 3.515625 | 4 | a = 1
b = 2
# 借助第三个变量,避免数据丢失
a, b = b, a # python中独有的交换变量的值
print(a)
print(b)
|
24031d350d9d24f8a9818d0b51545741286d0b35 | jiankangliu/baseOfPython | /PycharmProjects/02_Python官方文档/一、Python初步介绍/05_数据处理/5.1数据处理(第一部分).py | 3,171 | 3.90625 | 4 | #5.1.1读取文本文件
#infile = open(fileName,'r')
#创建一个程序和文件的连接,能够让程序从文件中读取数据。
#文件称作为了读取文件而打开(open for reading)
#或者为了输入而打开(open for input)
#open函数返回一个文件对象(file object)
#变量infile被用于从文件中读取行以及最终终端和文件连接。
#在文件为读取而被打开后,一个具有如下头部的for循环:
#for line in infile:
#用来连续访问文件中的行。
#例1 最初三任总统
def main():
file="FirstPresidents.t... |
7e6f79f1c1017c45aaad6e3767c327a1f0c760b7 | jiankangliu/baseOfPython | /PycharmProjects/面向对象/10-搬家居.py | 1,022 | 3.984375 | 4 | """
房子 -- 初始化数据:家居列表[ ],使用面积,生于面积,地理位置
家居 -- 初始化数据:作用/名字,占地面积
"""
class House(object):
def __init__(self, area, address):
self.jia_list = []
self.area = area
self.free_area = area
self.address = address
def __str__(self):
return f'房子位于{self.address},使用面积{self... |
0f0c2b71165908b69143488b544ec20e7192961b | jiankangliu/baseOfPython | /PycharmProjects/02_Python官方文档/一、Python初步介绍/03_Python控制流结构/3.2判断结构.py | 1,030 | 4.125 | 4 | #3.2.1 if-else语句
#例1 求较大值
num1=eval(input("Enter the first number: "))
num2=eval(input("Enter the second number: "))
if num1>num2:
print("The larger number is:",num1)
else:
print("The larger number is: ",num2)
#3.2.2 if语句
firstNumber=eval(input("Enter the first number: "))
secondNumber=eval(input("E... |
0518808edbf6f6c13bcbcfe395ca09e66a186e7a | jiankangliu/baseOfPython | /PycharmProjects/函数/12-列表推导式.py | 1,075 | 3.859375 | 4 | # # [1, 2, 3, 4... 9]
#
# # while
# # list1 = []
# # i = 1
# # while i <= 9:
# # # print(i)
# # list1.append(i)
# # i += 1
# #
# # print(list1)
#
# # for
# # list1 = []
# # for i in range(1, 10):
# # # print(i)
# # list1.append(i)
# #
# # print(list1)
#
# # [返回值 for i in range(1,... |
0470a4ea71b065618b576f55ab119ae856a12c44 | jiankangliu/baseOfPython | /PycharmProjects/函数/reduce.py | 337 | 3.65625 | 4 | import functools
list1 = [1, 2, 3, 4, 5]
def fun(a, b):
return a*b
reslut = functools.reduce(fun, list1)
a = reslut
print(a)
print(reslut)
print(id(a))
print(id(reslut))
a = 8
print(id(a))
list2 = [2, 44, 6567, 89]
def fun1(a, b):
return a if a > b else b
print(functools.reduc... |
9c55ad7e8197036af7822a81523e5eb59fa3c7c9 | jiankangliu/baseOfPython | /PycharmProjects/Python100题/36-求100以内的素数.py | 340 | 3.859375 | 4 | def prime_num(m, n):
while m <= n:
i = 2
while i < m:
if m % i == 0:
break
i += 1
if i == m and m > 2:
print(f'{m}是素数')
m += 1
m = int(input('请输入素数下限:'))
n = int(input('请输入素数上线:'))
prime_num(m, n)
|
16afb90926103eb4c258299d98f5163284fc81b5 | jiankangliu/baseOfPython | /PycharmProjects/函数/函数平均分配老师.py | 563 | 3.84375 | 4 | import random
teacher = list(input('请输入老师:'))
num = int(input('请输入办公室:'))
l = list()
while num > 0:
list1 = list()
l.append(list1)
num -= 1
def average_office(teacher, l):
m = 0
while True:
if len(teacher) == 0:
break
t = random.choice(teacher)
tea... |
b2f59e49830b5056576f60d4fe487f5940033fb7 | jiankangliu/baseOfPython | /PycharmProjects/2.25条件语句/猜拳.py | 1,078 | 3.734375 | 4 | import random
while 1 > 0:
player = input("请输入你猜拳(0代表石头,1代表剪子,2代表布,3退出程序):")
while 1 > 0:
if player != 0 and player != 1 and player != 2 and player != 3:
print("输入错误,请重新输入:", end="")
player = input()
continue
break
machine = random.randint(0, 2)
... |
2f806ff8dac10caf25a590ad2a09ff1b0ba5f5aa | jiankangliu/baseOfPython | /PycharmProjects/模块、包、异常/06-尝试循环读取文件数据.py | 721 | 3.71875 | 4 | """
1.尝试打开文件
1.1 尝试:循环读取数据并打印数据 -- 一次性读取一行 暂停2秒钟再打印
如果没有这个文件,捕获异常并提示没有这个文件
"""
import time
try:
f = open('1.txt')
try:
while True:
con = f.readline()
# 如果读取的数据的长度是0表示没有其他数据 -- 退出循环即可
if len(con) == 0:
break
time.slee... |
bc36f30e0bf2504e87b10476efb7209f166bdca5 | jiankangliu/baseOfPython | /PycharmProjects/正则表达式/正则判断电话号码.py | 293 | 3.59375 | 4 | import re
phone = input("请输入电话号码:")
rephone = input("请再次输入电话号码:")
res = re.match(r"(?P<area>\d{3,4})-(?P<phone>\d{6,8})(?P=area)-(?P=phone)", phone + rephone)
if res:
print('匹配成功', res.group('phone'))
else:
print('匹配失败')
|
02edafd78d460b01fe246a3cdaf534eefde8881c | jiankangliu/baseOfPython | /PycharmProjects/函数/函数1.py | 2,639 | 4.09375 | 4 | # def information():
# print('My name is Liu')
# print('My major is Python')
#
#
# def add(a, b):
# return a + b
#
#
# print(add(2, 3))
#
# def add_minus(a, b, c):
# print(f"{a}+{b}={a+b}")
# print(f"{a+b}-{c}={a+b-c}")
# return a + b - c
# result = add_minus(2,3,1)
# print(resul... |
dbaa7c83a99d5e1fd1f4edddb09f0df2b2711b2b | jiankangliu/baseOfPython | /PycharmProjects/2.25条件语句/条件语句.py | 371 | 3.8125 | 4 | age = int(input("请输入年龄:"))
while 1 > 0:
if age <= 0:
print("年龄有误,请重新输入:", end='')
age = int(input())
continue
if age < 18:
print(f"您的年龄是{age}岁,未成年,关闭系统!")
break
else:
print(f"您的年龄是{age}岁,可以上网。")
break
|
38b8c41b3d497297b35f2249c265c7d972b62d26 | jiankangliu/baseOfPython | /PycharmProjects/多进程/with关键字.py | 563 | 3.671875 | 4 | import threading
import time
g_num = 0
def add1():
global g_num
for i in range(100000):
with lock:
g_num += 1
print('add1:', g_num)
def add2():
global g_num
for i in range(100000):
with lock:
g_num += 1
print('add2:', g_num)
if _... |
e490efd956bacc8a7eaaa7bdb4f12f11868db8ba | kethan1/Scipy-Python | /twitter_friend_analysis.py | 1,859 | 3.921875 | 4 | from twitter import Twitter, OAuth
import matplotlib.pyplot as plt
import numpy as np
import sys
import json
"""
Hypothesis: If a Twitter user has more than 100 friends, than more than 50% of
that user's friends will have more than 100 friends.
Hypothesis, in simpler terms: Popular people tend to be friends with popu... |
56a016800e22c092fb3eb0a8d9df4284449fe7d0 | meaghankoch/shopping_cart | /practice.py | 445 | 3.59375 | 4 |
#i = 1
#while i < 21:
# print(i)
#for p in products:
# my_price = p["price"]
# print(f" + {p['name']} (${my_price})")
#products ["id"] = 1
#while products["id"] == 1 : # This constructs an infinite loop
# num = raw_input("Enter a product identifier :")
# print("You entered: ", num)
#
matchin... |
0d05079961394fefe3b18038a8c2c601573ab1b1 | chaofan-zheng/tedu-python-demo | /month01/all_code/day18/review02.py | 2,005 | 3.578125 | 4 | """
复习
函数式编程思想
适用性:多个函数主体结构相同,核心算法不同.
分:将主体结构与核心算法封装到单独函数中
隔:在主体结构中使用参数抽象核心算法
做:通过lambda表达式完成核心算法
"""
from common.iterable_tools import IterableHelper
class Employee:
def __init__(self, eid, did, name, money):
self.eid = eid # 员工编号
self.... |
6bf33ef7c5a63d103b36ee8cd0ef37b0c4e3de5d | chaofan-zheng/tedu-python-demo | /month01/all_code/day04/demo04.py | 687 | 3.6875 | 4 | """
小结 - 语句(流程控制)
选择语句:让代码有选择性的执行
if 条件:
代码
else:
代码
案例:判断每个月的天数
循环语句:让代码重复性的执行
while 条件:
代码
适用性:根据条件重复
案例:纸张对折多少次超过珠穆朗玛峰
for 变量 in range(开始,结束,间隔):
适用性:根... |
8fb61b6228c78233b5dcc0e0847d63e2bacd594a | chaofan-zheng/tedu-python-demo | /month01/all_code/day12/exercise03.py | 624 | 3.71875 | 4 | """
实现自定义类型列表,获取最大/删除功能
"""
class Color:
def __init__(self, r, g, b):
self.r = r
self.g = g
self.b = b
def __str__(self):
return "%d-%d-%d" % (self.r, self.g, self.b)
def __gt__(self, other):
return self.r + self.g + self.b > other.r + other.g + other.b
d... |
103e3c683bc95c21483593ef1404829a003d73fe | chaofan-zheng/tedu-python-demo | /month01/all_code/day05/exercise04.py | 962 | 4.03125 | 4 | """
列表基础操作-综合练习
八大行星:"水星" "金星" "地球" "火星" "木星" "土星" "天王星" "海王星"
-- 创建列表存储4个行星:"水星" "金星" "火星" "木星"
-- 插入"地球"、追加"土星" "天王星" "海王星"
-- 打印距离太阳最近、最远的行星(第一个和最后一个元素)
-- 打印太阳到地球之间的行星(前两个行星)
-- 删除"海王星",删除第四个行星
-- 倒序打印所有行星(一行一个)
"""
list_planet = ["水星", "金星", "火星", "木星"]
list_... |
68f0e0a5d1fdd810649cb34cda4a77064d67ad4f | chaofan-zheng/tedu-python-demo | /month01/all_code/day03/exercise12.py | 344 | 3.90625 | 4 | """
一张纸的厚度是0.01毫米
请计算,对折多少次超过珠穆朗玛峰(8844.43米)
思路:
数据: 厚度 次数
算法:厚度*=2 次数+=1
"""
# thickness = 0.00001
thickness = 1e-5
count = 0
while thickness < 8844.43:
thickness *= 2
count += 1
print("对折" + str(count) + "次")
|
2771cc8a7b9f0faaa779ac0a0fcf5dbfb64e57be | chaofan-zheng/tedu-python-demo | /month01/all_code/day07/homework/exercise06.py | 403 | 3.53125 | 4 | """
将列表中所有元素转换为一个字符串
列表:["我", "爱", "你", "p", "y", "t", "h", "o", "n", 666]
结果:我爱你python666
"""
list_message = ["我", "爱", "你", "p", "y", "t", "h", "o", "n", 666]
# "".join(list_message) # 666 是整数,不能拼接为str
str_message = "".join([str(item) for item in list_message])
print("转化后的字符串为:" + str_message)
|
1e0c426ab29825644b3584afb2fda66f8c438355 | chaofan-zheng/tedu-python-demo | /month01/all_code/project_month01/employee_info_manager_system.py | 3,223 | 3.765625 | 4 | class EmployeeModel:
def __init__(self, eid=0, did=0, name="", money=0):
self.eid = eid
self.did = did
self.name = name
self.money = money
def __str__(self):
return "%s的员工编号是%d,部门编号是%d,工资是%d" % (self.name, self.eid, self.did, self.money)
# 指定比较相同的依据
def __eq__(s... |
6f440bb2be146e1735b56bf48f5ce92262c33573 | chaofan-zheng/tedu-python-demo | /month01/all_code/day05/exercise06.py | 369 | 4.03125 | 4 | """
练习3:画出下列内存图
"""
import copy
list01 = ["北京", ["上海", "深圳"]]
list02 = list01
list03 = list01[:]
list04 = copy.deepcopy(list01)
list04[0] = "北京04"
list04[1][1] = "深圳04"
print(list01) # ?
list03[0] = "北京03"
list03[1][1] = "深圳03"
print(list01) # ?
list02[0] = "北京02"
list02[1][1] = "深圳02"
print(list02) # ?
|
18586dd7d612c453f987926d9fee66c7155e2487 | chaofan-zheng/tedu-python-demo | /month01/all_code/day13/demo06.py | 478 | 3.96875 | 4 | """
"""
class A:
def func01(self):
print("A - func01")
class B(A):
def func01(self):
print("B - func01")
super().func01()
class C(A):
def func01(self):
print("C - func01")
super().func01()
class D(B,C):
def func01(self):
print("D - func01")
... |
3ba28ea233a3f3736bbcd8d520b3369f33ee379b | chaofan-zheng/tedu-python-demo | /month01/all_code/day09/demo07.py | 819 | 4.46875 | 4 | """
面向对象:软件编程思想
找谁 干嘛?
现实事物 -抽象-> 类(模板) -具体-> 对象
车 class Car: Car(xx,xx,xx)
车牌 京E0001
品牌 奔驰
颜色 白色
"""
# 创建类(抽象化)
class Wife:
"""
自定义类 - 老婆
"""
# 数据
def __in... |
19dfb08cedc090607e631bfa6b521efa29233fc6 | chaofan-zheng/tedu-python-demo | /month01/all_code/day04/demo03.py | 478 | 3.671875 | 4 | """
跳转语句
"""
# 需求:累加1 -- 100整数
# 条件:能被3整除
# 思想:满足条件则累加
# sum_value = 0
# for number in range(1, 101):
# if number % 3 == 0:
# sum_value += number
# print(sum_value)
# 思想:不满足条件则跳过,否则累加
sum_value = 0
for number in range(1, 101):
if number % 3 != 0:
continue # 跳过本次循环,继续下次循环
# break #... |
a04882c6e51ff77d30d39c8f234e46d6f0ae9d75 | chaofan-zheng/tedu-python-demo | /month01/all_code/day04/demo13.py | 873 | 4.21875 | 4 | """
切片:定位多个元素
for number in range(开始,结束,间隔)
"""
message = "我是花果山水帘洞美猴王孙悟空"
# 写法1:容器名[开始: 结束: 间隔]
# 注意:不包含结束
print(message[2: 5: 1])
# 写法2:容器名[开始: 结束]
# 注意:间隔默认为1
print(message[2: 5])
# 写法3:容器名[:结束]
# 注意:开始默认为头
print(message[:5])
# 写法4:容器名[:]
# 注意:结束默认为尾
print(message[:])
message = "我是花果山水帘洞美猴王孙悟空"
# 水帘洞... |
727b4ee599937e2177ffb98ca6ffe9ed13ae116d | chaofan-zheng/tedu-python-demo | /month01/all_code/day06/demo01.py | 1,504 | 4.34375 | 4 | """
笔试题:
请叙述元组与列表的区别.
答:内存存储机制不同.
元组采用按需分配的存储机制,节省内存.
列表 预留空间 + 自动扩容,操作灵活
面试题:
为什么要有元组(为什么要有不可变).
答:任何数据本质都可以理解为不可变,元组就是不可变数据.(计算机世界)
但是在实际应用中,需要不断存储新数据,所以Python提供了列表.
Python语言有哪些数据类型
答:只可变与不可变2种类型
常用的可变数据:列表...
... |
d9a582c9be063e02d79a05f69d9a7788ee25b4c3 | chaofan-zheng/tedu-python-demo | /month01/all_code/day02/exercise05.py | 532 | 4 | 4 | """
练习:在终端中输入商品单价、购买的数量和支付金额。计算应该找回多少钱。
效果:
请输入商品单价:5
请输入购买数量:3
请输入支付金额:20
应找回:5.0
"""
# 1. 获取数据:单价,数量,金额
price = float(input("请输入商品单价:"))
count = int(input("请输入商品数量:"))
money = float(input("请输入商品金额:"))
# 2. 逻辑处理
result = money - price * count
# 3. 显示结果
print("应找回:" + str(result))
|
3aaedcac761e901224e61ca3bd995f29222a254d | chaofan-zheng/tedu-python-demo | /month01/all_code/day02/demo03.py | 443 | 3.765625 | 4 | """
变量
程序运行在哪里? -- 内存
程序在处理什么? -- 数据
变量:在内存中操作数据
语法:
变量名 = 数据
练习:exercise03
"""
name01 = "孙悟空"
name02 = "猪八戒"
name03 = name01 + name02 # 创建新数据
name01 = "齐天大圣" # 创建新数据,修改变量存储的地址
print(name01) # 齐天大圣
print(name03) # 孙悟空猪八戒
|
fb38af123134f6bfed2663766f006027f19e4334 | chaofan-zheng/tedu-python-demo | /month01/all_code/day02/demo10.py | 396 | 3.953125 | 4 | """
bool 运算
int类型:10 20 30 ...
bool类型:True False
命题:带有判断性质的陈述句
比较运算符:> < >= <= == !=
练习:exercise10
"""
# 命题: 我的职业是总统 True False
print(input("请输入您的职业:") == "总统")
# 命题:您是一个青年人18 40
print(18 <= int(input("请输入年龄")) <= 40)
|
82197b8cd58f72446bc57c493eeab61cd23fbc40 | chaofan-zheng/tedu-python-demo | /month01/all_code/day10/homework/exercise02.py | 1,148 | 4.09375 | 4 | """
面向对象
找谁?干嘛?
现实事物 -抽象-> 类 -具体-> 对象
2. 创建桌子类
数据:品牌,材质,尺寸(长,宽,高)
创建电脑类
数据:型号,CPU型号,内存大小,硬盘大小
行为:开机,关机
"""
# 现实事物 -抽象-> 类 -具体-> 对象
class Desk:
def __init__(self, brand="", material="", size=()):
self.brand = brand
self.material = ... |
49f2a08fa78e023a8453cb3ad9d912b50cba763b | chaofan-zheng/tedu-python-demo | /month02/day12/process02.py | 448 | 3.546875 | 4 | """
包含参数的进程函数
"""
from multiprocessing import Process
from time import sleep
# 带有参数的进程函数
def worker(sec, name):
for i in range(3):
sleep(sec)
print("I'm %s" % name)
print("I'm working")
# 按照位置传参
# p = Process(target=worker, args=(2, "Tom"))
# 按照关键字传参
p = Process(target=worker,
... |
4ea129f839988825cb63b8fbb294dd8edadcb662 | chaofan-zheng/tedu-python-demo | /month01/all_code/day07/exercise09.py | 267 | 4.21875 | 4 | # 练习2:创建函数,在终端中打印矩形.
def print_rectangle(number):
for row in range(number):
if row == 0 or row == number - 1:
print("*" * number)
else:
print("*%s*" % (" " * (number - 2)))
print_rectangle(8) |
d2bdd6b93d56863575896542acf8995db880c5f4 | chaofan-zheng/tedu-python-demo | /month01/all_code/day11/exercise06.py | 645 | 4.4375 | 4 | """
练习:
创建子类:狗(跑),鸟类(飞)
创建父类:动物(吃)
体会子类复用父类方法
体会 isinstance、issubclass与type的作用.
"""
# 从思想层面讲:先有子再有父,从子 -泛化-> 到父
# 从编码层面讲:先有父再有子,从父 -特化-> 到子
class Animal:
def eat(self):
print("吃")
class Dog(Animal):
def run(self):
print("跑")
class Bird(Animal):
de... |
52d27a07d787975725603b50590605b7463fe380 | chaofan-zheng/tedu-python-demo | /month01/all_code/day12/homework/exercise02.py | 645 | 4.125 | 4 | """
需求:小明使用手机打电话
划分原则:
数据不同使用对象区分 -- 小王/小孙...
行为不同使用类区分 -- 手机/卫星电话...
识别对象:
人类 手机
分配职责:
打电话 通话
建立交互:
人类 调用 手机
"""
class Person:
def __init__(self, name=""):
self.name = name
def call(self, communication):
pr... |
473fbf0d4efb2e7c974ef11878ad0733a3b23629 | chaofan-zheng/tedu-python-demo | /month02/day13/FTP/game2048.py | 3,188 | 3.953125 | 4 | """
2048 游戏核心算法
谈架构
显示(界面)与控制(算法)分离
控制台
PyQt
PyGame
谈算法
1. 高内聚:
上下移动 -矩阵转置-> 左右移动
向左移动 --> 合并数据 --> 零元素后移
向右移动 -翻转-> 合并数据 --> 零元素后移
2. 降维思想:
将二维列表的操作,改... |
3ca36abca2568ed6f33a053f8fb29888b11350c5 | chaofan-zheng/tedu-python-demo | /month01/all_code/day06/demo02.py | 566 | 3.96875 | 4 | """
元组应用
"""
month = int(input("请输入月份:"))
year = int(input("请输入年份:"))
# if 1 <= month <= 12:
# if month == 2:
# print("29天")
# # elif month == 4 or month == 6 or month == 9 or month == 11:
# elif month in (4, 6, 9, 11):
# print("30天")
# else:
# print("31天")
# else:
# prin... |
fa682eb7425810915d27422452eed4281724f76d | chaofan-zheng/tedu-python-demo | /month01/all_code/project_month01/student_info_manager_system/model.py | 525 | 3.84375 | 4 | class StudentModel:
"""
学生数据模型
"""
def __init__(self, name="", age=0, score=0, sid=0):
self.name = name
self.age = age
self.score = score
# 编号(对学生信息的唯一标记)
self.sid = sid
def __str__(self): # 对象 -> 字符串
return "我是%s,学号是%d,今年%d岁了,考试%d分" % (self.nam... |
0c32c4aa5fd0ae6ae898febe38665ff3d34d056b | chaofan-zheng/tedu-python-demo | /month01/all_code/day17/demo01.py | 824 | 3.765625 | 4 | """
内置生成器
enumerate : 获取元素的同时获取索引
价值:读取元素同时可以修改元素
"""
list01 = [65, 67, 78, 9, 76, 443, 4, 7]
# 需求:将列表中大于10的元素修改为10
"""
# 从头到尾读取数据
for item in list01:
if item > 10:
item = 10 # 修改变量item,与列表无关
for i in range(len(list01)):
if list01[i] > 10:
list01[i] = 10 # 通过索引定位元素再修改
pri... |
be3e780e2aa09537a6a6df9e65bc5c15eb4da166 | chaofan-zheng/tedu-python-demo | /month01/all_code/day11/homework/exercise03.py | 1,351 | 4.15625 | 4 | """
5. 创建电脑类,保护数据在有效范围内
数据:型号, CPU型号, 内存大小, 硬盘大小
不超过10个字符 大于0 元组长度大于等于1
"""
class Computer:
def __init__(self, model_number="", cpu="", memory=0, hard_disk=()):
self.model_number = model_number
self.cpu = cpu
self.memory = memory
self.hard_... |
056a7e12f13b2aa6be43d01f104a9abb8e2f90c1 | chaofan-zheng/tedu-python-demo | /month01/all_code/day12/homework/exercise03.py | 990 | 3.609375 | 4 | """
小明一次请多个保洁打扫卫生
效果:调用一次小明通知方法,可以有多个保洁在打扫卫生.
"""
class Client:
def __init__(self, name=""):
self.name = name
# 实参构建容器
# def notify_multiple(self, list_household_service):
# print(self.name, "通知")
# for service in list_household_service:
# service.cleaning()
... |
18fd91587fc11a03b306018628967a3b20abe2ef | chaofan-zheng/tedu-python-demo | /month01/all_code/day02/demo08.py | 348 | 3.9375 | 4 | """
算数运算符
+ - * 小数商/ 整数商// 余数% 幂运算**
练习:exercise06~08
"""
data01 = 5
data02 = 2
print(data01 // data02) # 2
print(data01 % data02) # 1
print(data01 / data02) # 2.5
# 1分钟有60秒
# 65秒是几分钟零几秒
print(65 // 60)
print(65 % 60)
print(data01 ** data02) # 5的2次方 5 * 5 |
30919fe622ba86171dd877fc3b6a6481b6825235 | chaofan-zheng/tedu-python-demo | /month05/spider/day01_course/day01_code/01_jdSpider.py | 526 | 3.78125 | 4 | """
向京东官网发请求,拿到响应内容
"""
import requests
# get(): 获取响应对象
resp = requests.get(url='https://www.jd.com/')
# text属性:获取响应内容-字符串(右键->查看网页源代码)
html = resp.text
# content属性:获取响应内容-bytes(抓取图片、文件、音频、视频...)
html = resp.content
# status_code属性:获取HTTP响应码
code = resp.status_code
# url属性:返回实际数据的URL地址
url = resp.url
pr... |
6e0e7124a077e1e2e49d84e50a811ea9d6a01de8 | chaofan-zheng/tedu-python-demo | /month01/all_code/day05/demo07.py | 573 | 3.703125 | 4 | """
列表转换为字符串:
result = "连接符".join(列表)
"""
list01 = ["a", "b", "c"]
result = "-".join(list01)
print(result) # a-b-c
# 需求:根据某些逻辑,生成一个字符串.
# str_result = ""
# for number in range(10):
# # 缺点:每次循环产生一个新字符串,替换之前变量,产生垃圾
# str_result = str_result + str(number)
# print(str_result)
# 解决:用可变数据,代替不可变数据.
list_result... |
abc9ad8fd61efc93f881e6faee6d01dd95f41e97 | chaofan-zheng/tedu-python-demo | /month01/all_code/day07/exercise07.py | 268 | 3.734375 | 4 | """
练习:降序(大 --> 小)
"""
list01 = [55, 65, 67, 76, 8, 6, 9, 64]
# 取数据
for r in range(len(list01) - 1):
# 作比较
for c in range(r + 1, len(list01)):
if list01[r] < list01[c]:
list01[r], list01[c] = list01[c], list01[r] |
bd0b563f17102731a44855f429bf70f8cb534e85 | chaofan-zheng/tedu-python-demo | /month01/all_code/day04/homework/exercise04.py | 650 | 3.515625 | 4 | # 在终端中累加 0 1 2 3
# 在终端中累加 2 3 4 5 6
# 在终端中累加 1 3 5 7
# 在终端中累加 8 7 6 5 4
# 在终端中累加 -1 -2 -3 -4 -5
result = 0
count = 0 # 开始0
while count < 4: # 3
result += count
count += 1# 0 1 2 3
print(result)
sum_value = 0
count = 2
while count < 7:
sum_value += count
count += 1
print(sum_value)
n... |
6e61f73c052a9312d1d4249d20f83d9613c530a4 | chaofan-zheng/tedu-python-demo | /month05/spider/day06_course/day06_code/03_music163.py | 744 | 3.515625 | 4 | """
selenium切换iframe子页面
"""
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url='https://music.163.com/#/discover/toplist')
# 1.切换iframe
driver.switch_to.frame('contentFrame')
# 2.提取歌曲数据
tr_list = driver.find_elements_by_xpath('//table/tbody/tr')
for tr in tr_list:
item = {}
item['rank'] ... |
f45a80d4254df3918d2841a0a9fff0e17a7e52ac | chaofan-zheng/tedu-python-demo | /month01/all_code/day07/demo06.py | 356 | 3.875 | 4 | """
函数
参数:使用功能 给 制作功能 传递的信息
"""
# 做
# 形式参数:表面,不真实,不具体
def attack(count):
for i in range(count):
print("直拳")
print("摆拳")
print("勾拳")
print("肘击")
print("侧踹")
# 用
# 实际参数:数据,真是,具体
attack(1)
attack(2) |
07230376a669a3387cf1534dc597808a1f5ce1e2 | chaofan-zheng/tedu-python-demo | /month01/all_code/day17/demo08.py | 443 | 3.5625 | 4 | """
lambda应用
"""
from common.iterable_tools import IterableHelper
list01 = [63, 5, 56, 7, 8, 9]
def condtion01(number):
return number < 10
# lambda number:number < 10
# 查找能被5整除的数字
def condition02(item):
return item % 5 == 0
for item in IterableHelper.find_all(list01, lambda number: number < 10):
... |
9eb5abf27e3764d8ad5885e90b01a4fb1f7fcb05 | chaofan-zheng/tedu-python-demo | /month01/all_code/day12/demo02.py | 402 | 3.953125 | 4 | """
"""
class Person(object):
def __init__(self, name="", age=0):
self.name = name
self.age = age
# 对象 --> 字符串
def __str__(self):
return f"我是{self.name},今年{self.age}岁了"
p01 = Person("小明", 22)
# 直接打印自定义对象,默认格式是:
# <__main__.Person object at 0x7f0d35f52e48>
print(p01)
p02 = Pers... |
637079bd35061224804679d181f456eaa18b1fc5 | harshaldevv/Cache | /2019306_HARSHAL_DEV_k_way_associative.py | 1,939 | 3.609375 | 4 | cache_size = 16 #int(input("Enter cache size "))
no_of_cache_line = 4 #int(input("Enter the number of cache lines "))
block_size = 4 #int(input("Enter block size or main memory size "))
value_of_k = 2 #int(input("Enter the value of K "))
cache = []
main_memory = []
no_of_sets = no_of_cache_line//value_of... |
81e6f08a89d80ea55b32a54f8f877daa9bd7d338 | bug-thiago/Exercicio-2 | /Exercicio02/Questao17.py | 316 | 3.71875 | 4 | def desconto(pr, p):
return pr - (pr * (p / 100))
try:
pr, p = float(input("Digite o valor correspondente ao preço do produto e o valor correspondente ao percentual de desconto: ")), float(input())
print("O preço do produto é %f." % (desconto(pr, p)))
except:
print("Você não forneceu valores reais.") |
fa5bf1a3b85185792af2546c3e5722c7b0481160 | bug-thiago/Exercicio-2 | /Exercicio02/Questao13.py | 280 | 3.875 | 4 | def treze(a):
if a >= 2013:
return 0
else:
return 2013 - a
try:
a = int(input("Digite o ano de nascimento: "))
i = treze(a)
if i == 0:
print(" não nasceu.")
else:
print("Essa pessoa tem %d anos." % (i))
except:
print("não forneceu um valor inteiro.") |
fc7d84c98ac51e1574515f5899e9cf2fc13f05ac | FreDouNet38/mon_projet_3 | /maze.py | 2,186 | 3.5 | 4 | #!/usr/bin/python3
# -*- coding: Utf-8 -*
#pylint: disable=wildcard-import, no-member, unused-wildcard-import, undefined-variable
""" The labyrinth game """
import pygame
from pygame.locals import *
from constants import SIDE, WINDOW_TITLE, IMAGE_MAC, IMAGE_NEEDLE, IMAGE_ETHER, IMAGE_TUBE
from classes import *
pyga... |
c3ca05745c7e4e5855c1fdbac2a6b83ea06ada84 | Monrother/leetcode_py | /37_Sudoku_Solver.py | 1,789 | 3.765625 | 4 | class Solution:
def solveSudoku(self, board: List[List[str]]) -> None:
"""
Do not return anything, modify board in-place instead.
"""
rows = [[False for i in range(9)] for j in range(9)]
cols = [[False for i in range(9)] for j in range(9)]
cells = [[False for i in ran... |
13f71b291b8b024b84cfaa19e110b11e9a0ba44b | aishraghavan/python_tricks | /python_list_comprehension.py | 379 | 3.984375 | 4 | def pythagorean_triples():
for x in range(1, 30):
for y in range(x, 30):
for z in range(y, 30):
if x**2 + y**2 == z**2:
print(x, y, z)
if __name__ == "__main__":
pythagorean_triples()
print "list_comprehension:"
print [(x,y,z) for x in range(1,30) for y i... |
50a42ee55b27a61e661ebf170997d1e98406a53b | betrouvaille/pythonCrawlerDevelopment | /lfl_readbook/chapter5/xpath_bs4_damai.py | 1,029 | 3.546875 | 4 | import requests
from bs4 import BeautifulSoup
import lxml.html
"""
2019年12月4日 周三
气死我了,原网址失效了,我又在大麦网上找了个网址,但是没想到啊。
没想到啊 舟哥说 python request只能获取静态页面,获取不了动态页面。
他让我去找崔哥,崔哥说建议我用我用chrome啥啥啥。。。
行8!!!!我今天就只处理静态的,动态的等我再学学再弄!!!!!!
"""
target = 'https://search.damai.cn/search.htm'
damai_html = requests.get(target).conten... |
e560585ea698d74b65a5bb49f68a94d2b7f04c15 | elsaversailles/Arithmetic-Function-1 | /Arithmetic Sequence Calculator.py | 569 | 3.890625 | 4 | #Written by Elsa Versailles
#CC BY 3.0
import math
print ("Arithmetic Sequence Calculator")
print ("")
n1 = int(input('First term: '))
print ("")
n2 = int(input('Number of Terms: '))
print ("")
n3 = int(input('Common difference: '))
print ("")
n4 = int(input('Sequence 1:'))
print ("")
n5 = int(input('Sequence 2 :'))
p... |
5a391b6015b94af3800dba89cf6ed07e94d1f445 | daniyaniazi/Python | /COLLECTION MODULE.py | 2,510 | 4.25 | 4 | """COLLECTION MODULE IN PYTHON """
#LIST TUPLE DICTIONARY SET ARE CONTAINER
#PYTHON HAS COLLECTION MODULE FOR THE SHORTCOMMING OF DS
#PRVIDES ALTERNATIVES CONTAINER OF BUILTIN DATA TYPES
#specializex collection datatype
"""nametupele(), chainmap, deque, counter, orderedDict, defaultdic , UserDict, UserList,UserString""... |
c66552f07520c68280a204a76d4bf25ff8f88470 | ZachLynch123/miscellaneous-scripts | /Encryption.py | 283 | 3.5 | 4 | #Simple encryption code
from Crypto.Cipher import AES
from Crypto import Random
key = b'Sixteen byte key'
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CFB, iv)
user_Keys = input('input string to encrypt: ')
msg = iv + cipher.encrypt(b, user_Keys)
print(msg)
|
6478dfc4d7c1277097dbce91cb71765bc59c9c9b | ZachLynch123/miscellaneous-scripts | /fileRenamer.py | 371 | 3.640625 | 4 | import os
def rename_files():
file_list = os.listdir(r"/Users/Zach/Downloads/prank")
#print (file_list)
#Get file names
saved_path = os.getcwd()
print("Current dir" + saved_path)
os.chdir(r"/Users/Zach/Downloads/prank")
for file_name in file_list:
os.rename(file_name,file_name.translate(None,"0123456789"))
o... |
11ca706bcfa0fa7e14a7a2f80c0c47107ef370c2 | singham3/python-programs | /rangoli.py | 569 | 3.96875 | 4 | #wap to print rangoli
import string
def print_rangoli(size):
alphabet=string.ascii_lowercase
for i in range(size-1,0,-1):
row=["-"]*(size*2-1)
for j in range(0,size-i):
row[size-1-j]=alphabet[j+i]
row[size-1+j]=alphabet[j+i]
print("-".join(row))
for i in range... |
f0a67e08f1ef87789899a93debbf58dc4ea0edd6 | singham3/python-programs | /class besic 4.py | 327 | 3.71875 | 4 | #basic class program
class student:
college="Matrix"
def __init__(self,r=-999,n="amit"):
self.roll=r
self.name=n
def Display (self):
print(self.roll,self.name,self.college)
s1=student(1,'ravi')
s2=student(2,'sanju')
s3=student()
#s1.Display()
student.Display(s1)
s2.Display()
s3.Disp... |
8565b1305eef363193f8034266f63091c3ca661e | singham3/python-programs | /count object created in static method.py | 473 | 3.734375 | 4 | #wap to count the number of object created class
class student:
t=0
def __init__(self):
student.t=student.t+1
def Display(self):
t=student()
student.staticmethod()
@staticmethod
def staticmethod():
print("Total number of obbject: ",student.t)
def __del__(self):
... |
e22d93d798074b9c948079ec90e1539aa829961d | singham3/python-programs | /class besic 6.py | 449 | 3.921875 | 4 | #basic class program
class student:
college="Matrix"
def __init__(self,i):
self.roll=int(input("Enter roll number of {} student: ".format(i+1)))
self.name=input("Enter name of {} student: ".format(i+1))
def Display (self):
print("roll={} \tname={} ".format(self.roll,self.name))
l=... |
a8909b0a1939526667719658f33c5b6328f15662 | singham3/python-programs | /static mathod and class method.py | 403 | 3.5625 | 4 | #wap to count the number of object created class
class method:
t=0
def __init__(self):
print("constructor")
self.a=10
def i_method(self):
print("instance method")
@staticmethod
def s_method():
print("staticmathod ")
@classmethod
def c_method(self):
pr... |
fabe1d69b4eef3f87a1378e5de931ff73ce38f9c | JonAWhite/BitcoinBudget | /geminipy.py | 8,044 | 3.78125 | 4 | """
This module contains a class to make requests to the Gemini API.
Author: Mike Marzigliano
"""
import time
import json
import hmac
import base64
import hashlib
import requests
class Geminipy(object):
"""
A class to make requests to the Gemini API.
Make public or authenticated requests according to th... |
6f6a30c997764bad22985c0a8053c88241f4f499 | themorsten/DataStructures | /DoublyLinkedList/DoublyLinkedList.py | 1,290 | 4.125 | 4 | class DoublyLinkedListNode:
def __init__(self,value):
self.value = value
self.next = None
self.prev = None
class DoublyLinkedList:
def __init__(self):
self.head = None
self.tail = None
def append(self, value): # добавить в конец
newNode = DoublyLinkedListNode(value)
if self.head: ... |
85d11bd8209a3391c232181e86a8924b72f4e025 | pazamelin/ORA_labs | /lab5/bees/algorithm.py | 6,271 | 3.671875 | 4 | from bees.problem import *
from bees.neihborhood_operators import *
from typing import List, Dict
from random import randrange
from random import shuffle
import random
from itertools import repeat
import numpy as np
import copy
def generate_random_solution(problem):
# A solution is constructed by assigning one no... |
aca916cd7150ccdc1dc3ddad48f5b41d53007f7f | StealthAdder/SuperBasics_Py | /functions.py | 2,101 | 4.46875 | 4 | # function is collection of code
# they together work to do a task
# they are called using a function call.
# to create a function we use a keyword called "def"
# --------------------------------------------------
# create a function.
def greetings():
print("Hello Dude!")
greetings() #calling the functi... |
a5cf1e466f653232015e5717c8723a43b4d82278 | steptobe/practice | /Tools/hello.py | 153 | 3.578125 | 4 | print('hello')
print('The quick brown fox', 'jumps over', 'the lazy dog')
print(100 + 200)
name = input('please enter your name: ')
print('hello,', name) |
1bd0d15676205111b4beefdead0fb38fffddf03c | Hasun-Shin/Python | /python_flask/py_quest_연습문제.py | 1,135 | 3.78125 | 4 | '''
# 문제 1.
문자열을 입력받아 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램을 작성하시오.
ex) python py_quest.py 실행 후 나타나는 입력란에
ABCDEFG 입력시
A G 출력
'''
str = input('문자를 입력하세요: ')
# 아래에 코드를 작성해 주세요.
print(str[0],str[-1])
'''
문제 2.
자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
ex) python py_quest.py 실행 후 나타나는 입력란에
2 입력시
0
1... |
a7a9626cad157d8ea8a19cac5e2f9505f0316da4 | Hasun-Shin/Python | /python_flask/python_basic.py | 313 | 3.640625 | 4 | number =123
number_two = -456
number_three = 7.89
#print(number)
#print(number_two)
#print(number_three)
#print(number,number_two,number_three)
a = 'abc'
b = '123'
#print(a, b)
c = 123
#print(a, b, c, 123)
#print(type(b),type(c),type(123))
print("안녕 world")
d = True
e = False
print(d, e, type(d), type(e)) |
4d5ea4c8ff8c14754353c151305ec959131c2702 | hexgnu/rl-course-oreilly | /notebooks/QLearner.py | 5,948 | 3.640625 | 4 | """Implement QLearner, a Reinforcement Learning class"""
import numpy as np
import random as rand
from copy import deepcopy
from collections import deque
class QLearner(object):
def __init__(self, num_states=100, num_actions=4, alpha=0.2,
gamma=0.9, rar=0.5, radr=0.99, dyna=0, verbose=False):
"""... |
0edf58afb1ec2dd6a36c6e6fc7086ec8201521ad | hu-tao39/Huxiansheng | /factorial_1.py | 316 | 3.921875 | 4 | def factorial(n):
result=n
for i in range(1,n):
result*=i
return result
number=int(input('请输入一个人正整数:'))
result=factorial(number)
print("%d的阶乘是:%d"%(number,result))
int(input('请输入一个人正整数:'))
result=factorial(number)
print("%d的阶乘是:%",result)
|
1816d13f104b453a2392e625c44b60cee2747a1c | renakeji/python | /20161101142if.py | 339 | 3.6875 | 4 | # -*- coding: utf-8 -*-
# @Author: renakeji
# @Date: 2016-11-10 11:42:04
# @Last Modified by: renakeji
# @Last Modified time: 2016-11-10 11:44:09
x = int(input("Please enter an integer:"))
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('zero')
elif x == 1:
print('single')
else:... |
af8180422ab1daa50265b3a6072d49d667818567 | whtstang/cti110 | /M3HW1_AgeClassifier_James.py | 386 | 4.09375 | 4 | # CTI-110
# M3HW1 - Age Classifier
# Jeremiah James
# 19 SEP 2017
#
def main():
age = int(input("How old is this person? "))
if age <= 1:
print("This person is an infant.")
elif age < 13:
print("This person is a child")
elif age < 20:
print("This person is a teenage... |
9773b1d9b2d6b88530811c179fc8bbc922615e37 | whtstang/cti110 | /M3Q2A-M_James.py | 281 | 3.6875 | 4 | # CTI 110
# Question M3Q2A-M
# Jeremiah James
# 24 SEP 2017
#
def main():
x = float(input("What is the temperature (F) of the sample? "))
if x <= 32:
print("Solid")
elif x <= 212:
print("Liquid")
else:
print("Gas")
main()
|
bccd4933d4fcd864d285480372c7591c748d990d | cugis2019dc/Emily-Short | /math.py | 444 | 3.8125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Jul 29 13:19:11 2019
@author: STEM
"""
def subtract(a,b):
subtract = a-b
print(subtract)
subtract(10,6)
"""
def multiply(b,h):
multiply = (b*h*1/2)
print(multiply)
multiply(10,4)
def area(b,h):
area = (b*h*1/... |
7a32a83205b0f0e678de60cc966bd15a6be684b6 | indoor-grow-lab-software/Lampen-Kontrollsofware | /LKSpython/Lampe.py | 892 | 3.75 | 4 | # Die Klasse Lampe erstellt.
class Lampe:
def __init__(self, LEDs = []):
self.LEDs = LEDs
# def update(self):
class LED(Lampe):
def __init__(self, name, farbe, helligkeit = 0):
"""
:param name: Der Name der LED z.b. 1 oder eins
:param farbe: Di... |
18810ebf60c3753621aa69b23fe4b67c93d21771 | Darshonik/saturday_python | /ideone_HOlPNe.py | 101 | 3.90625 | 4 | # your code goes here
#reversal of number of digits
n=raw_input()
num=n[::-1]
num=int(num)
print(num) |
c10c40d0a66884ee61f878d44186320b00db76dc | rhemon/flappybird | /core/obstacles.py | 4,590 | 4.15625 | 4 | """
This file provides all objects to prepare the obstacle
for the game.
The obstacle here are the plain rectangle blocks. In
between which the bird must pass through.
@author Ridhwanul Haque
@version 12.04.2020
"""
from random import random as rand
import numpy as np
from pygame import Rect
class Obstacle:
"... |
89edd52a8e28902a6331f7d939e3a369e3e14e69 | Aravind-2001/python-task | /4.py | 242 | 4.15625 | 4 | #Python program to divided two numbers using function
def divided_num(a,b):
sum=a/b;
return sum;
num1=int(input("input the number one: "))
num2=int(input("input the number one :"))
print("The sum is",divided_num(num1,num2))
|
b780c90b2bf5e993efbee165c551fd268ff66dc6 | Aravind-2001/python-task | /task9d.py | 141 | 3.59375 | 4 | num_list = [4,9,16,25,18,36,27,49,56]
result = list(filter(lambda x : (x % 9 == 0),num_list))
print("number divisible by 9 are :",result)
|
d0a6c8c1e0499392f47ca5fe08da564cb3d9355a | TanishaProgramer/Python | /list_prob2.py | 412 | 3.984375 | 4 | list1=[1,2,3,4,56,78,90,23,35,65,74,42,31,89,0,-43]
largest = list1[0]
for i in range(0,len(list1)):
if list1[i] > largest:
largest=list1[i]
print(largest)
## largest = 1
## 2
## 3
## 4
## 56
## 78
## 90
## 90
## 90
## 90
## 90
## 90
## 90
list1.remove(largest)
print(list1)
largest = list1[0]
for i ... |
55d9b814fa738f5505b36ac8b98d54034ca9fb09 | TanishaProgramer/Python | /dict1.py | 286 | 4.0625 | 4 | dictionary = {"name":"chirag","age":20,"class":"7th sem","salary":"0","job":"no"}
print("1 name \n 2 age \n 3 class \n 4 salary \n 5 job")
print("select one of them")
choice = int(input())
if choice ==1:
print(dictionary["name"])
elif choice==2:
print(dictionary["age"])
|
163a89e117bdd7f010ca50b081559756fb97f91a | TanishaProgramer/Python | /string3.py | 716 | 3.75 | 4 |
mystr = input("Enter any string")
newmystr = mystr.split(' ')
name_char = ['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']
count=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for j in newmystr:
for i in j:
index = name_char.index(i)
... |
a9f8c870e2c6218c8dd0abdf2ebacd48a4624d6e | Victor-Paiva/fem-cs | /src/Recursion/fact_test.py | 249 | 3.625 | 4 | def closure():
cache = [1]
def compute(n):
if n <= len(cache):
return cache[n-1 if n-1 > 0 else 0]
res = n * compute(n-1)
cache.append(res)
return res
return compute
c = closure()
print(c(5)) |
a84a8203b8701f85b0d976977fc6bd0fcd0ccea4 | Victor-Paiva/fem-cs | /src/Data-Structures/linkedList.py | 1,898 | 3.8125 | 4 | class Node:
def __init__(self, value):
self.value = value
self.next = None
def __str__(self):
return str(self.value)
class LinkedList:
def __init__(self):
self.head = self.tail = None
self.length = 0
def __str__(self):
rep = ''
cu... |
e5e6ac2d5d5b7219355e02e5b50d02aaa7d98d07 | ddatsko/isomorphic_graphs | /Discrede_math_Denys_Datsko.py | 7,915 | 3.90625 | 4 | import os
import random
def next_permutation(perm):
"""
(lst) -> lst
Precondition: all the elements must be different
Generates the next permutation by the given one
Return None if the permutation is the last
>>> next_permutation([1, 2, 5, 4, 3])
[1, 3, 2, 4, 5]
>>> next_permutation... |
72d3cb214ff95f422b2f4d80ad156f8fd90a9e18 | AmirZregat/PythonAssignment2 | /logic-1/squirrel_play .py | 443 | 3.546875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
def squirrel_play(temp, is_summer):
if temp>=60 and temp<=90 and not is_summer:
return True
elif temp>=60 and temp<=100 and is_summer:
return True
else:
return False
def main():
print(squirrel_play(70, False))
prin... |
8670ddcb2a5b65e18b966e314c0e5edbb7c27dc7 | AmirZregat/PythonAssignment2 | /Warmup-2/string_match .py | 440 | 3.84375 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
def string_match(a, b):
if len(a)<len(b):
l=len(a)
else:
l=len(b)
c=0
for i in range (l-1):
if a[i:i+2]==b[i:i+2]:
c=c+1
return c
def main():
print(string_match('xxcaazz', 'xxbaaz'))
print(string... |
debff26d43474a7abc73c7ed08ef2411e9facbce | AmirZregat/PythonAssignment2 | /list-2/count_evens .py | 377 | 3.796875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[6]:
def count_evens(nums):
c=0
for i in range(len(nums)):
if nums[i]%2==0:
c=c+1
return c
def main():
print(count_evens([2, 1, 2, 3, 4]) )
print(count_evens([2, 2, 0]))
print(count_evens([1, 3, 5]))
if __na... |
956ffb08e2d8b9fdeba4146a0a6b8d7ffb63f04e | AmirZregat/PythonAssignment2 | /Warmup-1/diff21 .py | 272 | 3.546875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[3]:
def diff21(n):
if n<21:
return 21-n
else:
return (n-21)*2
def main():
print(diff21(19))
print(diff21(10))
print(diff21(21))
if __name__ =='__main__':
main()
# In[ ]:
|
9d6507ae1d6534db449c230b3bb98bad2d0d31c6 | arjunshah1993/Algorithms | /array_sorted_recur.py | 255 | 3.984375 | 4 | arr = [1, 2, 3, 4]
def arr_sorted_recur(array):
if len(array) == 0 or len(array) == 1:
return True
return array[0] <= array[1] and arr_sorted_recur(array[1:])
if arr_sorted_recur(arr):
print("Sorted")
else:
print("Not sorted") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.