blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
edaee72925a72c34765b387091201a7ba6db956e
awilkinson88/SoftwareDesign
/chap12/anagram_sets.py
1,103
4.21875
4
def letters(s): """Returns the string with the letters of string s in alphabetical order. """ t = list(s) t.sort() t = ''.join(t) return t def make_dict(): """Creates a dictionary from a text file and then returns sets of anagrams""" d = {} fin = open ('words.txt') for line in fin: ...
true
037df5fe7d41b196c14ae8e7c7a20019c245ce67
awilkinson88/SoftwareDesign
/chap16/chap16ex.py
1,007
4.5
4
class Time(object): """Represents the time of day. attributes: hour, minute, second""" #We can create a new Time object #and assign attributes for hours, minutes, and seconds: time = Time() time.hour = 11 time.minute = 59 time.second = 30 #from datetime import * current = Time() current.year = 2013 current.month ...
true
5c6cd78b9bbb66ed67e6eac3f75592996bce684c
propersam/Grokking-Algorithm-Practice
/selection_sort.py
916
4.3125
4
def findSmallest(arr): """ Fucntion to find smallest element from array and return it's index location >> findSmallest([4,7,1,9,6,0]) 2 """ smallest = arr[0] # assign the element in array as smallest smallest_index = 0 # assign first index of array as index wi...
true
ac387ee9a61aea324424563c87f1b3e1ee349586
hritik1228/Python
/String Formatting.py
2,457
4.71875
5
# F-Strings & String Formatting In Python """ 1 String Formatting (% Operator) Python has a built-in operation that we can access with the % operator. This will help us to do simple positional formatting. If anyone knows a little bit about C programming, then they have worked with printf statement, which is ...
true
d3077b4b36594a4c3f2ee5973ec9bd6cb15c9ce0
fotisk07/Visualising-Gradient-Descend
/futils.py
2,623
4.1875
4
import numpy as np import matplotlib.pyplot as plt import math def derivative(x): '''This function computes the numerical value of the derivative of the cost function. Args: X (float) : Derivative function input value Returns: yhat (float) : The value of the derivative function '...
true
ca225b4ade3ef5031882eaac82407b823a65fe5d
quanyuexie/pythonProject8
/sorts_count.py
1,421
4.3125
4
# Author: Quanyue Xie # Date: 10/21/2020 # Description: count the number of change and compare in #bubble sort and insertion sort, and think the difference between #different kind of list #if the numbers in the list are almost sequential #the change number will be smaller, but the compare number will be the same a_l...
true
9adec7548d08c0d0697e357cb905ff24ccaf011c
DanieledG/ETH_Subjects
/MaturaArbeit/Decrypter.py
1,262
4.3125
4
#our password password = input("Choose a password, use only letters: ") #the text we want to decrypt cipherText = input("Enter the text you want to decrypt: ") #the alphabet we are going to use alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] #an empty...
true
7eb6fbd0616136a7446b7e0fb3e91c0cee84f3e4
mnishiguchi/python_notebook
/MIT6001x/week3/iterativePower_1.py
715
4.40625
4
# -*- coding: utf-8 -*- # calculates the exponential baseexp by simply using successive multiplication. # should compute base**exp by multiplying base times itself exp times # Your code must be iterative - use of the ** operator is not allowed. # take in two values - base can be a float or an integer; # ...
true
7768db3184fcb6e2253aa8da21bd8f919109c957
mnishiguchi/python_notebook
/MIT6001x/week2/pset1_longestSubstring.py
742
4.25
4
''' Assume s is a string of lower case characters. Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl', then your program should print Longest substring in alphabetical order is: beggh ''' s = raw_input('Type a string...
true
bd7a0fb7e0aea394b6d72abecb976ff53e8ec15e
mnishiguchi/python_notebook
/MIT6001x/week5/swapSort.py
1,444
4.15625
4
import random def swapSort(L): """ L is a list on integers """ print "Original L: ", L ctr = 0 # iterate L[0] through L[-1] for i in range( len(L) ): # prove the sub-list for the smaller int for j in range( i+1, len(L) ): # everytime sm...
true
7897e59325cda32b890fd19f430c0753fb4f4305
mnishiguchi/python_notebook
/MIT6001x/week2/pset2-2_ok.py
1,814
4.21875
4
# -*- coding: utf-8 -*- ''' Pset2 PROBLEM 2: PAYING DEBT OFF IN A YEAR (15 points possible) calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months. By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constan...
true
24307b45111157f390a27b6a9d13b3dbd2792645
mnishiguchi/python_notebook
/MIT6001x/week6/PSet6/applyCoder_test.py
1,436
4.25
4
import string # # Problem 1: Encryption # def buildCoder(shift): """ Returns a dict that can apply a Caesar cipher to a letter. The cipher is defined by the shift value. Ignores non-letter characters like punctuation, numbers and spaces. shift: 0 <= int < 26 returns: dict """ ...
true
adcdfd298b99f77ea5dbfc5d13d9c9126fd5c3ed
mnishiguchi/python_notebook
/MIT6001x/week2/bineryConverter.py
529
4.15625
4
# binaryConverter.py n = int(raw_input('Enter an integer: ')) # remember positive or negative if n < 0: isNeg = True n = abs(n) else: isNeg = False # storage of result, initialize as empty str result = '' # if 0, binary is 0 also if n == 0: result = '0' # calculate binary from 2**...
true
8d736b54c1af8058461e4a4abb4aed821b9971b6
Hisquare/Database-user-input
/userDbInput.py
2,711
4.40625
4
# TO ALLOW A USER ENTER DATA INTO A DATABASE WHILE THE CODE IS RUNNING. print('DATABASE TO RECIEVE WEEKLY TEMPERATURE DATA AND COMPUTE THEIR AVERAGE! ') a1 = input("enter date: ") a = int(input("enter temperature on day 1: ")) b1 = input("enter date: ") b = int(input("enter temperature on day 2: ")) c1 = input("e...
true
135a0840a43ca56a6a077792285d2fe39ec0ce83
shirwani/WebDevelopment
/Python/Section_1_Basic/Ex2_strings.py
701
4.5
4
#!/usr/bin/python print "Hello World" print "Hello " + "World" world = "World" print "Hello " + world print "Hello %s" % world name = "Bob" print "Hello " + world + ". My name is " + name + ". Hello " + name + "!" print "Hello %s. My name is %s. Hello %s!" % (world, name, name) str = 'Hello World!' print "########...
true
be7c7ac9ee9fd436bb143ed7ad5ae738ac5c054b
zosman1/learnpython
/p10.py
327
4.1875
4
#Welcome to Problem 10 #lines with a # in front of it are comments, they will be ignored by python #What does the following code output / what does it print? # With this problem we begin with the concept of loops # Lets start with the while loop counter = 0 while counter < 10: print(counter) counter = count...
true
c86f43ce872258bea4b4a86b9815b15bf752927d
The-Anonymous-pro/projects
/week 1 assignment/Assingment.py
1,027
4.40625
4
#!/usr/bin/env python # coding: utf-8 # ## ASSIGNMENT # # **Tomiwa Emmanuel O. Am a python programmer and this script will be solving quadratic equations**. A quadratic equation form is: **(ax² + bx + c = 0)** which is solved using a quadratic formular: **(-b +- √(b²-4ac))/2a** where a, b, c are numbers and **a**...
true
654c01c44d8a543dc60431ba09e723a3f5ae72e8
angamndiyata/Data-Science-
/compTask1.py
1,950
4.25
4
#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np # In[13]: #Why doesn’t #np.array((1, 0, 0), (0, 1, 0), (0, 0, 1,dtype=float) #create a two dimensional array? Write it the correct way. #Answer : The list for each row array is missing, matrix [] brackets mising for matrix array and the datatyp...
true
79a4539019cb728195ad92b030fc3dbe6335cacf
xavrb/numericalmethods
/Newton R/nr.py
1,309
4.21875
4
# Newton-Raphson method, a simple implementation import math from random import randint #f(x) - the function of the polynomial def f(x): function = (x*x) - (2*x) - 1 return function def derivative(x): #function to find the derivative of the polynomial h = 0.000001 derivative = (f(x + h) - f(x)) / h ...
true
51a86765d26f71463fce2ee6e805d3ff2d491008
Narvienn/MyPythonSandbox
/PracticePythonEx8_new.py
2,132
4.125
4
"""Make a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game) Remember the rules: - Rock beats scissors - Scissors beats paper - Paper beats rock""" import sys print("Welco...
true
829984ff431b046fa6a5a152d53cb68f0bf1a734
santosh449/Rock-Paper-Scissors-cod
/ROCK-PAPER+SCISSORS.py
2,910
4.28125
4
import random # Random Package from the library # Combinations of Inputs user_input = input("Enter either 'Rock', 'Paper', 'Scissor', 'Lizard', or 'Spock': ") print("You entered : ", user_input) possible_options = ['Rock', 'Paper', 'scissor', 'Lizard', 'Spock'] # Enter the code for Computer Input computer_i...
true
ff3496fef2a28cc981192ac559deb663c39ecfa3
mccornet/leetcode_challenges
/Python/0088.py
1,909
4.125
4
""" # 88. Merge Sorted Array - https://leetcode.com/problems/merge-sorted-array/ - Classification: Array, Two Pointers ## Challenge You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respect...
true
007b1267119578812e8589c587c9a891c38edaa2
constancedongg/Analysis_of_Algorithm
/graph/bfs_shortest_path.py
1,220
4.21875
4
''' Application: - Find people at a given distance from a person in social networks. - Identify all neighbour locations in GPS systems. - Search whether there is a path between two nodes of a graph and shortest path. Time complexity: exponential Space complexity: even worse, needs high memory ''' def bfs_shortest_pa...
true
90269575ecef57a9e5d6c82365231487340977d5
LiYChristopher/chris_rmotr
/week2_solo/dict_comphrension.py
898
4.15625
4
""" Write a function that receives a list and returns a dictionary with the elements initialized with the value 0. You MUST use dict comprehensions. Example: init_dict(['a', 'b', 'c']) # {'a': 0, 'b': 0, 'c': 0} """ def init_dict(a_list): return { i : 0 for i in a_list } if __name__ == '__main__': impor...
true
34a4686e520dfa72d21901a042965fcc9d18b9ab
amirarfan/INF200-2019-Exercises
/src/amir_arfan_ex/ex01/tidy_code.py
1,622
4.28125
4
from random import randint __author__ = "Amir Arfan" __email__ = "amar@nmbu.no" def randomnumgen(): """ A function which generates a random number with the sum of two numbers between 1 and 6 """ return randint(1, 6) + randint( 1, 6 ) # Used randint for clarity, as randint refers to rand...
true
8b30aa13655f35efc8e9a7275f335f086263f080
Gmiller290488/Programming-challenges
/Plus Minus or zero.py
556
4.15625
4
# Given an array of integers, calculate which fraction of its elements are positive, # which fraction of its elements are negative, and which fraction of its elements are zeroes, # respectively. # Print the decimal value of each fraction on a new line. positive = negative = zero = 0 n = int(input().strip()) arr = [in...
true
92a277a2281f82bf696d4b58ec5855409affb505
Divine11/InterviewBit
/Tree data structure/Valid_BST.py
1,269
4.3125
4
# Given a binary tree, determine if it is a valid binary search tree (BST). # Assume a BST is defined as follows: # The left subtree of a node contains only nodes with keys less than the node’s key. # The right subtree of a node contains only nodes with keys greater than the node’s key. # Both the left and right subt...
true
ceacd4c8afdcc1de7a3062fadce42346fe2b962a
Divine11/InterviewBit
/Tree data structure/Flatten_Binary_Tree_To_Linked_List.py
1,926
4.125
4
# Given a binary tree, flatten it to a linked list in-place. # Example : # Given # 1 # / \ # 2 5 # / \ \ # 3 4 6 # The flattened tree should look like: # 1 # \ # 2 # \ # 3 # \ # 4 # \ # 5 # \ # ...
true
aa0d85a5f743e69c34531ca22ce93ef424e1e612
Divine11/InterviewBit
/Stacks And Queues/Generate_All_Parentheses.py
841
4.125
4
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. # The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not. # Return 0 / 1 ( 0 for false, 1 for true ) for this problem def isValid(A): opening...
true
98fddce213b302c16acf32500065cbf5770ac820
jangui/archive
/Python-Scripts/circle.py
361
4.375
4
import math import turtle def drawCircle(x, y, r): """"Draws a cirlce using the turtle module""" #move to start of circle turtle.up() turtle.setpos(x + r, y) turtle.down() #draw the circle for i in range(0, 365, 5): a = math.radians(i) turtle.setpos(x + r*math.cos(a), y + r*math.sin(a)) dra...
true
a82c70a453682d9d8ed3aee73ed7b42fa042cb8b
fanbyprinciple/pymaths
/doing_math_with_python/chapter2/gravitational_formula.py
830
4.125
4
''' The relationship between gravitational force and distance between two bodies ''' import matplotlib.pyplot as plt from pylab import savefig # Draw the graph def draw_graph(x,y): plt.plot(x, y, marker='o') plt.xlabel('Distance in meters.') plt.ylabel('Gravitational force in Newton.') plt.title('Gra...
true
1731d8cdfed7335e7387e48ff9e4a64eb24b61f8
MiguelBalderrama/lab10
/70-100pt.py
1,483
4.4375
4
########################################## # # # Draw a house! # # # ########################################## # Use create_line(), create_rectangle() and create_oval() to make a # drawing of a house using the tKin...
true
69605eded459aa40bfdc8648549ba030fd809184
shahidcaan/AnimatedMovies
/src/Task2.py
803
4.3125
4
""" Task 2a Write a modified version of function readAllRecords() to read all the records from the file and return the records as a Python list. """ def readAllRecords(): file = open("MoviesData.txt", "r") allMovies = file.readlines() file.close() return allMovies """ Task 2b Write another funct...
true
7771b3a895ed8272bebe233aa9a7259d0a55d585
loingo95/leetcode
/symmetric-tree/symmetric-tree.py
942
4.125
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def isSymmetric(self, root: TreeNode) -> bool: return self.compare(root.left, root.right) ...
true
9bdbcd076778f3763ba80572ce2bf228e315f837
Koro6ok/CURSOR_HW
/HW2/1+1a.py
2,220
4.125
4
# 1. Create a class hierarchy of animals with at least 5 animals that have additional methods each, # create an instance for each of the animal and call the unique method for it. # Determine if each of the animal is an instance of the Animals class class Animal: def __init__(self, name): self.name = name ...
true
f101db7fe9fd9e8fde69ec4d1878d6a0676e24d3
pbeens/Challenges
/_in progress/Reddit Wandering Fingers/Wandering Fingers.py
2,240
4.28125
4
''' From https://goo.gl/s3VJAN Description Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter. Example image of Swype: http://www.swype.com/content/uploads/2014/09/swype_path.png You'll be given a string of charact...
true
3598b3a190968675d0ad57934d75d2a60bf40d53
Steelex/CSE
/Hangman - Steelex Garcia Period 3.py
1,552
4.21875
4
import random import string # Steelex Garcia # Period 3 """ A general guide for Hangman 1. Make a word bank - 10 items 2. Pick a random word from the item from the list 3. Add a guess to the list of letters guessed 4. Reveal letters already guessed 5. Create the win condition """ word_bank = ["monster", "metal", "fear"...
true
1ad3b19b27a9c0fc0a2b71475fe98afdc08638d1
moogzy/learnpythonthehardway
/ex3.py
1,038
4.5
4
#!/usr/bin/python # Prints statement for counting chickens print "I will now count my chickens:" # Addition then divisions for hens print "Hens", 25.0 + 30.0 / 6.0 # Subtractions then multiplication then modulus(remainder) print "Roosters", 100.0 - 25.0 * 3.0 % 4.0 # Prints statement for counting eggs print "Now I ...
true
34993d094b41a5a4fc249b610a563561576d93c3
codymalick/practice
/python/sorting/merge_sort.py
1,669
4.1875
4
"""Merge sort is a divide and conquor algorithm that breaks an array into subarrays to sort. Runtime Complexity: Best: O(nlogn) Worst: O(nlogn) Average: O(nlogn) Space Complexity: O(n) """ import random def generate_array(): return [random.randint(0, 100) for x in range(50)] def merge_s...
true
d1396f03cd112f90bdd2fdc374a0d7bd8ea235cd
rozifa/mystuff
/ex21.py
1,354
4.34375
4
#Defines four basic functions that each take two arguments: a, b. #Each function prints a string formatted with each of the input arguments #Then returns a value. This returned value can be stored in variables #IT IS NOT PRINTED, it simply tells the function what its final output should #be. This has to be stored or pr...
true
b42e2047f24f03c2a0a8af664c85fb2dbf0b2ae4
charan2108/pythonprojectsNew
/lists/numericallists/range.py
690
4.125
4
#range for value in range(1, 10): print(value) #using number as variable numbers = list(range(1, 100)) print(numbers) #evennumber evennumber = list(range(2,20,2)) print(evennumber) #oddnumber oddnumber = list(range(1,25,2)) print(oddnumber) # Squarenumber squares = [] for value in range(1,14): square =...
true
c64cee9be624e7234096eb01fc7056671c0eb05e
nikhilagopathi/sample
/app.py
2,016
4.375
4
#print("Hello world") # taking inputs from terminal #Patient_name = input('What is your name') #Age= input('what is your age') #status= input('status') #print ( "Hello " + Patient_name + " is" +Age + " years old and " + status) #birth_year = input('what is your birth year') #Age = 2021 - int(birth_year) #print(Age) ...
true
cf7a4a97ac0024dc0801ff38eadfce286614c85f
raygolden/leetcode-python
/src/groupAnagram.py
855
4.15625
4
#!/usr/bin/env python # given a list of words, write a function which # takes in the list, and groups the words together # according to which ones are anagrams of eachother # e.g. # input = ["art", "rat", "bats", "banana", "stab", "tar"] # output = [["art", "rat", "tar], ["bats", "stab"], ["banana"]] def groupAnagra...
true
180a462489d2ab4d66a7af27f1aba5bd7e09ccbf
anushreesaha/python_training
/source/comments.py
1,766
4.25
4
""" This module is used to practice comments """ import argparse from util.logger import get_logger #logger = get_logger() c = """this module is used to""" #logger.info(c) d = "this is module is used " \ "to" #logger.info(d) # ====================== Block comment Example ===================== # The main funct...
true
8c6671912024336f95d0f7ac9aaa4c45f856c9b6
ofirn21-meet/meet2019y1lab3
/lab_3-greeting.py
267
4.1875
4
name=(input("what is your name?")) name=(name.capitalize()) print("your name is "+str(len(name))+" letters long") print("the first letter of your name is "+(name[0].upper())+" and the last letter is "+name[-1].upper()) print(name[1:-1]) print("hello there,"+name)
true
f7b48f5f9dd62b25d36a7dd736da78d68c92ce2d
danilo-souza/PPA2
/SplitTheTip.py
1,352
4.34375
4
def check_3decimal(number): #checking if the input has more than 3 decimal places. #if the input only has 2 decimal places then round(number, 3) = round(number, 2) if not (round(number, 3) == round(number, 2)): #taking off the extra decimal digits number = (round(number - 0.005, 2)) ...
true
ca458b86f2e635c9c456006d705626717581f5ad
noeljt/ComputerScience1
/hws/hw3/hw3_part2.py
1,969
4.21875
4
""" Determines whether there are enough legos or substitutes. Author: Joe Noel (noelj) """ def lego_count(legos): size = raw_input("What type of lego do you need? ==> ") print size amount = int(raw_input("How many pieces of this lego do you need? ==> ")) print amount if size == '1x1':...
true
c966e80891eac9cc7e81a436d1c5c099ee753bce
noeljt/ComputerScience1
/hws/hw2/hw2part3.py
1,352
4.5
4
""" A program to calculate area and print the coinciding rectangle made of asteriks. Author: Joe Noel (noelj) """ height = int(raw_input("Height==> ")) print height width = int(raw_input("Width==> ")) print width area = height * width def burger(height, width): bun = "*" * width meat = "*" + ...
true
6902d83a4ffde4a77f1abe9dffbb7d8f5b0c3cf2
LiChangNY/fun_projects
/pandigital_prime.py
2,557
4.15625
4
""" A shortcut to solve this problem is to limit the search results. If you run process(9) below, the kernel will for sure die because there are too many combinations to check, let alone iterating from process(1) to process(9). Hence, we can test if the sum of the digits is divisible by 3. If it is, no matter how y...
true
61f1067aaebb09ef406c6cf7482359eabc15bdd7
cupofjoey/UdemyPython1
/numInput.py
788
4.15625
4
#lets do a small program to see if a person can guess the magic number. They have 3 chances. magic_numbers = [3, 9] chances = 3 for i in range(chances): print("This is attempt {}".format(i)) user_number = int(input("Enter a number between 1 and 10: ")) if user_number in magic_numbers: print("You gu...
true
46cf81159474f5a7f11d186e63d84cad13d9aa08
cupofjoey/UdemyPython1
/lowestInt.py
363
4.125
4
import random #Random number generator, 1-10. Each time it logs lowest number and prints it. minimum = 100 for index in range(10): random_number = random.randint(0, 100) print("The number generated is {}".format(random_number)) if random_number <= minimum: minimum = random_number print("The lowes...
true
5d07d7024b7a41d8cb8e8d774ca16cd2abcf04de
samruddhichitnis02/machine_learning
/week2/program2.py
230
4.34375
4
"""Write a Python program to reverse the order of the items in the array. """ x=[ ] n=int(input('Enter the number of elements-')) for i in range(n): a=input('Enter the elements-') x.append(a) print(x) x.reverse() print(x)
true
a12eea58d985d04493860c3f05ce114692811a49
samruddhichitnis02/machine_learning
/week2/List/program2.py
320
4.125
4
"""Write a Python program to multiplies all the items in a list.""" x=[ ] n=int(input('Enter the number of elements-')) for i in range(n): a=int(input('Enter the elements-')) x.append(a) print(x) mul=1 for i in range(len(x)): mul=mul*x[i] print('The multiplication of all the elements of the list is-',mul)
true
08defb345ecc26c325e8303a1f0e79fc64af0078
nwthomas/Intro-Python-I
/src/13_file_io.py
998
4.21875
4
""" Python makes performing file I/O simple. Take a look at how to read and write to files here: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files """ # Open up the "foo.txt" file (which already exists) for reading # Print all the contents of the file, then close the file # YOUR CODE HER...
true
b4f5e366402472de7b3fad0447546dd64777e7a9
sprungknoedl/python-workshop
/2010/src/workshop1.py
1,563
4.40625
4
#!/usr/bin/python # This file contains some example solutions to exercises given during the first # python workshop. spelling and grammar mistakes are my present to you ;) import os def find_mail(arg): """ searches a string for e-mail addresses. returns a list. """ # to append to a list, the list mus...
true
e123f84ee35ccdc36f10be03f16326e8e3949ba6
ZakBrinlee/Python-CSC-110
/Adventure_Game_Start.py
1,536
4.21875
4
# North Seattle College, CSC 110 # Week 0 Programming Assignment # Author: Zak Brinlee # Email: zbrinlee@gmail.com # This program is the start of an adventure game using python # Currently taking in 4 character attributes and a starting day of the story # Using multiple variables in multiple places in the story # inp...
true
58df8ee5223a342ab463cc0ac55c5f0bda9e951d
vivsnguyen/LeetCode-May-Challenge-2020
/cousins_in_a_binary_tree.py
2,046
4.125
4
""" In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree...
true
b897ab2a5f27398836936ce96ad1edb6cf1aa852
learnmv/HackerrankProblems
/string_manipulation/alternating_characters.py
541
4.1875
4
# title : ALternating Charecters #given a string containing characters A nad B only # we have to change it into a string such that there # are no matching adjacent characters. we are allowed # to delete zero or more characters in the string. def alternating(a): previous = a[0] delete = 0 for i in a[1:]: ...
true
e6efe1d716c6ef79c89bb9b0f52bb9329c63d2cc
ruqaiyasattar/androidproject2017
/exersice_3.10.py
868
4.25
4
#3.10 print("\n Exercise 3.10") river=['indus','jhelum','chenab','sutlej','kabul'] print("\n"+str(river)) print("Length od list "+str(len(river))+"\n") river.reverse() print("value in reverse order:\n"+str(river)) river.reverse() print("\nhere is the original list \n"+str(river)) print("Here is the sor...
true
b4c4ec6a7449c71dbb0908a5a17a1a0264764491
ruqaiyasattar/androidproject2017
/example_3.4.py
2,361
4.4375
4
#example 3.4 print("Guest invitation example\n") invitation=['daniel','john','michele'] print("whole list is :"+str(invitation)) print("I would like to invite you Mr "+invitation[0]+" for dinner"+"\n"+"I would like to invite you Mr "+invitation[1]+" for dinner"+"\n"+"I would like to invite you Mr "+invitation[2]+...
true
79ac0ebfbd72fd24a79b85f060163294c29276b7
moranpatrick/python-fundamentals
/02-date_time.py
767
4.40625
4
# Problem 2 - Write a program that prints the current time and date to the console. # This program displays the current date and time on the console screen. # Author - Patrick Moran g00179039 import datetime # import required for data nad time # Variable to store the current date and time curr_date_and_time = dateti...
true
01f060aad86a4ca1b555a4eff0c58eae920c702a
Lost-vox/Official-TC-RPS
/RPS Game Python.py
2,007
4.21875
4
import random human = 0 computer = 0 name = input("What is your name?") print("Hello",name) def Game(): global human global computer print("Computer score:", computer) print("Your score:", human) choice = input("Okay " + name + " Please choose Rock, Paper, or Scissors ...
true
9339c9a7790feec91de21f061dc4c1eeaefd9fd5
gopinathPersonal/general-python-scripts-
/oop.py
585
4.28125
4
# OOP class MyCar: is_automatic = True # this is class obj attribute and its not dynamic def __init__(self, name, age): # constructor method of class called when creating an object if (self.is_automatic): # we can also write Mycar.is_automatic self.x = name # when obj is created, obj will create the attrib...
true
21569911949d77b7eafd0c21c0bd00d9866a27e1
naimadswdn/isapy9-Damian
/dzien_3/zad3.py
1,039
4.1875
4
# Number of level is linear function of # amount # i # # 0 1 # 1 3 # 2 5 # 3 7 # # y=ax+b # i=1/2#-1/2 # #=2i+1 def pyramid_draw(): """Script to draw a pyramid consist of #, with given height.""" from time import sleep from dzien_2.repeat_y_or_n import repeat_y_or_n from dzien_2.check_if_goo...
true
ed4864b5be3182f5cbfe09e31c2c564a2ce72e12
kamesh051/django_tutorial-master
/python/control/loop.py
1,154
4.28125
4
import random import math print "Welcome to Sam's Math Test" '''logic to print random numbers''' num1 = random.randint(1, 1000) num2 = random.randint(1, 1000) num3 = random.randint(1, 1000) list = [num1, num2, num3] maxNum = max(list) minNum = min(list) sqrtOne = math.sqrt(num1) correct= False while(correct == False):...
true
f9482b39fbe1972b87402e9666fcd8acd3e7eecd
darknesspaladin/alllllien
/python_work/人生阶段.py
276
4.3125
4
age=17 if age<2: print('he is a baby!') elif age>=2 and age<4: print('he is studing walk.') elif age>=4 and age<13: print('he is a adult') elif age>=13 and age<=20: print('he is a teenager') elif age>=20 and age<=65: print('he is a man') else: print('he is an oldman!!')
true
15d554d1ce4400d1adabfe3747e546848ccad13f
Mampson/Cp1404
/Prac_02/valueError.py
975
4.5
4
""" CP1404/CP5632 - Practical Answer the following questions: 1. When will a ValueError occur? 2. When will a ZeroDivisionError occur? 3. Could you change the code to avoid the possibility of a ZeroDivisionError? """ try: numerator = int(input("Enter the numerator: ")) denominator = int(input("Enter the denomin...
true
c3b08c65e9bbaf429fb954828e8be94685776514
Vikaslakkacs/Python-understanding
/inheritance.py
2,620
4.28125
4
''' Created on Oct 12, 2018 Inheritance: Meaning: Taking something from your ancestors or from your father's Inhertance Definition: You can inherit classes and their method into the class which you are creating and use their methods. when you create a method with the same name as that their in the inherited method ...
true
6dbfbb33c4bad064f6af416e725bc07987ac808f
Vikaslakkacs/Python-understanding
/Special_methods.py
1,113
4.53125
5
''' Created on Oct 12, 2018 Special methods are methods which are used like normal functions for an objcet Eg: For a list we have Append method and that we cannot use it for the class method. Special methods are used as methods of the objects. @author: LAVIKAS ''' class Book(): def __init__(self,name)...
true
74de0da708c7eb792dea15afb23713d9d71af520
khang-le/assignment-7
/ass7.py
815
4.3125
4
#!/usr/bin/env python3 # Created by: Khang Le # Created on: Dec 2019 # This program uses lists and rotation def rotation(list_of_number, ratating_time): numbers = list_of_number[0] numbers = [list_of_number[(i + ratating_time) % len(list_of_number)] for i, x in enumerate(list_of_number)] ...
true
32d66c76145b6482fae5f1a56701cccb496c1104
CodeTemplar99/learnPython
/Functions/default_and _optional_arguments.py
862
4.625
5
# functions have default parameters # this means that when ever a function is called it must have it's argument equal to the # number of parameters # example of default argument def increment(number, by): return number + by # when this is called the number of arguments must be equal to the number of parameter...
true
0be04f727842960ca7c0adf46c7dbc02bfbf3c66
CodeTemplar99/learnPython
/Fundamentals_of_programming/infinite_loop.py
713
4.25
4
# an infinite loop is an endless loop that will continue # infinite loops useful when they are managed well but they can cause major memory consumption if not properly managed # example of a command review built on infinite loop while True: command = input("Enter a command: ") print(">>>" + " " + command) ...
true
7bb0040c38361ab5d9ffc69e11478a49db594b87
CodeTemplar99/learnPython
/Functions/keyword_arguments.py
1,023
4.25
4
# an argument is a value passed when calling a function def increment(number, by): return number+by value = increment(2, 1) print(value) # the above code will return 3 # to simplify this it can be written as def increment2(number, by): return number + by # value2 = increment2(2, 2) print(increment2(2, ...
true
8019e7fedd6f7f9ef0028aba4c714dabbda81129
CodeTemplar99/learnPython
/Data_structures/generator.py
1,306
4.5
4
from sys import getsizeof values = (x * 2 for x in range(5000)) # 64 bytes print("gen:", getsizeof(values)) values = (x * 2 for x in range(500000)) # 64 bytes still print("gen:", getsizeof(values)) values = [x * 2 for x in range(500)] # 2,140 bytes in memory print("list:", getsizeof(values)) # * * * * * * * * * *...
true
0c8df849c660e282cc8c1a19dee176766b10dd7f
CodeTemplar99/learnPython
/Fundamentals_of_programming/loop.py
1,077
4.53125
5
# loops are used to perform an action repeatedly # printing a message thrice for number in range(3): print("attempt") print("\n") # printing a message thrice and addingthe count for number in range(3): print("attempt", number) print("\n") # printing a message thrice and adding a number to the count for num...
true
6e0be4d4001ed398176a92718ccac61411e7a4bd
annebell881/ENGR-102
/Lab3a_Act1_f.py
884
4.28125
4
# -*- coding: utf-8 -*- """ Created on Fri Sep 4 08:08:17 2020 @author: Anne """ # By submitting this assignment, I agree to the following: # "Aggies do not lie, cheat, or steal, or tolerate those who do." # "I have not given or received any unauthorized aid on this assignment." # # Name: Annema...
true
b2878ba11f69b77d2a0e8fb4c80808a6c8cf18c7
poturnak/Python_practice
/0_Basics/4_Strings_custom_formatting.py
1,286
4.75
5
#! /library/Frameworks/Python.framework/Versions/3.5/python3.5 # =================================================================================================== # +++++++++ String format +++++++++ # in the old python notation we used % with some parameters to generate custom strings # new python way is to use strin...
true
c2bfca2aa7bfedb2c3dd3b6ecff6a74622f8ce02
poturnak/Python_practice
/3_Machine_learning/1_Numpy/5_Broadcasting.py
773
4.15625
4
#! /library/Frameworks/Python.frameork/Versions/3.5/python3.5w # when we add/subtract the arrays of different shape, numpy needs to do the broadcasting # broadcasting is when you bring arrays to the same dimensions import numpy as np arr = np.tile(np.arange(0, 40, 10), (3, 1)) arr = arr.transpose() print(arr) # arr1...
true
69bd5e7ce93d2e960c18ffab9b835ddc42e36647
poturnak/Python_practice
/2_Modules/12_Time.py
758
4.34375
4
#! /library/Frameworks/Python.framework/Versions/3.5/python3.5 # =================================================================================================== # ______________________ Time module ______________________ # time.time() - get current time # - can be used to calculate how long the program ...
true
fb455f07ebb00df4a0eff0db3ecd281c60d3278f
poturnak/Python_practice
/3_Machine_learning/1_Numpy/10_choose_take.py
1,297
4.1875
4
#! /library/Frameworks/Python.framework/Versions/3.5/python3.5 # first you specify indices [n, n1, n2] # --number of indices need to be the same as the maximum length of the array # --all arrays are of the same length # --indices are as high as the number of arrays to choose from # choose takes 1st element from array ...
true
51dfe63a067297775c0e4cb8124b73364fe8512f
DouglasParnoff/learning-python
/src/basic/data_types.py
1,212
4.46875
4
# Integer and Float types print("--- INT AND FLOAT ---") x = 2 # x is an integer y = 3.5 # y is a float print('x: ', + x) print('y: ', + y) print(type(x)) x = float(x) print(type(x)) # you can see more about float here: https://docs.python.org/3/tutorial/floatingpoint.html #NEVER do this: # print(5/0) # Bool type p...
true
d56c3cf2bdafa308ec0e4fa971ec377bd43458bf
Yashs744/Python-Workshop-2018
/Lists.py
1,156
4.59375
5
# Lists ''' Resouce: - https://realpython.com/python-lists-tuples/ - https://www.programiz.com/python-programming/methods/list ''' squares = [1, 4, 8, 16, 25, 36, 49] print (squares) for sq in squares: print (sq) # Append Method squares.append(64) squares.append(81) # Insert Method # ...
true
44cf5edade16397337809a8023048212ed6f57bd
ebinej97/Luminarpython
/functionalprogramming/mapFliter.py
478
4.15625
4
#map / filter # map is used to apply to all values # filter is used to apply to or filter out particular values lst=[10,20,30,40,50] # def square(num1): # return(num1**2) sqlst=list(map(lambda num1:num1**2,lst)) print(sqlst) cube=list(map(lambda num1:num1**3,lst)) print(cube) #print even no in a lsit lst=[10...
true
1a78eb3ca273b232f3eaa84076f438bfa3d70a48
Samyam412/lab_exercise
/lab exercise 1/question 5.py
1,299
4.25
4
""" A school decided to replace the desks in three classrooms. Each desk sits two students. Given the number of students in each class, print the smallest possible number of desks that can be purchased. The program should read three integers: the number of students in each of the three classes, a, b and c respectively....
true
a326f714fbb95f48217bcf7a556a9c574f9034db
RakValery/exadel-python-course-2021
/tasks/task02/Area_of_a_triangle.py
2,466
4.40625
4
# main menu import math print("\nWelcome to the triangle area calculation tool.") while True: print("\nMenu:","1. Calculate triangle area by base and height","2. Calculate triangle area by 2 sides and angle between them","3. Exit", sep = "\n") mitem = input("Enter menu item number: ") if mitem == "1": ...
true
13e42747c2fb0aaa3f2420bca6ba69065f5b9897
Naimul-Islam-Siam/Practice
/Python/1. new.py
630
4.1875
4
name = input("What is your name?") #scanf print("My name is " + name) print(bin(5)) #binary of 5 print(int("0b101", 2)) #first argument is a base 2 number, convert it to an int print(type(str(5))) #5 will be converted to str, then the type will be a string print(2 ** 3) #same as 2^3 a,b,c = 1,2,3 print(a) #1 print...
true
0eca9f2b4ba12c1e970ebdf42e360fa056782874
mgupte7/python-examples1
/pyFunctionEx.py
743
4.40625
4
# ----------------------------------------------- # ----------------Python Booleans---------------- # ----------------------------------------------- # ex1 a = 200 b = 33 if b > a: print("b is greater than a") else: print("b is not greater than a") # ex 2 - can evaluate any value using bool print(bool("Hello"))...
true
f3e80ed42c8d2a56a56475a7113268af47553a96
d80b2t/python
/bootcamp/age.py
764
4.21875
4
""" PYTHON BOOT CAMP BREAKOUT3 SOLUTION; created by Josh Bloom at UC Berkeley, 2012 (ucbpythonclass+bootcamp@gmail.com) """ import datetime born = datetime.datetime(1974,1,1,13,2,2) now = datetime.datetime.now() # note... .utcnow() gives the universal time, .now() # gi...
true
daccc2ee8168191bbde866527da51bd23a535154
brandann/GarbageCode
/PYTHON/Examples/first_class.py
487
4.21875
4
class Point: 'Represents a point in two-dimensional geometric coordinates' def __init__(self, x=1, y=3): '''Initilies the position of...''' self.move(x, y) def move(self, x, y): "Move the point to a new location in 2D space." self.x = x self.y = y def reset(self): """Resets the points to 0,0""" self.m...
true
7e7cf2311d1334f7a81ada6dd686b966e2ed484a
nidhinp/Anand-Chapter3
/problem7.py
659
4.28125
4
""" Write a function make_slug that takes a name converts it into a slug. A slug is a string where spaces and special charactes are replaces by a hyphen, typically used to create blog post URL from post title. It should also make sure there are no more than one hyphen in any place and there are no hyp...
true
f9791bed2c7d8f1c61c0490161549f113359926e
liugenghao/pythonstudy
/class/inheritPrac.py
2,464
4.1875
4
class School: def __init__(self,name,address): self.name = name self.address = address self.students = [] self.teachers = [] def enroll(self,obj): self.students.append(obj) print("为%s办理入校手续" %obj.name) def hire(self,obj): self.teachers.append(obj) ...
true
6cc30f2f71b11cfb74e224d02263b30616440df4
DaniVasq/holbertonschool-higher_level_programming
/0x06-python-classes/2-square.py
463
4.125
4
#!/usr/bin/python3 class Square: """class Square""" def __init__(self, size=0): """init size as zero, an int""" self.__size = size """assigning size as a private instance attribute""" if not isinstance(size, int): """if not of type int, then...""" raise Ty...
true
75e1875d123f37227aecd398b895d01ecd8a53ac
SlawomirMiszkurka/Zadania-2
/Zad 14.py
329
4.53125
5
##### # Calculation of the area and circumference of a circle ## # determine radius and PI radius= 5 PI= 3.14 # calculate area area=PI*radius**2 # calculate circumference circumference= PI*radius*2 # display results print(f'"When radius is {radius} area equals {area} and circumference equals {circumfere...
true
f85ab90e37619328b8b65fe3583bf46d42d03f09
chimel3/stormbowl
/fixtures.py
2,666
4.15625
4
import config import random def create_fixture_list(): ''' ABOUT: Uses the circle algorithm to produce a round-robin style fixture list. ''' ''' IDEAS: ''' print("starting create_fixture_list") # Create a new list to hold the clubs. Whilst I could just use the list of club...
true
21f7bda2d4ba911344f137e0d548234a4a549b1f
nicholsl/PythonProjects
/higher1.py
1,843
4.3125
4
'''higher1.py Jed Yang, 2016-11-10 We have seen how to use map, filter, and functools.reduce to process lists. But these methods do not seem to save a lot of coding, if we have to write a helper function each time to use them. There must be a better way. ''' # Here is the sum-of-ints example using 'redu...
true
d8b916b65c65277c1da54b68ca2b2090b7cc57e3
2019zding/Python
/queue.py
681
4.21875
4
class Queue(): # initialization def __init__(self): self.items = [] # enqueue, which means adding an item to a queue def enqueue(self, items): return self.items.insert(0, items) # dequeue, which means removing an item from a queue def dequeue(self): return self.items.p...
true
3871b9f00a64fede68646972e686281a0e48d7c5
Anandkumarasamy/Python
/demo_list3.py
218
4.125
4
#Write a Python program to get the difference between the two lists. list1=[1,3,5,7,9] list2=[1,2,4,6,7,8] list3=list(set(list1+list2)) for num in list1: if num in list2: list3.remove(num) print(list3)
true
50a0b77c4ad3ab29283826d2a17de365c18ad5fa
Anandkumarasamy/Python
/demo_list8.py
399
4.125
4
#30 Write a Python program to get the frequency of the elements in a list. list1=[10,10,10,10,20,20,20,20,40,40,50,50,30] dic={} for num in list1: if num in dic: dic[num]=dic[num]+1 else: dic[num]=1 print('the frequency of the elements:',dic) list2=[] for key,value in dic.items(): for iterat...
true
6f8213f2accd85b86e89dda2d72130e65c1b41be
Murthidn/my-python
/Notes/Basic/9-Range.py
273
4.15625
4
r=range(5) for i in r: print(i) #like size, print 0 - 4 #we can specify start point also print('--') r=range(2,6) for i in r: print(i) #prints from 2 - 5, last elem ignored #you can also pass step value print('-------') r=range(2,8,2) for i in r: print(i)
true
9d40d060c1f6fc76f44a3827f3ef95060ade33d5
maggieee/code-challenges
/reverse_keep_order.py
1,237
4.34375
4
"""In this challenge, you need to reverse a string, keeping the word themselves in order, and preserving exact spacing. For example, for the string: " hello_kitty " This should produce: " kitty hello " (Note that we keep the 3 spaces before hello, the two spaces between “hello” and “kitty," and the space afte...
true