blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
637c98c17ed65d72a4538fb19958ed10198a017b
onkcharkupalli1051/pyprograms
/ds_nptel/test 2/5.py
676
4.28125
4
""" A positive integer n is a sum of three squares if n = i2 + j2 + k2 for integers i,j,k such that i ≥ 1, j ≥ 1 and k ≥ 1. For instance, 29 is a sum of three squares because 10 = 22 + 32 + 42, and so is 6 (12 + 12 + 22). On the other hand, 16 and 20 are not sums of three squares. Write a Python function sumof3squares...
true
812dde47bf82dde83275c5a6e5c445ef6a0171ab
onkcharkupalli1051/pyprograms
/ds_nptel/NPTEL_DATA_STRUCTURES_TEST_1/ques4.py
580
4.34375
4
""" Question 4 A list is a non-decreasing if each element is at least as big as the preceding one. For instance [], [7], [8,8,11] and [3,19,44,44,63,89] are non-decreasing, while [3,18,4] and [23,14,3,14,3,23] are not. Here is a recursive function to check if a list is non-decreasing. You have to fill in the missing ar...
true
62edb5acaf0f4806e84966e822083a39cdf66805
YhHoo/Python-Tutorials
/enumerate.py
477
4.125
4
''' THIS IS enumerate examples**** it allows us to loop over something and have an automatic counter ''' c = ['banana', 'apple', 'pear', 'orange'] for index, item in enumerate(c, 2): # '2' tell the enumerate to start counting from 2 print(index, item) ''' [CONSOLE] 2 banana 3 apple 4 pear 5 orange ''' c = ['...
true
1dd0e6d8e73c6dbd174227baf893ad6695f56dab
thisguyisbarry/Uni-Programming
/Year 2/Python/labtest2.py
2,048
4.5
4
import math class Vector3D(object): """Vector with 3 coordinates""" def __init__(self, x, y, z): """Takes in coordinates for a 3d vector""" self.x = x self.y = y self.z = z self.magnitude = 0 def __add__(self, v2): """Adds two 3D vectors (x+a, ...
true
30e68edadbaba888f4e0c6b4f04e074a43051738
The-Blue-Wizard/Miscellany
/easter.py
627
4.40625
4
#!/bin/python # Python program to calculate Easter date for a given year. # This program was translated from an *ancient* BASIC program # taken from a certain black papercover book course on BASIC # programming whose title totally escapes me, as that was # during my high school time. Obviously placed in public # domai...
true
132c7a205f2f0d2926e539c172223fb505a0f2c1
L-ByDo/OneDayOneAlgo
/Algorithms/Searching_Algorithms/Binary Search/SquareOfNumber.py
1,338
4.25
4
#Find the square of a given number in a sorted array. If present, Return Yes with the index of element's index #Else return No #Program using Recursive Binary Search #Returns True for Yes and False for No def BinarySearch(arr, left, right, NumSquare): #check for preventing infinite recursive loop if right >=...
true
94e17585ee5d0fc214dea1cbc886bd8fa33af30e
EmreCenk/Breaking_Polygons
/Mathematical_Functions/coordinates.py
2,277
4.5
4
from math import cos,sin,radians,degrees,sqrt,atan2 def cartesian(r,theta,tuple_new_origin=(0,0)): """Converts height given polar coordinate r,theta into height coordinate on the cartesian plane (x,y). We use polar coordinates to make the rotation mechanics easier. This function also converts theta into ra...
true
893fff12d545faa410309b4b2b087305e6ad99cc
AxiomDaniel/boneyard
/algorithms-and-data-structures/sorting_algorithms/insertion_sort.py
1,596
4.59375
5
#!/usr/bin/env python3 def insertion_sort(a_list): """ Sorts a list of integers/floats using insertion sort Complexity: O(N^2) Args: a_list (list[int/float]): List to be sorted Returns: None """ for k in range(1, len(a_list)): for i in range(k - 1, -1, -1): ...
true
deb7f660c0f607492dbbcd59c71936876c893b35
Erik-D-Mueller/Python-Neural-Network-Playground
/Version1point0/initial.py
1,363
4.3125
4
# 02-12-2020 # following along to a video showing how to implement simple neural network # this is a perceptron, meaning it has only one layer import numpy as np # sigmoid function is used to normalize, negatives values return a value below 1/2 and approaching zero, positive values return above 1/2 and approaching 1...
true
1326800eed0a49d19b8e959f7d58e2e65195963a
ImtiazMalek/PythonTasks
/input.py
215
4.375
4
name=input("Enter your name: ")#user will inter name and comment age=input("Enter your age: ")#and we are saving it under various variables print("Hello "+name+", you are "+age+" years old")#it'll print the result
true
45e52f554eee3a9c1153ab1fe29bedac254891a3
sitati-elsis/teaching-python-demo
/inheritance.py
760
4.1875
4
class Parent(): def __init__(self,last_name,eye_color): print ("Parent constructor called") self.last_name = last_name self.eye_color = eye_color def show_info(self): print "%s %s" %(self.last_name,self.eye_color) billy_cyrus = Parent("Cyrus","blue") billy_cyrus.show_info() class Child(Parent): def __ini...
true
2245c07a64384e77a44b9540fcd551f245492289
ShimaSama/Python
/email.py
344
4.3125
4
#program to know if the email format is correct or not email=input("Introduce an email address: ") count=email.count('@') count2=email.count('.') end=email.rfind('@') #final start=email.find("@") if(count!=1 or count2<1 or end==(len(email)-1) or start==0): print("Wrong email address") else: print(...
true
5fc28ab298c14b482825b23bb6320ca32e50b514
sudiptasharif/python
/python_crash_course/chapter9/fraction.py
1,763
4.4375
4
class Fraction(object): """ A number represented as a fraction """ def __init__(self, num, denom): """ :param num: integer numerator :param denom: integer denominator """ assert type(num) == int and type(denom) == int, "ints not used" self.num = num ...
true
253e80b1f9ae499d49eb0d79c34b821e0c8dfb6d
waditya/HackerRank_Linked_List
/09_Merge_Sorted_LinkList.py
2,952
4.28125
4
""" Merge two linked lists head could be None as well for empty list Node is defined as class Node(object): def __init__(self, data=None, next_node=None): self.data = data self.next = next_node return back the head of the linked list in the below method. """ def MergeLists(headA, headB): ...
true
6647f2a03e8d08ca8807c5dad2c2a0694d264713
SethGoss/notes1
/notes1.py
363
4.28125
4
# this is a comment, use them vary often print(4 + 6) # addition print(-4 -5) #subtraction print(6 * 3) #multiplication print(8 / 3) #division print(3 ** 3) #exponents - 3 to the 3rd power print(10 % 3) #modulo gives the remainder print(15%5) print(9%4) # to make variable, think of a name name = input("Wh...
true
c8af7a794f8074f9c803cd7ebb61ae00b509f475
Frigus27/Structure-Iced
/iced/game_object.py
2,130
4.1875
4
""" game_object.py -------------- The implement of the objects in the game. The game object is the minimum unit to define a interactive object in a game, e.g. a block, a road, a character, etc. In Structure Iced, you can easily define an object by simply inherit the class game_object. A game object requires the argum...
true
c28d9ede48b5c683d129d8f18c93f823fe72be38
artsyanka/October2016Test1
/centralLimitTheorem-Outcomes-Lesson16.py
1,088
4.125
4
#Write a function flip that simulates flipping n fair coins. #It should return a list representing the result of each flip as a 1 or 0 #To generate randomness, you can use the function random.random() to get #a number between 0 or 1. Checking if it's less than 0.5 can help your #transform it to be 0 or 1 import rand...
true
b579e7e4c50ed64154b48830b5d7e6b22c21dd64
Rogerd97/mintic_class_examples
/P27/13-05-2021/ATM.py
934
4.125
4
# https://www.codechef.com/problems/HS08TEST # Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction # if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction # (including bank charges). For each successful withdrawal the ...
true
5ff84a677d4a9595a5d05185a7b0aecacea9e3dd
Rogerd97/mintic_class_examples
/P62/12-05-2021/if_else_2.py
1,325
4.34375
4
# Write a program that asks for the user for the month number # your script should convert the number to the month's name and prints it # Solution 1 # month_number = input("Insert a month number: ") # month_number = int(month_number) # months = {"1": "enero", "2": "febrero", "3": "marzo"} # if month_number < 1 or m...
true
3b41d3051d166653385c7072bab3f1fc7bb3e462
Rogerd97/mintic_class_examples
/P62/26-05-2021/exercise_1.py
540
4.46875
4
# Write a Python script to display the various Date Time formats # a) Current date and time # b) Current year # c) Month of year # d) Week number of the year # e) Weekday of the week # f) Day of year # g) Day of the month # h) Day of week import datetime def print_dates(): date = datetime.datetime.now() print...
true
9d386d7dece46d9e947ae02c509e0ff10fa08be5
levi-fivecoat/Learn
/datatypes/strings.py
473
4.28125
4
my_str = "This is a string." my_str_2 = "I am a strings. I can contain numbers 12345" my_str_3 = "1390840938095" username = "levi : " # YOU CAN ADD STRINGS my_str = username + my_str my_str_2 = username + my_str_2 # YOU CAN SEE WHAT KIND OF DATA TYPE BY USING TYPE() print(type(my_str)) # UPPERCASES STRING my_str ...
true
aa878f2bfc544a6ffdb642d6279faba0addc552c
Juxhen/Data14Python
/Introduction/hello_variables.py
1,333
4.25
4
# a = 5 # b = 2 # c = "Hello!" # d = 0.25 # e = True # f = [1,2,3] # g = (1,2,3) # h = {1,2,3} # # print(a) # print(b) # print(c) # # # How to find the type of variables # print(type(a)) # print(type(b)) # print(type(c)) # print(type(d)) # print(type(e)) # print(type(f)) # print(type(g)) # print(type(h)) # CTRL + / To ...
true
c4b2d02cb02ff875450fc56f1b839cab49b85af6
SDBranka/A_Basic_PyGame_Program
/hello_game.py
718
4.15625
4
#Import and initialize Pygame library import pygame pygame.init() #set up your display window screen = pygame.display.set_mode((500,500)) #set up a game loop running = True while running: # did user click the window close button? for event in pygame.event.get(): if event.type == pygame.QUIT: ...
true
fc89779a2cf480512ac48b7a21c5d344a30e56d6
Seanie96/ProjectEuler
/python/src/Problem_4.py
1,154
4.34375
4
""" solution to problem 4 """ NUM = 998001.0 def main(): """ main function """ starting_num = NUM while starting_num > 0.0: num = int(starting_num) if palindrome(num): print "palindrome: " + str(num) if two_factors(num): print "largest number: " + str...
true
95eb8f40f40eed4eebfa1e13dcb0117b80cb6832
mamare-matc/Intro_to_pyhton2021
/week3_strings.py
1,347
4.5
4
#!/usr/bin/python3 #week 3 srting formating assignment varRed = "Red" varGreen = "Green" varBlue = "Blue" varName = "Timmy" varLoot = 10.4516295 # 1 print a formatted version of varName print(f"'Hello {varName}") # 2 print multiple strings connecting with hyphon print(f"'{varRed}-{varGreen}-{varBlue}'") # 3 print...
true
cd21e893b48d106b791d822b6fded66542924661
a12590/LeetCode_My
/100-149/link_preoder(stack)_flatten.py
1,798
4.1875
4
#!/usr/bin/python # _*_ coding: utf-8 _*_ """ 非递归先序遍历,注意rtype void要求 """ # 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 flatten(self, root): """ :type root:...
true
9f12786f688abb908c333b2249be6fb18bdcd1d6
keyurbsq/Consultadd
/Additional Task/ex6.py
258
4.4375
4
#Write a program in Python to iterate through the string “hello my name is abcde” and print the #string which is having an even length. k = 'hello my name is abcde' p = k.split(" ") print(p) for i in p: if len(i) % 2 == 0: print(i)
true
d63d46c893052f76ea6f0906dd7166af5793a27b
keyurbsq/Consultadd
/Additional Task/ex4.py
245
4.3125
4
#Write a program in Python to iterate through the list of numbers in the range of 1,100 and print #the number which is divisible by 3 and is a multiple of 2. a = range(1, 101) for i in a: if i%3 == 0 and i%2==0: print(i)
true
da83ffdd1873d70f4f5321c09c0a3ff1fb1ffc85
r0meroh/CSE_CLUB_cpp_to_python_workshop
/people_main.py
1,580
4.25
4
from person import * from worker import * import functions as fun def main(): # create list of both types of objects people = [] workers = [] # prompt user answer = input("adding a Person, worker? Or type exit to stop\n") answer = answer.upper() while answer != 'EXIT': # if an...
true
e0058dfbb608836b24d131f6c92cabc1c551ad68
rjraiyani/Repository2
/larger_number.py
272
4.125
4
number1 = int(input('Please enter a number ' )) number2 = int(input('Please enter another number ' )) if number1 > number2: print('The first number is larger.') elif number1 < number2: print('The second number is larger.') else: print('The two numbers are equal.' )
true
edd5cf21f14675cf6a4af3d6f20a082bd48ab1ae
davidlkang/foundations_code
/shopping_list.py
1,423
4.125
4
def show_help(): print(""" Type 'HELP' for this help. Type 'CLEAR' to clear your list. Type 'DEL X' where 'X' is the number of the element you want to remove. Type 'SHOW' to display your list. Type 'DONE' to stop adding items. """) def add_to_list(user_input): shopping_list.append(user_input.lower()) prin...
true
7ca179a45c2136eb638a635b700909482a5376fb
davidlkang/foundations_code
/login_app.py
1,277
4.25
4
users = { "user1" : "password1", "user2" : "password2", "user3" : "password3"} def accept_login(users, username, password): if username in users: if password == users[username]: return True return False def login(): while True: if input("Do you want to sign in?\n(...
true
f02e6f8d9a81b072ab3582f1469a62cc25b0905b
takaakit/design-pattern-examples-in-python
/structural_patterns/flyweight/main.py
901
4.34375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- from structural_patterns.flyweight.large_size_string import LargeSizeString ''' Display a string consisting of large characters (0-9 digits only). Large character objects are not created until they are needed. And the created objects are reused. Example Output ----- Pleas...
true
bad357e547032486bc7e5b04b7b92351148a2b19
21milushcalvin/grades
/Grades.py
1,649
4.25
4
#--By Calvin Milush, Tyler Milush #--12 December, 2018 #--This program determines a test's letter grade, given a percentage score. #--Calvin Milush #-Initializes variables: score = 0 scoreList = [] counter = 0 total = 0 #--Calvin Milush #-Looped input for test scores: while (score != -1): score = in...
true
3f2832d039f29ef99679e8c51d42f5fb08b1dcff
pullannagari/python-training
/ProgramFlow/contrived.py
425
4.21875
4
# con·trived # /kənˈtrīvd/ # Learn to pronounce # adjective # deliberately created rather than arising naturally or spontaneously. # FOR ELSE, else is activated if all the iterations are complete/there is no break numbers = [1, 45, 132, 161, 610] for number in numbers: if number % 8 == 0: #reject the lis...
true
7f9b228de7c12560ac80445c6b1a4d7543ddc263
pullannagari/python-training
/Functions_Intro/banner.py
1,312
4.15625
4
# using default parameters, # the argument becomes # optional at the caller def banner_text(text: str = " ", screen_width: int = 60) -> None: """ centers the text and prints with padded ** at the start and the end :param text: string to be centered and printed :param screen_width: width of the screen on...
true
232c40b3f47c42c8a33fcc5d7e4bde2719969080
Hemalatah/Python-Basic-Coding
/Practice2.py
2,684
4.125
4
#CRAZY NUMBERS def crazy_sum(numbers): i = 0; sum = 0; while i < len(numbers): product = numbers[i] * i; sum += product; i += 1; return sum; numbers = [2,3,5]; print crazy_sum(numbers); #FIND THE NUMBER OF PERFECT SQUARES BELOW THIS NUMBER def square_nums(max): num = 1; count = 0; while num < max: produ...
true
1ba2daae4ad916e06b92b9277ca113d64bbd3a84
miss-faerie/Python_the_hard_way
/ex3.py
507
4.25
4
hens = int(25+30/6) roosters = int(100-25*3%4) eggs = int(3+2+1-5+4%2-1/4+6) print() print("I will now count my chickens:") print("Hens",hens) print("Roosters",roosters) print("Now I will count the eggs:",eggs) print() print("Is it true that 3+2 < 5-7 ?",(3+2)<(5-7)) print("What is 3+2 ?",3+2) print("What is 5-7 ?",5...
true
16e176e7b1f43c5c78feea53472ad5cdf2949955
tsabz/ITS_320
/Option #2: Repetition Control Structure - Five Floating Point Numbers.py
1,321
4.25
4
values_dict = { 'Module 1': 0, 'Module 2': 0, 'Module 3': 0, 'Module 4': 0, 'Module 5': 0, } # first we want to have the student enter grades into set def Enter_grades(): print('Please enter your grade for Module 1:') values_dict['Module 1'] = int(float(input())) print('Please enter y...
true
f13d14609b6c98949dc2e70a7de24f4a5e443ca0
taeheechoi/coding-practice
/FF_mergeTwoSortedLists.py
1,061
4.1875
4
# https://leetcode.com/problems/merge-two-sorted-lists/ # Input: list1 = [1,2,4], list2 = [1,3,4] # Output: [1,1,2,3,4,4] def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: #create dummy node so we can compare the first node in each list dummy = ListNode() #ini...
true
2190f7f62adf79cd2ee82007132c9571e4f0e68b
Codeducate/codeducate.github.io
/students/python-projects-2016/guttikonda_dhanasekar.py
950
4.1875
4
#This program will tell people how much calories they can consume until they have reached their limit. print("How old are you") age = int(input()) print("How many calories have you consumed today?") cc = int(input()) print("Are you a male or female?") gender = input() print("Thanks! We are currently calculating your d...
true
98e78ab456a9b654f37b48fd459c6b24f2560b93
afmendes/alticelabs
/Programs and Applications/Raspberry Pi 4/Project/classes/Queue.py
595
4.1875
4
# simple queue class with FIFO logic class Queue(object): """FIFO Logic""" def __init__(self, max_size: int = 1000): self.__item = [] # adds a new item on the start of the queue def enqueue(self, add): self.__item.insert(0, add) return True # removes the last items of the q...
true
eba5b2a0bceea1cc3848e70e0e68fc0f0607a677
tanishksachdeva/leetcode_prog
/9. Palindrome Number.py
1,083
4.3125
4
# Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. # Follow up: Could you solve it without converting the integer to a string? # Example 1: # Input: x = 121 # Output: true # Example 2: # Input: x = -121 # Output: false # Explanation: From left t...
true
084a8d9a138e77eba923726e61c139b58170073d
femakin/Age-Finder
/agefinder.py
1,116
4.25
4
#Importing the necessary modules from datetime import date, datetime import calendar #from datetime import datetime #Getting user input try: last_birthday = input('Enter your last birthdate (i.e. 2017,07,01)') year, month, day = map(int, last_birthday.split(',')) Age_lastbthday = int(input("Age, as at las...
true
57249ecd6489b40f0ca4d3ea7dd57661b436c106
tjastill03/PythonExamples
/Iteration.py
343
4.15625
4
# Taylor Astill # What is happening is a lsit has been craeted and the list is being printed. # Then it is sayingfor each of the listed numbers # list of numbers numberlist = [1,2,3,4,5,6,7,8,9,10] print(numberlist) # iterate over the list for entry in numberlist: # Selection over the iteration if (entry %...
true
fee46693ff557202fba24ba5a16126341624fdd6
lepaclab/Python_Fundamentals
/Medical_Insurance.py
2,599
4.6875
5
# Python Syntax: Medical Insurance Project # Suppose you are a medical professional curious #about how certain factors contribute to medical #insurance costs. Using a formula that estimates #a person’s yearly insurance costs, you will investigate #how different factors such as age, sex, BMI, etc. affect the pr...
true
49f8b9cfb5f19a643a0bacfe6a775c7d33d1e95d
denvinnpaolo/AlgoExpert-Road-to-Cerification-Questions
/Recursion/NthFibonacci.py
713
4.34375
4
# Nth Fibonacci # Difficulty: Easy # Instruction: # # The Fibonacci sequence is defined as follows: the first number of the sequence # is 0 , the second number is 1 , and the nth number is the sum of the (n - 1)th # and (n - 2)th numbers. Write a function that takes in an integer "n" # and returns the nth ...
true
adffbd365423fb9421921d4ca7c0f5765fe0ac60
denvinnpaolo/AlgoExpert-Road-to-Cerification-Questions
/Arrays/ThreeNumSum.py
1,745
4.34375
4
# ThreeNumSum # Difficulty: Easy # Instruction: # Write a function that takes in a non-empty array of distinct integers and an # integer representing a target sum. The function should find all triplets in # the array that sum up to the target sum and return a two-dimensional array of # all these triplets. The...
true
e7499f4caab0fb651b8d9a3fc5a7c374d184d28f
akhileshsantoshwar/Python-Program
/Programs/P07_PrimeNumber.py
660
4.40625
4
#Author: AKHILESH #This program checks whether the entered number is prime or not def checkPrime(number): '''This function checks for prime number''' isPrime = False if number == 2: print(number, 'is a Prime Number') if number > 1: for i in range(2, number): if number % i ==...
true
4fe9d7b1d738012d552b79fb4dc92a3c65fa7e53
akhileshsantoshwar/Python-Program
/Programs/P08_Fibonacci.py
804
4.21875
4
#Author: AKHILESH #This program calculates the fibonacci series till the n-th term def fibonacci(number): '''This function calculates the fibonacci series till the n-th term''' if number <= 1: return number else: return (fibonacci(number - 1) + fibonacci(number - 2)) def fibonacci_without_...
true
3060667c2327aa358575d9e096d9bdc353ebedaa
akhileshsantoshwar/Python-Program
/Programs/P11_BinaryToDecimal.py
604
4.5625
5
#Author: AKHILESH #This program converts the given binary number to its decimal equivalent def binaryToDecimal(binary): '''This function calculates the decimal equivalent to given binary number''' binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = d...
true
c3e19b89c753c95505dc168514dd760f486dd4b9
akhileshsantoshwar/Python-Program
/OOP/P03_InstanceAttributes.py
619
4.21875
4
#Author: AKHILESH #In this example we will be seeing how instance Attributes are used #Instance attributes are accessed by: object.attribute #Attributes are looked First in the instance and THEN in the class import random class Vehicle(): #Class Methods/ Attributes def type(self): #NOTE: This is not a ...
true
74d0b16405a97e6b5d2140634f2295d466b50e64
akhileshsantoshwar/Python-Program
/Programs/P54_PythonCSV.py
1,206
4.3125
4
# Author: AKHILESH # In this example we will see how to use CSV files with Python # csv.QUOTE_ALL = Instructs writer objects to quote all fields. # csv.QUOTE_MINIMAL = Instructs writer objects to only quote those fields which contain special characters such # as delimiter, quotechar or any of the c...
true
0488727a912f98123c6e0fdd47ccde36df895fbd
akhileshsantoshwar/Python-Program
/Programs/P63_Graph.py
2,160
4.59375
5
# Author: AKHILESH # In this example, we will see how to implement graphs in Python class Vertex(object): ''' This class helps to create a Vertex for our graph ''' def __init__(self, key): self.key = key self.edges = {} def addNeighbour(self, neighbour, weight = 0): self.edges[neig...
true
8271310a83d59aa0d0d0c392a16a19ef538c749d
akhileshsantoshwar/Python-Program
/Numpy/P06_NumpyStringFunctions.py
1,723
4.28125
4
# Author: AKHILESH import numpy as np abc = ['abc'] xyz = ['xyz'] # string concatenation print(np.char.add(abc, xyz)) # ['abcxyz'] print(np.char.add(abc, 'pqr')) # ['abcpqr'] # string multiplication print(np.char.multiply(abc, 3)) # ['abcabcabc'] # numpy.char.center: This function returns an array of the requ...
true
384c45c69dc7f7896f84c42fdfa9e7b9a4a1d394
tobyatgithub/data_structure_and_algorithms
/challenges/tree_intersection/tree_intersection.py
1,392
4.3125
4
""" In this file, we write a function called tree_intersection that takes two binary tree parameters. Without utilizing any of the built-in library methods available to your language, return a set of values found in both trees. """ def tree_intersection(tree1, tree2): """ This function takes in two binary tre...
true
212ea767940360110c036e885c544609782f9a82
tobyatgithub/data_structure_and_algorithms
/data_structures/binary_tree/binary_tree.py
1,454
4.375
4
""" In this file, we make a simple implementation of binary tree. """ import collections class TreeNode: def __init___(self, value=0): self.value = value self.right = None self.left = None def __str__(self): out = f'This is a tree node with value = { self.val } and left = { se...
true
8e05603d65047bb6f747be134a6b9b6554f5d9cc
ganguli-lab/nems
/nems/nonlinearities.py
757
4.21875
4
""" Nonlinearities and their derivatives Each function returns the value and derivative of a nonlinearity. Given :math:`y = f(x)`, the function returns :math:`y` and :math:`dy/dx` """ import numpy as np def exp(x): """Exponential function""" # compute the exponential y = np.exp(x) # compute the fir...
true
4851bf916952b52b1b52eb1d010878e33bba3855
tusvhar01/practice-set
/Practice set 42.py
489
4.25
4
my_tuple = tuple((1, 2, "string")) print(my_tuple) my_list = [2, 4, 6] print(my_list) # outputs: [2, 4, 6] print(type(my_list)) # outputs: <class 'list'> tup = tuple(my_list) print(tup) # outputs: (2, 4, 6) print(type(tup)) # outputs: <class 'tuple'> #You can also create a tuple u...
true
37c28ad515026a3db91878d907f7d31e14f7e9a7
tusvhar01/practice-set
/Practice set 73.py
472
4.125
4
a=input("Enter first text: ") b=input("Enter second text: ") a=a.upper() b=b.upper() a=a.replace(' ','') b=b.replace(' ','') if sorted(a)==sorted(b): print("It is Anagram") # anagram else: print("Not Anagram") #An anagram is a new word formed by rearranging the letters of a word, usin...
true
bd50429e48eae21d7a37647c65ae61866c1e97cb
dviar2718/code
/python3/types.py
1,259
4.1875
4
""" Python3 Object Types Everything in Python is an Object. Python Programs can be decomposed into modules, statements, expressions, and objects. 1. Programs are composed of modules. 2. Modules contain statements. 3. Statements contain expressions. 4. Expressions create and process objects Object Type Example -...
true
1a7b97bce6b4c638d505e1089594f54914485ec0
shaner13/OOP
/Week 2/decimal_to_binary.py
598
4.15625
4
#intiialising variables decimal_num = 0 correct = 0 i = 0 binary = '' while(correct==0): decimal_num = int(input("Enter a number to be converted to binary.\n")) if(decimal_num>=0): correct = correct + 1 #end if else: print("Enter a positive integer please.") #end else #end...
true
294115d83f56263f56ff23790c35646fa69f8342
techreign/PythonScripts
/batch_rename.py
905
4.15625
4
# This will batch rename a group of files in a given directory to the name you want to rename it to (numbers will be added) import os import argparse def rename(work_dir, name): os.chdir(work_dir) num = 1 for file_name in os.listdir(work_dir): file_parts = (os.path.splitext(file_name)) os.rename(file_na...
true
f08a7e8583fe03de82c43fc4a032837f5ac43b06
bartoszmaleta/python-microsoft-devs-yt-course
/25th video Collections.py
1,278
4.125
4
from array import array # used later names = ['Bartosz', 'Magda'] print(names) scores = [] scores.append(98) # Add new item to the end scores.append(85) print(scores) print(scores[1]) # collections are zero-indexed points = array('d') # d stands for digits points.append(44) points.append(12...
true
9eb9c7ecf681c8ccc2e9d89a0c8324f94560a1f3
bartoszmaleta/python-microsoft-devs-yt-course
/31st - 32nd video Parameterized functions.py
878
4.28125
4
# same as before: def get_initial2(name): initial = name[0:1].upper() return initial first_name3 = input("Enter your firist name: ") last_name3 = input("Enter your last name: ") print('Your initials are: ' + get_initial2(first_name3) + get_initial2(last_name3)) # ___________________ def get_iniial(name...
true
6544630135a7287c24d1ee167285dc00202cb9aa
MMVonnSeek/Hacktoberfest-2021
/Python-Programs/avg-parse.py
1,168
4.15625
4
# Total, Average and Count Computation from numbers in a text file with a mix of words and numbers fname = input("Enter file name: ") # Ensure your file is in the same folder as this script # Test file used here is mbox.txt fhandle = open(fname) # Seeking number after this word x x = "X-DSPAM-Confidence:" y = len(x) ...
true
6934e148c95348cd43a07ddb86fadc5723a0e003
MMVonnSeek/Hacktoberfest-2021
/Python-Programs/number_decorator.py
543
4.34375
4
# to decorate country code according to user defined countrycode # the best practical way to learn python decorator country_code = {"nepal": 977, "india": 91, "us": 1} def formatted_mob(original_func): def wrapper(country, num): country = country.lower() if country in country_code: ret...
true
dc882ac280f0b5c40cbc1d69ee9db9529e1ad001
Raviteja02/CorePython
/venv/Parameters.py
2,308
4.28125
4
#NonDefault Parameters: we will pass values to the non default parameters at the time of calling the function. def add(a,b): c = a+b print(c) add(100,200) add(200,300) print(add) #function address storing in a variable with the name of the function. sum=add #we can assign the function variable to any user ...
true
3b1bbf74275f81501c8aa183e1ea7d941f075f56
Tadiuz/PythonBasics
/Functions.py
2,366
4.125
4
# Add 1 to a and store it in B def add1(a): """ This function takes as parameter a number and add one """ B = a+1 print(a," if you add one will be: ",B) add1(5) print(help(add1)) print("*"*100) # Lets declare a function that multiplies two numbers def mult(a,b): C = a*b return C ...
true
b2c4bb3420c54e65d601c16f3bc3e130372ae0de
nfarnan/cs001X_examples
/functions/TH/04_main.py
655
4.15625
4
def main(): # get weight from the user weight = float(input("How heavy is the package to ship (lbs)? ")) if weight <= 0: print("Invalid weight (you jerk)") total = None elif weight <= 2: # flat rate of $5 total = 5 # between 2 and 6 lbs: elif weight <= 6: # $5 + $1.50 per lb over 2 total = 5 + 1.5 ...
true
b5dd5d77115b2c9206c4ce6c22985e362f13c15e
nfarnan/cs001X_examples
/exceptions/MW/03_input_valid.py
529
4.21875
4
def get_non_negative(): valid = False while not valid: try: num = int(input("Enter a non-negative int: ")) except: print("Invalid! Not an integer.") else: if num < 0: print("Invalid! Was negative.") else: valid = True return num def get_non_negative2(): while True: try: num = int(i...
true
b862f9fd6aad966de8bd05c2bfcb9f9f12ba61f5
mhashilkar/Python-
/2.9.7_Variable-length_arguments.py
590
4.5
4
# When you need to give more number of arguments to the function # " * "used this symbol tho the argument that means it will take multiple value # it will be a tuple and to print that args you have to used the for loop def printinfo(args1, *vartuple): print("Output is: ") print(args1) for var in vartuple:...
true
b0c57e4bbcfa9a9e6283ebceeca1a0a5594a28c5
ramyashah27/chapter-8-and-chapter-9
/chapter 9 files are op/03write.py
382
4.15625
4
# f = open('another.txt', 'w') # f.write("this file is created through writing in 'w'") # f.close() # this is to make/open file and will add (write) all data in it, it will overright f = open('another.txt', 'a') f.write(' and this is appending') f.close() #this is to add data in the end # how many times we r...
true
b2c09cf42fa22404a0945b1746176a1b847bd260
dobtco/beacon
/beacon/importer/importer.py
974
4.125
4
# -*- coding: utf-8 -*- import csv def convert_empty_to_none(val): '''Converts empty or "None" strings to None Types Arguments: val: The field to be converted Returns: The passed value if the value is not an empty string or 'None', ``None`` otherwise. ''' return val if va...
true
31d79ed21483f3cbbc646fbe94cf0282a1753f91
OceanicSix/Python_program
/parallel_data_processing/data_parition/binary_search.py
914
4.125
4
# Binary search function def binary_search(data, target): matched_record = None position = -1 # not found position lower = 0 middle = 0 upper = len(data) - 1 ### START CODE HERE ### while (lower <= upper): # calculate middle: the half of lower and upper middle = int((lowe...
true
33e560583b1170525123c867bb254127c920737f
OceanicSix/Python_program
/Study/Search_and_Sort/Insertion_sort.py
840
4.34375
4
# sorts the list in an ascending order using insertion sort def insertion_sort(the_list): # obtain the length of the list n = len(the_list) # begin with the first item of the list # treat it as the only item in the sorted sublist for i in range(1, n): # indicate the current item to be posit...
true
f23588e2e08a6dd36a79b09485ebc0f7a59ed6b7
chiragkalal/python_tutorials
/Python Basics/1.python_str_basics.py
930
4.40625
4
''' Learn basic string functionalities ''' message = "it's my world." #In python we can use single quotes in double quotes and vice cersa. print(message) message = 'it\'s my world.' #Escape character('\') can handle quote within quote. print(message) message = """ It's my world. And I know how to save this ...
true
be83f2c448015ca8108ba665a057ce30ef3e7ed0
Lucchese-Anthony/MonteCarloSimulation
/SimPiNoMatplotlib.py
885
4.21875
4
import math import random inside = 1 outside = 1 count = 0 def inCircle(x, y): #function that sees if the coordinates are contained within the circle, either returning false or true return math.sqrt( (x**2) + (y**2) ) <= 1 while True: count = count + 1 #random.uniform generates a 'random' number betw...
true
209c616fe9c622b4269bddd5a7ec8d06d9a27e86
paula867/Girls-Who-Code-Files
/survey.py
2,480
4.15625
4
import json import statistics questions = ["What is your name?", "What is your favorite color?", "What town and state do you live in?", "What is your age?", "What year were you born?"] answers = {} keys = ["Name", "Favorite color", "Hometown","Age", "Birthye...
true
c2123be019eca85251fbd003ad3894bb51373433
jacobroberson/ITM313
/hw2.py
1,516
4.5
4
''' This program provides an interface for users to select a medium and enter a distance that a sound wave wil travel. Then the program will calculate and display the time it takes for the waveto travel the given distance. Programmer: Jacob Roberson Course: ITM313 ''' #Intialize variables selection = 0 medium ...
true
ee3615b1612d3340005a8b07a6e93bc130153591
JanJochemProgramming/basic_track_answers
/week3/session/dicts.py
338
4.25
4
capitals = {"The Netherlands": "Amsterdam", "France": "Paris"} capitals["Japan"] = "Tokyo" for country in reversed(sorted(capitals)): print(country, capitals[country]) fruit_basket = {"Apple": 3} fruit_to_add = input("Which fruit to add? ") fruit_basket[fruit_to_add] = fruit_basket.get(fruit_to_add, 0) + 1 pr...
true
8ec7c46f57e44354f3479ea02e8e0cf34aaec352
oreqizer/pv248
/04/book_export.py
1,691
4.1875
4
# In the second exercise, we will take the database created in the # previous exercise (‹books.dat›) and generate the original JSON. # You may want to use a join or two. # First write a function which will produce a ‹list› of ‹dict›'s # that represent the books, starting from an open sqlite connection. import sqlite3...
true
a0151ddb3bc4c2d393abbd431826393e46063b89
zachacaria/DiscreteMath-II
/q2.py
1,356
4.15625
4
import itertools import random def random_permutation(iterable, r): "Random selection from itertools.permutations(iterable, r)" pool = tuple(iterable) r = len(pool) if r is None else r return tuple(random.sample(pool, r)) # Function to do insertion sort def insertionSort(arr): # Traverse through...
true
115b477fb7b86d34e9df784d43bfe29b2dcbf06a
tanyastropheus/holbertonschool-higher_level_programming
/0x0B-python-input_output/1-number_of_lines.py
364
4.28125
4
#!/usr/bin/python3 def number_of_lines(filename=""): """count the number of lines in a text file Args: filename (str): file to be counted Returns: line_num (int): number of lines in the file. """ line_num = 0 with open(filename, encoding="UTF8") as f: for line in f: ...
true
fafd561f1c3020231747a3480278bcf91c457a82
AYamaui/Practice
/exercises/cyclic_rotation.py
1,998
4.3125
4
""" An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved ...
true
5f404ca2db9ce87abe64ba7fd1dd111b1ceeb022
matt969696/holbertonschool-higher_level_programming
/0x07-python-test_driven_development/100-matrix_mul.py
1,965
4.25
4
#!/usr/bin/python3 """ 2-matrix_mul module - Contains simple function matrix_mul """ def matrix_mul(m_a, m_b): """ Multiplies 2 matrices Return the new matrix The 2 matrix must be non null list of list The 2 matrix must be multiable All elements of the 2 matrix must be integers or floats "...
true
6aef4c2a49e81fe1fe83dacb7e246acee51ab11c
Floozutter/silly
/python/montyhallsim.py
2,038
4.15625
4
""" A loose simulation of the Monty Hall problem in Python. """ from random import randrange, sample from typing import Tuple Prize = bool GOAT = False CAR = True def make_doors(doorcount: int, car_index: int) -> Tuple[Prize]: """Returns a representation of the doors in the Monty Hall Problem.""" return tup...
true
c7e11b86d21975a2afda2485194161106cadf3b3
ariquintal/StructuredProgramming2A
/unit1/activity_04.py
338
4.1875
4
print("Start Program") ##### DECLARE VARIABLES ###### num1 = 0 num2 = 0 result_add = 0 result_m = 0 num1 = int(input("Enter number1\n")) num2 = int(input("Enter number2\n")) result_add = num1 + num2 result_m = num1 * num2 print("This is the add", result_add) print("This is the multiplication", result_m) print ("P...
true
b9c3c868e064818e27304573dec01cc97a4c3ab1
candacewilliams/Intro-to-Computer-Science
/moon_earths_moon.py
299
4.15625
4
first_name = input('What is your first name?') last_name = input('What is your last name?') weight = float(input('What is your weight?')) moon_weight = str(weight* .17) print('My name is ' + last_name + '. ' + first_name + last_name + '. And I weigh ' + moon_weight + ' pounds on the moon.')
true
ed89b53b3082f608adb2f612cf856d87d1f51c78
SandySingh/Code-for-fun
/name_without_vowels.py
359
4.5
4
print "Enter a name" name = raw_input() #Defining all vowels in a list vowels = ['a', 'e', 'i', 'o', 'u'] name_without_vowels = '' #Removing the vowels or rather forming a name with only consonants for i in name: if i in vowels: continue name_without_vowels += i print "The name without v...
true
8fbcb251349fe18342d92c4d91433b7ab6ca9d53
gsaikarthik/python-assignment7
/assignment7_sum_and_average_of_n_numbers.py
330
4.21875
4
print("Input some integers to calculate their sum and average. Input 0 to exit.") count = 0 sum = 0.0 number = 1 while number != 0: number = int(input("")) sum = sum + number count += 1 if count == 0: print("Input some numbers") else: print("Average and Sum of the above numbers are: ", sum / (coun...
true
4731e40b41f073544f2edf67fb02b6d93396cd7b
hbomb222/ICTPRG-Python
/week3q4 new.py
819
4.40625
4
username = input("enter username ") # ask user for username user_dict = {"bob":"password1234", "fred":"happypass122", "lock":"passwithlock144"} # create dictionary of username password pairs if (username == "bob" or username == "fred" or username == "lock"): # check if the entered username matches any of the known val...
true
5e3d41c1d7e1d49566416dced623ae593b58c079
nickwerner-hub/WhirlwindTourOfPython
/Scripting/03_RangeFunctionExample.py
270
4.34375
4
#RangeFunctionExample.py # This example demonstrates the range function for generating # a sequence of values that can be used in a for loop. pi = 3.1415 for r in range(0,100,20): area = (r ** 2) * pi print "The area of a circle with radius ", r, "is ", area
true
313925e1c6edb9d16bc921aff0c8897ee1d2bdf5
nickwerner-hub/WhirlwindTourOfPython
/Scripting/07_WriteDataExample.py
1,620
4.34375
4
#WriteDataExample.py # This script demonstrates how a file object is used to both write to a new text file and # append to an existing text file.In it we will read the contents of the EnoNearDurham.txt # file and write selected data records to the output file. # First, create some variables. "dataFileName" will po...
true
1fc51bc3ec116ee0663399bffae6825020d33801
abdbaddude/codeval
/python/jolly_jumper.py3
2,166
4.1875
4
#!/usr/bin/env python3 """ JOLLY JUMPERS CHALLENGE DESCRIPTION: Credits: Programming Challenges by Steven S. Skiena and Miguel A. Revilla A sequence of n > 0 integers is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. eg. 1 4...
true
87c2fcfcaa140e8971926f8da3098c5abe781271
Nadeem-Doc/210CT-Labsheet
/Labsheet 5 - Task 2.py
1,542
4.21875
4
class Node(): def __init__(self, value): self.value=value self.next=None # node pointing to next self.prev=None # node pointing to prev class List(): def __init__(self): self.head=None self.tail=None def insert(self,n,x): #Not actually perfe...
true
f0664f2b9a826598dc873e8c27d53b6623f67b5b
Vanagand/Data-Structures
/queue/queue.py
1,520
4.21875
4
#>>> Check <PASS> """ A queue is a data structure whose primary purpose is to store and return elements in First In First Out order. 1. Implement the Queue class using an array as the underlying storage structure. Make sure the Queue tests pass. 2. Re-implement the Queue class, this time using the linked list imp...
true
de5f1ae3bae6d0744cd18ded1ec0631d48fbb559
TanvirKaur17/Greedy-4
/shortestwayToFormString.py
912
4.125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Oct 29 08:30:10 2019 @author: tanvirkaur implemented on spyder Time Complexity = O(m*n) Space Complexity = O(1) we maintain two pointers one for source and one for target Then we compare the first element of source with the target If we iterate through ...
true
0f8df2bb7f0ca56f34737d85faa3aeb5d4c8a300
emmanuelagubata/Wheel-of-Fortune
/student_starter/main.py
1,188
4.15625
4
# Rules print('Guess one letter at a time. If you want to buy a vowel, you must have at least $500, otherwise, you cannot buy a vowel. If you think you know the word or phrase, type \'guess\' to guess the word or phrase. You will earn each letter at a set amount and vowels will not cost anything.') from random import ...
true
355df5e645f38513d4581c5f3f08ed41568c59e2
zaincbs/PYTECH
/reverseOfString.py
375
4.375
4
#!/usr/bin/env python """ Define a function reverse, that computes the reversal of a string. For example, reverse("I am testing") should return the string "gnitset ma I". """ def reverse(s): k= "" for i in range (len(s)-1, -1, -1): k = k + s[i] return k def main(): v = reverse("This is testing...
true