blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
56877d21b959e799b8511980517d4b48ef965a1a
santoshikalaskar/Basic_Advance_python_program
/Python-logical/logical/stopwatch.py
1,063
4.21875
4
import datetime class StopWatch: #Method to start STOPWATCH def start_stopWatch(self) : a = str(input("Enter \'S\' to start : ")) start_timer = a.upper() if start_timer == "S": print('Stop watch started !!!') return datetime.datetime.now() else : ...
c7eb6330c67c54309b2bdb66379dddd656059c6b
JupyterJones/Covid-19_Research_Notebooks
/Custom/DIST.py
526
3.703125
4
#!/usr/bin/env python # figure distance between two locations given in Lat and long import math def distance(Start, End): lat0, lon0 = Start lat1, lon1 = End radius = 6371 # km #radius = 3958.756 # miles lat = math.radians(lat1-lat0) lon = math.radians(lon1-lon0) a = math.sin(lat/2) * mat...
a7442c6ae7282222a7f3f4aee1687df7f6e7c548
JupyterJones/Covid-19_Research_Notebooks
/Custom/FileSearch.py
1,123
4.03125
4
#!/usr/bin/env -m python #Searches a file enter search term and filename #Range is to give context before and after the search term. #It defaults to eight lines before the word and eight lines after. #USAGE: #from FileSearch import filesearch #search ="urcrnrlat" #filename = "basemap.help" #filesearch(s...
a38b6fc927a5689a6452aa11fab020f7a54a6cd9
buszuj/Authomate-boring-stuff-with-Python
/Virtual Die.py
219
3.6875
4
def die() import random print("Choose your die size") x = input() print(random.randint(1, int(x))) print("again? y, n?") again = input() if again == "y": die() else: print("Good bye! ;D") die()
210769f2d012e71188ef79ebb64796456301a21a
UST-MICO/OpenFaasFunctions
/MessageTransformation/ContentFilter/RemoveElements/remove_elements/handler.py
598
3.8125
4
""" Element Remover ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ This function can be used to filter out certain elements from an incoming message. The elements, that shall be removed are referenced by the user in 'keys'. """ import json # The keys of the elements, that shall be removed keys = ['testKey1', 'testKey2'] def handle(req): """ ...
c2636c5160eb1f0055cb2472c9f93dcc21f07d50
gauriindalkar/list
/second max num.py
214
3.8125
4
######saral que 4 # number=[50,40,23,70,56,12,5,10,7] # i=0 # sum=number[i] # length=len(number) # while i<length: # a=number[i] # if a<sum: # sum=a # i=i+1 # print(a,"is second greater number")
13a4acd50324788712a89c24f4bb189bf3a1ffe7
gauriindalkar/list
/find length.py
162
3.6875
4
###find index # names_list=["annu","shivam","deepa","pooja","rupa"] # i=0 # while i<len(names_list): # m=names_list[i] # print(names_list[1]) # i=i+1
65c1dfe4b78c005ad8bec76211cc04c9e419d7d1
gauriindalkar/list
/reverse list.py
171
3.671875
4
######saral que 5 # places=["delhi","gujrat","rajanstan","punjab","kerala"] # place1=[] # i=1 # length=len(places) # while i<=length: # print(places[-i]) # i=i+1
5ea46b880a7a64ef477272fcd2daccd05d01be70
HustWolfzzb/Python_Set
/GUIofCalculator.py
3,212
3.765625
4
import math from tkinter import * class GUI: def __init__(self): #the self function window=Tk() window.title("Calculator made by HustWolf") menubar=Menu(window) window.config(menu=menubar) operationMenu=Menu(menubar,tearoff=0) menubar.add_cascade(label="Operation",menu=operationMenu) operationMenu.add...
b4fc2e85e6c9474e4fd7155ebd63d4be27e7e1cd
960314scott/python200818
/guessonetime.py
253
3.53125
4
import random rum=random.randint(1,10) a = input("請輸入數字?") if a=="1" or a=="2" or a=="3" or a=="4" or a=="5" or a=="6" or a=="7" or a=="8" or a=="9" or a=="10": if a == rum: print("正確") else: prin("錯誤")
efede6efa006016cd90af292fc4b677c2cf10fcf
J14032016/LeetCode-Python
/tests/algorithms/p0092_reverse_linked_list_ii_1_test.py
861
3.765625
4
import unittest from leetcode.algorithms.p0092_reverse_linked_list_ii_1 \ import ListNode, Solution from tests.algorithms.list_helper import convert_linked_list_to_list class TestReverseLinkedList(unittest.TestCase): def test_reverse_linked_list(self): solution = Solution() a = ListNode(1) ...
2b1e3122cbbba41dc9c4b71ffb774fc9e8f41c92
J14032016/LeetCode-Python
/leetcode/algorithms/p0212_word_search_ii.py
1,416
3.734375
4
from typing import List, Set from leetcode.algorithms.p0208_implement_trie import Trie class Solution: def findWords(self, board: List[List[str]], words: List[str]) -> List[str]: trie = Trie() result = set() rows, columns = len(board), len(board[0]) visited = [[False for _ in range...
1699438b49a03cc9fd5a496f65ae12cb08cf18ef
J14032016/LeetCode-Python
/leetcode/algorithms/p0430_flatten_a_multilevel_doubly_linked_list_1.py
800
3.796875
4
# Definition for a Node. class Node: def __init__(self, val, prev, next, child): self.val = val self.prev = prev self.next = next self.child = child class Solution: def flatten(self, head: 'Node') -> 'Node': if not head: return None if head.child: ...
c76394d07d2759ddcc8488ef19c0e01184f49866
J14032016/LeetCode-Python
/leetcode/algorithms/p1299_replace_elements_with_greatest_element_on_right_side_2.py
633
3.546875
4
import heapq from typing import List class Node(object): def __init__(self, value: int, index: int): self.value = value self.index = index def __lt__(self, other): return self.value < other.value class Solution: def replaceElements(self, arr: List[int]) -> List[int]: len...
d7b0c128d3908427eb74cd7864966969423ed8b8
J14032016/LeetCode-Python
/leetcode/algorithms/p0098_validate_binary_search_tree_1.py
683
3.671875
4
import sys class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def isValidBST(self, root: TreeNode) -> bool: if not root: return True return self._is_valid(root.left, -sys.maxsize, root.val) and \ ...
ad01f189d5a4b3697ebcb2c23c674643b90844b5
J14032016/LeetCode-Python
/leetcode/algorithms/p0094_binary_tree_inorder_traversal_1.py
534
3.671875
4
from typing import List class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def inorderTraversal(self, root: TreeNode) -> List[int]: values = [] self._traversal(root, values) return values def _traversa...
c5130487028a5585a366049ad3630f20b3554158
J14032016/LeetCode-Python
/leetcode/algorithms/p0146_lru_cache.py
1,569
3.546875
4
class Node: def __init__(self, key, value, prev=None, next=None): self.key = key self.value = value self.prev = prev self.next = next class LRUCache: def __init__(self, capacity: int): self.capacity = capacity self.caches = {} self.head = Node(-1, -1) ...
ce5e813d97618f2d0c815d4389aef0b878d9e42e
J14032016/LeetCode-Python
/tests/algorithms/p0188_best_time_to_buy_and_sell_stock_iv_test.py
506
3.5625
4
import unittest from leetcode.algorithms.p0188_best_time_to_buy_and_sell_stock_iv \ import Solution class TestBestTimeToBuyAndSellStock(unittest.TestCase): def test_best_time_to_buy_and_sell_stock(self): solution = Solution() self.assertEqual(0, solution.maxProfit(2, [])) self.assertE...
c51d01074a90de0641d537e79d021c01af762efc
J14032016/LeetCode-Python
/leetcode/algorithms/p0061_rotate_list_2.py
569
3.5625
4
class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def rotateRight(self, head: ListNode, k: int) -> ListNode: if not head: return None i = 1 current = head while current.next: i += 1 current...
13dbc53cdbb1addbf39aa27aac8ac4d98324580e
J14032016/LeetCode-Python
/leetcode/algorithms/p0414_third_maximum_number.py
452
3.53125
4
import sys from typing import List class Solution: def thirdMax(self, nums: List[int]) -> int: max1, max2, max3 = -sys.maxsize, -sys.maxsize, -sys.maxsize for n in nums: if n > max1: max3, max2, max1 = max2, max1, n elif max2 < n < max1: max...
036cea0f61b11c6d7170a081f5dbd01e3b3ef61e
J14032016/LeetCode-Python
/leetcode/algorithms/p0845_longest_mountain_in_array.py
697
3.671875
4
from typing import List class Solution: def longestMountain(self, arr: List[int]) -> int: max_length = 0 length = len(arr) i = 0 while i < length: start, top, end = i, i, i while top + 1 < length: if arr[top + 1] <= arr[top]: ...
06250b28190ea2a0fc6267410482598bb5a50c3f
J14032016/LeetCode-Python
/tests/algorithms/p0017_letter_combinations_of_a_phone_number_test.py
487
3.5625
4
import unittest from leetcode.algorithms\ .p0017_letter_combinations_of_a_phone_number import Solution class TestLetterCombinationsOfAPhoneNumber(unittest.TestCase): def test_letter_combinations_of_a_phone_number(self): solution = Solution() expected_lists = ['ad', 'ae', 'af', 'bd', 'be', 'bf'...
fdc09392606dbaa4da061b3a530db0f87a8dc68c
J14032016/LeetCode-Python
/leetcode/algorithms/p0338_counting_bits_1.py
314
3.6875
4
from typing import List class Solution: def countBits(self, num: int) -> List[int]: return [self._hammingWeight(x) for x in range(num + 1)] def _hammingWeight(self, n: int) -> int: count = 0 while n > 0: n = n & (n - 1) count += 1 return count
25571b1132285ac2098147a558981c2acb855467
J14032016/LeetCode-Python
/tests/algorithms/p0212_word_search_ii_test.py
609
3.859375
4
import unittest from leetcode.algorithms.p0212_word_search_ii import Solution class TestWordSearch(unittest.TestCase): def test_word_search(self): solution = Solution() board = [ ['o', 'a', 'a', 'n'], ['e', 't', 'a', 'e'], ['i', 'h', 'k', 'r'], ['i',...
5ebd0b40dd7278a01d1cb5411831372e9f21eb92
J14032016/LeetCode-Python
/tests/algorithms/p0121_best_time_to_buy_and_sell_stock_1_test.py
377
3.515625
4
import unittest from leetcode.algorithms.p0121_best_time_to_buy_and_sell_stock_1 \ import Solution class TestBestTimeToBuyAndSellStock(unittest.TestCase): def test_best_time_to_buy_and_sell_stock(self): solution = Solution() self.assertEqual(5, solution.maxProfit([7, 1, 5, 3, 6, 4])) ...
8b16986f7ad8d726468aab0b667cd91de545c99f
J14032016/LeetCode-Python
/tests/algorithms/p0103_binary_tree_zigzag_level_order_traversal_2_test.py
660
3.609375
4
import unittest from leetcode.algorithms.p0103_binary_tree_zigzag_level_order_traversal_2 \ import Solution, TreeNode class TestBinaryTreeZigzagLevelOrderTraversal(unittest.TestCase): def test_binary_tree_zigzag_level_order_traversal(self): solution = Solution() a = TreeNode(3) b = Tre...
74f2d35ed5fb2c477ef20db829287d76e1130c8b
J14032016/LeetCode-Python
/tests/algorithms/p0259_3sum_smaller_test.py
256
3.5625
4
import unittest from leetcode.algorithms.p0259_3sum_smaller import Solution class Test3SumSmaller(unittest.TestCase): def test_3sum_smaller(self): solution = Solution() self.assertEqual(2, solution.threeSumSmaller([-2, 0, 1, 3], 2))
a270a7acd63dcb4d906314bbc5e783c40331b857
J14032016/LeetCode-Python
/leetcode/algorithms/p0151_reverse_words_in_a_string.py
570
3.53125
4
class Solution: def reverseWords(self, s: str) -> str: words = [] i = 0 while i < len(s): while i < len(s) and s[i] == ' ': i += 1 word = '' while i < len(s) and s[i] != ' ': word += s[i] i += 1 ...
4bb944609eb211e88d09fc4577f8e464465846d1
J14032016/LeetCode-Python
/tests/algorithms/p0125_valid_palindrome_test.py
352
3.640625
4
import unittest from leetcode.algorithms.p0125_valid_palindrome import Solution class TestValidPalindrome(unittest.TestCase): def test_valid_palindrome(self): solution = Solution() self.assertTrue( solution.isPalindrome('A man, a plan, a canal: Panama')) self.assertFalse(solut...
7a9aea38db6ffa238c2f97801803b084ffe2a44f
J14032016/LeetCode-Python
/tests/algorithms/p0189_rotate_array_1_test.py
314
3.515625
4
import unittest from leetcode.algorithms.p0189_rotate_array_1 import Solution class TestRotateArray(unittest.TestCase): def test_rotate_array(self): solution = Solution() nums = [1, 2, 3, 4, 5, 6, 7] solution.rotate(nums, 3) self.assertListEqual([5, 6, 7, 1, 2, 3, 4], nums)
a800831d7afced248189f3ec7098ebc59afa111f
J14032016/LeetCode-Python
/leetcode/algorithms/p0073_set_matrix_zeroes_3.py
947
3.671875
4
from typing import List class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: if not matrix: return m, n = len(matrix), len(matrix[0]) is_first_row_zero = False is_first_column_zero = False for i in range(m): for j in range(n): ...
1e54636829408e5566b2e1cb58e4d7d5e824c9b7
J14032016/LeetCode-Python
/leetcode/algorithms/p0037_sudoku_solver.py
1,202
3.5625
4
from typing import List class Solution: def solveSudoku(self, board: List[List[str]]) -> None: self._solve(board) def _solve(self, board: List[List[str]]) -> bool: for row in range(9): for column in range(9): if board[row][column] != '.': contin...
1bc299b013ae72351ddb3dc20ec5da72bf245a29
J14032016/LeetCode-Python
/tests/algorithms/p0541_reverse_string_ii_test.py
264
3.59375
4
import unittest from leetcode.algorithms.p0541_reverse_string_ii import Solution class TestReverseString(unittest.TestCase): def test_reverse_string(self): solution = Solution() self.assertEqual('bacdfeg', solution.reverseStr('abcdefg', 2))
6f3081c6a00a1fa0aee4fc652ba5750d892d2455
DementedJim/programming
/3 семестр/Тема 1/ИСР/Задание 2.py
614
3.859375
4
''' Иванов Дмитрий, ИВТ3 1.2. Разработка скрипта, вычисляющего сумму первых n-членов арифметической прогрессии (использование функций, условных операторов). ''' def arithmprog(): i, a, k, n = 0, 0, 1, int(input('Введите количество членов арифметической прогрессии: ')) while i<n: a = a + k...
ea647a448a7b7d09a50e28c94c3222a587e5e52b
DementedJim/programming
/6 семестр/Подсчет слов.py
377
3.546875
4
def wordcounter(s): c = 1 words = s.split(' ') for i in words: if(i not in '1234567890[]{}.,!+-;'): yield print("Длина {0}-го слова {1}: {2}".format(c, i, len(i))) c+=1 a = input("Введите текст: \t\n") iterator = wordcounter(a) try: while True: item = next(iterator) ex...
0c990c9c23661d2a75ebf9308b4e8aa7b58d222e
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit13/class_demo10.py
535
3.96875
4
"""Demo 類別的範例。 這個模組示範文件字串的寫法。""" #類別的註解。 class Demo: """類別的文件字串。""" # __init__() 的註解。 def __init__(self, v1=11, v2=22): """ __init__() 的文件字串。""" self.__a = v1 self.__b = v2 # 方法的註解。 def do_something(self): """方法的文件字串。""" return self.__a + self.__b if __name__ == "__main__": d = Demo...
14e829f1641c67e57d07d4b028e85825e1265d73
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit22/hello_demo.py
404
3.984375
4
from tkinter import * root = Tk() root.title("Hello") text = Label(root, text="請輸入暱稱:", width="30", height="2") text.pack() name = Entry(root, width="30") name.pack() button = Button(root, text="執行") button.pack() result = Label(root, text="", width="30", height="2") result.pack() root.mainlo...
8361072f6a6b0bafb4e60257a60a2110946b941d
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit11/class_demo7.py
456
3.640625
4
class Demo: def __init__(self, v1=11, v2=22): self.__a = v1 self.__b = v2 def get_a(self): return self.__a def get_b(self): return self.__b def set_a(self, value): self.__a = value def set_b(self, value): self.__b = value def do_something(self): return self.__a + self.__b ...
e50ce0307416a1d97c3ff6ac94ed753aa5b949a6
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit08/big_demo.py
186
3.78125
4
def big(a, b): if a > b: return a else: return b print() print(big(33, 22)) print(big("John", "Mary")) print() # 檔名: big_demo.py # 作者: Kaiching Chang # 時間: July, 2014
edabf0a69c6636b6fba7b4c27dc69e1571eb1c9d
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit20/exercise2002.py
772
3.625
4
from random import shuffle class GuessGame: def __init__(self, digit=None): if digit == None or digit < 3 or digit > 6: self.length = 4 else: self.length = digit self.set_game(); def set_game(self): while True: self.answer = [chr(i) for i in range(48, 58)] ...
651c4ab6e132ba1cba7a0ccb4717526017136609
kevin510610/Book_AGuideToPython_Kaiching-Chang
/unit34/inherit.py
430
4.375
4
# 父類別 class SuperClass: def __init__(self): print("superclass") def supermethod(self): print("supermethod") # 子類別 class SubClass(SuperClass): def __init__(self): super().__init__() print("subclass") def submethod(self): print("submethod") if __name__ == "__main__": demo = SubClass() ...
37ca09a9b03974680bb56794f8f8a30938b71113
yarik-kv/exam
/exam.py
540
3.59375
4
class calc: def __init__(self, n): self.n = n def __add__(self, x): return self.n + x def __sub__(self, x): if x==str: raise TypeError if self.n > x: return self.n - x else: return x - self.n def __mul__(self, x): if...
9ad75cfde8130aaac096747919a212491e989a51
semin1012/03.Algorithm
/hw_12_2020182032/visualizer.py
2,175
3.5625
4
import turtle scale = 450 edge_line_color = 'green' edge_weight_color = 'blue' city_circle_color = 'gray' city_anno_color = 'brown' city_name_color = 'black' def setup(cities): turtle.speed(0) turtle.shape('circle') turtle.hideturtle() global min_x, min_y, max_x, max_y min_x, max_x = float('inf'), float('...
31e7d270617bb08a4ac41f0b8dcebbab6f7b15a4
imashnyov/DevOps_internal_course
/Python/4.py
482
3.859375
4
''' Список vlans это список VLANов, собранных со всех устройств сети, поэтому в списке есть повторяющиеся номера VLAN. Из списка нужно получить уникальный список VLAN-ов, отсортированный по возрастанию номеров. ''' vlans = [10, 20, 30, 1, 2, 100, 10, 30, 3, 4, 10] sorted_vlans = list(sorted(set(vlans))) print(sorted_...
053aa325e1aa9c95e1fda0bbb4ee65dc675e5fae
python20180319howmework/homework
/zhangliqiang/20180407/h4.py
1,922
4.28125
4
#4. 回答一下问题 # 1) python面向对象的特点是什么 # 2) 继承给我带来什么好处 # 3) super关键字有什么作用 # 4) 定义类的__init__方法可以有返回值吗,自己尝试一下 # 5) 当子类定义了与父类相同的方法的时候,会怎么样 # 6) 实例化对象的时候,类的什么方法会自动调用 # 7)一下几天语句体现了python的什么特性 # “i love python”.count('0') # (1,2,3,2,1,5,6,2,9).count(2) # [1,2,3,2,1,2,2,4,5,6,5,5].count(5) # 8...
74505a8e3b4a7af9a9af945133c2b6dd6371a78d
python20180319howmework/homework
/caixiya/20180330/2.py
286
3.921875
4
''' 2.用递归方式实现pow(x, y)的功能,你的函数名为mypow() ''' def mypow(x, y): if y == 1: return x elif y > 1: return(x * mypow(x,y-1)) if __name__ == '__main__': x,y = eval(input("请输入两个数字x,y")) print("{}的{}次幂为{}".format(x,y,mypow(x,y)))
57b57da243708f13d71b779aacbf3eaaab1e42f4
python20180319howmework/homework
/liuqi/20180327/h5.py
679
3.828125
4
""" 5.读入用户输入的一个字符串,判断字符串中有多少个大写字母 多少个数字,多少个 小写字母 提示: 判断一个字符串是否是数字:isdigit() 例如"1".isdigit()为True 得到单个字符串对应的值 ord("A") == 65 """ print("请输入:") text = input() num1 = 0 num3 = 0 num2 = 0 for word in text: if word.isdigit()==True: num3 += 1 elif ord("a") <= ord(word) <=ord("z"): num1 += 1 elif ord("A")<...
5f7f722bfddc472e2d653d0907f8526ee60a6620
python20180319howmework/homework
/caoxu/20180328/h3.py
398
3.875
4
#定义一个函数,计算给定的整型数是否为质数 def number(n): if n <= 1: print("error") elif n == 2 or n==3: return 1 else: for i in range(2,((n//2)+1)): if n%i != 0: return 1 else: return 0 if __name__ == '__main__': l = int(input("输入一个整型数:")) s = number(l) if s: print("{}是质数".format(l)) else: print("{}不是质数".f...
4ed56982cb6fda3906fde013a00a5bc5508d84a6
python20180319howmework/homework
/caoxu/20180328/h1.py
292
3.90625
4
'''定义一个函数,实现字符串的len方法 例如mylen("hello") 得到5 要求不要使用python内置的len()''' def mylen(l): cnt = 0 for i in l: cnt+=1 return cnt if __name__ == "__main__": h=input("输入一个字符串:") print("{}的长度为{}".format(h,mylen(h)))
2ef0298a723a5ab81038c0218e163bb3a4c5a7d7
python20180319howmework/homework
/zhangzhen/20180326(2)/text5.py
667
3.859375
4
''' .现在有一个列表,li = [1,2,3,'a','b','4','c'],有一个字典(此字典是 动态生成的,并不知道里面有多少键值对,所以用 dic = {} 模拟此字典 ); 现在需要完成这样的操作:如果字典没有‘k1’这个键,那么就创建这个‘k1’这个键和 对应的值(该键值设为空列表),并将列表li中的索引位为奇数对应的元素,添加到‘k1’ 这个键对应的值中 ''' #列表 li = [1,2,3,'a','b','4','c'] #字典 dic = {} #新的列表 l = [] if dic.get("k1",-1)== -1: dic["k1"]= "" for i in range(len(li)): ...
4421cc0650976e42b65e4b88cfbce30aabc386d2
python20180319howmework/homework
/caoxu/20180403/h2.py
775
4.3125
4
''' 定义一个北京欢乐谷门票类,应用你所定义的类,计算两个社会青年和一个学生平日比节假日门票能省多少钱 票价是: 除节假日票价100元/天 节假日为平日的1.2倍 学生半价 ''' class Tickets(object): def __init__(self,*,price = 100): self.__price = price def vacation(self): self.__price = self.__price * 1.2 return self.__price def student(self): self.__price = se...
b36e4008dc8347236ba30a288f80d61a3123bef4
python20180319howmework/homework
/zhangliqiang/20180329/h2.py
603
3.921875
4
#2. 定义一个函数: #1)判断输入的字符串是否是回文字符串 (例如:"上海自来水来自海上"为回文字符) def huiwen(strs): strslist = list(strs) print ("将入参的字符串转换成list:", strslist) strslist.reverse() print ("将list进行反转:", strslist) newstring = ''.join(strslist) print ("将反转后的list再转换成字符串:", newstring) if newstring == strs: print ("是回文!") ...
9166756176f103c5e2be03cab986b05ea848a796
python20180319howmework/homework
/huangyongpeng/20180327/h3.py
486
3.609375
4
#水仙花数 from math import * ''' num=int(input("输入三位整形数:")) baiwei=num//100 shiwei=(num//10)%10 gewei=num%10 count=0 if num==baiwei*baiwei*baiwei+shiwei*shiwei*shiwei+gewei*gewei*gewei: print("{}是水仙花数".format(num)) else: print("{}不是水仙花数".format(num)) print(count) ''' for i in range(100,1000): baiwei=i//100 shi...
9ae55616e3a6ec1b071f37debcfb79a9e4736712
python20180319howmework/homework
/yaojikai/20180327/h7.py
257
3.578125
4
#7,请删除字典中的键'k5',如果不存在键'k5',则输出"对不起!不存在你要删除的元素" dic = { } num = 0 for key in dic.keys(): num += 1 if num >= 5: dic.pop(k5) else : print("对不起!不存在你要删除的元素。")
da9ebbf4ef6ec61d4c53f4128f3e93a50e0ce054
python20180319howmework/homework
/zhangzhen/20180326(2)/text8.py
152
3.578125
4
#8.删除元祖中的所有重复的元素,并生成一个列表 s = [1,1,1,3,2,58,1,3,0,3,574] l = set(s) t2 = tuple(l) print(type(t2),t2)
664d75518f38d36e3f69baa6cd65823e5fab8a2d
python20180319howmework/homework
/fengxiaolu/20180326/1/4.py
145
3.5
4
x=int(input("输入一个数字")) if x in range(101:) print("你好棒啊!继续努力“) elsa: print("乖乖,你咋这么不听话呢")
b7863db2867351dff9c2f98f984a3eca1da5cc4e
python20180319howmework/homework
/zhangqi/20180403/3.py
1,039
4.0625
4
''' 3.模拟一个乌龟吃小鱼的游戏 假设游戏背景在x * y的范围内进行(0<=x<=10, 0<=y <=10) 游戏中有1只乌龟和5条小鱼 它们移动的方向是随机的 乌龟每移动一次可能是1或者2(随机的),小鱼每次就移动1 当移动的游戏背景边缘,自动向反方向移动 乌龟的初识体能值是100 乌龟每移动一次,体能值-1 小鱼不增加也不消耗体能 当乌龟和小鱼坐标重叠,就算乌龟吃掉已知小鱼,乌龟的体能值立即上升10 当乌龟体能为0时,则乌龟死掉,game over,群鱼嘲笑"小样!还想吃我" 如果小鱼全部被吃掉,游戏也结束!乌龟大笑"哈哈哈哈!敢惹我...
50bfc0e66d77804112417fd834f46b772c2d1479
python20180319howmework/homework
/lifei1/20180424/untitled2/python/python2018/test.py
106
3.515625
4
#求得100的前n项和 #将1到100累加起来--- a=1 sum=0 while a<=100: sum=sum+a a=a+1 print(sum)
1b0d1e6274110a9506209ec1f2df0c7dd15eb2ca
python20180319howmework/homework
/zhangzhen/20180327/text1.py
847
4.15625
4
'''1.让用户输入他的体重(kg)和身高(m),判断他的BMI,根据他的BMI指标合理的给出建议 BMI = 体重 / 身高*身高 BMI < 18.5 “你这么瘦,可以肆无忌惮的大吃大喝啦" y18.5 <= BMI < 25 “兄弟!你离模特就差八块腹肌了” 25 <= BMI < 30 “控制你自己哦!脂肪有点多啦” BMI >= 30 “不能再吃了!跑几圈去吧,你也可以是男神” ''' weight = int(input("请输入您的体重kg:")) height = float(input("请输入您的身高m:")) BMI= weight/(height*height) if BMI< 1...
f8834b84ccf7dc8d15846c7ed849092ee599f451
python20180319howmework/homework
/zhangzhen/20180326(2)/text4.py
1,104
3.734375
4
#总结整型、浮点、字符串、列表、元祖、字典、集合的常用方法,且比较各自擅长的领域 ''' 1,列表是可修改可变的,有序的,可迭代的,有索引,可以是任意数据类型,可以包含任意多数据 列表的常用方法 append:向列表中添加项 insert:在列表的指定位置加入值 索引 l[][] pop:删除 index:返回列表中第一个匹配项的下标 reverse:列表反转 2,元组是不可修改不可变的,有序的,可迭代的,有索引 tuple 没有添加,删除,修改等方法 3,字典是可修改可变的,无序的,无索引,可迭代的,键不可以是可变的(list,dict)而且不能重复(键都是唯一的),值可以是任意类型,可存储任意多的对象 字典的常用方法 pop:...
6d0653481a3e848ac96222f3c64a1368968809d2
python20180319howmework/homework
/zhangliqiang/20180328/w3.py
304
3.8125
4
#3.定义一个函数,计算给定的整型数是否为质数 def zhishu(num): for i in range(2,num//2+1): if num % i == 0: return 0 return 1 n = int(input("请输入一个整形数")) if zhishu(n)== 0 : print("{}不是一个质数".format(n)) else: print("{}是质数".format(n))
f2770b59396ce0c9a06b5cf18cdc38ed19c0a5d1
python20180319howmework/homework
/lifei1/20180402/3.py
107
3.546875
4
def h(word): word=word[0].upper()+word[1:].lower() return word print(list(map(h,["iIlH","LoUi","kOu"])))
ab7d21c2e39e59e54a2eca1854e47dbde53332c4
python20180319howmework/homework
/liuqi/20180327/h1.py
870
4.3125
4
""" 1.让用户输入他的体重(kg)和身高(m),判断他的BMI, 根据他的BMI指标合理的给出建议 BMI = 体重 / 身高*身高 BMI < 18.5 “你这么瘦,可以肆无忌惮的大吃大喝啦" 18.5 <= BMI < 25 “兄弟!你离模特就差八块腹肌了” 25 <= BMI < 30 “控制你自己哦!脂肪有点多啦” BMI >= 30 “不能再吃了!跑几圈去吧,你也可以是男神” """ weight = int(input("请输入体重(kg):")) height = float(input("请输入身高(m):")) BMI = weight/(height*height) if BMI < 1...
ff040d50375e801b19fca068e7607b06d421b9f7
python20180319howmework/homework
/huangchaoqian/20180327/t2.py
274
3.65625
4
#随机产生一个正整数,不要使用python内置方法,求得其二进制表达,并输出 import random #import string n=random.randint(1,1000) print(n) l=[] while n!=0: a=n%2 b=n//2 l.append(str(a)) n=b l.reverse() a="".join(l) #print(type(a)) print(int(a))
75f5955c7834cefea26b554dc34cb5d45402fb5e
python20180319howmework/homework
/lifei1/20180424/untitled2/python/python2018/meiju.py
769
3.59375
4
from enum import Enum week=Enum('WEEK',("Mon","Tues","Wed","Thur","Fri","Sat","Sun")) for name,member in week.__members__.items(): print(name,member,member.value) class Week(Enum): Sun=0 Mon=1 Tues=2 Wed=3 Thur=4 Fir=5 Sat=6 print(Week.Sun) print(Week.Sun.value) print(Week['Wed'].value) print(Week(6)) impor...
4945cdc9c9ee68ff5977c174415b19e71ed32660
python20180319howmework/homework
/zhangzhen/20180328/text1.py
391
3.984375
4
''' 1.定义一个函数,实现字符串的len方法 例如mylen("hello") 得到5 要求不要使用python内置的len() 提示字符串的终止条件是""空串 ''' # 定义一个函数 def num (mystr): count = 0 for i in mystr: #print(i) count += 1 return count mystr = input("请输入一个字符串:") print(num(mystr)) #判断空串不要用空字符串""去比较
0553309632abce6cc85aa506c83662ce7a13821e
python20180319howmework/homework
/huangchaoqian/20180402/t4.py
193
3.5
4
#利用reduce实现列表中元素求积 from functools import reduce #l=[1,2,3,4,5,6] def myreduce(l): r=reduce(lambda x,y:x * y,l) print(r) l=eval(input("please input list:")) myreduce(l)
5cba7fef05646ffa7a250172dd8cdc8501e56ce5
python20180319howmework/homework
/caixiya/20180328/3.py
449
3.921875
4
''' 定义一个函数,计算给定的整型数是否为质数 ''' def isprime(num): if num>=2: for i in range(2,num//2+1): if(num%i==0): return False else: return True else: #print("{}是质数".format(num)) return True else: #print("{}不是质数".format(num)) return False num=int(input("请输入一个整型数:")) if isprime(num): print("{}是质数".forma...
25adfcad908561cef833d914dfbca28c9fa2214b
python20180319howmework/homework
/huangyongpeng/20180328/h5.py
648
3.640625
4
''' 现在有一个列表,li = [1,2,3,'a','b','4','c'],有一个字典(此字典是 动态生成的,并不知道里面有多少键值对,所以用 dic = {} 模拟此字典 ); 现在需要完成这样的操作:如果字典没有‘k1’这个键,那么就创建这个‘k1’这个键和 对应的值(该键值设为空列表),并将列表li中的索引位为奇数对应的元素,添加到‘k1’ 这个键对应的值中 ''' li=[1,2,3,'a','b','4','c'] dic={} res=print(dic.get("k1",-1)) l=[] if res==-1: dic["k1"]=" " print(dic) for i in range(7): if ...
de830c0b30b1bf3b03ee4ba6bf3a664886c0be6f
python20180319howmework/homework
/zhangzhen/20180328/text4.py
426
3.796875
4
''' 4. 定义一个函数,完成以下功能: 1) 输入两个整型数,例如输入的是3, 5 2) 此函数要计算的是3 + 33 + 333 + 3333 + 33333(到5个为止) ''' a,b=eval(input("请输入两个整型数:")) def run(a,b): sum1 = 0 for i in range(b): sum1 = sum1+a*((b-i)*pow(10,i)) i += 1 return sum1 print(run(a,b)) #定义一个列表 #分别把 3,33,333,'''添加到列表 #最后求列表的和
f4d49a189fc4ffc8a07ce5102e94a98e4ac16b32
python20180319howmework/homework
/liuqi/20180328/h3.py
352
3.921875
4
""" 3.用户任意输入他的生日,判断他输入00后,90后,还是80后 """ year =int( input("请输入你的生日年份:")) if year > 1900 and year < 2000: print("你是90后") elif year <= 1900 and year >= 1800: print("你是80后") elif year >= 2000: print("你是00后") else: print("我也不知道你是几零后")
5f248a801f223d4b2d8c1440497284597f3ff255
python20180319howmework/homework
/huangchaoqian/20180323/t6.py
168
3.828125
4
n=int(input("please input a year:")) if n%400==0 or n%100!= 0 and n%4==0: print("this year have {} day".format(366)) else: print("this year have {} day".format(365))
44ea4fb1bf02dbcdbff5003bfbdaef4bf56fc9b6
python20180319howmework/homework
/caixiya/20180424/lfplanbattle/python/python2018/class5.py
387
3.703125
4
class A(object): def __init__(self): print("init A is called") class B(A): def __init__(self): print("init B is called") #A.__init__(self) super(B,self).__init__() class C(A): def __init__(self): print("init C is called") #A.__init__(self) super(C,self).__init__() class D(B,C): def __init__(self): ...
881ff0f490a1d34d6d9c89a22183102f04b9264a
python20180319howmework/homework
/zhangzhen/20180402/text1.py
176
3.59375
4
#1. 如果有两个字符串"hello" 和 “world”,生成一个列表,列表中元素["hw", "eo", "lr"] l = [x + y for x in "hello" for y in "world" ] print(l)
ba33b05049ecc0c43e2157fca7f215c532ddf971
python20180319howmework/homework
/wuhan/20180412/h1.py
1,407
3.78125
4
''' 创建三个函数,非别的功能是, 求得斐波那契数列的第n项, 求n的阶乘,求n的前n项和 请比较三个函数单线程分别调用,和三个函数多线程并发的效率(相差多长时间) 假定n的值是15 ''' from time import * import threading def fib_re(n): if n < 1: print("Wrong input! ") return -1 else: if(n == 1 or n == 2): return 1 else: return fib_re(n-1) +...
d0560c5f50e1aee22dd63fc6f7c37593614f46a1
python20180319howmework/homework
/zhangqi/20180329/t5.py
302
3.671875
4
#5. 使用递归函数,实现求得斐波那契数列的第n项 def fibo(n): if n <= 1: return n else: return(fibo(n - 1)+ fibo(n - 2)) a = int(input("请问要输出第几项")) if a <= 0: print("请输入正数") else: for i in range(a): print(fibo(i))
a13b932b0799d5835fa1dbad30f7fce74d7b070d
python20180319howmework/homework
/zhangliqiang/20180326/z2.py
3,461
3.796875
4
#1.编写一个计时器,将计时结果显示出来 import time t = time.time() for i in range(6): tl = time.localtime(i) ts = time.strftime("%S",tl) print(ts) time.sleep(1) #2.随机产生一个正整数,不要使用python内置方法,求得其二进制表达,并输出 import random l1 = (random.randint(0,100)) print("l1=%d"%(l1)) l = [] count = 0 while l1>0: for i in range(l1): l.ap...
bd36838fac07222c7dd5b23190368995bc9e28ec
python20180319howmework/homework
/huangchaoqian/20180328/t4.py
401
3.8125
4
''' 定义一个函数,完成以下功能: 1) 输入两个整型数,例如输入的是3, 5 2) 此函数要计算的是3 + 33 + 333 + 3333 + 33333(到5个为止) ''' def func(m,n): a=0 l=[] for i in range(n): a=a*10+m l.append(a) # print(l[i]) print(l) s=0 for i in l: s+=i print("以上数的总和是:",s) # print(type(s)) m,n=eval(input('please input two num:')) func(m,n)
2a887e7a34a8a1d971552ff02fd0f124ca3ff965
python20180319howmework/homework
/caoxu/20180401/h2.py
309
3.96875
4
''' 用递归方式实现pow(x, y)的功能,你的函数名为mypow() ''' def mypow(x,y): if y == 1: return x elif y > 1: return x * mypow(x,(y-1)) else: print("error") if __name__ == '__main__': x,y = eval(input("请输入两个数x,y:")) print("{}的{}次幂为:{}".format(x,y,mypow(x,y)))
a1a529f0feda16c65c39c365339a0742c292fa2c
python20180319howmework/homework
/liuqi/20180330/watch_1.py
834
4.1875
4
""" 电子表工程 00:00:00 七管 用到turtle/datetime """ import turtle as tt # 画线 def drawLine(isdraw): tt.pendown() if isdraw else tt.penup() tt.pensize(10) tt.forward(40) tt.right(90) # 画数字0 1 2 3 4 5 6 7 8 9 def drawDight(number): drawLine(True) if number in (2,3,4,5,6,8,9) else drawLine(False) drawLine(True) if number i...
26a6f095788abffa556ef6aa1df3a72afcb37582
python20180319howmework/homework
/zhangqi/2.py
1,001
4.375
4
''' 定义一个列表的操作类: Listinfo 包括方法 列表元素添加:add_key(keyname) [keyname:字符串或者整型] 列表元素取值:get_key(num) [num:整数类型] 列表合并: update_list(list) [list: 列表类型] 删除并且返回最后一个元素: dl_key() ''' class Listinfo(object): def __init__(self, key, num): self.__key = key def get_key(self): return self.__num def get_list(self, *list): s...
9ee7239519e28fb76888ca24996043c9e24fb846
python20180319howmework/homework
/zhangliqiang/20180329/h4_2.py
701
3.75
4
import turtle as tt def drawLine(isdraw): tt.pendown()if isdraw else tt.penup() tt.pensize(5) tt.color("blue") tt.forward(40) tt.right(90) def drawDigit(number): drawLine(True) if number in (2,3,4,5,6,8,9) else drawLine(False) drawLine(True) if number in (0,3,4,5,6,7,8,9) else drawLine(False) drawLine(Tru...
ca5e772b97413da7a00bfe5bc7bb8d806512d00e
python20180319howmework/homework
/wuhan/20180329/m5.py
344
3.71875
4
def mygrade(g): if 90<=g<=100: print("你的成绩等级是A") if 80<=g<=89: print("你的成绩等级是B") if 70<=g<=79: print("你的成绩等级是C") if 60<=g<=69: print("你的成绩等级是D") if 0<=g<=59: print("你的成绩等级是E") if __name__=='__main__': a=int(input('请输入成绩:')) mygrade(a)
a8d416614b5132db10556edece7105107680a158
python20180319howmework/homework
/wuhan/20180330/h4.py/m3.py
2,011
3.6875
4
import datetime import m2 as mye from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) down() def big_Circle(size): #函数用于绘制心的大圆 speed(2000) for i in range(150): forward(size) right(0.3) def small_Circle(size): #函数用于绘制心的小圆 speed(2000) for i in range(210): ...
ae08205c4d1291fe1d4e00dce290ef7a4ec26ea7
python20180319howmework/homework
/wangzhansen/20180402/h3.py
427
4
4
''' 3. 利用map()函数将用户输入的不规范的英文名字,变为首字母大写,其他字符小写的形式 1) 假定用户输入的是["lambDA", “LILY”, “aliCe”] ''' def suibian(s): s = str(s) for i in range(s): a = 0 b = 0 if 'A' <= s[0] <= 'Z'and 'a' <= s[i] <= 'z': return s else : a = s[0].upper b = s[:1].lower return a + b s = "lambDA" print(suibian(s)) ...
01f3717249401e4143b797aca4977d1e2b4539f7
python20180319howmework/homework
/caixiya/20180404/3.py
4,414
3.578125
4
''' 3. 根据字典的特性模拟一个通讯录,完成一下功能,用户根据输入的数选择功能 1) 1.查找电话号码 2) 2.增加联系人 3) 3.删除联系人 4) 4.修改联系人的电话号码 5) 5.退出通讯录,并将所有联系人写入文件,要求写入文件后的格式为 例如: 王占森 123455556 刘淇 222222333335 尝试使用面向对象编程 ''' import sys import os import pickle from enum import Enum,unique class Person...
3327677edb24ff4c25b6de1b7beaf752af8d7699
python20180319howmework/homework
/zhangliqiang/20180409/h4.py
1,313
3.734375
4
#4.现有两个进程,1号进程向文件写入10个"hello" 2号进程向文件写入10个"world",两个进程并发执行 #如何使得文件中的内容一定是"hellohellohellohellohello.....worldworldworld......." from multiprocessing import Process, Pool, Lock import time, os def newprocess(flname, mylock): mylock.acquire() time.sleep(1) f1 = open(flname, "r+") fistline = f1.readl...
577f70ab41ae3e8cad3c6a95e71f3eab11c37831
python20180319howmework/homework
/zhangzhen/20180326(2)/text3.py
296
3.625
4
''' 3.用户任意输入他的生日,判断他输入00后,90后,还是80后 ''' date = input("输入您的生日:") bir = int(date[0:4]) if 1979<bir<1990: print("您是80后") elif 1989<bir<2000: print("您是90后") elif bir >1999: print("您是00后") else : print("您OUT了")
aa5e1876c3289f937c506f0fb1b74e3ca7dfa649
python20180319howmework/homework
/huangchaoqian/20180327/t1.py
195
3.609375
4
#编写一个计时器,将计时结果显示出来 import time #tl=time.localtime() for i in range(100): tl=time.localtime() ts=time.strftime("%H:%M:%S",tl) print(ts,end="\r") time.sleep(1)
70a49e3c523bed3223ca2bc8a972a0bbccdac5a2
python20180319howmework/homework
/wangzhansen/20180403/h2.py
706
3.859375
4
''' 2.定义一个北京欢乐谷门票类,应用你所定义的类,计算两个社会青年和一个学生平日比节假日门票能省多少钱 票价是: 除节假日票价100元/天 节假日为平日的1.2倍 学生半价 ''' class Menpiao(object): def run(self): pass class Qingnian(Menpiao): def run(self): s = (100 * 1.2 - 100) * 2 print("两个青年平日比节假日门票能省{}元钱".format(s)) class Xuesheng(Menpiao): def run(self): ...
6fba1978b8c99942c604c0ef80759a240b9cf05e
asatrya/etl-lab
/transform-q1.py
2,869
3.65625
4
# Q1: How many new customers did we have by store location (city)? # Equivalent SQL Query: # SELECT # city.city, # COUNT(customer.customer_id) AS customer_count # FROM # customer # LEFT JOIN store ON # store.store_id = customer.store_id # LEFT JOIN address ON # address.address_id = store.address_id # LEFT JOIN ci...
bca47c276fe64d5c6c910c9e1eca20d75df7d289
ankurjain8448/leetcode
/binary-tree-maximum-path-sum.py
675
3.734375
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): # https://leetcode.com/problems/binary-tree-maximum-path-sum/description def postorder(self, node): if node: l = self.postorder(node.left) ...
8498989c161d91ab0138d97856126d27b89d6c57
ankurjain8448/leetcode
/binary-tree-paths.py
743
3.90625
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 binaryTreePaths(self, root): """ :type root: TreeNode :rtype: List[str] """ t...
01eac23f5419b53072ededf6d1ba38c7fb35ff28
ankurjain8448/leetcode
/reverse-integer.py
636
3.53125
4
# class Solution(object): # def reverse(self, x): # """ # :type x: int # :rtype: int # """ # rev = int(str(abs(x))[::-1]) # return 0 if len(str(bin(rev))[2:]) > 31 else int(rev) if x > 0 else -int(rev) class Solution(object): def get_rev(self, n): temp = ...
78a76a69d9ac4c0d6d4b818f7feeb8898c8465d5
ankurjain8448/leetcode
/clone-graph.py
631
3.640625
4
# Definition for a undirected graph node # class UndirectedGraphNode: # def __init__(self, x): # self.label = x # self.neighbors = [] class Solution: # @param node, a undirected graph node # @return a undirected graph node def dfs(self, node): if node in self.visited_nodes: return self.visited_nodes[node]...
6c54d7b9d83f94071b325bc5fb79ee87e7f6e0cc
poojaplavilla/Python
/WeekdayOrWeekEnd(If_Else)/prac.py)
253
3.6875
4
#!/usr/bin/python import sys def main(): day=sys.argv[1] if day=='Sat' or day=='Sun': print("Weekend") #give input usinf CLA else: print("Weekday") if __name__=='__main__': main()
d1a6fec7bf05b5606f3e37c0d29a981ffa2c8ea7
kogos/Scipy_codes
/dimension_validate.py
970
3.703125
4
__author__ = 'stephen' from numbers import Number def dim_validate(param): """ Test if dim is a Number and is >= 0. >>> dim_validate(5) True >>> dim_validate(-5) False >>> dim_validate("a string") False """ return isinstance(param, Number) and param >= 0 and param is not str...
f8dfb74cbbfd8736625ed28d7e51fb7d3535c04c
pj0616/RecViz
/utils/genlist.py
1,699
3.890625
4
import imdb from fetch_list import get_list import sys def write2file(l): ''' Writes a list to data.txt Parameter: l(list): The elements of this list are written to data.txt separated by newlines ''' fp=open("utils/data.txt",'w') for entry in l: ...
be36b6d01bf99343cb8480ace21b9e983218335b
khang-le/unit5-01-PYTHON
/tc_tf.py
298
4.03125
4
#!/usr/bin/env python3 # Created by: Khang Le # Created on: November 2019 # This program convert TC to TF def main(): tc = int(input("Enter temperature in Celsius: ")) tf = 9/5 * tc + 32 print("The temperature in Fahrenheit is: {}".format(tf)) if __name__ == "__main__": main()
a2abc2394f4b5625fae4e2b856c54e6ac95125f3
silvuple/w3resource.com-python-exercises
/tuples_exercises_python.py
5,449
4.875
5
""" 1. Write a Python program to create a tuple. """ my_empty_tuple = () my_another_empty_tuple = tuple() my_single_tuple = 'abc', my_multiple_tuple = 'abc', 'bcd', 'xyz' my_multiple_tuple_with_braktes = ('abc', 'bcd', 'xyz') my_list = [1, 2, 3, 3, 4] my_tuple_from_list = tuple(my_list) print(my_empty_tuple, type(my...