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
4c50dd25df1e0fedab1b06d75d650abe65d762ce
ecastan960/holbertonschool-higher_level_programming
/0x0B-python-input_output/10-student.py
945
3.5625
4
#!/usr/bin/python3 """ My class module """ class Student: """ My class """ first_name = '' last_name = '' age = 0 def __init__(self, first_name, last_name, age): """[summary] Args: first_name ([type]): [description] last_name ([type]): [description] ...
d91a27498ec0294ae92f0fdcbaf046c0a8f711dc
XiaoHua0202/1808090503521-stu.zjtu.edu.cn
/王者荣耀.py
4,281
3.578125
4
import random print('-'*40) print('\t欢迎来到王者荣耀') print('-'*40) role = input('请选择游戏人物(1.鲁班 2.后羿 3.李白 4.孙尚香)') coins = 1000 print('欢迎!{}来到王者荣耀,当前金币为:{}'.format(role,coins)) weapons = [['屠龙刀',500],['倚天剑',800],['98k',1000],['鹅毛扇',800],['手榴弹',200],['樱花枪',500]] weapon_list = [] while True: choice = input('请输入:\n1.购买武器\n2....
1daf2db78044c8a1fcd44d918f5156a06ea9c75d
KartikKannapur/Algorithms
/00_Code/01_LeetCode/559_MaximumDepthofN-aryTree.py
1,385
4.25
4
""" Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. For example, given a 3-ary tree: We should return its max depth, which is 3. """ """ # Definition for a Node. class Node(object): def __init__(se...
b4f0f0a2746fe03ceebd1007794f815f4d5c36a1
KartikKannapur/Algorithms
/00_Code/01_LeetCode/557_ReverseWordsinaStringIII.py
704
4.21875
4
# #Given a string, you need to reverse the order of characters # #in each word within a sentence while still preserving whitespace # #and initial word order. # #Example 1: # #Input: "Let's take LeetCode contest" # #Output: "s'teL ekat edoCteeL tsetnoc" # #Note: In the string, each word is separated by single space and ...
8dffb495dad60c1db58f333fe904c9b5bccf8ca3
KartikKannapur/Algorithms
/00_Code/01_LeetCode/121_BestTimetoBuyandSellStock.py
1,501
4.03125
4
""" Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. Example 1: Input: [7, 1, 5, 3, 6, 4] Output: 5 max. difference = 6-...
2f883b3bd4645908e4b77ed0ae0669be10e283be
KartikKannapur/Algorithms
/00_Code/01_LeetCode/876_MiddleoftheLinkedList.py
1,440
4.1875
4
""" Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Output: Node 3 from this list (Serialization: [3,4,5]) The returned node has value 3. (The judge's serialization of this n...
5dbec02ee2f33d1a2858cad020fd5f23852c364c
KartikKannapur/Algorithms
/00_Code/01_LeetCode/142_LinkedListCycleII.py
768
3.984375
4
# #Given a linked list, return the node where the cycle begins. If there is no cycle, return null. # #Note: Do not modify the linked list. # #Your runtime beats 67.82 % of python submissions. # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # se...
d906e2b4ec5c664142b010a433db26d7900fb5a3
KartikKannapur/Algorithms
/00_Code/01_LeetCode/70_ClimbingStairs.py
618
3.921875
4
""" You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. """ class Solution(object): def climbStairs(self, n): """ :type n: int :rtyp...
602750c19d6f198161d370a3d29d26e2b4708df9
KartikKannapur/Algorithms
/00_Code/01_LeetCode/781_RabbitsinForest.py
1,277
3.890625
4
""" In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those answers are placed in an array. Return the minimum number of rabbits that could be in the forest. Examples: Input: answers = [1, 1, 2] Output: 5 Explanation: Th...
8de3e7f205ede4092b7ea4961e78efe81f34271a
KartikKannapur/Algorithms
/00_Code/01_LeetCode/456_132Pattern.py
1,557
3.734375
4
""" Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list. Note: n will be less than 15,000. Example 1: Input: [1, 2, 3, 4] Outpu...
b6170ce52bdfdb7b7d0ec309432ed36234f1ede4
KartikKannapur/Algorithms
/00_Code/01_LeetCode/26_RemoveDuplicatesfromSortedArray.py
1,610
3.890625
4
""" Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example: Given nums = [1,1,2], Your function should return length ...
9dce88959dac597b1b9f5a2644010f7de2339ff9
KartikKannapur/Algorithms
/00_Code/01_LeetCode/525_ContiguousArray.py
1,630
4.09375
4
""" Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1. Example 2: Input: [0,1,0] Output: 2 Explanation: [0, 1] (or [1, 0]) is a longest contiguous sub...
fad736d0e299dd285238bb6ab01cb8d1444314ac
KartikKannapur/Algorithms
/00_Code/01_LeetCode/283_MoveZeroes.py
1,807
4.09375
4
""" Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0]. Note: You must do this in-place without making a copy of the array. Minimi...
e9a1f7f92c7d888ab70fe09ca91e45d4bda6d162
KartikKannapur/Algorithms
/00_Code/02_HackerRank/Dynamic_Programming/Fibonacci_Modified.py
507
4.25
4
""" https://www.hackerrank.com/challenges/fibonacci-modified/problem """ # !/bin/python3 import sys def fibonacciModified(t1, t2, n): # Complete this function memo = [0] * (n + 1) memo[0] = t1 memo[1] = t2 for i in range(2, n + 1): memo[i] = memo[i - 2] + (memo[i - 1] ** 2) return ...
7b60b68b7fb1f6e0f71f016fee6c1a5fa25289a3
KartikKannapur/Algorithms
/00_Code/01_LeetCode/239_SlidingWindowMaximum.py
1,155
4.28125
4
""" Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. Example: Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3 O...
cc550993a53d81def55435606cf93ed3a780be63
KartikKannapur/Algorithms
/00_Code/01_LeetCode/12_IntegertoRoman.py
3,310
4.125
4
""" Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is...
af3f55697e403625e792e3e7705d5a97d9afd2a4
KartikKannapur/Algorithms
/00_Code/01_LeetCode/83_RemoveDuplicatesfromSortedList.py
1,000
3.859375
4
""" Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. Your runtime beats 67.55 % of python submissions. """ # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # ...
12f7336b760f6f1ee7d88939a2aad503ade752e0
KartikKannapur/Algorithms
/00_Code/01_LeetCode/347_TopKFrequentElements.py
1,647
3.765625
4
""" Given a non-empty array of integers, return the k most frequent elements. For example, Given [1,1,1,2,2,3] and k = 2, return [1,2]. Your runtime beats 52.16 % of python submissions. """ class Solution: def topKFrequent(self, nums, k): """ :type nums: List[int] :type k: int :r...
1899d32c9f367561a9a3f25f188e9d6c52ed9d59
KartikKannapur/Algorithms
/00_Code/01_LeetCode/457_CircularArrayLoop.py
2,431
3.875
4
""" You are given an array of positive and negative integers. If a number n at an index is positive, then move forward n steps. Conversely, if it's negative (-n), move backward n steps. Assume the first element of the array is forward next to the last element, and the last element is backward next to the first element....
becd208345fadb3e6228d080ced33a6926294b45
KartikKannapur/Algorithms
/00_Code/01_LeetCode/415_Add Strings.py
636
4.03125
4
""" Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero. Your runtime beats 92.30 % of python submissions """ class S...
9cd6cda37a87288b604549a983a306cff9c69e7e
KartikKannapur/Algorithms
/00_Code/01_LeetCode/139_WordBreak.py
1,809
3.984375
4
""" Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not...
e087020aee0af2114644db882947f529f4d2cc8a
KartikKannapur/Algorithms
/00_Code/01_LeetCode/222_CountCompleteTreeNodes.py
1,667
3.921875
4
""" Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last ...
a0f18029a583c69f083db31f713c75919bc4b1d8
KartikKannapur/Algorithms
/00_Code/01_LeetCode/92_ReverseLinkedListII.py
1,174
4
4
""" Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list. """ # Definition for singly-linked list. # class ListNode(object): # ...
029d8072222dc0db8cab8d643870307789e1752f
KartikKannapur/Algorithms
/00_Code/01_LeetCode/287_FindtheDuplicateNumber.py
1,196
3.921875
4
# #Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. # #Note: # #You must not modify the array (assume the array is read only). # #You must use only...
3537a58b2af3189f9b38b73c8109c9c2d3b470eb
KartikKannapur/Algorithms
/00_Code/01_LeetCode/976_LargestPerimeterTriangle.py
1,012
3.96875
4
""" Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it is impossible to form any triangle of non-zero area, return 0. Example 1: Input: [2,1,2] Output: 5 Example 2: Input: [1,2,1] Output: 0 Example 3: Input: [3,2,3,4] Output:...
cd1d5ae088fc786391b2a0ff3c27dd874420d13f
KartikKannapur/Algorithms
/00_Code/01_LeetCode/332_ReconstructItinerary.py
1,832
4.5625
5
""" Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK. Note: If there are multiple valid itineraries, you should return the itinerary th...
c93dd93b025ab7807327fb6f43ddc6364fccac5b
KartikKannapur/Algorithms
/00_Code/01_LeetCode/49_GroupAnagrams.py
1,619
4.09375
4
""" Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note: All inputs will be in lowercase. The order of your output does not matter. """ class Solution: def groupAnagrams(self, strs): ...
57d0a57e4210d00fe1292929713fb034ba626276
KartikKannapur/Algorithms
/00_Code/01_LeetCode/779_K-thSymbolinGrammar.py
1,207
3.765625
4
""" On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-indexed.) (1 indexed). Examples: Input: N = 1, K = 1 Output:...
e7cd56377adf96443a99a576b85fd23524bc7312
KartikKannapur/Algorithms
/00_Code/01_LeetCode/443_StringCompression.py
2,271
3.78125
4
""" Given an array of characters, compress it in-place. The length after compression must always be smaller than or equal to the original array. Every element of the array should be a character (not int) of length 1. After you are done modifying the input array in-place, return the new length of the array. Follow up...
0a1b65a184da3df85610fbe3760ae972c2834db1
KartikKannapur/Algorithms
/00_Code/01_LeetCode/883_ProjectionAreaof3DShapes.py
2,987
4.5
4
""" On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Now we view the projection of these cubes onto the xy, yz, and zx planes. A projection is like a shadow, that maps our 3 dimen...
be84527e83193f52bf3a8fa9aad6906c82a84101
KartikKannapur/Algorithms
/00_Code/01_LeetCode/453_MinimumMovestoEqualArrayElements.py
1,079
3.96875
4
""" Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,3] Output: 3 Explanation: Only three moves are needed (remember each move increments two elements): [1,2,3] => [2,3,3]...
7655cf01c1c8da4010bb9d6b2e95eb4746dc11a1
KartikKannapur/Algorithms
/00_Code/01_LeetCode/378_KthSmallestElementinaSortedMatrix.py
679
4.0625
4
""" Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. Example: matrix = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ], k = 8, return 1...
24ea31762444a62ad6d997c484bf624da5cdd2a5
KartikKannapur/Algorithms
/02_Coursera_Algorithmic_Toolbox/Week_01_MaximumPairwiseProduct.py
991
4.1875
4
# Uses python3 __author__ = "Kartik Kannapur" # #Import Libraries import sys # #Algorithm: # #Essentially we need to pick the 2 largest elements from the array # #Method 1: Sort the array and select the two largest elements - Very expensive # #Method 2: Scan the entire array twice by maintaining two indexes - Max1 an...
438b56ff17d913127357f376e97f993bd27503a4
KartikKannapur/Algorithms
/00_Code/01_LeetCode/172_FactorialTrailingZeroes.py
500
3.828125
4
""" Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. """ class Solution: def trailingZeroes(self, n): """ :type n: int :rtype: int """ """ Method 1: n/5 + n/25 + n/125 + n/625 ... ...
5665f9277ac82b9265ce9f68dd0eae68d0ecdc9d
Cgost/AccountBook
/1_AccountBook.py
6,949
3.5625
4
''' 項目 account_name 收入 支出 money 結餘 total 備註 comment ''' import os import datetime ISOTIMEFORMAT = "%Y-%m-%d %H:%M:%S" total = 0 class AccountBill(): """docstring for AccountBill""" def __init__(self, date, name): self.date = date self.name = name self.bill = 0 ...
de294f5c836a46c177a959252b19299fc3839792
testmywork77/WorkspaceAbhi
/python_practice/Fundamentals/if_elif_else_1.py
225
3.859375
4
brand=input("Enter your favourite brand") if brand == "Lego": print("Nice Brand") elif brand == "Asda": print("Cool Brand") elif brand == "Argos": print("Good Brand") else: print(f"{brand} is a bad brand")
433a0c8f308cd3f69a98eef4ba8136de15c3eee7
testmywork77/WorkspaceAbhi
/python_practice/Fundamentals/for_7.py
98
3.921875
4
list=eval(input("Enter List: ")) sum = 0; for x in list: sum=sum+x; print(f"the sum = {sum}")
950e019702f534105369ef8d70380546c910e1dc
testmywork77/WorkspaceAbhi
/Year 8/Casting.py
812
4.28125
4
name = "Bruce" age = "42" height = 1.86 highscore = 128 # For this activity you will need to use casting as appropriate. # Using the data stored in the above variables: # 1. Use concatenation to output the sentence - "Bruce is 1.86m tall." print(name + " is " + str(1.86) + "m tall.") # 2. Use concatenation to output th...
bd3d80133d7780eaacc843d4f7f9a144a6a56802
testmywork77/WorkspaceAbhi
/Year 8/Concatenation_Practice.py
1,042
4.34375
4
name = "Abhinav" age = "11" fav_sport = "Cricket" fav_colour = "red" fav_animal = "lion" # Create the following sentences by using concatenation # Example: A sentence that says who he is and how old he is print("My name is " + name + " and I am " + age + " ,I like to play " + fav_sport) # NOTE: Don't forget about sp...
9d040b164bc4ca3c1e2b38175b905bf036add469
testmywork77/WorkspaceAbhi
/Year 8/Remainder_Calculator.py
230
4
4
answer_1 = int(input("Think of any whole number")) answer_2 = int(input("Think of another whole number")) answer = answer_1 // answer_2 remainder = answer_1 % answer_2 print("you got " + str(answer) + " r " + str(remainder))
44607693fc8c5d8ea020eaa90ce843fdf26b2147
testmywork77/WorkspaceAbhi
/python_practice/Fundamentals/if_1.py
105
3.984375
4
# if name = input("Enter your name") if name == "Abhinav": print(f"Hello, my name is {name} too")
b5458a99801e918676a8090a76bf03b669df45bc
testmywork77/WorkspaceAbhi
/Year 8/Which Team.py
591
4.03125
4
print("Hi, i like football") answer = input("What football team do you suport?, note that team names need to be written in full form"".").lower() if answer == "manchester united": print("Man U 4 life !!!") elif answer == "manchester city": print("We are ferice rivals, but we will beat you!") elif answer == ...
6de801f1ca040cec0a38416aea9b7826afc14cf2
shivanitekriwal1/Python-Libraries
/download video.py
212
3.671875
4
#file for downloading any video import urllib url = input("enter the url of the video here") name = input("enter the name of the video") print "downloading" urllib.urlretrieve(url, "name.mp4") print "downloaded"
5e4c61814044dfc199a2a5008b759dbff77d192b
MikelSotomonte/mask-turret
/shooting_test.py
326
3.78125
4
suma = 0 average = 0 var = 0 var = str(input("variable test: ")) #1 cifras while True: var2 = str(input("variable N: ")) var = str(var) + str(var2) var = var[1:9] print(str(var)) for char in var: suma += int(char) average = suma/8 print("sum: " + str(suma) + ", average: " + str(ave...
811cec02c51f24dc6ff4d654ea389a87bd003d81
abhi154/5005-python-day4
/equality.py
127
4.09375
4
a=int(input("enter a value ")) b=int(input("enter b value")) if a==b: print("both r equal") else: print("both are not equal")
adb651fcdca4bd91628afb27cb0c1e8a7b4ad59c
JamesPZilverberg/CatanSimulator
/catan_utils/simple_bot.py
3,044
3.96875
4
from abc import ABCMeta, abstractmethod class Bot(metaclass=ABCMeta): def __init__(self): self.resources = {'lumber': 0, 'grain':0, 'brick':0, 'ore':0, 'wool':0} self.dev_cards = {'knight':0, 'monopoly':0, 'year of plenty':0, 'road builder':0, 'victory point':0} self.longest_road = False ...
486846e9c5aeaa3244f239355a596cccca56c8b6
enelesmai/intro-python
/modulo4.py
247
3.640625
4
#read a file ejemplo = "example1.txt" file1 = open(ejemplo,"r") file1 print(file1.name) print(file1.mode) lee = file1.read() print(lee) file1.close() with open(ejemplo,"r") as archivo: FileContent = archivo.read() print(FileContent)
45aa24a33a276e68a83ce7df27b6172445219cc1
arthurnage/thesis
/data_partition/partition.py
901
3.703125
4
import mmh3 from abc import ABC, abstractmethod class Partitioner(ABC): """ Class that implements different data partition options """ @abstractmethod def make_partition(self, value, n): """returns index of a chosen shard for data""" pass class RoundRobin(Partitioner): def __i...
ca7e0b792cf5c8c41aec4ae00c6046a7895c0de7
suned/pfun
/src/pfun/immutable.py
903
3.953125
4
from dataclasses import dataclass class Immutable: """ Super class that makes subclasses immutable using dataclasses Example: >>> class A(Immutable): ... a: str >>> class B(A): ... b: str >>> b = B('a', 'b') >>> b.a = 'new value' AttributeEr...
e112f3c50a3e99e6bc711dcac2c1bf4a46f45c48
flyingSprite/spinelle
/learning/pep498_formatter_string.py
97
3.71875
4
name = 'John' my_name = f'My name is {name}!' print(my_name) # Print result: My name is John!
d520099f493506be0bc32e0e7a227f7be7016930
FierySwampshire/weeb2psp
/sconutils.py
1,479
3.828125
4
import subprocess from sys import stderr as STDERR from sys import exit def eprint(errmsg): """Prints `errmsg` to STDERR.""" print(errmsg, file=STDERR) def die(errmsg): """Prints message and exits Python with a status of one.""" eprint(errmsg) exit(1) def runpretty(args): """ Run a giv...
d1c7cadba59a9c79cf30df4167483821263c15e5
krishnaja625/CSPP-1-assignments
/m6/p3/digit_product.py
416
4.125
4
''' Given a number int_input, find the product of all the digits example: input: 123 output: 6 ''' def main(): ''' Read any number from the input, store it in variable int_input. ''' N3 = int(input()) N2 = N3 N = abs(N3) S = 0 K = 0 if N > 0: S = 1 while N > 0: N2 = N%10 S = S*N2 N = N//10...
6cdeb77b7e0518a092a04ff5c08193453f857a56
mcheshier1/dvc
/dvc/prompt.py
419
3.625
4
import sys try: # NOTE: in Python3 raw_input() was renamed to input() input = raw_input except NameError: pass def prompt(msg, default=False): # pragma: no cover if not sys.stdout.isatty(): return default answer = input(msg + u' (y/n)\n').lower() while answer not in ['yes', 'no', 'y...
6b9ba7c88152a4e9f3aba80eaae234dd51a58f2a
biringaChi/python-crash-course
/exercise_9.py
11,521
4.21875
4
class Dog(): def __init__(self, name, age): # Initialize name and age attributes self.name = name self.age = age def sit(self): # Simulate a dog sitting in response to a command return self.name.title() + " is now sitting." def roll_over(self): # Simulate r...
9bc35dfe3bef38f715841985f5e62c18b47cf483
Gauravd1234/Trigonometric-graphs
/Trig_graphs.py
501
3.796875
4
from matplotlib import pyplot as plt import numpy as np from numpy import pi print("\n") print("What type of graph do you want?: ") trig_type = input("S for sine, C for cosine and T for tangent: ") if trig_type.lower() == "s": x = np.linspace(0, 2*pi, 360) y = np.sin(x) elif trig_type.lower() == "c": x =...
065d5fda40b2c6f28f7736e946076f3b3d709f27
Santoshi321/PythonPractice
/ListExcercise.txt
1,866
4.15625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jul 8 15:06:30 2019 @author: sgandham """ abcd = ['nintendo','Spain', 1, 2, 3] print(abcd) # Ex1 - Select the third element of the list and print it abcd[2] # Ex2 - Type a nested list with the follwing list elements inside list abcd mentioned above...
23122823b0cc2e1ca9638b448d3bcae6beda273e
HankChow/leetcode
/83-Remove_Duplicates_from_Sorted_List.py
441
3.609375
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ ret = head if head is None: return head while head is not None: wh...
89b956c823e6da5dd76c42191ce4e637add9e647
sraaphorst/pyncomb
/pyncomb/permtj.py
3,057
3.546875
4
#!/usr/bin/env python # # Copyright 2009 Sebastian Raaphorst. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
24c0fe4adafc0d3e54366845e6a4650ed9e7ef5b
rebecca16/CYPAbigailAD
/libro/problemas_resueltos/capitulo1/problema1_6.py
137
3.65625
4
DIAS = int (input("Ingresa un numero determinado de dias")) SEG = DIAS * 24 * 60 * 60 print (f" En { DIAS } dias hay { SEG } segundos")
9996f4b93c4f91733742a6793da400f6b3bab637
rebecca16/CYPAbigailAD
/funcion_print_el_que_si_es_xd.py
750
4.125
4
# print tiene 4 formas de uso """ 1.- con comas 2.- con signo '+' 3.- con la funcion format () 4.- Es con una variante de format () """ # Con comas #un espacio y haciendo casting de tipo edad = 10 nombre = "Juan" estatura = 1.67 print (edad , estatura , nombre ) # con '+' hace lo mismo pero no realiza el casting auto...
d71c882977efbe61956796594bd179611a9d719e
rebecca16/CYPAbigailAD
/diccionarios.py
1,661
3.78125
4
#diccionarios {'llave' : 'valor'} alumno={'num_cta':'201647757473', 'nombre': ('José', 'Perez', 'García'), 'semestre': '1', 'promedio':'0.0', 'materias':['CyP','Álgebra','Cálculo','Geometría','IntroICO'], 'regular':True , 'lagrimas_por_examen': 5, 'dirección':{ ...
067bdca15533644caec4633b3ca30d12f320fa99
rebecca16/CYPAbigailAD
/libro/problemas_resueltos/capitulo1/Ejemplo2_3.py
332
4
4
# El programa, dado como dato la calificación de un alumno en un examen, escribe "aprobado" si su calificación es mayor o igual que 8 y "reprobado" en caso contrario CAL = float (input("Ingresa tu calificacion de examen: ")) if CAL >= 8: print (f" Aprobrado") else: print (f" Reprobado") print (" Fin del progra...
414388d86c66dc0a8c432478a9b264cbe72126ad
rebecca16/CYPAbigailAD
/libro/Ejemplo2_12.py
779
4
4
A = int (input("Escribe un numero entero ")) B = int (input("Escribe un numero entero ")) C = int (input("Escribe un numero entero ")) if A > B : if A > C : if B > c : print(f"Los numeros de forma descendente quedan asi: {A}, {B},{C}") else: print(f"Los numeros de forma desce...
8ad1f34a31d374a37486f6b8b01144525f2d9353
Ollie-Holme/Data-Structure
/Python/BinaryTree.py
3,838
4.09375
4
class Node: # Node constructor def __init__(self, data): self.val = data self.left = None self.right = None class BinaryTree: # Binary Tree constructor def __init__(self): self.root = None # insert(x) # insert a new node [x] to the binary tr...
dbe602ec4b952bb989298f7d638386a6171e33de
Ollie-Holme/Data-Structure
/Python/Deque.py
4,879
3.828125
4
class Deque: # Deque constructor def __init__(self): self.deque = [] # appendLeft(x) # add [x] to the left side of the deque def appendLeft(self, x): self.deque = [x] + self.deque # appendRight(x) # add [x] to the right side of the Deque def appendRight(self...
b366c138f57e53985b14912a9f3f2bf4bfebaefe
mowayao/modelcompression-2019
/pruning/kmeans.py
2,342
3.578125
4
import torch import numpy as np import pdb def pairwise_distance(data1, data2=None, device=-1): r''' using broadcast mechanism to calculate pairwise ecludian distance of data the input data is N*M matrix, where M is the dimension we first expand the N*M matrix into N*1*M matrix A and 1*N*M matrix B ...
6442ef0f20ef291537ad62c1559843ef6c58716a
j-concepcion/parking-system
/tests/test_fuel.py
689
3.5
4
from unittest import TestCase from fuel import Fuel class TestFuel(TestCase): def test_correctly_initialised(self): fuel = Fuel(0.55) self.assertEqual(0.55, fuel.current_level) self.assertEqual(1.75, fuel.price_per_litre) def test_to_string(self): fuel = Fuel(0.55) sel...
533617b06bf477c68732a07886168ad14abbb2bf
nitroexe/snake
/engine_module.py
2,703
3.734375
4
import pygame from pygame.locals import * class Engine(): def __init__(self): super().__init__() self.clock = pygame.time.Clock() self.time = 0 self.coord_by_direction = {"W" : (0, -1), "S" : (0, 1), "D" : (1, 0), "A" : (-1, 0)} def tick(self): self.key_eve...
0e86c55c8d226bc20b421093f10736c47f973b13
kidbytes/pdsa
/algo_python/algo_graph.py
1,324
3.921875
4
# String Transformation # Given a dictionary D, strings s and t, find if s produces t. # Is there a way to go from s to t using words within the Dictionary? # We can define an undirected graph with words in dictionary. There is # a path between u and v if u and v differ by only 1 character. # The problem can be solved ...
b002f1cdd465c6abe2a87abf466903260a8f4bd2
kidbytes/pdsa
/python/heap.py
3,660
3.8125
4
''' A B C D E F G A B C D E F G 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 8 * Assume full binary tree Number of nodes at tree level i = 2^i # i starts at 0 Children of node at index i are at (2*i+1) and (2*i+2) Parent of node at index i is at (i-1)/2 E...
3630cc5aeda264cc010df9809a3ef48d809b9cb3
myNameArnav/dsa-visualizer
/public/codes/que/que.py
1,771
4.25
4
# Python3 program for array implementation of queue INT_MIN = -32768 # Class Queue to represent a queue class Queue: # __init__ function def __init__(self, capacity): self.front = self.size = 0 self.rear = capacity - 1 self.array = [None]*capacity self.capacity = capacity ...
ed57a1ae2c3abd176cf440c00857b411899dd32e
myNameArnav/dsa-visualizer
/public/codes/dfs/dfs.py
1,868
4.28125
4
# Python3 program to implement DFS # This function adds an edge to the graph. # It is an undirected graph. So edges # are added for both the nodes. def addEdge(g, u, v): g[u].append(v) g[v].append(u) # This function does the Depth First Search def DFS_Visit(g, s): # Colour is gray as it is visited par...
0b31ab215883c683821b63d344b4839e00a911fa
dr-rodriguez/AdventofCode2015
/day16.py
3,995
4.125
4
""" --- Day 16: Aunt Sue --- Your Aunt Sue has given you a wonderful gift, and you'd like to send her a thank you card. However, there's a small problem: she signed it "From, Aunt Sue". You have 500 Aunts named "Sue". So, to avoid sending the card to the wrong person, you need to figure out which Aunt Sue (which you...
d805bdf53368e4287fb2515ddd2e15628c1fe7b7
dr-rodriguez/AdventofCode2015
/day4.py
877
4.09375
4
""" Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the economically forward-thinking little girls and boys. To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least five zeroes. The input to the MD5 hash is some secret key (your puzzle input, given...
32dbe4688d12bb0ebf55349a16e9a3c7d872fdb4
mokarian/EntityDisambiguation
/utils.py
7,289
3.546875
4
""" This file contains methods that may frequently being used in this project """ import json import os import csv from itertools import chain, combinations import yaml import pandas as pd class Utils: """ This class contains methods that may frequently being used in this project """ def __init__(se...
e7cee09cd20031bd8c9d9bc8bd49893b166b0dfc
fabriciodisalvo/cs50ai
/project0/degrees/test_module.py
2,589
3.625
4
from degrees import * def testing(): # Load data from files into memory print("Loading data...") load_data("small") print("Data loaded.") print() print("Test 01: Valeria Golino and Cary Elwes") source, target = ("Valeria Golino", "Cary Elwes") source = person_id_for_name(sou...
bac8d9a7b59576412ee0babd85a164f2145c673a
hnko/uva-judge
/recursion/10344.py
391
3.71875
4
solution = ['Impossible', 'Possible'] def solve(res, i, line): #print(res) if i == len(line): if res == 23: return True else: return False return solve(res+line[i], i+1, line) or solve(res-line[i], i+1, line) or solve(res*line[i], i+1, line) return ans while True: line = [int(i) for i in input().sp...
a99eb3c488de1e6aef6a4afb81e41856f882df01
hnko/uva-judge
/recursion/10018.py
384
3.5625
4
# AC - recursion def is_palindrome(arr): i, j = 0, len(arr)-1 while i<j: if arr[i] != arr[j]: return False i += 1 j -= 1 return True def solve(cnt, line): if is_palindrome(line) and cnt: return cnt, line return solve(cnt+1, str(int(line) + int(line[::-1])) ) t = int(input()) for _ in range(t): line ...
845eb59fadcf44283e94e624929672290f53c183
hnko/uva-judge
/string-loop/12577.py
197
3.546875
4
# AC - compare string t = 1 while True: line = input() if line =='Hajj': print('Case %d: Hajj-e-Akbar' % t) elif line == 'Umrah': print('Case %d: Hajj-e-Asghar' % t) else: break t += 1
40146753cdbb0a6de8de8d84701d642ee7270f6a
baradl/eisenrecorder
/parsing/converter.py
4,400
4.15625
4
from utils import helper as he import math def convert_to_month(month): assert type(month) is int or type(month) is str if type(month) is int: assert month in range(1,13) try: month = int(month) except: month = month.lower() month = month[0:3] months_abbrev = ["jan", ...
0cd562f0e6232f617a8b295b4492f3c35a98c6c9
NBizzell/EduKit3
/Code/9-avoidance-GPIOZero.py
921
3.578125
4
# CamJam EduKit 3 - Robotics # Worksheet 9 – Obstacle Avoidance GPIO Zero version # by Neil Bizzell (@PiVangelist) from gpiozero import DistanceSensor, CamJamKitRobot # Import DistanceSensor and CamJamKitRobot Classes from the GPIOzero library from time import sleep # Import sleep function from the time library # def...
87d3b77e2041df1ba7d98d5234ff6736170105d5
den01-python-programming-exercises/exercise-4-16-payment-card-MrFathed
/src/payment_card.py
555
3.609375
4
class PaymentCard: def __init__(self, opening_balance): self.balance = opening_balance def __str__(self): return "The card has a balance of {} pounds".format(self.balance) def eat_affordably(self): if self.balance >= 2.60: self.balance -= 2.60 def eat_heartily(self...
34111863f4c7b8b13ab690bb1f1ab2b940aeccdc
vivekbharatha/AV-Python-DS
/03/babynames/babynames.py
1,188
3.5625
4
import sys import re def extract_names(filename): result = [] file_ = open(filename, 'rU') fileText = file_.read() yearM = re.search(r'Popularity\sin\s(\d\d\d\d)', fileText) if not yearM: print("Couldn't find year") sys.exit(1) year = yearM.group(1) result.append(year) rankndNames = re.findall(r'<td>(\d...
d78d4b827bc6013444e4db630cd1261773a0bea8
Bcdirito/django_udemy_notes
/back_end_notes/python/level_two/object_oriented_notes/oop_part_two.py
791
4.53125
5
# Example class Dog(): # Class Object Attributes # Always go up top species = "Mammal" # initializing with attributes def __init__(self, breed, name): self.breed = breed self.name = name # can be done without mass assignment my_dog = Dog("German Shepherd", "Louis") # can be...
cbe163e303680151068921f28356da61645383ac
Bcdirito/django_udemy_notes
/assessments/python/level_two/Part3_OOP_Project.py
5,733
4.28125
4
##################################### ### WELCOME TO YOUR OOP PROJECT ##### ##################################### # For this project you will be using OOP to create a card game. This card game will # be the card game "War" for two players, you an the computer. If you don't know # how to play "War" here are the basic r...
e0e1e5e7770e40492dcc674300b2dece6998b3f6
johananlai/set-associative-cache
/Cache.py
4,831
3.53125
4
import ReplacementAlgorithm class Cache: def __init__(self, slots, size, alg="lru"): """ :param slots: Number of slots; specifies the -way associativity of the cache :param size: Total number of slots in the cache :param alg: String that determines algorithm type. Used by Replacem...
6f9796d586862a4084d2a8e0034abe8a5cf1a84f
nataliak29/HackerRank
/Easy/timeconversion.py
441
4.0625
4
#https://www.hackerrank.com/challenges/time-conversion/problem s='11:05:45AM' def timeConversion(s): timeofday=s[-2:] time=s[:-2] hour=time[:2] final=str() if timeofday=='PM' and int(hour)!=12 : final=str(int(hour)+12)+str(time[2:]) elif timeofday=='AM' and int(hour)==12...
ddbea116d99607fb8a3e7be64ad88e4d8018a398
nataliak29/HackerRank
/Easy/negposnumbers.py
497
3.609375
4
#https://www.hackerrank.com/challenges/plus-minus/problem arr =[-4, 3, -9, 0, 4, 1] def plusMinus(arr): negnum=0 posnum=0 zeros=0 for i in range(len(arr)): if arr[i]<0: negnum+=1 elif arr[i]>0: posnum+=1 else: zeros+=1 posres...
5d8b72bfd1cbd69f0cdda8a898738114643bb6e1
nataliak29/HackerRank
/Easy/electronicshop.py
347
3.59375
4
#https://www.hackerrank.com/challenges/electronics-shop/problem keyboards=[4] drives=[5] b=5 def getMoneySpent(keyboards, drives, b): try: result= b-min([b-(key+dri) for key in keyboards for dri in drives if b-(key+dri)>=0 ]) except: result= -1 return result print(getMoneySpe...
d88f780118e29926c65fb226807e6b6173eb6965
AshurMotlagh/CECS-174
/Lab 3.11.py
86
3.875
4
age = input("Enter your age to convert to days: \n") age = int(age) * 365 print(age)
5b95eec49a8aeffe945d1a95894665593601c001
AshurMotlagh/CECS-174
/num_exception.py
365
4.0625
4
total = 0 while True: try: user = float(input("Enter a number, or 2 non-numbers to quit:")) total = total + float(user) except ValueError: try: user = input("Enter a number, or another non-number to quit:") total = total + float(user) except ValueError: ...
8ab7907db4a0bc2c946bd26e7c250d8e9b8c0cbb
AshurMotlagh/CECS-174
/Lab 4.9.py
695
3.984375
4
# Define the price of a stamp in pennies. FIRST_CLASS_STAMP_PRICE = 44 dollars = float(input("Enter number of dollars:")) dollars = dollars * 100 # Compute and print the number of stamps to dispense. stamps = dollars // FIRST_CLASS_STAMP_PRICE print("First class stamps", int(stamps)) # Compute the number of quarters,...
7818320f52c6cd9e0c3de36dc4150276721470cc
AshurMotlagh/CECS-174
/Lab 11.8.py
1,425
3.984375
4
grades = {} good = ['A', 'B', 'C', 'D', 'F'] while True: user = input("(A)dd, (R)emove, (M)odify, (P)rint all, or (Q)uit?").upper() if user == 'A': name = input("Enter the name of the student: ") if name in grades: print("Sorry, that student is already present.") else: ...
f4ddf222cd4c3d87ffee555eb23937de49298016
AshurMotlagh/CECS-174
/Lab 3.13.py
223
4.375
4
## # Print the first 3 letters of a string, followed by ..., followed by the last 3 letters of a string. ## word = input("Enter a word with longer than 8 letters: ") print("The new word is", word[0:3], "...", word[-3:])
2d4d79552c196932d1db0e01116200de81484875
AshurMotlagh/CECS-174
/Lab 6-20.py
248
3.734375
4
user = input('Enter a sequence of comma-separated numbers: ') user_list = user.split(',') output = '' for i in range(len(user_list)): if user_list[i].isdigit() and int(user_list[i]) % 2: output += user_list[i] + ',' print(output[:-1])
74617e97c33f80b5bf340e1689797f7ada7c6e17
AshurMotlagh/CECS-174
/removeSpace.py
192
4.1875
4
user = input("Enter a string: ") user = user[::-1] print("The new string: ", end='') for character in user: if character == ' ': continue else: print(character, end='')
74f19af5f36dfc7d6819dd797574160b0769729a
Alblanca/take-off-technologies-atm-problem
/model/account.py
564
3.765625
4
class Account: def __init__(self, account_id, pin, balance): self.account_id = account_id self.pin = pin self.balance = float(balance) def deposit(self, amount): """ Sets new balance after depositing amount :param amount: amount to be deposited :return: ...
a98adad1cc615c158e21b7ade85b434943db27c7
JoelAhfeldt/smt-lib
/smtnode.py
1,268
3.75
4
class Node: def __init__(self, data=None): self.data = data self.children = [] def add_child(self, obj): self.children.append(obj) def print_tree(self): text="" text=self.print_tree_rec(text) print(text) def print_tree_rec(self,text): if len(sel...
4751d2e49a406ea0d40368f5de71ec8e709e4689
SharedModels/ConnectFour
/human_play.py
359
3.59375
4
class HumanPlay: def action(self, state, c, oc): print(state) correct = True while correct: print('Type attack:') attack = input() attack = int(attack) if attack > 6 | attack < 0: print('Attack must be between 0 and 6') ...
0f9d53f47e6e28a8be5e8c8d0d88885c78eb9d73
doofenshmirtzInc/elem-ai
/jamcshan-haupadhy-nguyeji-a2/part1/SebastianAutoPlayer.py
5,284
3.625
4
# Automatic Sebastian game player # B551 Fall 2020 # Jack McShane (jamcshan@iu.edu) # # Based on skeleton code by D. Crandall # # # This is the file you should modify to create your new smart player. # The main program calls this program three times for each turn. # 1. First it calls first_roll, passing in a Dice obj...