blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
10ebf62e1de8ec1425c4d9dc2d4f5e3695b7c9db
Rexben001/Sprint-Challenge--Data-Structures-Python
/names/binary_search.py
2,668
4.15625
4
class BinarySearchTree: def __init__(self, value): self.value = value self.left = None self.right = None # Insert the given value into the tree def insert(self, value): # check if the value is less than the root, move to the left if value <= self.value: #...
true
19769aed17db2f45f59f3231fb70f22c1e810108
yangbolin/python
/basic/function.py
231
4.1875
4
#output every element in an array using python print "Hello python"; raw_input("Press any key to close this window..."); def sort(array): for index in range(len(array)): print(array[index]) arr = [1, 2, 3, 4, 5] sort(arr);
true
51740775a29d16095e79e2cc973f366b1ea113aa
samzad/PythonforCybersecurity
/end/CH06/passHasher.py
892
4.125
4
#!/usr/bin/env python3 # Script that hashes a password #By Ed Goad # date: 2/5/2021 import crypt # Simple script that takes an unhashed password and a salt # We then hash the password + salt using various types # Sample data # Password: Password01 # Salt: G.DTW7g9s5U7KYf5 # SHA-512 result: # $6$G.DTW7g9...
true
8145514215f4f87af0c764fb0ec1d2a6fcafedd0
samzad/PythonforCybersecurity
/end/CH03/Loopy.py
1,640
4.375
4
#!/usr/bin/env python3 # example workign with Loops #By Ed Goad # date: 2/5/2021 # Suggestion # build out 1 function at a time and walk through them with the debugger # not necessary to run all functions def forLoop(): for x in range(6): print(x) def whileLoop(): count = 0 while (cou...
true
b171c3430aa397cfe574c9d2c3523bc474702541
markthornton66/Test
/Chapter 9 - Classes/Exercise 9.2.py
867
4.25
4
# this is exercise 9.2 class Restaurant(): """this creates a class which describes a restaurant""" def __init__(self, restaurant_name, cuisine_type): """initializes the description of a particular restaurant""" self.restaurant = restaurant_name self.cuisine = cuisine_type def desc...
true
b5709ac6b96dfd95e397770bb1169f4480663f55
ChrisWeiner/CS362_InClassActivity_Calculator
/CW_calculator.py
1,194
4.1875
4
def addition(x,y): return x+y def subtraction(x,y): return x-y def multiplication(x,y): return x*y def division(x,y): if(float(y) == 0): print("Cannot divide by zero") return else: return x/y try: print("Enter the first number: ") input1 = input() x = float...
true
118696046544d93fb00e48dab14bf8247c07c938
CodecoolBP20172/pbwp-3rd-si-code-comprehension-mhenrik
/comprehension.py
1,715
4.34375
4
import random # import random module guessesTaken = 0 # assign 0 to guessesTaken variable print('Hello! What is your name?') # output the string myName = input() # assign myName to user input number = random.randint(1, 20) # assign number to a random number between 1 and 20 print('Well, ' + myName + ', I am thi...
true
32b777de6e2c865e32ab5670f325c0e909499af6
AlbertoJim04/Python-
/AlbertoJimenezMidtermProj.py
1,674
4.25
4
#INF360 - Programming with Python #Alberto Jimenez #Midterm Project ''' The purpose of this project is for the user to be able to Save Contact Information, Print contact list,for the FINAl version Id like to add Search or remove. Functionalities that are NOT quite there : As of now I am not able to add mpre than o...
true
b8e5873bbbab4e61ab2788fc12a984cdb3820ff9
udaynarwal72/pythontutorial
/lectures/file writing.py
1,712
4.46875
4
# MODES # “w” mode: # Here “w” stands for write. After opening or creating a file, a function, f.write() is used to insert text into the file. The text is written inside closed parenthesis surrounded by double quotations. There is a certain limitation to the write mode of the opening file that it overrides the existin...
true
12552318daf219377df52a4146337cf152f2073d
jacqui-can2/School-Work
/First_Function.py
1,212
4.53125
5
#Jacqueline Cantu #Computer Science 1370.02 #ConvertLab #Part 1:brute force program: """ f = float(input("Enter a temperature in Fahrenheit: ")) c = (f - 32.0) * (5/9) print("{0:.2f}" .format(f), "degrees in Fahrenheit is","{0:.2f}".format(c), "degrees in Celcius.") """ #Part 2: # define your conversion f...
true
4092aa6f6fc069b8dc6f6660a43396eefcfdecee
ofkarakus/python-assignments
/Python Basics/3-Control Flow Statements/Assignment-1/Assignment - 1 (if-Statements).py
712
4.34375
4
# Task : Let's say you left a message in the past that prints a password you need. To see the password you # wrote, you need to enter your name and the program should recognize you. # Write a program that # Takes the first name from the user and compares it to yours, # Then if the name the user entered is the same a...
true
12bc90e64fe63486cd3e616c1f0f6e6b4e5d7973
ofkarakus/python-assignments
/Questions - Answers/question_answer_8.py
524
4.15625
4
# Define a “function” to calculate permutation of 2 numbers. # Reminder: P(n,r) = n!/(n-r)! # Clue: Defining a function that calculates factorial of given number, may be # helpful. def factorial(x): fact = 1 for i in range(1, x+1): fact *= i return fact def permutation(n,r): return factorial...
true
92e9b982723b2ffe42c84983b5227797a1757c39
aegersz/tf-and-python-examples
/timestable.py
341
4.40625
4
''' Python program to find the multiplication table (from 1 to 10)''' num=1 # To take input from the user num = int(input("Display multiplication table of? ")) use for loop to iterate 10 times for i in range(1, 11): if num != i: print(num,'x',i,'=',num*i) for j in range(1, 11): print(num,'x',j,'='...
true
3d963563a29e7ddc6d98ff87433029de7ff33b6e
Vijay-Arulvalan/Codex
/Python/Geeks/type.py
339
4.25
4
#python convertion to demonstrate type convertion #Using int(), float() #initialize string s = "10010" #printing string converting in int base 2 c = int(s, 2) print("After converting to integer base 2 : ", end = '') print(c) #printing string converting to float e = float(s) print("After converting to float: ", en...
true
4d9137cb2d08b599c07a64a56d86547d801d5351
Vijay-Arulvalan/Codex
/Python/crash/file_mul.py
764
4.46875
4
#Word_count with loop for multiple files def count_words(filename): """Count the approximate word in the file""" try: with open(filename) as file_object: contents = file_object.read() except FileNotFoundError: # pass #if we use pass then this error wont be considered it will pas...
true
20c186b0981501ea7d9bd4a63c2f5b2fd22e9abe
Vijay-Arulvalan/Codex
/Python/crash/num.py
466
4.625
5
for value in range(1,6): print(value) #to list the numbers num = list(range(1,6)) #if we want a list of numbers we can convert the output of range into the list() function print(num) #to get the even_numbers even_numbers = list(range(2,21,2)) print(even_numbers) #to get the odd numbers odd_numbers = list(range(1...
true
702e37ffcac302f9f27ee4f8562f42bc69d53358
angelineh64/code-dump
/hidalgo_tempconversion.py
347
4.5625
5
# Angeline Hidalgo # February 2, 2020 # Prompts user to enter the temperature in Fahrenheit. Fahrenheit = float(input("What is the temperature in Fahrenheit: ")) Celsius = (Fahrenheit - 32) * 5/9 # The equation for converting Fahrenheit to Celsius. print('Your temperature in Celsius is: ', Celsius) # Prints ...
true
7e763b486b947077c40cffa32118ecbac7de8538
chetanpv/python-snippets
/LevelTwo/input_lines_formatting.py
501
4.28125
4
# Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized. # Suppose the following input is supplied to the program: # Hello world # Practice makes perfect # Then, the output should be: # HELLO WORLD # PRACTICE MAKES PERFECT print "\n...
true
c4b3002d2a62dced4588f430a26f47972ec35540
chetanpv/python-snippets
/LevelOne/factorial.py
414
4.15625
4
# Question: # Write a program which can compute the factorial of a given numbers. # The results should be printed in a comma-separated sequence on a single line. # Suppose the following input is supplied to the program: # 8 # Then, the output should be: # 40320 def fact(x): if x == 0: return 1 ...
true
bb1f0091f49a4bafde99de3b67427100894d7db4
smsenger/InClass_Exercises
/Hotel/5RmHotel_checkOut.py
1,818
4.15625
4
#dictionary of hotel rooms paired with name #some rooms pre-populated to check function in isolation hotel = { '101' : {'occupant_name': 'Darlene Alderson', 'occupant_phone': 1234567891, 'has_prepaid' : 'True', }, '102': {}, '103': {}, '104': { 'occupant_name': 'Darlene Alderson',...
true
b047d0402271ceda20b505c7cf4f299e1c714bc9
AustinTSchaffer/DailyProgrammer
/Cracking the Coding Interview/Python/ctci/chapter01/_q04.py
2,216
4.5
4
def palindrone_permutation(some_string: str) -> bool: """ Returns `True` if the input string is a permutation of a palindrome, meaning the string can be rearranged into a palindrome. Only takes alphabet characters into consideration. Palindromes are sequences of letters that are identical forwards...
true
95bf7763939f1e22486a15d2f96d7a01f3b339d3
cu-swe4s-fall-2019/test-driven-development-rymo1354
/math_lib.py
2,567
4.15625
4
import sys import math def list_mean(L): """ computes the mean of a list of numbers Arguments _________ L : list of ints or floats calculate mean of this list Returns _______ mean : float """ try: s = 0 for v in L: s += v return s ...
true
d3276750ba7b85f346443ff821e3770cee857a8d
KarunaAthichan/BasicPythonProgramming
/primenumber.py
493
4.34375
4
n = int(input("Enter a number : ")) # Set the flag, isprime = "true" isprime = "true" ''' to find a prime number, start div by 2 to till half of the number; but n//2+1 is absolute division + 1 number because of for loop''' if n>1: for i in range(2,n//2+1): if n%i == 0: isprime = "false" ...
true
854ee9adc34f597d39eeac06ad2a4586fe2c7e74
KarunaAthichan/BasicPythonProgramming
/AbstractClassConcreteClass.py
1,767
4.6875
5
# Abstract Class # Abstract Base Class and Abstract method import from abc import ABC, abstractmethod # Animal class inherit from ABC class class Animal(ABC): # create initialiser function def __init(self, name): self.__name = name # create abstract method, it shouldn't have any information ...
true
a28c7aad99db82eee3bef40b2ae87a1b61eacccf
KarunaAthichan/BasicPythonProgramming
/FunctionSquareNumber.py
682
4.3125
4
# defining a function def sqrt(n): # create an unlimited while loop while True: # multiply the numbers and send result to main function yield n * n # increment the number n = n + 1 # get the start and end number of a square n = int(input("Enter the start value of a square")) x =...
true
59d821bb88b15d897c116571ced47f6a10d37186
KarunaAthichan/BasicPythonProgramming
/StudentManagementList.py
1,186
4.125
4
#create an empty list lst=[] #Create while loop for unlimited loop running while True: print("*"*25) print("1.Enter name\n2.Search name\n3.update name\n4.delete name\n5.exit") print("*"*25) n = int(input("Enter the option")) if n==1: entername = input("Enter the name :") print("Entered name is :",en...
true
d05b6d8768db327989dbb64c31075dd3a6b47fd3
KarunaAthichan/BasicPythonProgramming
/Inheritance_PublicPrivate_OOP.py
1,165
4.46875
4
''' Write an object oriented program that performs the following tasks: 1. Create a class called Chair from the base class Furniture 2. Teakwood should be the type of furniture that is used by all furnitures by default 3. The user can be given an option to change the type of wood used for chair if he wishes to 4. The n...
true
802b5db25595951fbfac4a62c4224d71e531732a
zheng129/School-Projects
/Python Projects/#44.py
819
4.4375
4
## # Zheng, Yixing # October 2, 2016 # CS 122 # # A program that prompts the user for a frequency value and prints a description # of the corresponding part of the electromagnetic spectrum ## # Get input frequency = int(input("Enter the frequency: ")) # Determind the frequency is in which catalog and print out the re...
true
9e07d84b46aa80fa37e520d52d13362f8c51aa30
buzsb/python_practice
/src/binary_search.py
2,110
4.125
4
def binary_search(sorted_list, searched_element): if not sorted_list: return None start = 0 end = len(sorted_list) - 1 while start <= end: middle_element = (start + end) / 2 if sorted_list[middle_element] == searched_element: return middle_element if sorted_l...
true
3fc5218658995a4c2e4168555be20765923daa21
idayat092/Project-Euler
/Solutions/solution_004.py
763
4.21875
4
"""Problem 4: Largest palindrome product 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.""" # Define the range of 3 digit numbers minimum = 100 maximum = 999 m...
true
fe16e34b895f9f61e8b4a01462b578d439f74d3b
shruti3009/HackerRankCodes
/FindAverageMarks.py
1,436
4.28125
4
""" You have a record of N students. Each record contains the student's name, and their percent marks in Maths, Physics and Chemistry. The marks can be floating values. The user enters some integer followed by the names and marks for N students. You are required to save the record in a dictionary data type. The user t...
true
c670cedf2367558020de6f6c7fad8594e53dad44
Penqor/HOMEGROWNGILL
/HGG_calculatePrice.py
1,238
4.5
4
""" 2.8 Calculate Price """ # random order to calculate price with order = {'apples': {'price': 4, 'quantity': 5}, 'oranges': {'price': 2, 'quantity': 2}, 'milk': {'price': 5, 'quantity': 22}, 'orange juice': {'price': 5, 'quantity': 4}, 'peanuts': {'price': 0.5, 'quantity': 8}} # create a function which calcu...
true
653affc139d3e516aa769cf55b4c7b59bc6c198d
wmeller/BCOC-Tools
/min_subnet_size.py
2,861
4.15625
4
''' These are helper functions for network design. min_subnet_size determines the smallest class C network which will support the number of hosts specified as an input. It will work when passed in a list of host requirements, or a single number. It uses the equation network_size = rounddown(32-ln(hosts_needed+2)/ln(2))...
true
9411c9ddf3afe1bc169dea8cc9e9866c16c62b3c
cblank210/python-challenge
/PyBank/main.py
1,346
4.21875
4
# PyBank Homework solution # import modules import os import csv # Create a variable for csv file budget = "Resources/budget_data.csv" # Tell the program to open the file, skip the header row, and create a list for each column with each row of information with open(budget) as csv_file: reader = csv.reader(csv_...
true
0ff553593c80be124c09e799882dce0955634881
nyu-compphys-2017/section-1-kstoreyf
/riemann.py
901
4.375
4
# This is a python file! The '#' character indicates that the following line is a comment. from __future__ import division import numpy as np # The following is an example for how to define a function in Python # def tells the compiler that hello_world is the name of a function # this implementation of hello_world tak...
true
fcb69653d0977ec72e9ae1ce5040102ae67bb805
RedFantom/practice-python
/Exercise 03 - Lists.py
342
4.21875
4
print "Please enter a list in the form of [n, n, n]" numbers = input() new_numbers = list() index = 0 print "Please enter the number you want to be the maximum" condition = int(raw_input()) for number in numbers: if(number <= condition): print number new_numbers.append(number) index = index ...
true
4aa5cd667c1b816e710a9b9a814f95934f8470e5
Shifat89/PythonLearningTry
/condition.py
332
4.1875
4
x=input("x value is= ") x=int(x) if (x>=5): print("x greater than or equal to 5!") if(x==5): print('x is equal to 5') else: print('x is greater than 5') else: print('x is less than 5!') no=input('number only!=') try: isNo=float(no) except: isNo=-1 print('number...
true
8c06d7f9709d2fdf6d4b4d21ef7ee835f35060a7
japerry911/CodingExercises
/Python/CountPrimes.py
773
4.375
4
""" ---Count Primes--- Count the number of prime numbers less than a non-negative number, n. Example 1: Input: n = 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. Example 2: Input: n = 0 Output: 0 Example 3: Input: n = 1 Output: 0 Constraints: 0 <= n <= 5 * 10^6 """ def...
true
91ab16b0b003cddc25cf093b4dc70a03656caee9
mukuld/python
/66_television.py
2,115
4.25
4
# Python Programme Number 66 # Simulate a Television set # Programmer: Mukul Dharwadkar # Date: 8 September 2006 # Final Date: 9 June 2009 class Television(object): """A virtual Telly""" def __init__(self, channel=1, volume=10): self.channel = channel self.volume = volume """ Empty modu...
true
3dd7dd865ec13e281d718badf35f70983d9c04bf
mukuld/python
/25_hero_inventory_v2.py
1,300
4.21875
4
# Python Programme Number 25 # Hero's Inventory v2.0: Demonstrates the power TUPLES # Programmer: Mukul Dharwadkar # Date: 8 March 2006 # Create an tuple with some items and display inventory = ("Sword", "Shield", "Armour", "Healing Potion") print "\nYou have:" for item in inventory: print item raw_...
true
404f1d937641c263346f5d329bf47b9616505797
mukuld/python
/rps.py
2,358
4.4375
4
# An all-time favorite game of Rock Paper Scissors. # Programmer: Mukul Dharwadkar # Date: June 27 2017 import random def instructions(): """Displays the game instructions""" print('''\n Today we will play the perennial favorite game of...\n Rock! Paper!! Scissors!!!.\n The objective of the game is to outthink...
true
6c76a1ca92a70a8d041b86d37d59c49d7e4a83c0
mukuld/python
/13_guess_number.py
1,190
4.4375
4
# Python Programme Number 13 # Guess my number game # Programmer: Mukul Dharwadkar # Date: 24 February 2006 # # In this game, the computer picks a random number between 1 and 100. # The player of the game has to guess the number. After each guess, # the computer tells the player whether the guess is too high or too low...
true
7d45e333f473086eb662b1f9de774eed74d9328d
mukuld/python
/Nandini/area_of_a_rectangle.py
271
4.3125
4
<<<<<<< HEAD length = input("Enter length of a rectangle: ") ======= length = input("Enter length of a rectangle: ") >>>>>>> Setting up my python repository width = input("Enter width of a rectangle: ") area = length * width print "The area of the rectangle is: ", area
true
5ca3d3302c318a4239d63919109fd676d492a595
303tek/EDx-MITx--6.00.1x
/semordnilap.py
362
4.28125
4
def semordnilap(str1, str2): ''' str1: a string str2: a string returns: True if str1 and str2 are semordnilap; False otherwise. ''' if len(str1)!=len(str2): return(False) elif str1=='' and str2=='' : return(True) else: return (str1[0] == str2[-1...
true
aceb9fdcc8738e21c1837005ded3a256114bef4b
xiashuijun/Projects-1
/Find_Cost_of_Tile_to_Cover_W_H_Floor.py
388
4.25
4
########################################### # Author: klion26 # Date: 2014/11/01 # Problem: Find Cost of Tile to Cover W*H Floor ########################################### # calculate the cost of W*H Floor def calCost(w, h, cost): return w*h*cost w = input("input the width: ") h = input("input the h...
true
e9895677359ca1801cd6df7abc2c47035f3eebcc
wrobe0709/Project-Euler
/pythagorean_triplet.py
613
4.59375
5
""" A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. """ from math import sqrt def pythagorean_triplet(): for a in range(1, 334): ...
true
bc4c1554d12209d2b36a7fb3752fb7e07d237ff2
amondal2/tutorials
/algorithms/binary_search.py
630
4.15625
4
# python implementation of binary search import math def binary_search(array, value): left = 0 right = len(array)-1 while left <= right: middle = math.floor((left+right)/2) if array[middle] < value: left = middle+1 elif array[middle] > value: right = middle -...
true
2bf0485767fbd4d838e40611302baa6366ae14a7
mboersma/exercism-python
/word-count/word_count.py
538
4.1875
4
"""Given a phrase, count the occurrences of each word in that phrase.""" from collections import Counter import re def word_count(phrase): """Return a dict counting the occurrences of each word in a phrase.""" pattern = r""" [a-zA-Z0-9]+ # one or more alphanumeric characters (?<!\\) # not prec...
true
03d622fb7e1f449c8232ecadbe470688c6ee9ea1
Maycol29/Python_es
/Practica 2/ej7p2.py
252
4.34375
4
palindromo = str(input("ingrese una palabra ")) #initial string reversed=''.join(reversed(palindromo)) # .join() method merges all of the characters resulting from the reversed iteration into a new string print(reversed) #print the reversed string
true
446090f56aa8674fcbb734162f6defe3195366b3
ritesingh/Python_AcadView
/assignment_seven.py
1,900
4.125
4
#Q.1- Create a function to calculate the area of a circle by taking radius from user. def carea(r): return (22/7)*r*r r=float(input("enter the radius of circle: ")) print("the area of the circle will be: ",carea(r)) """Q.2- Write a function “perfect()” that determines if parameter number is a perfect numbe...
true
cfdf038732ae53116f69ae57ed0c9fc4ea50a775
ritesingh/Python_AcadView
/assignment_twenty.py
994
4.25
4
import pandas as pd #Q.1 - Create a dataframe with your name , age , mail id and phone number and add your friends’s information to the same. val={'Name':['Ritesh Singh'],'Age':[20],'Email':['gettoriteshsingh@gmail.com'],'ph no.':['9056669767']} df=pd.DataFrame(val) df.loc[1]=['Piyush',22,'piyushkp1000@gmail.com'...
true
7faa2bf0f6cf7edf8e7afbae6b07f56d85de940f
tonyxuxuxu/Leetcode-Training
/4.median_of_two_sorted_arrays.py
1,476
4.15625
4
""" There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 = 2.5 """ class So...
true
14ec5e3e7a23aa94ad94231b572c63c2319dc71d
GabyLE/Learning-Python
/PythonForEverybody/Python Data Structures/Assigments/ex_07_02.py
1,021
4.28125
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 be...
true
c947306e87460461deb692f372989f98e33666c9
Uthaeus/w3_python
/19.py
347
4.40625
4
# Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchanged. def add_is(s): beg = s[0:2] if beg == "Is": return s else: return "Is " + s.lower() user_in = input("Enter a string\n...
true
625f29da9b2b7fcdac9f8db578d5596f435a8ce8
Uthaeus/w3_python
/26.py
350
4.1875
4
# Write a Python program to create a histogram from a given list of integers. def histogram(l): li = map(int, l.split(',')) for x in li: output = "" times = x while(times > 0): output += '*' times -= 1 print(output) test = [2, 3, 6, 5] histogram(test) user_in = input("Enter some nu...
true
6cf34b42a17e5073c22fe0046b9cf75e0502d799
Uthaeus/w3_python
/37.py
421
4.34375
4
# Write a Python program to display your details like name, age, address in three different lines. def info(n, age, add): result = f""" Name: {n}\nAge: {age}\nAddress: {add} """ result2 = f"Name: {n}\nAge: {age}\nAddress: {add}" print(result) print(result2) user_n = input("Enter your name: ") user_age = ...
true
c8a58d3f181fb739209ed5667e576cef25571285
Uthaeus/w3_python
/110.py
441
4.15625
4
# Write a Python program to get numbers divisible by fifteen from a list using an anonymous function. def fifteens(l): result = [] for x in l: if x % 15 == 0: result.append(x) print(result) t1 = [3, 567, 543, 565, 150, 300] fifteens(t1) num_list = [45, 55, 60, 37, 100, 105, 220] # use anonymou...
true
2f549c26f6bda8dfca24dc55f4002c78523d8f90
Uthaeus/w3_python
/36.py
331
4.21875
4
# Write a Python program to add two objects if both objects are an integer type. def type_check(a, b): if isinstance(a, int) and isinstance(b, int): result = a + b else: result = "Need two numbers" return result print(type_check(3, 4)) print(type_check('a', 3)) print(type_check('a', 'b')) print(type_c...
true
885c0d6b5509209bafedf6cd78071dbe8c6b2317
MichalNetik/ProjectE
/python/even_fibonacci_numbers_002/main.py
659
4.34375
4
def _fibonacci_generator(num: int): """ Yield fibonacci numbers which are lesser than num. """ previous_number = 0 current_number = 1 yield previous_number yield current_number while (previous_number + current_number) < num: previous_number, current_number = current_number, previ...
true
4387a3ab364d86f474086550e5d659fbc931f217
christinenyries/guess-number
/main.py
1,835
4.125
4
import random from functools import wraps def computer_says(*args, **kwargs): print(f"{'COMPUTER':10}: " + "".join(args), **kwargs) def user_says(*args, **kwargs): return input(f"{'USER':10}: " + "".join(args), **kwargs) def guess(n): """Asks user to guess a random number from 1 to `n`. Args: ...
true
a423cf6ffe570a9af0b4d6f02c172468494cc79e
AyaAshrafSABER/ACM-Python-Training-
/session 3/Factorial using while loop.py
330
4.4375
4
# number to find the factorial of number = 6 # start with our product equal to number product = number while number > 1: # decrement number with each iteration until it reaches 1 number -= 1 # multiply the product so far by the current number product *= number # print the factorial of number print...
true
d530833a68f480ce4606d56c16a4dc7d7c0a07ea
Mr-Snailman/gf-robot
/pi/examples/tell-time.py
257
4.125
4
import time from datetime import datetime while (1): now = datetime.now() hour = now.hour minute = now.minute second = now.second day = datetime.today().weekday() if hour == 7 and minute = >= 0 and day < 5: print "It's 7:00 on a weekday"
true
3072085c14bedd4e6622d64b8ed3a2fbba1fe0e0
mayankt90/Python100QuesChallenge
/Day6.2.py
543
4.4375
4
# You are required to write a program to sort the (name, age, score) tuples by ascending order where name is string, age and score are numbers. The tuples are input by console. The sort criteria is: # 1: Sort based on name # 2: Then sort based on age # 3: Then sort by score # The priority is that name > age > score. ...
true
da99093124d8386823de414a265a6a277837d36b
LinhQuach13/python-exercises
/warmup.py
2,368
4.40625
4
# Exercise #1 # write the code to take a string and produce a dictionary out of # that string such that the output looks like the following: Some thoughts: # You'll need a way to get the first part of the # string and a way to get the second part of the string # Feel free to make new variables/data types # in betwe...
true
90e44f1290bbabb0f4cf7a1ef69928e301180675
ArpanBalpande/10-Python-built-in-functions-you-should-know
/hex_2.py
965
4.375
4
def rgb_to_hex(rgb_triple): """Function that maps a RGB tuple representation to a hexadecimal string Parameters: rgb_triple (tuple): RGB tuple representation (red, green, and blue) Returns: hex_string (string): Hexadecimal string representation '0xRRGGBB' """ hex_string = '' # we loop th...
true
7ca9526abfd17a3153d6f55a36b031d03004bf68
janvande/Practice
/String Lists.py
1,132
4.25
4
#yourString = input('Please provide a string, we will check if it is a palindrome - Bob') #listString = [] #revString = [] #stringLength = len(yourString) #for char in yourString: # listString.append(char) #for revcar in range(stringLength): # revString.append(yourString[((stringLength-1)-revcar)]) #test1 = ''.jo...
true
833fe6291f44143574abee6fab25f30c9d0a7daf
EM-Lee/coding-skills
/Exercises for Programmers - 57 challenges/ch.01/2017.04.26.py
246
4.1875
4
bill = float(input("What is the bill? ")) tipRate = int(input("What is the tip percentage? ")) total = bill + bill * tipRate / 100 print "The tip is " + "{:d}".format(tipRate) + "%." print "The total is $" + "{:.2f}".format(total) + "."
true
a2ea0070ebd9c2ce8ea4fe32c3f5a7974d2d62bf
robinwettstaedt/codewars-kata
/6KYU/word_spinning.py
551
4.15625
4
""" 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 (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 present. """ def spin_words(se...
true
d9331a66ec8e1c7484cb7abca09c62b334421ff9
ckmcknight/project-euler
/P1-P9/P8.py
727
4.21875
4
# Written in Python for easier file manipulation. # Find the largest product of 13 adjacent numbers that can be found in the # integer in the accompanying file P8Number.txt #Reads the number in as a string def readNum(fileName): f = open(fileName) return f.read().replace("\n", "") def largestProduct(fileName,...
true
21255462b73edbd0d833c9fee1cfeabbfd2249f5
JosephReps/3D-Crossword
/word_list.py
1,151
4.15625
4
""" Creates word list of valid words from the 'words.txt' file. """ import re def filter_wordlist(): ''' Filters the word list, removing invalid words. ''' word_list = [] with open('words.txt', 'r') as f: for line in f: if re.match("^[a-z]+$", line[:-1]) and len(line[:-1]) > 2:...
true
892ff9e201a6a11132d97901fb7787b19d3050a9
abhisheksharma28/pythonTraining
/PythonTraining/Lists.py
1,001
4.125
4
friends = ["kevin", "karen", "jim"] # can make the variables number, boolean like ["kevin", 20, True] # 0 1 2 # -3 -2 -1 print(friends[0]) print(friends[-1]) # to access items from the back print(friends[1:]) # print all starting from 1 friends = ["kevin", "karen", "...
true
28f3198c3bbacb978620711a4f46818373db971f
abhisheksharma28/pythonTraining
/PythonTraining/if statements.py
313
4.28125
4
is_male = True is_tall = False if is_male and is_tall: #or and both works print("You are a male or tall or both") elif is_male and not(is_tall): print("You are a short male") elif not(is_male) and is_tall: print("You are not a male but are tall") else: print("You are neither male nor a male")
true
8bfa4294ac0e984c86925ba96a1354720ec2ce65
ikelbrown/novTryPy
/Jayanth/lists/remove.py
326
4.15625
4
# remove method can be used to remove a value from a list # This does not return any value but removes the given object from the list.\ # Only one occurance is removed at each call. aList = [123, 'xyz', 'zara', 'abc', 'xyz']; print aList aList.remove('xyz'); print "List : ", aList aList.remove('abc'); print "List : ",...
true
ac3cf734512b24b647e54cc6901eb5b6e50696d0
manishawsdevops/pythonmaster
/Python Basics - Part I/builtinfuns_methods.py
583
4.15625
4
#Built in Functions and Methods #https://docs.python.org/3/library/functions.html greet = 'Hellooworld' print(len(greet)) print(greet[:len(greet)]) #Functions and Methods # Functions accepts arguments in curly brackets like print() # Methods are like which start with "." in the front line .format() quote = 'to be or...
true
81043d5f834d16343145796af4c9caf39d169562
manishawsdevops/pythonmaster
/Python Basics - Part I/strings.py
1,330
4.46875
4
#strings print(type("Manish Gandhi!!")) username = 'baahubali' password = 'rajamouli' #Long strings can be used for multi line strings. long_string = ''' WOW O O --- ''' print(long_string) first_name = 'Manish' last_name = 'Dodda' print(first_name + ' ' + last_name) #Strig concatenation. # Strings can concat...
true
39e49aef157f095f28c078797a8ede1b1be49040
manishawsdevops/pythonmaster
/Advanced_Python_Generators/Generator.py
1,094
4.53125
5
# Generator # This is advanced topic, these are in python allows us to generate values over a time. # range() is a generator. # Generators can be used to generate a sequence. # These are prettu hard initially to understand but they are memory optimised. Observe carefully the # below example. If a function has "yield"...
true
d3dc731322432241c96e22709a55aebb40b909c2
manishawsdevops/pythonmaster
/Python Basic - Part II/is_vs_==.py
397
4.125
4
# there are cases where we get confused with 'is' and == # == this checks for the equality of the value. # is this checks for the exact same value in the same memory address location. print(True == False) print('1' == 1) print([] == 1) print(10 == 10.0) print([] == []) print(True is False) print('1' is 1) print([] i...
true
51d34a9a625dd70cd5cfe31042f9662fa0cfdeef
manishawsdevops/pythonmaster
/Python Basics - Part I/augmented_operator.py
288
4.21875
4
#Augmented assignment Operator. some_value = 5 #some_value = some_value + 2 # Rather than having above we can use the below - Its a short hand of above some_value += 2 print(some_value) some_value = 5 some_value -= 2 print(some_value) some_value = 5 some_value *= 2 print(some_value)
true
5143def8758f9e20ba825eeecca55a67227f17c1
Balakrishnababu/app_1.py
/game.py
1,392
4.125
4
import random from time import sleep choice = ["Rock", "Paper", "Scissors"] computer = random.choice(choice) player = False while player == False: print("Welcome to Rock, Paper and Scissors!") print("\nPlease, wait the game is loading....") sleep(10) player = input("Which one do you want to choose?\n'Rock': 'Roc...
true
df7e77a554aca8f265d03f930539faadf98335d4
yongxuUSTC/challenges
/power.py
1,577
4.28125
4
#Question: Write a program to calculate x^n #Answer: #1. Observation: # 1.1 exponent is a positive integer #2. Algorithm: # 2.1: Dividing & conquering using the least significant bit in the exponent and using a iterative function will improve efficiency #3. Complexity # 3.1: O(n/2) where n is the expon...
true
e132d689f6ff94796211b1775dcebe5baefeb20e
yongxuUSTC/challenges
/prime.py
942
4.15625
4
import math #source: https://www.jeffknupp.com/blog/2013/04/07/improve-your-python-yield-and-generators-explained/ def get_primes(input_list): result_list = list() for element in range(len(input_list)): if is_prime(input_list[element]): result_list.append(input_list[element]) return re...
true
73285b5adeeb2e017c419f0ce837839950cfe383
yongxuUSTC/challenges
/python-intro3.py
2,280
4.3125
4
#DATA STRUCTURE: Sort, Max, Min #a.sort() Inplace sort #sorted() returns a new list, works for lists and dict ####Sort List lucky = ['22', '11', '31'] print(lucky) lucky.sort(reverse=True) print("sorted in reverse ...") print(lucky) print("~~~~~~~~~") #### xyz = ['abcd','abcdef', 'abc'] print(xyz) xyz.sort(key=len,r...
true
d32685a3d1bbb8d5e307cbb7556e990bcb0dc33d
yongxuUSTC/challenges
/binary-tree-next-right.py
2,137
4.25
4
#Given a full binary tree, populate the nextright pointers in each node ''' OBSERVATION: 1. Modify pre order traversal to check for left and right nodes 2. if node has a left node set right sibling 3. if node has a right node set right sibling using PREVIOUSLY found value! 4. Traversing using the nextright attribute...
true
c035097be69c564e519ead42cb1d6c85b18a5d0e
yongxuUSTC/challenges
/list-find-consecutive-positive-values-target.py
991
4.125
4
''' Given unsorted list of positive values check if there are consecutive values that add to to a given target OBSERVATION: 1. unsorted list 2. postive values 3. consecutive values 4. return TRUE or FALSE ''' ''' Algorithm: 1. start and current pointer set to index position 0 2. Iterate the list and advance current ...
true
e4f594d9fdf3325bc86b02e011d6ef5fadd2c834
yongxuUSTC/challenges
/mylib/BinaryTreeTraversal.py
2,138
4.21875
4
#Binary Tree Traversal Library class BinaryTree: def __init__(self,data): self.data = data self.left = None self.right = None def insertRight(self,node): self.right = node def insertLeft(self,node): self.left = node ### def preOrder(root): if root is None: return print(root.data,end=" ") preOrder(...
true
d274e643102e52a5b9c3c53d7a51c87ff6a1422f
yongxuUSTC/challenges
/bit-count-1s.py
927
4.125
4
''' Write an efficient program to unset the right most bit and count number of 1s in binary representation of an integer REFERENCE: http://www.geeksforgeeks.org/count-set-bits-in-an-integer/ NOTES: Brian Kernighan’s Algorithm 1. Subtraction of 1 from a number toggles all the bits (from right to left) till the rightm...
true
e06332460631e7beec991665055d1fb4be0cc0d9
tusharsadhwani/intro-to-python
/2. Data Structures/5-modules.py
1,000
4.28125
4
"""To install this module, run `pip install terminaltables` in your console""" from terminaltables import AsciiTable def print_table(employees): t = AsciiTable([ ['Employee Name', 'Employee Salary'], *[(emp['name'], emp['salary']) for emp in employees] ]) print(t.table) employees = [] ...
true
d4b73a22cf71da7bbe1bbb24dfd7b7c0238ab728
SamanAsgarieh/Python_exercise
/Search/binary_search_tree.py
1,807
4.25
4
class BinarySearchTree: def __init__(self, value, depth=1): self.value = value self.depth = depth self.left = None self.right = None def insert(self, value): if (value < self.value): if (self.left is None): self.left = BinarySearchTree(value, ...
true
b9de5665d1d427c985b6a364e8fea1fcf3e61349
shivamdattapurkayastha99/python-rough-sheets
/d11.py
874
4.375
4
# to reverse a linked list class Node: def __init__(self,data): self.data=data self.next=None class linkedlist: def __init__(self): self.head=None def reverseUtil(self,curr,prev): if curr.next is None: self.head=curr curr.next=prev return ...
true
d49a7dc144987323893918e94e14dc6eee2d8651
janewu0828/code_practice
/interview_questions/leetcode/python/src/leetcoding_challenge/week-1_august_1st_august_7th/3409/test_detect_capital.py
1,268
4.34375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Given a word, you need to judge whether the usage of capitals in it is right or not. # We define the usage of capitals in a word to be right when one of the following cases holds: # 1. All letters in this word are capitals, like "USA". # 2. All letters in this word are...
true
c947b45381cc3a574f51b0a0042d252494292b98
lvhimabindu/Algorithms
/insertion_sort.py
1,943
4.40625
4
import sys ''' This program implements the insertion sort algorithm. Input: A list of integers or floating point numbers or strings. Output: Sorted list (in ascending order). Insertion Sort Algorithm: Below we discuss the insertion sort technique. Intuition: Insertion sort works the same way as one would sort ...
true
1e160b8dbcfd7db0a2e9332cf6046111570cfcae
harshith-1989/python
/RelationOfANumber.py
400
4.21875
4
number = input("Please enter a number : ") try: number = int(number) except: print ("please enter a valid number. Aborting") exit(1) for a in range(number-10, number+10): if number>a : print ("{} is greater than {}".format(number,a)) elif number==a : print ("{} is equal to {}".forma...
true
7f6e5b74d2b1acfb6c12bd9c0175f4d372224735
sreedhargs89/pythonTraining
/arm.py
684
4.375
4
################################################################### ## Exercise to find the given/input number is armstrong of not ## Logic: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 ...
true
675f35c5c8ce55b519004e367bd2893030f946f2
yanfriend/python-practice
/licode/lc701.py
1,911
4.15625
4
""" Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Note that there may exist multiple valid ways for the insertion, as...
true
0b1849a01723ee1d9a02d2d0cea5d76a2a3abe9b
jury16/Python_Course
/11_4.py
1,015
4.5
4
# 1.Create an empty class Dog # 2.Create two Dog objects. Display them on the screen # 3.Add two methods to the Dog class: jump and run. Methods display Jump! and Run! # 4.Add the change_name method to the Dog class. # The method accepts a new name as input and changes the name attribute of the object. # Create on...
true
a0af375821619394c3078644bab888cf5373c334
Saddleworth-Sam/Programming-Year-10
/Year 9 - Recap/Exercise 3.py
1,019
4.3125
4
import random#Allows randomNumber to work maxNumber = 20#The max number that can be used is 10 randomNumber = 10#This is what randomNumber is guess = 0#This is what guess is numberOfGuesses = 0#How many guesses you have had' while guess != randomNumber:#This is a while loop guess = int(input("Your guess:"))#This i...
true
37638b3686a2db40172a43d83afb963f8430634c
Saddleworth-Sam/Programming-Year-10
/Year 8 - Recap/CoinToss.py
1,390
4.21875
4
#This code tosses the coin import random#This allows random.choice to work def cointoss(): options = ("heads", "tails")#These are the options result = random.choice(options)#This randomly chooses heads or tails 6 times print ("\n") #Print blank line print (result)#This prints what the result is coint...
true
f2380f41aee9572a8eb93308eb026c0841f0702c
Saddleworth-Sam/Programming-Year-10
/Year 8 - Recap/Conditional IF statements.py
509
4.34375
4
#This code tells you if your answer is correct or wrong answer = input("Do cats bark? ") #putting a space between the ? and " makes a space between the question and answer if answer == ("no"):#If the answer is no it will print the code below print ("\n")#Prints a blank line print ("You are correct.")#This will...
true
3368c7bf14369f03e7fd6b6540ab43cd44084e4c
thisguycodez/python-hangman
/test1.py
1,222
4.53125
5
''' * list is a built-in 'collections' data type in python used to store multiple values in 1 variable. * Created with square brackets [] * each value should be separated with commas * you can store all data types within a list (string,integer,function,etc.) * you can add values to it upon creation or with the 'appe...
true
1a157aca46d19ea8d50779d93c5914778b64318d
janwirth/Prog1_WS17
/WS17_HA02/add_numbers.py
2,174
4.125
4
#!/usr/local/bin/python3 # -*- coding: utf-8 -*- """ Prompt for two numbers and print the sum of the range that spans between them """ __author__ = "Jan Wirth <contact@jan-wirth.de" __version__ = "0.0.1" from functools import reduce def sum_from_to(a, b): """ recursively sums the inclusive range between...
true