blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
5289eb779cd01c726e97a497af2295e5130f1f25
yprodev/p2016-00004-python-data-structures
/lesson3-list-and-tuple/l3_part8.py
398
4.40625
4
# iteration # ================================================== fruits = ['apple', 'banana', 'apple', 'pear', 'strawberry'] for fruit in fruits: print('My favourite fruit is the ', fruit) for fruit in fruits[:3]: print('Favourite fruit is the ', fruit) # We can delete the items as we iterate for idx, fruit in en...
true
b4cda5194f1cbff5bbcc1dbf703e27d6c2fc2d7f
yprodev/p2016-00004-python-data-structures
/lesson1-dict-type/l1_part22.py
2,893
4.21875
4
# Semantics of Object versus Dictionaries class Foo1: def __getattr__(self, attr): return attr def __getitem__(self, key): return key foo1 = Foo1() # ================================================== # Using get item protocol to get three keys print(foo1['two words']) print(foo1['123']) print(foo1['abc/def'...
true
a59c63cfd1963a58841ad60a91b31cbe83fb580f
yprodev/p2016-00004-python-data-structures
/lesson1-dict-type/l1_part8.py
1,313
4.40625
4
# We know that there is an error when we want to retrieve the # DEFAULT key value pair when the key does not exists. # So we can write some helper function ''' def get_word(d, word): if word in d: return d[word] return None ''' xs1 = {'one': 'uno'} # We can expand this code to add the default value def get_word...
true
0a5eeb19ce45b4e4bb72306ecfcead2eb5e89021
DarrenIsaacson/My-class-codes
/ColorMixer.py
1,314
4.53125
5
# Author = Darren Isaacson # This program is designed to create mix colors based off what the user has for colors. #This allows the user to choose 2 colors color1 = input("Choose a color between red, blue, and yellow to mix. ") color2 = input("Choose another color you want to mix between red, blue, and yellow. ...
true
d74698cccca892050150408977d37adbf478919d
DarrenIsaacson/My-class-codes
/Apollo.py
699
4.25
4
# Author = Darren Isaacson # This program is designed to define if a question is right or wrong # This function asks the question year = int(input("When did Apollo 11 land on the moon")) # This defines if the answer from the input was correct if year == 1969 : print("Correct!") else : print("Sorry, ...
true
7a13f911d326c02a20f7eda5addfcc9aed50e53c
Rick24/210CT-CW
/completed/Week 3 Q1 (6).py
838
4.34375
4
#Write the pseudocode and code for a function that reverses the words in a sentence. #Input: "This is awesome" Output: "awesome is This". Give the Big O notation def string_reverse(string): #0(n + 2) """a function which splits a given string and creates a new one with the input ...
true
9f6d10f7cd6d2758e3375f35fc2ac1141b7937e6
aberke/string-compression
/compression.py
2,438
4.1875
4
import sys from re import match def compress(inputString): """compression algorithm: - The input is a string, and the output is a compressed string. - A valid input consists of zero or more upper case english letters A-Z. - Any run of two or more of the same character converted to two of that character plu...
true
09b7525b151ffcb037bee87384f578cdfa859081
TrongPhamDA/CodeWars-Kata-Python
/kata/name_of_billboard.py
960
4.53125
5
''' Instructions You can print your name on a billboard ad. Find out how much it will cost you. Each letter has a default price of £30, but that can be different if you are given 2 parameters instead of 1. You can not use multiplier "*" operator. If your name would be Jeong-Ho Aristotelis, ad would cost £600. 20 leters...
true
a1cce3fb00a63107df2789824a719aa9adb6fb0a
Mahmud-Buet15/Problem-Solving
/Leetcode/171. Excel Sheet Column Number.py
605
4.1875
4
def titleToNumber(s): """ Takes a string as a columnTitle that represents the column title as appear in an Excel sheet, returns its corresponding column number. """ #making a dictionary of numbers and letters numbers=list(range(1,27)) # print(numbers) letters=[i for i in "ABCDEFGHIJKLMNO...
true
e52db0735f6202a9870a6546a9c800a7a2676a69
jaybhagwat/Python
/RegularExpression/Sample.py
485
4.15625
4
#Write a program to accept a file name from user and print all the words starting with small or capital t and ending in small or capital e import re def Regular(input_file): parser=re.compile(r"T\b(\w+)\bE",re.IGNORECASE) line=input_file.readline() while line!='': output=parser.finditer(line) for i in output: ...
true
f41a62e13cc2ad3b9ac84c62b87002c1f45bca35
jaybhagwat/Python
/RegularExpression/RemovingComntFromFileSingleandMultiple.py
675
4.125
4
#write a program to accept a file name from user and delete comments from it import re def DeletingCommentFromPyFile(input_file): try: fd=open(input_file) data=fd.read() x=re.sub(r"'''(.|\s|\n)*?'''","",data) file=open("NewFile.txt","w+") file.write(x) file.close() f1=open("NewFile.txt","r") f2=ope...
true
8eabed93c4e55e3e1e5fb3f51b9c1b7a5a24a9a6
somethingvague/cracking
/data_structures/c2_linked_lists/questions/partition.py
710
4.125
4
"""Question 2.4 Partition a linked list around a value x such that all the nodes less than x come """ def partition(node, partition_value): """Partitions a linked list on a value by moving elements to elements to the head or tail Args: node: head of linked list partition_value: value on which...
true
814841d156341f825528472a0c9ab6ed4b03ba81
ptrgags/panoramas
/util.py
946
4.125
4
def rescale(in_min, in_max, out_min, out_max, value): """ rescale value linearly from the range [old_min, old_max] to the range [new_min, new_max] :param float in_min: The low end of the current range :param float in_max: The high end of the current range :param float out_min: The low end of th...
true
abf254915d3d6c93745ac05687aff135c36b6a74
JCarlos831/cs50
/week7/pset6/caesar/caesar.py
1,534
4.40625
4
from cs50 import get_string import sys # Get Key # Check to see if user entered key and only two arguments if len(sys.argv) == 2: # Assign second argument to key key = int(sys.argv[1]) else: # Return error message print("Error: Must enter a non negative integer after python caesar.py") sys.exit(1)...
true
936846e520337f6c328f6bf70e15de45cbf9bf25
karthikeya-remilla/Projects
/Calculator.py
1,237
4.375
4
# Defining the calculator's logic def calculator(): print("Hello! Welcome to Py Calculator. Following operations are available for you: \n 1. Addition(+) 2. Subtraction(-) 3. Multiplication (*) 4. Division(/) 5. Remainder(%)") choice = int(input("Enter your choice now: ")) a = float(input("Enter op...
true
39d74c739a9cc39b16cf351263c07f970ff71ae5
Anzanrai/AlgorithmicToolbox
/week4_solution/binary_search.py
711
4.125
4
# Uses python3 def binary_search(a, x): left, right = 0, len(a) while left < right: mid = (right + left) // 2 if x == a[mid]: return mid if x > a[mid]: left = mid+1 else: right = mid return -1 # write your code here def linear_sear...
true
61e0a197ac036910fc4cbfde305fc9cad3c7c518
Anzanrai/AlgorithmicToolbox
/week4_solution/closest.py
1,749
4.125
4
#Uses python3 from collections import namedtuple coordinate_point = namedtuple('coordinate_point', ['x', 'y']) def calculated_min_distance(points): calculated_distances = [] for i in range(len(points)): for j in range(i+1, len(points)): calculated_distances.append(calculate_distance(point...
true
48f7bc644388b061347561167e499ee4fecd9896
seongyeon-97/Python-for-Everybody
/ex5/ex5_2.py
420
4.125
4
largest = None smallest = None while True: sval = input('Enter a number: ') if sval == 'done': break try: fval=int(sval) except: print('Invalid input') continue if largest is None or fval>largest: largest = fval if smallest is None or fval...
true
c35464a1132a4e8702c35e4ec37b90d99483ac54
HudsonLaForce/Lab5
/Time.py
2,956
4.21875
4
class Time: def __init__(self, h, m, s): while m >= 60 or s >= 60: # while the format is incorrect if s >= 60: # if there are too many seconds s -= 60 m += 1 if m >= 60: # if there are too many minutes m -= 60 h += 1...
true
4aa496482c9f9899e234e0c5c7843adc4f17f6e4
LionelEisenberg/CloudComp-Testing
/main_file.py
1,621
4.46875
4
### Imports import sys ### Declare variables NUM_ARGS = 3 def swap(array, i, j): temp = array[i] array[i] = array[j] array[j] = temp return array def bubble_sort(array): for i in range(len(array)): for j in range(len(array) - i - 1): if array[j] > array[j+1]: array = swap(array, j, j + 1) return array...
true
37827b554d03bb32d50fa38ff49e31c42d8de639
muhammad-aqib/codewars-programs
/simple_pig_latin.py
556
4.1875
4
# Move the first letter of each word to the end of it, then add "ay" to the end of the word. # Leave punctuation marks untouched. # pig_it('Pig latin is cool') # igPay atinlay siay oolcay # pig_it('Hello world !') # elloHay orldway ! def pig_it(text): sentence_words = text.split(" ") final_list = [] ...
true
2e5426c0458ec06300a676f8d3e50f8bd509b7fa
Bea-Nuri/PCC_Chapter_3_-_Introducing_Lists
/chapter_3_cars.py
896
4.40625
4
cars = ["bmw", "audi", "toyota", "subaru"] cars.sort() #short list by change the order of the list to store them alphabeticaly PERMANENTLY (A-Z) print(cars) cars = ["bmw", "audi", "toyota", "subaru"] cars.sort(reverse = True) #short list in reverse order (Z-A) print(cars) #shorting a list temporarily with the shorted...
true
6b90aa0ffe5d65487836ef03c2a8b5df5e5cd920
JiahuiZhu1998/Interview-Preparing
/googleOA_Q4_mysolution.py
1,858
4.28125
4
# Array X is greater than array Y if the first non-matching element in both arrays has a greater value in X than in Y. # For example, # for arrays X and Y such that: X = [1, 2, 4, 3, 5] Y = [1, 2, 3, 4, 5] # X is greater than Y because the first element that does not match is larger in X (i.e. for X...
true
eb038b9d72ee95f8944be57a2b6c669fd3d7212a
jdclifton2/HackerRankProblems
/stairCase
353
4.15625
4
#!/bin/python3 import math import os import random import re import sys # Complete the staircase function below. def staircase(n): stair_case = "" padding = n for num in range(n): stair_case = stair_case + "#" print(stair_case.rjust(padding," ")) if __name__ == '__main__': n ...
true
84772d3ccbb9de2a1bd73af4816bec65ffca6799
chethanagopinath/DSPractice
/bst.py
1,595
4.1875
4
class Node: def __init__(self, data=None): self.data = data self.left = None self.right = None class BST: def __init__(self, root): self.root = None def insert(self, data): if self.root is None: self.root = Node(data) else: #helper function that checks if self.root(the current node) at every iter...
true
88321d1d9b7c2c43c459529c5e73493eb6b75886
skillsapphire/python-complete-course
/concepts/2_data_structures/1_list.py
1,071
4.5
4
# list is unordered collection of one or more similar or dissimilar items can be stored together simple_list = [] # An empty list with no elements integer_list = [20, 10, 30, 40] # list of integers storing numbers print(integer_list) print(type(integer_list)) integer_list.sort() print(integer_list) # Sorted in ascen...
true
1fa8a8f83ba4a7ec689cd4bb8db7fd271d10f0fb
savannah-dmm/MadLibs-Project
/main.py
1,538
4.15625
4
#MADLIBS def story1(): print("chose story 1") name = input("What is your name? ") fruit = input ("What is your favorite fruit? ") store = input("Name a store:") enemy = input("Name an enemy:") print("My name is (%s). I was in the mood for some (%s). So I went to (%s) to get (%s). But (%s) got the last of (%...
true
d1f4cc3f60b050bb5e75fb1034faa9a733eb4788
bitamins/Pong
/pong.py
1,589
4.15625
4
""" author: Michael Bridges date: october 3, 2016 info: play with the up and down arrow keys, you are the paddle on the right the ball speeds up after every round the first player to score 3 wins """ import sys import pygame # modules from settings import Settings from paddle import Paddle from game_statistic...
true
03500538999d1a10d02806f46dc66f8d8ba1a056
Jarvis2021/Coding-Dojo
/python_stack1/_python/python_fundamentals/forloopsbasicii.py
2,363
4.46875
4
# Biggie Size Given a list, write a function that changes all positive numbers in the list to "big". # def convertbig(x): # y = len(x) # for i in range(y): # if x[i] > 0: # x[i] = "big" # else: # pass # return x # # print(convertbig([2,0,-1, 3, 5, -5])) # Count Pos...
true
f6f66ee684a0be221c36fb7db2748e018880c054
skfreego/Python-Strings
/whats_your_name.py
826
4.28125
4
""" Task:- You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hello firstname lastname! You just delved into python. Input Format:- The first line contains the first name, and the second line contains the last name. Output Format:- Print ...
true
3be51014409cbc8ad2cae8a867b06a952c2278fc
patildayananda/Raspberry-Pi
/button_ledPPT.py
825
4.15625
4
import RPi.GPIO as GPIO # Use the pin numbers from the ribbon cable board GPIO.setmode(GPIO.BCM) # Set up this pin as input. GPIO.setup(18, GPIO.IN) #Set up led pin as output GPIO.setup(17, GPIO.OUT) GPIO.setup(23, GPIO.OUT) # Check the value of the input pin GPIO.input(18) # Hold down the button, run ...
true
2107de81b870713bbf708e875af92250e1a5d929
00Bren00/hello-world
/Control_Structures/ForLoops.py
213
4.4375
4
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")# for loops is basically a for each loop for i in range(5): print("hello!")#for loop more similar to its use in other languages
true
358543e118684a22a80ce9c72f05c3b40a2eec78
galeal2/CodeU
/assignment_6.py
1,591
4.15625
4
# Rearranging cars def rearrange_cars(cars, order): ''' Input: - 2 list of integers cars = a list of integers that represents the cars order = a list of integers that represents in which order should the cars be rearranged Returns a list that contains all the...
true
a5f4d09014b333c745f8760e785fd5311526176e
Muneeb97/Python
/p1_word_count.py
396
4.34375
4
#enter a specific letter to count the number of times it is present in the sentence. import re string = input('Enter a sentence\n').upper() letter=input('Which letter to find\n').upper() def count(letter,string): wrd_count = re.findall(r"['{}']".format(letter),string) print("The number of times letter {} ...
true
a45835b3596a0a4e481a55b3b9684024a4d8cb35
caiquemarinho/python-course
/Exercises/Module 04/exercise_07.py
280
4.4375
4
""" Read a temperature in Fahrenheit and convert it to Celsius. Formula: C= 5.0*(F-32)/9.0 """ print('Please, insert the temperature in Fahrenheit') fahrenheit = float(input()) celsius = 5.0*(fahrenheit-32)/9.0 print(f'{fahrenheit} Fahrenheit is {celsius} Celsius degrees')
true
4e760dc107f2299b2f7ae32ee018d8d01c64fa37
caiquemarinho/python-course
/Exercises/Module 04/exercise_32.py
233
4.21875
4
""" Read a number and prints the number that comes before it and the one that comes after it. """ print('Please, insert a number') num = int(input()) num2 = num*3+1 num3 = num*2-1 total = num2+num3 print(f'The sum is {total}')
true
057b2406aebd962b659f261b1e1d0b420d5d5b63
caiquemarinho/python-course
/Exercises/Module 04/exercise_06.py
265
4.3125
4
""" Read a temperature in Celsius and convert it to Fahrenheit. Formula: F= C*(9.0/50)+32 """ print('Please, insert the temperature in Celsius') celsius = float(input()) fahrenheit = (celsius*(9.0/5.0)+32) print(f'{celsius} Celsius is {fahrenheit} Fahrenheit')
true
a68d682ba6d441b9d7fb69ec1ee318a0ef65ed40
caiquemarinho/python-course
/Exercises/Module 05/exercise_03.py
300
4.375
4
""" Read a real number. If it is positive print it's square root, if it's not print the square of it. """ import math print('Insert a number') num1 = float(input()) if num1 > 0: print(f'The square root of {num1} is {math.sqrt(num1)}') else: print(f'The square of {num1} is {num1**2}')
true
7361041ae643649002c3b1ede74231748319fe9c
caiquemarinho/python-course
/Exercises/Module 04/exercise_36.py
380
4.40625
4
""" Read the ray and height of a cylinder and print it's volume. Formula: V = π * ray² * height """ π = 3.14159265359 print('Insert the ray of the cylinder') r = float(input()) print('Insert the height of the cylinder') h = float(input()) v = π * r**2 * h print(f'The volume of the cylinder is: {v}') v2 = π * (r...
true
0cd6f0c079b4df00a6bf596e83b36b552d4beec5
bprasad2960/LearningPython
/calenders_refinished.py
1,272
4.46875
4
# Author: Littl # CreatedDate: 8th July 2021 # Example file for working with Calendars # # import the calendar module import calendar # create a plain text calendar c = calendar.TextCalendar(firstweekday=1) str = c.formatmonth(2017,1,0,0) print(str) # create an HTML formatted calendar h = calendar.HTML...
true
079b2473043fcab09fef745c8e6bc93276a0cdc5
JariMutikainen/pyExercise
/final/part6.py
1,916
4.1875
4
# This is the part 6 of the final exercises of the Python 3 Boot Camp. # 1. Write a function letter_counter(), which accepts a string and returns # a function. The inner function takes in a letter and returns the number # of times the letter appears in the string. def letter_counter(string): l_string = string.lowe...
true
a7755e54c6dc7284c5a785f8e7fa4f9535cf85bc
JariMutikainen/pyExercise
/experiments/multiple_letter_count.py
260
4.40625
4
def multiple_letter_count(word): """Counts the number of occurrences of each character in the input string. """ return {ch : word.count(ch) for ch in word} word = 'awesome' print(multiple_letter_count(word)) print(multiple_letter_count.__doc__)
true
1f726023a684966c7e3836679981dd3bec233510
JariMutikainen/pyExercise
/list_manipulation/list_manipulation.py
2,062
4.625
5
# This file contains the functions needed for # A. Removing an item from the beginning or end of a list and # B. Adding an item to the beginning or into the end of a list. # # The following examples demonstrate the use of these functions. # # list_manipulation([1,2,3], "remove", "end") # 3 # list_manipulation([1...
true
6e655318c71ff3693f9ba1207e402140ba60757e
vpetrigo/courses
/programming/adaptive-python/group_2/chocolate.py
743
4.21875
4
#!/usr/bin/env python3 # coding=utf-8 import sys def is_breakable(n, m, segment_size): """ Function determines whether it is possible to break off chocolate bar (n * m size) to exactly of given @segment_size in one cut example: n=2 m=4 segment_size=6 -> YES n=2 m=10 segment_size=7 -> NO ...
true
16b05d0e7416a4bd2a9445a0da3c050a6e6a06f8
candyer/leetcode
/01189_maxNumberOfBalloons.py
1,112
4.125
4
# https://leetcode.com/problems/maximum-number-of-balloons/description/ # 1189. Maximum Number of Balloons # Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. # You can use each character in text at most once. Return the maximum number of instan...
true
46c655f64c742e2a8726bebdb98757853285e66a
candyer/leetcode
/2021 May LeetCoding Challenge/25_evalRPN.py
1,996
4.15625
4
# https://leetcode.com/explore/challenge/card/may-leetcoding-challenge-2021/601/week-4-may-22nd-may-28th/3755/ # Evaluate Reverse Polish Notation # Evaluate the value of an arithmetic expression in Reverse Polish Notation. # Valid operators are +, -, *, and /. Each operand may be an integer or another expression. # N...
true
576fd486d74f83452d685d44000ffc09f53e3575
candyer/leetcode
/2021 February LeetCoding Challenge/23_searchMatrix.py
1,869
4.25
4
# https://leetcode.com/explore/challenge/card/february-leetcoding-challenge-2021/587/week-4-february-22nd-february-28th/3650/ # Search a 2D Matrix II # Write an efficient algorithm that searches for a target value in an m x n integer matrix. # The matrix has the following properties: # Integers in each row are sor...
true
293b8e1acc57c624778c78fd83f06746501f371e
candyer/leetcode
/2020 July LeetCoding Challenge/09_widthOfBinaryTree.py
2,072
4.15625
4
# https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/545/week-2-july-8th-july-14th/3385/ # Maximum Width of Binary Tree # Given a binary tree, write a function to get the maximum width of the given tree. # The width of a tree is the maximum width among all levels. # The binary tree has the same s...
true
efc8cd59d6a09a9f2b30058f46e72a25a0d1eecd
candyer/leetcode
/findDuplicates.py
1,116
4.15625
4
# https://leetcode.com/problems/find-all-duplicates-in-an-array/description/ # 442. Find All Duplicates in an Array # Given an array of integers, 1 <= a[i] <= n (n = size of array), some elements appear twice and others appear once. # Find all the elements that appear twice in this array. # Could you do it without ex...
true
6c917fc11f5b8c27119005ff162620e9e49b8fda
candyer/leetcode
/hammingDistance.py
768
4.125
4
# https://leetcode.com/problems/hamming-distance/description/ # 461. Hamming Distance # The Hamming distance between two integers is the number of positions at which the # corresponding bits are different. # Given two integers x and y, calculate the Hamming distance. # Note: 0 <= x, y < 231. # Example: Input: ...
true
169e2f9c02e65ab1bf3b91675ba01d63159c7de3
candyer/leetcode
/2020 August LeetCoding Challenge/28_rand10.py
1,052
4.125
4
# https://leetcode.com/problems/implement-rand10-using-rand7/description/ # Implement Rand10() Using Rand7() # Given a function rand7 which generates a uniform random integer in the range 1 to 7, # write a function rand10 which generates a uniform random integer in the range 1 to 10. # Do NOT use system's Math.rand...
true
f5e9a9c7f199acfa1bb91a7e4968b383d08dbd10
candyer/leetcode
/2020 June LeetCoding Challenge/10_searchInsert.py
1,318
4.1875
4
# https://leetcode.com/explore/featured/card/june-leetcoding-challenge/540/week-2-june-8th-june-14th/3356/ # Search Insert Position # Given a sorted array and a target value, return the index if the target is found. # If not, return the index where it would be if it were inserted in order. # You may assume no dupli...
true
a52e1858dc6284a96a984ed3fe62de767b0fb740
candyer/leetcode
/2020 August LeetCoding Challenge/11_hIndex.py
1,338
4.34375
4
# https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3420/ # H-Index # Given an array of citations (each citation is a non-negative integer) of a researcher, # write a function to compute the researcher's h-index. # According to the definition of h-index on Wiki...
true
1076aca598e93ccdb8fb001e0628f4a16bc8ba70
santosh-bitra/Python-Projects
/love-calculator.py
2,022
4.21875
4
#Love Percentage Calculator #Just an intro message on the program/app print("Hello.! Welcome to the love calculator. \n" "This in an app where you enter the your name along with your crush's name \n" "and you get to know how good will it work between you two .!!") #inout the names to be stored as below va...
true
9291b4cc0152295e8d8fbe8c2cbe6957a96c1353
Brigittie/Python-Exercises
/backwardsSentences.py
584
4.28125
4
def backwards_sentence(sentence): word_list = sentence.split(" ") #splits my sentence into a list, using "space" as the delimiter list_of_strings = (word_list[::-1]) #returns my list of words from beginning to end of array, with -1 increment print(" ".join(list_of_strings)) backwards_sentence("It is s...
true
ca6a6d4e6f69962621194ad8302a2071ca7b9144
manasharma90/python_learn
/revise.py
1,868
4.34375
4
#!/usr/bin/env python3 # Your task is to find all the palindromes in the support_files/words_alpha.txt file. # This file contains thousands of english words, your program needs to create a list of all the palindromes within this list. import sys # First function is to read the file and create a list of words from ...
true
059520ec1315dcb72de22c041c3394b24b988dc2
Sattik-Tarafder/PYHTON
/leap year.py
353
4.5
4
# Python program to check if year is a leap year or not year = 300 # To get user input, un-comment code below # year = input("Year: ") # if not year.isnumeric(): # exit("Invalid number") # year = int(year) if not year%100 == 0 and year%4 == 0 or year % 400 == 0: print(f"{year} Is a leap year") else: pri...
true
5fad106f4bf6cfb60ddd7eb569cb5d2f763161e2
persocom01/TestPython
/18_iterators_and_generators.py
839
4.15625
4
# Demonstrates iterator class function. class Countdown: def __init__(self, start): # Demonstrates isinstance function to check argument type. if not isinstance(start, int): raise TypeError self.start = start + 1 def __iter__(self): return self def __next__(se...
true
adb1528232be4b60dafd5fab215495ae5132bb9d
Johncwithers5/Data_Gathering_and_Warehousing
/learning_python/solutions/week_1/problem3.py
1,439
4.375
4
# Problem 2 - Find out what two dictionaries have in common # # ===== Description: # Get used to using python dictionaries by using built-in dictionary functions keys() and items() # # # ===== Instructions: # Complete the exercises below by completing the missing code for the python functions to accomplish th...
true
64547f138c96614a06217ac35e0d79baf0d6082c
Anthony-69/cp1404practicals
/Practical 2.4 exceptions_demo.py
1,070
4.53125
5
""" 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: ")) while numerator == 0: numerator =...
true
b2dbca21f5bca7665185fc9ad50c804594648ae1
BhagyashreeKarale/dichackathon
/2.py
419
4.3125
4
# Q2. Write a Python program to create a dictionary from a string. # Note: Track the count of the letters from the string. # Sample string : 'w3resource' # Output: {'w': 1, '3': 1, 'r': 2, 'e': 2, 's': 1, 'o': 1, 'u': 1, 'c': 1} string='w3resource' sdic={} slist=list(string) for i in slist: count=0 for k in r...
true
85949203e39a22ab479b7bce4cfd844b115343a1
hoangsangnguyen/Python-Tutorial
/Even_more_practice.py
923
4.15625
4
#Even more practice def break_words(stuff): words = stuff.split(' ') return words def sort_words(words): """sort the words""" return sorted(words) def print_first_word(words): """Print the first word after popping it off """ word = words.pop(0) print(word) def print_last_word(words): """ Print the last word ...
true
f90cbfedda93964288ae9de5ec2244f8651a3ab5
UGC04950/Html--css---and-Python-BootCamp
/python/strings.py
887
4.40625
4
# Strings # Basics # Single or Double Quote 'hello' "hello" # Indexing my_string = 'abcdefg' print(my_string[0]) # Slicing print(my_string[2:]) # up to but not including that index print(my_string[:3]) # define start and ending point - up to but not including 5 print(my_string[2:5]) # defi...
true
8d52c60d92abcb5c144be7355cfd4f716a644214
garnoth/python
/week4/9.5.py
336
4.1875
4
#!/usr/bin/python2 def uses_all(word, chars): for l in chars: if not l in word: return False return True prompt = "input a word. hit enter and enter all of the letters that must beincluded in the word\n" user_input_a = raw_input(prompt) user_input_b = raw_input('and the letters\n') print uses_all(user_input_...
true
cb0ba39dc8339b51498adb653c6f452ef1bd100e
enriquedlh97/ucsd_algos
/algos/algorithmic_toolbox/week_one/maximum_pairwise_product.py
2,661
4.40625
4
""" Problem: Find the maximum product of two distinct numbers in a sequence of non-negative integers. Input: A sequence of non-negative integers sample_input: [1, 2, 3, 7, 4, 6] Output: The maximum value that can be obtained by multiplying two different elements from the sequence. sample_outp...
true
715ed14a91724aa14e423cbe048c2d0bba0d697f
SabariVig/python-programs
/CodeWars/CW-8-Count-Odd-Numbers-Below-N.py
391
4.15625
4
""" https://www.codewars.com/kata/count-odd-numbers-below-n/train/python Given a number n, return the number of positive odd numbers below n, EASY! oddCount(7) //=> 3, i.e [1, 3, 5] oddCount(15) //=> 7, i.e [1, 3, 5, 7, 9, 11, 13] """ q=15023 print((q//2)) #Final Sol# def odd_count(n): return (...
true
ffded136ff2ee4d7e6e68a38f647763823271fcd
JustinTrombley96/Intro-Python-I
/src/lecture2.py
2,545
4.1875
4
# pass-by-reference vs passing-by-value # define a function that multiplies its input by 2 # this function passes its input by-value # if the input is not too memory-expensive, then it's a lot # def mult_by_2(x): return x * 2 y = 12 print(id(y)) #140708980879968 z = mult_by_2(y) print(z) #24 # passing-by-referen...
true
cd0ddaf12893bd8e0b4e9742208d5a7aacfa752f
ppinko/python_knowledge_library
/functions/functions_tips.py
2,017
4.6875
5
""" None - A function that reaches the end of execution without a return statement will always return None. """ def do_nothing(): pass print(do_nothing()) # Out: None """ Defining a function with an arbitrary number of arguments """ def func(*args): # args will be a tuple containing all values that are pass...
true
c14c6fdfcddf172e8f8f7f0e3f9a214d57b06095
ppinko/python_knowledge_library
/equality_operator/equality_operator.py
2,108
4.21875
4
""" The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands refer to the same object or not. Mutable data types when we create a new variable with the same value store it in different location, as the value can be changed """ list1 =...
true
ee2dcc0d3b705ae2e149d259a428c6c345f6d315
BhattChandresh/break-the-ice-with-python
/Day9/Question30.py
844
4.3125
4
# Question: # Define a function that can accept two strings as input and print the string with maximum length in console. # If two strings have the same length, then the function should print all strings line by line. print("-- Simple Method --") def get_maxlength_string(str1,str2): max_len_string = list()...
true
9dacaefdee87d8464483ae4308131a21d505c24a
BhattChandresh/break-the-ice-with-python
/Day8/Question22.py
356
4.28125
4
# Question: # Write a program to compute the frequency of the words from the input. # The output should output after sorting the key alphanumerically. sentences = input() my_dict = dict() my_list = sentences.split(" ") for item in my_list: my_dict[item] = my_list.count(item) for words, count in sorted(my_dict.item...
true
7880301af7f7ae1213960f5a6e7a77709457e6ad
loganknecht/CrackingTheCodingInterviewExercises
/InterviewQuestions/Amazon/print_all_nodes_that_do_not_have_sibling/problem.py
1,227
4.25
4
import node # sorted order # print all nodes separated by spaces which don't have siblings in the tree # Should be 1, 3, and 6 def printSibling(node, nodes_without_siblings): does_left_node_exist = (node.left is not None) does_right_node_exist = (node.right is not None) do_both_nodes_exist = (node.right...
true
9c9ca7800ce5c2e1fabe954ee35081e34ffb6f88
e68425971/270201029
/lab4/example2.py
329
4.25
4
numbers = int(input("how many numbers: ")) evenNumbers = 0 oddNumbers = 0 for i in range(1, numbers+1): entry = int(input("Enter an integer: ")) if entry % 2 == 0: evenNumbers += 1 else: oddNumbers += 1 print("percentage of even numbers"+""+(evenNumbers/numbers)*100+"%") #percentage of eve...
true
c06e1253a941648ac710eb4ae0835e9d5d505a8d
e68425971/270201029
/lab1/example6.py
252
4.125
4
first = float(input("write the first car's velocity ")) second = float(input("write the second car's velocity ")) road= float(input("how many km is your road ")) result = (road / (first + second) ) * 60 print(f"they will crash {result} minutes later")
true
694a94f5ca61e0fb9c9d7361a49281c746922e51
KJNoonan/Code-samples
/hw6palendrome.py
298
4.125
4
##method to recursively check if a word is a palendrome ##racecar def palindrome(s, l): if l <= 1:##base case return True elif l > 1 and s[0].upper() == s[l-1].upper(): return palindrome(s[1:l-1],l-2) else: return False s = "racecar" print(palindrome(s,len(s)))
true
9c28beab7ff13121d9bf8c440dc3adbdd2778007
halla4317/cti110
/M6HW2HallA.py
946
4.3125
4
# Write a program that generates a random number in the range of 1 through 100 # 6 Nov 2017 # CTI-110 M6HW2-Random Number Guessing Game # Hall, A import random # This command gives us the random numbers and also shows how many guesses the user gets def main(): guesses = 6 guesses -= 1 number = random.ra...
true
91cb09ca78239eacb408015a4f02389f41a9c9b7
Hannah-Pierre/lab10
/70-100pt.py
1,536
4.40625
4
########################################## # # # Draw a house! # # # ########################################## # Use create_line(), create_rectangle() and create_oval() to make a # drawing of a house using the tKin...
true
45a0034c3fe2fe8c1f59a7e34143fd49fd03f0f3
terranigmark/the-python-workbook-exercises
/part2/e34_even_odd.py
443
4.46875
4
""" Write a program that reads an integer from the user. Then your program should display a message indicating whether the integer is even or odd. """ def main(number): result = True if number % 2 == 0: return print(f"The number {number} is EVEN") else: return print(f"The number {number} i...
true
6aa80247c20955c54a990fb43335a0f5f983edca
terranigmark/the-python-workbook-exercises
/part1/e33_old_bread.py
1,251
4.1875
4
""" A bakery sells loaves of bread for $3.49 each. Day old bread is discounted by 60 percent. Write a program that begins by reading the number of loaves of day old bread being purchased from the user. Then your program should display the regular price for the bread, the discount because it is a day old, and the total ...
true
d3f7973d61fb0f457f1387c1d3bf54748c675e3a
terranigmark/the-python-workbook-exercises
/part1/e14_height_units.py
761
4.5625
5
""" Many people think about their height in feet and inches, even in some countries that primarily use the metric system. Write a program that reads a number of feet from the user, followed by a number of inches. Once these values are read, your program should compute and display the equivalent number of centimeters. "...
true
b3ef9a501393988066a26d38cf8d3c0f779309b9
terranigmark/the-python-workbook-exercises
/part2/e38_days_in_months.py
1,080
4.53125
5
""" The length of a month varies from 28 to 31 days. In this exercise you will create a program that reads the name of a month from the user as a string. Then your program should display the number of days in that month. Display “28 or 29 days” for February so that leap years are addressed. """ def main(month, thirthy...
true
28b871a58ce446aa12d17e1bb645c8a0baa366ea
terranigmark/the-python-workbook-exercises
/part1/e15_distance_units.py
527
4.3125
4
""" In this exercise, you will create a program that begins by reading a measurement in feet from the user. Then your program should display the equivalent distance in inches, yards and miles. """ def main(feet): ft_to_in = feet * 12 ft_to_yd = feet * 0.33333 ft_to_mi = feet * 0.00018939 return print(...
true
92da730b6d513adc6885331179c13eff47b95c1f
Santhoshkumard11/Day_2_Day_Python
/Simple_Recursion.py
310
4.25
4
# to implement simple recursion # method to calculate the sum of n numbers total = 1 def SumOfNNUmbers(number): if(number==1): return ( 1 ) else: return number * SumOfNNUmbers ( number-1 ) print("The sum of {} number is {}".format(2,SumOfNNUmbers(3)))
true
dcc327dae0458d82c0283908170bb78e196bf626
shashankdevan/Assignments
/Knights_Tour.py
2,101
4.15625
4
#!/usr/bin/python #Name: Shashank Devan (sdevan1) #Course: CMSC 671 #Subject: Homework 2 #Program: Knight's Tour #Instructions to run: python <filename>.py <size_of_board> import sys #increase the recursion stack depth to accomodate higher board sizes sys.setrecursionlimit(9999999) b_size=-1 board=[] counter=1 neigh...
true
94c1b3dfdbb8bce3282eac1cbeaef417550d9d23
zlqm/p_config
/p_config/converter.py
986
4.125
4
import re class Converter: """Convert raw value to expected format. For example: when you get port value from `os.environ`, you may get a '80', then you have to convert it into int. """ def convert(self, value): return value def __call__(self, value): return self.convert(valu...
true
e4b1e21bf7a71b1a24739edbbc86eb87759bd164
unsortedtosorted/DynamicProgramming
/knapsack/findTargetSubsets.py
893
4.21875
4
""" Given a set of positive numbers and a target sum ‘S’. Each number should be assigned either a ‘+’ or ‘-’ sign. We need to find out total ways to assign symbols to make the sum of numbers equal to target ‘S’. Example 1: 1, 1, 2, 3 Input: {1, 1, 2, 3}, S=1 Output: 3 Explanation: The given set has '3' ways to make ...
true
789d1661e47d55803e7cb394e38c05456d60e9bb
hawkinsj1384/CTI110
/M6HW1_TestGrades_Hawkins.py
1,216
4.4375
4
# This program calculates average and grade letter # November 17, 2017 # CTI-110 M6HW1 - Test Average and Grade # Jalessa Hawkins def main(): # Here the user will input five test grades. scores = input("Enter five test scores separated by commas: ") return [int(num) for num in scores.split(",")] # T...
true
4214e6182dd06916a391c383107bbbc6043d1096
gupta437/DS
/graph/shortest_path_out_of_maze.py
1,744
4.375
4
""" We have considered BFS and DFS graph traversal algorithms in the previous lectures. You task is to design an algorithms with breadth-first search that is able to find the shortest path from a given source to a given destination. The maze is represented by a two-dimensional list. [ [S, 1, 1, 1, 1], [0, 1, 1, ...
true
e483a04cdd33c829ff5198d5fa2b9592bdf81b8e
kstoltzenburg/SoftwareTesting-Learning
/lp3thw/ex5_more-variables.py
1,301
4.59375
5
#!/usr/bin/env python3.6 name = 'Zed A. Shaw' age = 35 # not a lie height = 74 # inches weight = 180 # lbs eyes = 'Blue' teeth = 'White' hair = 'Brown' print(f"Let's talk about {name}.") print(f"He's {height} inches tall.") print(f"He's {weight} pounds heavy.") print("Actually that's not too heavy.") print(f"He's ...
true
366eaf14b40a3b9fcef3d81ab1128a61f1f95945
dxmahata/codinginterviews
/leetcode/shortest_word_distance.py
1,242
4.125
4
''' Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. For example, Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Given word1 = “coding”, word2 = “practice”, return 3. Given word1 = "makes", word2 = "coding", return 1. No...
true
a17d2d49949f062d9acb477cba4b69f23d105a7a
Rajnikumar-data/pythonista
/python_unit_testing/Unit_testing.py
922
4.1875
4
# unit_testing # Simple function def upper_name(name): return name.upper() print(upper_name("Rajni")) # Same function for testing def upper_name(name): return name.upper() if upper_name("Rajni") == "RAJNI": print('pass') else: print('fail') ### Levels of Testing with given example # ...
true
06a0d35047a0fa1a6760f225419139f53e7b394d
greggwilliam/Python-Useful-Code
/polynomial_regression_GG.py
1,515
4.125
4
# Polynomial Regression Model - Deciding if the a new employee is lying about salary. #Importing the libraries import numpy as np #Needed for all maths things...use it for everything import matplotlib.pyplot as plt #Used for plotting graphs! import pandas as pd #Used for importing and managing data sets #Importing th...
true
257b5f53a72eb11c29e65dc2ce0aa7b361b7b110
ridamsharma33/cs50
/substitution.py
709
4.25
4
import sys def main(): n = len(sys.argv) if n != 2: print("Usage: Please provide a key.") return 1 key = sys.argv[1] if len(key) != 26 or not key.isalpha(): print("Usage: Key must contain 26 charaters.") return 1 else: print(f'Ciphertext: {substitution(ke...
true
f831407e70808e2370ba53ba0cabf5ce98d88218
emilyalice2708/houses-python-sql
/import.py
1,062
4.1875
4
import csv from sys import argv, exit from cs50 import SQL # Set up database connection with student database: db = SQL("sqlite:///students.db") # If incorrect number of arguments given, error and exit: if len(argv) != 2: print("Incorrect number of arguments given") exit(1) # Save csv file to a variable csv_...
true
9d4f712e2f715b5aec47f0efd3cde3a2349b0422
bhuvi8/python-basic-pgms
/fibonacci.py
653
4.1875
4
#!/usr/bin/env python """Fibonacci series This program generates n fibonacci series numbers and prints them to the screen, where n is given as a command line argument to the program """ __author__ = "Bhuvanesh Kumar (bhuvibhuvanesh@gmail.com)" __version__ = "0.1" __date__ = "2014-01-22 23:37" __license__ = "WTFPL" imp...
true
61ee21439317b8ce9cb05e15a85ee8e12b1c8735
Kcheung42/Hacker_Rank
/Data_Structures/Linked_List/Reverse_LinkedList.py
551
4.28125
4
""" Reverse a linked list 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 ReverseUtil(head, cur, prev): i...
true
dcf9f242f5723e82b01cd61b5f8f8aa24f095b4e
RoxanaDeSantAdria/my-python-codes
/basic calculations
712
4.375
4
#!/usr/bin/python # operation = input("What should I do? Type '+' to add, '-' to subtract, '*' to multiply, '/' to divide") # if (operation is '-') : print('subtract'), number - number2 # !/usr/bin/python number = input("Please enter a number") number2 = input("Please enter a number") operation = input("What should ...
true
f7a34e98e4edef48a6e261f641f995af6e4e3303
shrddha-p-jain/Python
/Assignment 0/11.py
332
4.1875
4
n = input("Enter a string: ") def reverse(s): return s[::-1] def palindrome(s): rev = reverse(s) if s.lower()==rev.lower(): return True else: return False a = palindrome(n) if a: print("Yes, {} is a palindrome".format(n)) else: print("No, {} is not a palindrome"....
true
3a5cddb5fa7c275ccc0b75347521056c91a1fdcb
crosbymichael1/beginner-project-solutions
/Higher Lower Guessing Game /main.py
892
4.1875
4
import random game = True guesses = 0 newnumber = True while newnumber: computer = random.randrange(1,101) while game: print("The computer randomly selects a number between 1 and 100 and you have to guess what the number is.\n") guesses = guesses + 1 user = int(input("Guess the Numbe...
true
b773668a0aa336794331e9dd3aac274ec0e95bd0
OIrabor24/beginner-projects
/rock_paper_scissors_two.py
917
4.34375
4
"""Ask the user to choose between rock, paper or scissors, then check who has won the game! Next print out text letting the player know who has won the game!""" import random def rock_paper_scissors(): player = input("Please select 'r' for rock, 'p' for paper, or 's' for scissors: ") choices = ['r', 'p', 's...
true