blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
0d7273d3c8f1599fa823e3552d5dfe677f2eb37b
AdarshMarakwar/Programs-in-Python
/Birthday Database.py
1,456
4.15625
4
import sys import re birthday = {'John':'Apr 6','Robert':'Jan 2','Wayne':'Oct 10'} print('Enter the name:') name=input() if name in birthday.keys(): print('Birthday of '+name+' is on '+birthday[name]) else: print('The name is not in database.') print('Do you want to see the entire databse?'...
true
f6f745b08e14bb8d912565e1efecf3bbf9a437a1
mnk343/Automate-the-Boring-Stuff-with-Python
/partI/ch3/collatz.py
321
4.1875
4
import sys def collatz(number): if number%2 : print(3*number+1) return 3*number+1 else: print(number//2) return number//2 number = input() try : number = int(number) except ValueError: print("Please enter integer numbers!!") sys.exit() while True: number = collatz(number) if number == 1: break ...
true
34ce2cbc18f6a937592da46d748ce032e709cfa4
Rusvi/pippytest
/testReact/BasicsModule/dictionaries.py
867
4.125
4
#Dictionaries (keys and values) # simple dictionary student = { "name": "Mark", "student_id": 15163, "feedback": None } #Get values print(student["name"])# = Mark #print(student["last_name"]) KeyError if there is no key #avoid by get("key","default value") print(student.get("last_name","Unknown_key"))# = ...
true
0eb8624cbe3c84cfbeeb7c3494e271fb00bfb726
SchoBlockchain/ud_isdc_nd113
/6. Navigating Data Structures/Temp/geeksforgeeks/geeksforgeeks_BFS_udacity.py
1,679
4.3125
4
# Program to print BFS traversal from a given source # vertex. BFS(int s) traverses vertices reachable # from s. from collections import defaultdict # This class represents a directed graph using adjacency # list representation class Graph: # Constructor def __init__(self): # default dictionary to...
true
4599cd49493f9376018cee225a14f139fd9c316f
m-tambo/code-wars-kata
/python-kata/counting_duplicate_characters.py
1,112
4.21875
4
# https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1/train/python # Write a function that will return the count of distinct # case-insensitive alphabetic characters and numeric digits # that occur more than once in the input string. # The input string can be assumed to contain only # alphabets (both uppercase and ...
true
39dd901b68ac263934d07e52ace777357d37edbc
ProgrammingForDiscreteMath/20170828-karthikkgithub
/code.py
2,881
4.28125
4
from math import sqrt, atan, log class ComplexNumber: """ The class of complex numbers. """ def __init__(self, real_part, imaginary_part): """ Initialize ``self`` with real and imaginary part. """ self.real = real_part self.imaginary = imaginary_part def __rep...
true
aef037a891c81af4f75ce89a534c7953f5da6f57
christian-million/practice-python
/13_fibonacci.py
653
4.1875
4
# 13 Fibonacci # Author: Christian Million # Started: 2020-08-18 # Completed: 2020-08-18 # Last Modified: 2020-08-18 # # Prompt: https://www.practicepython.org/exercise/2014/04/30/13-fibonacci.html # # Write a program that asks the user how many Fibonnaci numbers to generate and then generates them. # Take this opportu...
true
88157f9c38fd2952634c6a17f987d0d1a5149965
git-uzzal/python-learning
/genPrimeNumbers.py
579
4.21875
4
def isPrime(n): for num in range(2,n): if n % num == 0: return False return True def get_valid_input(): ''' Get valid integer more than equal to 3''' while(True): try: num = int(input('Enter a number: ')) except: print("I dont undersand that") continue else: if num < 3: print("Number m...
true
e5d7cde3aa799b147de8bb6a5ff62b308cac45d5
ruchit1131/Python_Programs
/learn python/truncate_file.py
896
4.1875
4
from sys import argv script,filename=argv print(f"We are going to erase {filename}") print("If you dont want that hit Ctrl-C") print("If you want that hit ENTER") input("?") print("Opening file") target=open(filename,'w') print("Truncating the file.") target.truncate()#empties the file print("Writ...
true
d636b023af3f4e570bef64a37a4dbb5a162bd6db
chavarera/codewars
/katas/Stop gninnipS My sdroW.py
1,031
4.34375
4
''' Stop gninnipS My sdroW! Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is pre...
true
1b081dfc115a840dde956934dbab0ee5f3b41891
harshaghub/PYTHON
/exercise.py
457
4.15625
4
"""Create a list to hold the to-do tasks""" to_do_list=[] finished=False while not finished: task = input('enter a task for your to-do list. Press <enter> when done: ') if len(task) == 0: finished=True else: to_do_list.append(task) print('Task added') """Display to-...
true
f4bd846af010b1782d0e00da64f0fdf4314e93ba
mikikop/DI_Bootcamp
/Week_4/day_3/daily/codedaily.py
700
4.1875
4
choice = input('Do you want to encrypt (e) or decrypt (d)? ') cypher_text = '' decypher_text = '' if choice == 'e' or choice == 'E': e_message = input('Enter a message you want to encrypt: ') #encrypt with a shift right of 3 for letter in e_message: if ord(letter) == 32: cypher_text += chr(ord(letter)) else:...
true
25e86fc49773801757274ede8969c27c68168747
mikikop/DI_Bootcamp
/Week_4/day_5/exercises/Class/codeclass.py
1,542
4.25
4
# 1 Create a function that has 2 parameters: # Your age, and your friends age. # Return the older age def oldest_age(my_age,friend_age): if my_age > friend_age: return my_age return friend_age print(oldest_age(34,23)) # 2. Create a function that takes 2 words # It must return the lenght of the longer...
true
aff2134f2e4a76a59dc2d99184a548e17f290de0
LStokes96/Python
/Code/teams.py
945
4.28125
4
#Create a Python file which does the following: #Opens a new text file called "teams.txt" and adds the names of 5 sports teams. #Reads and displays the names of the 1st and 4th team in the file. #Create a new Python file which does the following: #Edits your "teams.txt" file so that the top line is replaced with "This ...
true
58d75067e577cf4abaafc6e369db8da6cf8e7df1
FL9661/Chap1-FL9661
/Chap3-FL9661/FL9661-Chap3-3.py
2,254
4.5
4
# F Lyness # Date 23 Sept 2021 # Lab 3.4.1.6: the basics of lists # # Task: use a list to print a series of numbers hat_numbers = [1,2,3,4,5] #list containing each number value known as an element print ('There once was a hat. The hat contained no rabbit, but a list of five numbers: ', hat_numbers [0], hat_numbers [...
true
6c68a4b129524de39ef050160decd697dfec5a86
sigrunjm/Maximum-number
/maxnumb.py
471
4.4375
4
num_int = int(input("Input a number: ")) # Do not change this line # Fill in the missing code #1. Get input from the user #2. if number form user is not negative print out the largest positive number #3. Stop if user inputs negative number max_int = 0 while num_int > 0: if num_int > max_int: max_int = ...
true
28962e9e8aaa5fb3ce7f67f8b4109c426fed0f65
yaseenshaik/python-101
/ints_floats.py
539
4.15625
4
int_ex = 2 float_ex = 3.14 print(type(float_ex)) # Float/normal division print(3 / 2) # 1.5 # Floor division print(3 // 2) # gives 1 # Exponent print(3 ** 2) # 9 # Modulus print(3 % 2) # 1 # priorities - order of operations print(3 + 2 * 4) # 11 # increment int_ex += 1 print(int_ex) # round (takes a...
true
dae861a719ced79a05da501c28302a2452395924
abercrombiedj2/week_01_revision
/lists_task.py
493
4.4375
4
# 1. Create an empty list called `task_list` task_list = [] # 2. Add a few `str` elements, representing some everyday tasks e.g. 'Make Dinner' task_list.append("Make my bed") task_list.append("Go for a run") task_list.append("Cook some breakfast") task_list.append("Study for class") # 3. Print out `task_list` print(t...
true
a430e9bb28ae56dfe1309b2debbfff29b73a41b8
milincjoshi/Python_100
/95.py
217
4.40625
4
''' Question: Please write a program which prints all permutations of [1,2,3] Hints: Use itertools.permutations() to get permutations of list. ''' import itertools l = [1,2,3] print tuple(itertools.permutations(l))
true
fac3f0586e4c82f66a35d23b3ec09640da8dab44
milincjoshi/Python_100
/53.py
682
4.6875
5
''' Define a class named Shape and its subclass Square. The Square class has an init function which takes a length as argument. Both classes have a area function which can print the area of the shape where Shape's area is 0 by default. Hints: To override a method in super class, we can define a method with the sa...
true
2822a1bdf75dc41600d2551378b7c533316e6a86
milincjoshi/Python_100
/45.py
318
4.25
4
''' Question: Write a program which can map() to make a list whose elements are square of elements in [1,2,3,4,5,6,7,8,9,10]. Hints: Use map() to generate a list. Use lambda to define anonymous functions. ''' #print map([x for x in range(1,11)], lambda x : x**2) print map( lambda x : x**2,[x for x in range(1,11)])
true
bc2efffa5e46d51c508b6afa2f5deda322a77765
milincjoshi/Python_100
/28.py
247
4.15625
4
''' Question: Define a function that can receive two integral numbers in string form and compute their sum and then print it in console. Hints: Use int() to convert a string to integer. ''' def sum(a,b): return int(a)+int(b) print sum("2","4")
true
9de6d50bce515e0003aaff576c3c92d04b162b9d
chandanakgd/pythonTutes
/lessons/lesson6_Task1.py
1,513
4.125
4
''' * Copyright 2016 Hackers' Club, University Of Peradeniya * Author : Irunika Weeraratne E/11/431 * * 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-...
true
6a0c9526c14dd7fb71a9ba8002d3673e7da8b29b
yangzhao1983/leetcode_python
/src/queue/solution225/MyStack.py
1,512
4.125
4
from collections import deque class MyStack(object): def __init__(self): """ Initialize your data structure here. """ self.q1 = deque() self.q2 = deque() def push(self, x): """ Push element x onto stack. :type x: int :rtype: None ...
true
a657612ac1dbce789b2f2815e631ffad2a8de060
AlexMazonowicz/PythonFundamentals
/Lesson2.1/solution/urlvalidator_solution.py
1,040
4.28125
4
import requests def validate_url(url): """Validates the given url passed as string. Arguments: url -- String, A valid url should be of form <Protocol>://<hostmain>/<fileinfo> Protocol = [http, https, ftp] Hostname = string Fileinfo = [.html, .csv, .docx] """ protocol_valid = True valid_pro...
true
79a2b5f3b7e3594ed0137ed3f0d12912f15e6d6f
mulus1466/raspberrypi-counter
/seconds-to-hms.py
302
4.15625
4
def convertTime(seconds): ''' This function converts an amount of seconds and converts it into a struct containing [hours, minutes, seconds] ''' second = seconds % 60 minutes = seconds / 60 hours = minutes / 60 Time = [hours, minutes, second] return Time
true
45d1a3a08d68b4f7f24f36b9dc01f505ee715004
JamesSG2/Handwriting-Conversion-Application
/src/GUI.py
1,998
4.40625
4
#tkinter is pre-installed with python to make very basic GUI's from tkinter import * from tkinter import filedialog root = Tk() #Function gets the file path and prints it in the command #prompt as well as on the screen. def UploadAction(event=None): filename = filedialog.askopenfilename() print('Selected:', fil...
true
fcfe2cc13a4f75d0ea9d47f918a7d53e3f8495df
cs-fullstack-2019-fall/python-basics2f-cw-marcus110379
/classwork.py
1,610
4.5
4
### Problem 1: #Write some Python code that has three variables called ```greeting```, ```my_name```, and ```my_age```. Intialize each of the 3 variables with an appropriate value, then rint out the example below using the 3 variables and two different approaches for formatting Strings. #1) Using concatenation and the...
true
3763ee2e94ab64e04a0725240cdc3a7a6990a3ad
yz398/LearnFast_testing
/list_module/max_difference.py
1,314
4.125
4
def max_difference(x): """ Returns the maximum difference of a list :param x: list to be input :type x: list :raises TypeError: if input is not a list :raises ValueError: if the list contains a non-float or integer :raises ValueError: if list contains +/-infinity ...
true
70276b8e585bd6299b8e9a711f5271089f25ab04
BenjaminLBowen/Simple-word-frequency-counter
/word_counter.py
938
4.25
4
# Simple program to list each word in a text that is entered by the user # and to count the number of time each word is used in the entered text. # variable to hold users inputed text sentence= input("Type your text here to count the words: ") # function to perform described task def counting_wordfunc(sentence): #...
true
c7b32d7c040304d87a25b09008f6045d0d5d304b
rj-fromm/assignment3b-python
/assignment3b.py
530
4.375
4
# !user/bin/env python3 # Created by: RJ Fromm # Created on: October 2019 # This program determines if a letter is uppercase or lowercase def main(): ch = input("Please Enter a letter (uppercase or lowercase) : ") if(ord(ch) >= 65 and ord(ch) <= 90): print("The letter", ch, "is an uppercase letter")...
true
27b16e6ee0cbd9477fc99475382e5e8e95d1efb7
gautamdayal/natural-selection
/existence/equilibrium.py
2,379
4.28125
4
from matplotlib import pyplot as plt import random # A class of species that cannot reproduce # Population is entirely driven by birth and death rates class Existor(object): def __init__(self, population, birth_rate, death_rate): self.population = population self.birth_rate = birth_rate sel...
true
1a5f5335e97941b5797ba92bc13877e4a73acd00
markagy/git-one
/Mcq_program.py
1,487
4.25
4
# Creating a class for multiple choice exam questions.Each class object has attribute "question" and "answer" class Mcq: def __init__(self, question, answer): self.question = question self.answer = answer # Creating a list of every question test = [ "1.How many sides has a triangle?\n (a) 1\...
true
a3e8cfb8a4f8f7765e9088883440d151e6d972d5
nagios84/AutomatingBoringStuff
/Dictionaries/fantasy_game_inventory.py
767
4.1875
4
#! python3 # fantasy_game_inventory.py - contains functions to add a list of items to a dictionary and print it. __author__ = 'm' def display_inventory(inventory): total_number_of_items = 0 for item, quantity in inventory.items(): print(quantity, item) total_number_of_items += quantity ...
true
017b0543fd031602af8129b05cd6567ce67fc5db
AnuraghSarkar/DataStructures-Algorithms_Practice
/queue.py
1,671
4.53125
5
class queue: def __init__(self): self.items = [] def enqueue(self, item): """ Function to add item in first index or simply enqueue. Time complexity is O(n) or linear. If item is added in first index all next items should be shifted by one. Time depends upon list length....
true
a29f06832bf4caa10f1c8d4141e96a7a50e55bb9
YashMali597/Python-Programs
/binary_search.py
1,180
4.125
4
# Binary Search Implementation in Python (Iterative) # If the given element is present in the array, it prints the index of the element. # if the element is not found after traversing the whole array, it will give -1 # Prerequisite : the given array must be a sorted array # Time Complexity : O(log n) # Space complexity...
true
d089562243b35b8be2df3c31888518a235858c43
xiaoying1990/algorithm_stanford_part1
/merge_sort.py
2,293
4.53125
5
#!/usr/bin/python3 import random def merge_sort(ar): """ O(n*log(n)), dived & conquer algorithm for sorting array to increasing order. :param ar: type(ar) = 'list', as a array of number. :return: None, while sorting the parameter 'arr' itself. We can change it, because list is mutable. """ ar...
true
0e48b82567ddcd2eabacdb0c1a4fb514f0e97eb7
darwinini/practice
/python/avgArray.py
655
4.21875
4
# Program to find the average of all contiguous subarrays of size ‘5’ in the given array def avg(k, array): avg_array = [] for i in range(0, len(array) - k + 1): sub = array[i:i+k] sum, avg = 0, 0 # print(f"The subarray is {sub}") for j in sub: sum+= j avg =...
true
0c0718a685533344d5fea9cfdf1ec9d925dbdcd9
Surya0705/Number_Guessing_Game
/Main.py
1,407
4.3125
4
import random # Importing the Random Module for this Program Random_Number = random.randint(1, 100) # Giving our program a Range. User_Guess = None # Defining User Guess so that it doesn't throw up an error later. Guesses = 0 # Defining Guesses so that it doesn't throw up an error later. while(User_Guess != Random_Num...
true
16d1c6a7eca1df4440a78ac2f657a56fa1b8300b
bnew59/sept_2018
/find_largest_element.py
275
4.21875
4
#Assignment: Write a program which finds the largest element in the array # def largest_element(thing): # for num in thing: # if num + 1 in # elements = [1, 2, 3, 4] a=[1,2,3,4,6,7,99,88,999] max = a[0] for i in a: if i > max: max=i print(max)
true
c64b1e0c45ea4de9c2195c99bfd3b22ab2925347
Samyak2607/CompetitiveProgramming
/Interview/postfix_evaluation.py
1,133
4.15625
4
print("For Example : abc+* should be entered as a b c + *") for _ in range(int(input("Enter Number of Test you wanna Test: "))): inp=input("Enter postfix expression with space: ") lst=inp.split(" ") operator=['+','-','/','*','^'] operands=[] a=1 for i in lst: if(i not in operator): ...
true
d5bcb62f24c54b161d518ac32c4a2434d01db76e
PaLaMuNDeR/algorithms
/Coding Interview Bootcamp/16_linked_list.py
1,665
4.25
4
""" Return the middle node of a Linked list. If the list has an even number of elements, return the node at the end of the first half of the list. DO NOT use a counter variable, DO NOT retrieve the size of the list, and only iterate through the list one time. Example: const l = LinkedL() l.insertLast('a') ...
true
edbbd4fe3fc4a8646c52d70636369ff1c1c23bd5
PaLaMuNDeR/algorithms
/Coding Interview Bootcamp/10_capitalize.py
2,096
4.28125
4
import timeit """ Write a function that accepts a string. The function should capitalize the first letter of each word in the string then return the capitalized string. Examples: capitalize('a short sentence') -> 'A Short Sentence' capitalize('a lazy fox') -> 'A Lazy Fox' capitalize('look, it is wor...
true
52cf1f1b5914447294ae9eb29b40abaa5086f644
PaLaMuNDeR/algorithms
/Algo Expert/113_group_anagrams.py
894
4.34375
4
""" Group Anagrams Write a function that takes in an array of strings and returns a list of groups of anagrams. Anagrams are strings made up of exactly the same letters, where order doesn't matter. For example, "cinema" and "iceman" are anagrams; similarly, "foo" and "ofo" are anagrams. Note that the groups of anagrams...
true
cdfa714d56aad96ba4cbcd6ff4dfd25865d8e085
PaLaMuNDeR/algorithms
/Algo Expert/101_Two_number_sum.py
819
4.125
4
""" Two Number Sum Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. If any two numbers in the input array sum up to the target sum, the function should return them in an array, in sorted order. If no two numbers sum up to the target sum, the function should...
true
995aaacefeb011ff0ef04a62d4c9fd4688b4450e
PaLaMuNDeR/algorithms
/Algo Expert/124_min_number_of_jumps.py
1,006
4.125
4
""" Min Number Of Jumps You are given a non-empty array of integers. Each element represents the maximum number of steps you can take forward. For example, if the element at index 1 is 3, you can go from index Ito index 2, 3, or 4. Write a function that returns the minimum number of jumps needed to reach the final inde...
true
edca001ae4dd97c5081f1c6421a457eec39f4ff4
yasab27/HelpOthers
/ps7twoD/ps7pr2.py
1,179
4.25
4
# # ps7pr2.py (Problem Set 7, Problem 2) # # 2-D Lists # # Computer Science 111 # # If you worked with a partner, put his or her contact info below: # partner's name: # partner's email: # # IMPORTANT: This file is for your solutions to Problem 2. # Your solutions to problem 3 should go in ps7pr3.py instead. import r...
true
8ed7f544dd1ba222cf0b96ee7f1e3a2b18b9e993
krathee015/Python_assignment
/Assignment4-task7/task7_exc2.py
722
4.375
4
# Define a class named Shape and its subclass Square. The Square class has an init function which # takes length as argument. Both classes have an area function which can print the area of the shape # where Shape’s area is 0 by default. class Shape: def area(self): self.area_var = 0 print("area of...
true
83e8f766412009bd71dea93ed83a1d1f17414290
krathee015/Python_assignment
/Assignment3/task5/task5_exc2.py
376
4.34375
4
print("Exercise 2") # Write a program in Python to allow the user to open a file by using the argv module. If the # entered name is incorrect throw an exception and ask them to enter the name again. Make sure # to use read only mode. import sys try: with open(sys.argv[1],"r") as f: print(f.read()) except: ...
true
d282703436352013daf16052b74fd03110c645c8
krathee015/Python_assignment
/Assignment1/Task2/tasktwo_exercise2.py
984
4.125
4
print ("Exercise 2") result = 0 num1 = eval(input("Enter first number: ")) num2 = eval(input("Enter second number: ")) user_enter = eval(input("Enter 1 for Addition, 2 for Subtraction, 3 for Division, 4 for Multiplication, 5 for Average: ")) if (user_enter == 1): result = num1 + num2 print ("Addition of two ...
true
904d7bf1450e3838387f787eb0411593c739d5f0
kunal5042/Python-for-Everybody
/Course 2: Python Data Structures/Week 3 (Files)/Assignment_7.2.py
1,119
4.125
4
""" 7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below....
true
b3be5eaf872a254f8cec7c7eb33740c9c4f30303
kunal5042/Python-for-Everybody
/Course 1: Programming for Everbody (Getting Started with Python)/Week 6 (Functions)/Factorial.py
603
4.28125
4
# Here I am using recursion to solve this problem, don't worry about it if it's your first time at recursion. def Factorial(variable): if variable == 0: return 1 return (variable * Factorial(variable-1)) variable = input("Enter a number to calculate it's factorial.\n") try: x = int(variabl...
true
07f9f576b76b56b5f258d563de4b24cf8f5f2673
kunal5042/Python-for-Everybody
/Course 2: Python Data Structures/Week 5 (Dictionaries)/Dictionaries.py
1,291
4.3125
4
""" Dictionaries: Dic are python's most powerful data collection. Dic allow us to do fast database-like operations in python. Dic have different names in different languages. For example: Associative Arrays - Perl / PHP Properties or Map or HashMap - Java Property Bag - C# /.Net """ def dictionaryDemo(): #Initi...
true
e52b318f5ef1e29c6f6ff08ef2fb68336c62ab4b
kunal5042/Python-for-Everybody
/Course 1: Programming for Everbody (Getting Started with Python)/Week 5 (Comparison Operators, Exception Handling basics) /Assignment_3.1.py
1,066
4.28125
4
""" 3.1 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use ...
true
c2138c13915b9f7cde94d6989b462023e1b1becc
kunal5042/Python-for-Everybody
/Assignments-Only/Assignment_7.1.py
1,002
4.46875
4
""" 7.1 Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file words.txt to produce the output below. You can download the sample data at http://www.py4e.com/code3/words.txt """ import urllib.request, urllib.parse, u...
true
97e1c7c3c00067602ca94705bb73f097d464a735
ShrutiBhawsar/problem-solving-py
/Problem4.py
1,547
4.5
4
#Write a program that asks the user how many days are in a particular month, and what day of the # week the month begins on (0 for Monday, 1 for Tuesday, etc), and then prints a calendar for that # month. For example, here is the output for a 30-day month that begins on day 4 (Thursday): # S M T W T F S # 1 2 3 # 4 5 6...
true
4f03b84942530c09ff2932e497683e5f75ccbf9c
ShrutiBhawsar/problem-solving-py
/Problem2_USerInput.py
1,237
4.3125
4
#2. Print the given number in words.(eg.1234 => one two three four). def NumberToWords(digit): # dig = int(digit) """ It contains logic to convert the digit to word it will return the word corresponding to the given digit :param digit: It should be integer :return: returns the string back ...
true
dcee80352c93df7f9dccfef14c15ea31dd7bfe88
databooks/databook
/deepml/pytorch-examples02/nn/two_layer_net_module.py
1,980
4.21875
4
import torch """ A fully-connected ReLU network with one hidden layer, trained to predict y from x by minimizing squared Euclidean distance. This implementation defines the model as a custom Module subclass. Whenever you want a model more complex than a simple sequence of existing Modules you will need to define your...
true
75e8edfa8f01a8605e6f8fb37fecfe5f23d1ce2f
lpython2006e/student-practices
/12_Nguyen_Lam_Manh_Tuyen/2.7.py
610
4.1875
4
#Write three functions that compute the sum of the numbers in a list: using a for-loop, a while-loop and recursion. # (Subject to availability of these constructs in your language of choice.) def sum_with_while(lists): list_sum = 0 i = 0 while i < len(lists): list_sum += lists[i] i += 1 ...
true
820baad5f24cfc52195fbf11f5c74214812a1b76
lpython2006e/student-practices
/12_Nguyen_Lam_Manh_Tuyen/1.3.py
308
4.25
4
#Modify the previous program such that only the users Alice and Bob are greeted with their names. names=["Alice","Bob"] name=() while name not in names: print("Please input your name") name = input() if name=="Alice": print("Hello",name) elif name=="Bob": print("Hello",name)
true
56dbe18f5cd493157d153647e82cc9b94fcb8f6c
Bhaveshsadhwani/Test
/ASSESSMENT/Que14 .py
281
4.3125
4
# -*- coding: utf-8 -*- """ Created on Tue Oct 10 16:25:08 2017 @author: User """ num = input("Enter a positive number:") if (num > 0) and (num &(num-1))==0: print num,"is a power of 2" else: print num,"is not a power of 2 "
true
4ff98dc017eda7df9a80c19e72fab899eac3b044
YuhaoLu/leetcode
/1_Array/easy/python/rotate_array.py
1,677
4.125
4
""" 0.Name: Rotate Array 1.Description: Given an array, rotate the array to the right by k steps, where k is non-negative. Could you do it in-place with O(1) extra space? 2.Example: Input: [1, 2, 3, 4, 5, 6, 7] and k = 3 Output: [5, 6, 7, 1, 2, 3, 4] 3.Solution: array.unshift ...
true
8244b2c89489b52681b49174ee7889ec473cf6d7
YuhaoLu/leetcode
/4_Trees/easy/python/Symmetric_Tree.py
2,166
4.53125
5
""" 0.Name: Symmetric Tree 1.Description: Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center) 2.Example: Given linked list: 1 / \ 2 2 / \ / \ 3 4 4 3 Input: root =...
true
1df94c11e36c23bd17752519659f96de91f7ea97
johnerick89/iCube_tasks
/task2.py
735
4.375
4
def get_maximum_value_recursion(weight,values,capacity, n): ''' Function to get maximum value Function uses recursion to get maximum value ''' if n==0 or capacity == 0: return 0 if weight[n-1]>capacity: return get_maximum_value_recursion(weight,values,capacity, n-1) else...
true
951e6870e1c504e5e17122f8cb7a8600d13115bc
jtpio/algo-toolbox
/python/mathematics/cycle_finding.py
1,154
4.21875
4
def floyd(f, start): """ Floyd Cycle Finding implementation Parameters ---------- f: function The function to transform one value to its successor start: The start point from where the cycle detection starts. Returns ------- out: tuple: - mu: int Position at ...
true
ed32eff5d2a297f299deacf1e22d68193494fcce
Starluxe/MIT-6.00.1x-Introduction-to-Computer-Science-and-Programming-Using-Python
/Problem Set 1/Problem 3 - Longest Alphabetcal Substring.py
1,187
4.28125
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 # In the case of ties, print the ...
true
b2da8890a183783c996070701b900c866f235d61
Starluxe/MIT-6.00.1x-Introduction-to-Computer-Science-and-Programming-Using-Python
/Final Exam/Problem 3.py
631
4.1875
4
# Implement a function that meets the specifications below. # def sum_digits(s): # """ assumes s a string # Returns an int that is the sum of all of the digits in s. # If there are no digits in s it raises a ValueError exception. """ # # Your code here # For example, sum_digits("a;35d4") retu...
true
94846af53f588d81cf57e822044d204cb5fef2d1
lukelafountaine/euler
/23.py
1,887
4.25
4
#! /usr/bin/env python # A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. # For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, # which means that 28 is a perfect number. # # A number n is called deficient if the sum of its proper div...
true
f3d520e3294cb123db91beab99d28c34c939b1d0
lukelafountaine/euler
/1.py
426
4.34375
4
#! /usr/bin/env python # If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. # The sum of these multiples is 23. # # Find the sum of all the multiples of 3 or 5 below 1000. def sum_of_multiples(n, bound): multiples = (bound - 1) / n return n * ((multiples * (multip...
true
87351efb827796bdde84fa15df577ad52b615ff5
jfulghum/practice_thy_algos
/LinkedList/LLStack.py
1,496
4.1875
4
# Prompt # Implement a basic stack class using an linked list as the underlying storage. Stacks have two critical methods, push() and pop() to add and remove an item from the stack, respectively. You'll also need a constructor for your class, and for convenience, add a size() method that returns the current size of the...
true
be1d46e5b24abc08a5ea94810dc69cc3297bbc29
jfulghum/practice_thy_algos
/LinkedList/queue_with_linked _list.py
1,352
4.5625
5
# Your class will need a head and tail pointer, as well as a field to track the current size. # Enqueue adds a new value at one side. # Dequeue removes and returns the value at the opposite side. # A doubly linked list is one of the simplest ways to implement a queue. You'll need both a head and tail pointer to keep t...
true
20059f23388b82201b8a8210f90fe3cc04a16e5a
31337root/Python_crash_course
/Exercises/Chapter5/0.Conditionial_tests.py
500
4.15625
4
best_car = "Mercedes" cars = ["Mercedes", "Nissan", "McLaren"] print("Is " + cars[0] + " the best car?\nMy prediction is yes!") print(cars[0] == best_car) print("Is " + cars[1] + " the best car?\nMy prediction is nop :/") print(cars[1] == best_car) print("Is " + cars[2] + " the best car?\nMy prediction is nop :/") pr...
true
c7663e6804cc478e517727f7996c6f5df936d364
jerrywardlow/Euler
/6sumsquare.py
592
4.1875
4
def sum_square(x): '''1 squared plus 2 squared plus 3 squared...''' total = 0 for i in range(1, x+1): total += i**2 return total def square_sum(x): '''(1+2+3+4+5...) squared''' return sum(range(1, x+1))**2 def print_result(num): print "The range is 1 through %s" % num print "...
true
de7890db84895c8c8b9e5131bbf7528dc9e3a74f
Annarien/Lectures
/L6.2_25_04_2018.py
356
4.3125
4
import numpy #make a dictionary containing cube from 1-10 numbers= numpy.arange(0,11,1) cubes = {} for x in numbers: y = x**3 cubes[x]=y print ("The cube of "+ str(x) +" is "+ str(y)) # making a z dictionary # print (cubes) print (cubes) #for x in cubes.keys(): #want to list ...
true
e1336bc4c6810f7cd908f333502a3b6c83ca394c
bossenti/python-advanced-course
/sets.py
1,137
4.21875
4
# Set: collection data-type, unordered, mutable, no duplicates # creation my_set = {1, 2, 3} my_set_2 = set([1, 2, 3]) my_set_3 = set("Hello") # good trick to count number of different characters in one word # empty set empty_set = set # {} creates a dictionary # add elements my_set.add(4) # remove elements my_se...
true
6ba34b1bcd307cbac829ad8fbaba27571cd2c807
punkyjoy/LearningPython
/03.py
514
4.125
4
print("I will now count my chickens") print("hens", 25.00+30.00/6.0) print("roosters", 100.0-25.0*3.0%4.0) print("Now I will count the eggs:") print(3.0+2.0+1.0-5.0+4.0%2.0-1.0/4.0+6.0) print("Is is true that 3.0+2.0<5.0-7.0?") print(3.0+2.0<5.0-7.0) print("What is 3+2?", 3.0+2.0) print("What is 5-7?", 5-7) #this i...
true
d4bad854227ad91b7ad5a305906060837f0a11fa
Prince9ish/Rubik-Solver
/colors.py
1,592
4.1875
4
'''For representing color of the rubik's cube.''' from pygame.locals import Color from vpython import * class ColorItem(object): '''WHITE,RED,BLUE,etc are all instances of this class.''' def __init__(self,name="red"): self.name=name self.color=color.red self.opposite=None de...
true
ae471d6db283d8d28d6fe43934656f47a5192cec
claudiordgz/GoodrichTamassiaGoldwasser
/ch01/c113.py
357
4.125
4
__author__ = 'Claudio' """Write a pseudo-code description of a function that reverses a list of n integers, so that the numbers are listed in the opposite order than they were before, and compare this method to an equivalent Python function for doing the same thing. """ def custom_reverse(data): return [data[len(...
true
47ade36bd4fc754b29fd7a3cd898ddef5b87ca7e
smholloway/miscellaneous
/python/indentation_checker/indentation_checker.py
2,876
4.375
4
def indentation_checker(input): # ensure the first line is left-aligned at 0 if (spaces(input[0]) != 0): return False # emulate a stack with a list indent_level = [] indent_level.append(0) # flag to determine if previous line encountered was a control flow statement previous_line_was_control = False # iter...
true
d1f00fa6f224748010687c63f08e01a3142d62cf
pawlmurray/CodeExamples
/ProjectEuler/1/MultiplesOf3sAnd5s.py
688
4.3125
4
#get all of the multiples of threes and add them up def sumOfMultiplesOfThrees(max): currentSum = 0 threeCounter = 3 while(threeCounter < max): currentSum+= threeCounter threeCounter += 3 return currentSum #Get all of the multiples of fives and add them up, if they are #evenly divis...
true
d7468de2be523b14bb8cddf5e10bf67e64663fe9
Kartikkh/OpenCv-Starter
/Chapter-2/8-Blurring.py
2,789
4.15625
4
## Blurring is a operation where we average the pixel with that region #In image processing, a kernel, convolution matrix, or mask is a small matrix. It is used for blurring, sharpening, #embossing, edge detection, and more. #This is accomplished by doing a convolution between a kernel and an image. # https://www.yo...
true
514fbfa2e340addc29c2a928a6ace99c042fcb7b
jmtaysom/Python
/Euler/004ep.py
643
4.25
4
from math import sqrt def palindrome(): """ A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. """ for x in range(999,100,-1): ...
true
5904acd697e84a4063452b706ab129537e53ab5b
Aryamanz29/DSA-CP
/gfg/Recursion/binary_search.py
627
4.15625
4
#binary search using recursion def binary_search(arr, target): arr = sorted(arr) #if array is not sorted return binary_search_func(arr, 0, len(arr)-1, target) def binary_search_func(arr, start_index, end_index, target): if start_index > end_index: return -1 # element not found mid = (start_index+end_index) //2...
true
d346746005b6b2a5c0b25a92e63f92c0bbadfa89
Aryamanz29/DSA-CP
/random/word_count.py
1,116
4.125
4
# You are given some words. Some of them may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification. # Note: # All the words are composed of lowercase English letters only. # Input Format...
true
eba979bd967c81ba4ad6d2435ffb09b3e4f5059f
n1e2h4a/AllBasicProgram
/BasicPython/leadingzero.py
264
4.21875
4
mystring="python" #print original string print("the original string :--- "+ str(mystring)) #no of zeros want zero=5 #using rjust()for for adding leading zero final=mystring.rjust(zero + len(mystring), '0') print("string after adding leading zeros : " + str(final))
true
435fd488d1a513ebebcfc35354be57debca54442
n1e2h4a/AllBasicProgram
/ListPrograms.py/MinimumInList.py
213
4.125
4
table = [] number = int(input("Enter number of digit you want to print:---")) for x in range(number): Element = int((input(' > '))) table.append(Element) table.sort() print("Smallest in List:", *table[:1])
true
18b9d6e60429bcfc31d56ece3f3d1c1c79bb30d6
abdul1380/UC6
/learn/decorater_timer.py
1,792
4.4375
4
""" The following @debug decorator will print the arguments a function is called with as well as its return value every time the function is called: """ import functools import math def debug(func): """Print the function signature and return value""" @functools.wraps(func) def wrapper_debug(*args, **kwarg...
true
d4cbd946ea754ed8bddb1f487f6a4250c4e3a96b
dengxinjuan/springboard
/python-syntax/words.py
319
4.15625
4
def print_upper_words(words,must_start_with): for word in words: for any in must_start_with: if word.startswith(any): result = word.upper() print(result) print_upper_words(["hello", "hey", "goodbye", "yo", "yes"], must_start_with={"h", "y"})
true
5e26fa7180ec61b226b2824f4c3d4120df770254
ptsiampas/Exercises_Learning_Python3
/18_Recursion/Exercise_18.7.2a.py
1,089
4.375
4
import turtle from math import cos, sin def cesaro_fractal(turtle, order, size): """ (a) Draw a Casaro torn line fractal, of the order given by the user. We show four different lines of order 0, 1, 2, 3. In this example, the angle of the tear is 10 degrees. :return: """ if order == 0: # T...
true
712a129202333470151c53d20af112057b41d9f6
ptsiampas/Exercises_Learning_Python3
/15._Classes and Objects_Basics/Exercise_15.12.4.py
1,970
4.375
4
# 4. The equation of a straight line is “y = ax + b”, (or perhaps “y = mx + c”). The coefficients # a and b completely describe the line. Write a method in the Point class so that if a point # instance is given another point, it will compute the equation of the straight line joining # the two points. It must return the...
true
b10e4275bac85b19fbd094a6e205386b6f73f169
ptsiampas/Exercises_Learning_Python3
/07_Iteration/Exercise_7.26.16.py
1,062
4.125
4
# Write a function sum_of_squares(xs) that computes the sum of the squares of the numbers in the list xs. # For example, sum_of_squares([2, 3, 4]) should return 4+9+16 which is 29: # # test(sum_of_squares([2, 3, 4]), 29) # test(sum_of_squares([ ]), 0) # test(sum_of_squares([2, -3, 4]), 29) import sys def test(actual,...
true
ad104e36e782364406c66006947e838a5ec2ab4d
ptsiampas/Exercises_Learning_Python3
/05_Conditionals/Exercise_5.14.11.py
710
4.25
4
# # Write a function is_rightangled which, given the length of three sides of a triangle, will determine whether the # triangle is right-angled. Assume that the third argument to the function is always the longest side. It will return # True if the triangle is right-angled, or False otherwise. # __author__ = 'petert' ...
true
087cad1c17766f45940c7e98e789862465ba2934
ptsiampas/Exercises_Learning_Python3
/18_Recursion/Exercise_18.7.3.py
1,236
4.4375
4
from turtle import * def Triangle(t, length): for angle in [120, 120, 120]: t.forward(length) t.left(angle) def sierpinski_triangle(turtle, order, length): """ 3. A Sierpinski triangle of order 0 is an equilateral triangle. An order 1 triangle can be drawn by drawing 3 smaller triang...
true
fa87af0a96105b9589fad9a32955db349089d5cd
ptsiampas/Exercises_Learning_Python3
/18_Recursion/Exercise_18.7.10.py
1,506
4.21875
4
# Write a program that walks a directory structure (as in the last section of this chapter), but instead of printing # filenames, it returns a list of all the full paths of files in the directory or the subdirectories. # (Don’t include directories in this list — just files.) For example, the output list might have elem...
true
3de631c83b785cac3822aaaf26d06e85a32ce736
ptsiampas/Exercises_Learning_Python3
/21_Even_more_OOP/Examples_Point21.py
2,367
4.5625
5
class Point: """ Point class represents and manipulates x,y coords. """ def __init__(self, x=0, y=0): """ Create a new point at the origin """ self.x = x self.y = y def __str__(self): # All we have done is renamed the method return "({0}, {1})".format(self.x, self.y) ...
true
dbdf7c1059cffe23b0d8c47348e25e0c9347ed7e
ptsiampas/Exercises_Learning_Python3
/01_03_Introduction/play_scr.py
615
4.15625
4
import turtle # Allows us to use turtles wn = turtle.Screen() # Creates a playground for turtles wn.bgcolor("lightgreen") # Sets window background colour wn.title("Hey its me") # Sets title alex = turtle.Turtle() # Create a turtle, assign to alex alex.color("blue") # pen colour blue ale...
true
6c151bbd8c7b00728fc6288bce8cec511d839050
ptsiampas/Exercises_Learning_Python3
/06_Fruitful_functions/Exercises_6.9.14-15.py
1,449
4.53125
5
# 14. Write a function called is_even(n) that takes an integer as an argument and returns True if the argument is # an even number and False if it is odd. import sys def test(actual, expected): """ Compare the actual to the expected value, and print a suitable message. """ linenum = sys._getframe(1...
true
2217a5fe8973d2d5a8d900f1c5ddc9b2b07f5689
sobinrajan1999/258213_dailyCommit
/print.py
518
4.28125
4
print("hello world") print(1+2+3) print(1+3-4) # Python also carries out multiplication and division, # using an asterisk * to indicate multiplication and # a forward slash / to indicate division. print(2+(3*4)) # This will give you float value print(10/4) print(2*0.75) print(3.4*5) # if you do not want float value the...
true
c0ced71bc1ef01689981bdc9f5c0f227ac76226a
rosexw/Practice_Python
/1-character_input.py
842
4.125
4
# https://www.practicepython.org/ # Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old. # name = raw_input("What is your name: ") # age = int(input("How old are you: ")) # year = str((2018 - age)+100) ...
true
b96824853b54624a33730716da977019b9958c3d
BubbaHotepp/code_guild
/python/palindrome.py
505
4.1875
4
def reverse_string(x): return x[::-1] def compare(x,y): if x == y: return True else: return False def main(): user_input = input('Please enter a word you think is an anagram: ') print(user_input) input_reversed = reverse_string(user_input) print(input_reversed) x = co...
true