blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
3aa6555c1783ec5428bed334fdb94f429bc0b087
Girum-Haile/PythonStudy
/DecisionMaking.py
806
4.125
4
# if statement -It is used to decide whether a certain statement or block of statements will be executed or not. # simple if statement age = int(input("Enter your age: ")) # we use input() to get input from a user if age <= 30: print("accepted") # nested if statement name = input("enter name") sex = input("enter...
true
a7d1334d4cdcb8b8273111a495eb2d3bf0badc9d
Girum-Haile/PythonStudy
/OOP-Class.py
1,290
4.28125
4
# class - creates user defined data structure. # class is like a blue print of an object # class creation class New: pass class Dogs: type = "Doberman" # class attributes atr = "mamal" def method(self): print("Dog breed:", self.type) print("Dog atr:", self.atr) Dog1 = Dogs() # o...
true
d8a274f82384cce62ec81666552b1c45484cf035
aduanfei123456/algorithm
/back_track/array_sum_combinations.py
827
4.25
4
""" WAP to take one element from each of the array add it to the target sum. Print all those three-element combinations. /* A = [1, 2, 3, 3] B = [2, 3, 3, 4] C = [1, 2, 2, 2] target = 7 */ Result: [[1, 2, 4], [1, 3, 3], [1, 3, 3], [1, 3, 3], [1, 3, 3], [1, 4, 2], [2, 2, 3], [2, 2, 3], [2, 3, 2], [2, 3, 2], [3, 2, 2], [...
true
8cab6c1c7f300b82ba739fc47993357228e2601b
yiyinghsieh/python-algorithms-data-structures
/cw_odd_or_even.py
1,081
4.46875
4
"""Codewars: Odd or Even? 7 kyu URL: https://www.codewars.com/kata/5949481f86420f59480000e7/train/python Task: Given a list of numbers, determine whether the sum of its elements is odd or even. Give your answer as a string matching "odd" or "even". If the input array is empty consider it as: [0] (array with a zero)....
true
fdeebbb4cdf146cb9f1456617c4ab9e0b240917d
raviss091/assignment
/CS102 Assignment Q-03.py
1,251
4.25
4
# CS102 Assignment-03, Python Program for Post order and Depth first level search. # 19BCS091, RAVI SHANKAR SHARMA class Node: def __init__(self,key): self.left = None self.right = None self.val = key def printInorder(root): if root: printInorder(root.left) ...
true
ed8f1be00e133ac5283ff5c2db68d744937a5886
JHolderguru/OPP
/dog_class.py
2,203
4.40625
4
# Abstract and create the class dog # from animal import * # from cat_class import * class Dog(Animal): # this is a special method # it comes defined either was but we can re-write it # this methods stands for initialize class object AKA the constructor # in other languages # Allows us to set...
true
eda80049c2742dd09afdfc8c103418a3ce33f200
Chruffman/Personal-Projects
/binary_search.py
1,398
4.28125
4
# Recursive function that uses the binary search algorithm to find a given value in a list in O(logn) time # Does not require a sorted list, sorting is performed within def binary_search(arr, val): # if the list is empty or there is only one element and it is not the value we are looking for if len(arr) == ...
true
e4ced192f6fab6fddf6101649759fee018ae522a
saadmgit/python-practice-tasks
/task8.py
958
4.4375
4
# TASK 8: Take integers input from user as a comma separated make_list = [] odd_list = [] input_nums = str(input("Enter numbers in comma ',' separated : ")) # Taking input as a comma separated input_list = input_nums.split(",") # Making string a list for i in input_list: ...
true
5b3821a5bd436027a0672d2755fdcffdbd8257d7
AthulKrishna14310/Learn_Python
/dictionary.py
1,049
4.3125
4
#Initialise _dictionary={ "Name":"Game of Thrones", "Actor":"Peter Dinglage", "Actress":"Emilia Clarke", "Director":"George Lucas", "Year":2011, "Episodes":73, "Season":8, } #Print Element print(_dictionary["Season"]) _year=_dictionary["Year"] print(_year) #Changing value _dictionary["Year...
true
c5b812e1751f4dfdc560e58bfb4aa24a73bb92e3
prasen7/python-examples
/time_sleep.py
393
4.1875
4
import time # Write a for loop that counts to five. for i in range(1,6): print(i,"Mississippi") # Body of the loop - print the loop iteration number and the word "Mississippi". time.sleep(1) # suspend the execution of each next print() function inside the for loop for 1 second # Write a prin...
true
3344d7f063149be56690a4065d2f5e69b2d4b379
prasen7/python-examples
/pyhton_read.py
1,840
4.3125
4
# python reading materials #1. decorator: # a decorator is a design pattern in python that allows a user to add new # functionality to an existing object without modifying its structure. from time import time def timer(func): def f(*args, **kwargs): before=time() rv=func(*args, **kwargs) ...
true
c809a4e3c916ac15635078c03d4cd71f13e0e7ea
prasen7/python-examples
/listslice.py
1,007
4.375
4
# Lists (and many other complex Python entities) are stored in different ways than ordinary (scalar) variables. # 1. the name of an ordinary variable is the name of its content. # 2. the name of a list is the name of a memory location where the list is stored. # The assignment: list2 = list1 copies the name of t...
true
99c8dff869acb2bf89280f747bb371a3d5824e81
Johanna-Mehlape/TDD-Factorial
/TDD Factorial/factorial.py
705
4.375
4
#factorial.py """python code to find a Factorial of a number""" def factorial(n): """factorial function""" try: #to try the input and see if it is an integer n = int(n) #if it is an integer, it will print out its factorial except:#if it is not an integer, except will return an message p...
true
c0bb38dc8e38eac9c7f1d1bad6a3ba60f217fbbd
steve1998/scripts
/palindromechecker.py
1,010
4.1875
4
# checks if a word is a palindrome # palindrome function def palindrome(str): reversedWord = str[::-1] # comparison of each word if str.lower() != reversedWord.lower(): return False return True def main(): filename = input("Enter list of words to check for palindrome: ") counter ...
true
15dc717ca6ab36098948ad026d04c3095a1ddfcd
greenstripes4/CodeWars
/ipadress.py
2,063
4.40625
4
""" Task An IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way: Given a string s represents a number or an IP address. Your task is to convert it to another representation(number to IP address or IP address to number). You can assume that all inputs are valid. ...
true
9f77a05bef30a373aa6099a9b4ee181fc3d51b1e
greenstripes4/CodeWars
/DataReverse.py
694
4.40625
4
""" A stream of data is received and needs to be reversed. Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example: 11111111 00000000 00001111 10101010 (byte1) (byte2) (byte3) (byte4) should become: 10101010 00001111 00000000 11111111 (byte4) (byte3) (byte...
true
0ad5b8175ba2ae7b9d4e563e6ecc1ad591232314
greenstripes4/CodeWars
/digital_root.py
522
4.21875
4
""" A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has two digits, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers. Here's how it works: digital_root(16) => 1 + 6 => 7 """ ...
true
06f8cd83c2cb510474d0788e473731b5cfc9b40e
carlos-hereee/Intro-Python-I
/src/05_lists.py
858
4.1875
4
# For the exercise, look up the methods and functions that are available for use # with Python lists. x = [1, 2, 3] y = [8, 9, 10] # For the following, DO NOT USE AN ASSIGNMENT (=). # Change x so that it is [1, 2, 3, 4] # YOUR CODE HERE x.append(4) print("\n Adds 4 to the end: ", x) # Using y, change x so that it i...
true
82d9cd4a618eb4d035049bf4570942c7ca1cbe43
millerg09/python_lesson
/ex20.py
1,914
4.1875
4
# imports the `argv` module from sys from sys import argv # sets up the script name and input_file as script argument variables script, input_file = argv # creates the first function `print_all`, which accepts one input variable `f` def print_all(f): # the function is designed to use the read function with no ext...
true
8c23df48951b0371225a507dffa4fb3198290d9d
utk09/BeginningPython
/2_Variables/2_variables.py
534
4.15625
4
# Variables are like Boxes. Their name remains the same, but values can be changed over the time. number1 = 7 number2 = 4 print(number1 * number2) # insted of values, we now write variables here. print(number1 - number2 * 3) alpha = number1 / number2 beta = number1 // number2 print(type(alpha)) # Prints type of var...
true
9297906d5a60f20b9081d2a280e5fc91646c1ec0
utk09/BeginningPython
/8_MiniPrograms/14_Recursion.py
1,215
4.375
4
# We will find the sequence of Fibonacci Numbers using recursion. # Recursive function is a function that calls itself, sort of like loop. # Recursion works like loop but sometimes it makes more sense to use recursion than loop. # You can convert any loop to recursion. ... Recursive function is called by some external ...
true
62bd1fc8066ef085eee494f2d5277a7f68437f81
cugis2019dc/cugis2019dc-Najarie
/Code Day_3.py
2,818
4.1875
4
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import plotly dir(plotly) print("My name is Najarie") print("Hello how are you doing") print(5*2) print(5/2) print(5-2) print(5**2) print((8/9)*3) print("5*2") def multiply(a,b): multiply = a*b print(mul...
true
df639a127a816b127c320bfd00ed5b68b7d9ae27
amahfouz/tweet-analyser
/count_freq.py
784
4.21875
4
''' Counts word frequencies in a text file. Words to be counted are read from a file. ''' import codecs import sys import re import time def count_occurrences(f, w): count = 0 for line in f: index = 0 words = re.split(r'[\n\r\t-_ #]', line) for word in words: if (word == w): count = count + 1 ret...
true
ea4bb376bc5c3f27b6020fe3cbb8ec7b07183251
erikgust2/OpenAI-Feedback-Testing
/dataset/Fahrenheit/Fahrenheit_functionality.py
344
4.25
4
def celsius(): fahrenheit = float(input("Enter a temperature in Fahrenheit: ")) celsius = ((fahrenheit - 32) * 5) / 9 print("The equivalent temperature in Celsius is", celsius) if(celsius > 32): print("It's hot!") elif(celsius < 0): print("It's cold!") else: print("It's ...
true
705173744a8f66d1d65cf99066aad1e8831b7089
erikgust2/OpenAI-Feedback-Testing
/dataset/AgeName/AgeName_syntax.py
657
4.21875
4
def greet_user(): # Get the user's name and age name = input("What's your name? ") age = int(input("How old are you? ")) # Print a greeting message with the user's name and age print(f"Hello, {name}! You are {age} years old.") # Check the user's age and print a message based on it ...
true
b17474f526fe2477e64276c73297618417b6c334
Shriukan33/Skyjo
/src/cards.py
1,460
4.15625
4
from random import shuffle class Deck: """ Deck class handles original deck building and drawing action. """ def __init__(self): self.cards = [] # Deck is represented with a list of numbers from -2 to 12 self.minus_two = 5 # Number of minus two in build self.zeroe...
true
d823f2c91294dcc305f292d808f71707d95de09d
ntnshrm87/Python_Quest
/Prob6.py
588
4.125
4
# Prob 6 list_a = ['Raman', 'Bose', 'Bhatt', 'Modi'] # Case 1 print(list_a[10:]) # Case 2 try: print(list_a[10]) except IndexError as e: print("Error is: ", e) # Case 3 print(list_a[:-10]) # Solution: # [] # Error is: list index out of range # [] # Reference: # Its really a tricky one # The problem is if...
true
15734f950406d76a0c1e67dede382e095b0e1a34
shokri-matin/Python_Basics_OOP
/05InputQutputImport.py
622
4.25
4
# Python Output Using print() function print('This sentence is output to the screen') # Output: This sentence is output to the screen a = 5 print('The value of a is', a) # Output: The value of a is 5 print(1,2,3,4) # Output: 1 2 3 4 print(1,2,3,4,sep='*') # Output: 1*2*3*4 print(1,2,3,4,sep='#',end='&') # Output:...
true
0449ecdfe040d45fc538696b97d0f7e0de6f106f
shokri-matin/Python_Basics_OOP
/17Files.py
1,443
4.125
4
# Hence, in Python, a file operation takes place in the following order. # 1-Open a file # 2-Read or write (perform operation) # 3-Close the file # f = open("test.txt") # open file in current directory # f = open("C:/Python33/README.txt") # specifying full path # f = open("test.txt") # equivalent to 'r' or '...
true
4380065a6a07c72549544d4fe1cc38ee0d7fd623
dmyerscough/codefights
/sumOfTwo.py
728
4.25
4
#!/usr/bin/env python def sumOfTwo(a, b, v): ''' You have two integer arrays, a and b, and an integer target value v. Determine whether there is a pair of numbers, where one number is taken from a and the other from b, that can be added together to get a sum of v. Return true if such a pair exists...
true
1eb28eb14c6dc0144de440ee62f1b560978a7f3c
shraddha136/python
/assn7.2.py
1,116
4.625
5
#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
085f1364d25c4bf0d60c3ae0f3c140c8bf2aa024
Chewie23/PythonAlgo
/One-Offs/General/circle_problem.py
1,334
4.34375
4
""" prompt: Given a point and a radius which designate a circle, return a random point within that circle. """ #Fun math #The solution is a fun formula. I am hesitant to delve further into this since #I would never be required to derive the Pythagoreas formula and customize it #to a circle. I mean, it's logic...
true
1dd547f756e6e226c03f9caebc596c826c64480e
Chewie23/PythonAlgo
/Recursion/bubble_sort.py
536
4.28125
4
#Recursion bubble sort. If you though regular bubble sort was bad #Remember, it's comparing two elements, and swapping. Then keep on going #through until no more swapping #Iteratively, we have a swapping bool, and a while loop #Or we have outer for loop that will go through ALL of the array def bubble(arr): #Thi...
true
9fc2d9c7597c35c254505f3a19e53ee17a9e2dca
DanielMelero/Search-engine
/ordsearch.py
2,085
4.15625
4
def linear(data, value): """Return the index of 'value' in 'data', or -1 if it does not occur""" # Go through the data list from index 0 upwards i = 0 # continue until value found or index outside valid range while i < len(data) and data[i] != value: # increase the index to go to the n...
true
6b7c7ddae9d6d57e407648aedf281330bc7e69b9
asset311/comp-sci-fundamentals
/strings/permutation_palindrome.py
1,224
4.25
4
''' Check if any permutation of a string is a valid palindrome. A brute force approach is to generate all permutations of the string = O(n!) Then for each of those permutations to check if it is a palindrome = 0(n) For the total time of O(n*n!) - that's extremely long. A simple solution is to think about what a palin...
true
a95868ce9c1ac1482b03c42db38b972225059858
asset311/comp-sci-fundamentals
/arrays/permutations_list.py
1,058
4.28125
4
''' Generate all permutations of a set Permutation is an arrangement of objects in a specific order. Order of arrangement of object is very important. The number of permutations on a set of n elements is given by n!. Example 2! = 2*1 = 2 permutations of {1, 2}, namely {1, 2} and {2, 1} 3! = 3*2*1 = 6 permutations o...
true
e6a2b110b16792d4de45200f61cb9bfb1be2e2e0
Hansen-L/MIT-6.0001
/ps4/test.py
1,207
4.125
4
import string letter_to_number_dict={} number_to_letter_dict={} num = 1 shift = 2 #First make a dictionary that holds the default letter-number correspondence for char in string.ascii_lowercase: letter_to_number_dict[char] = num number_to_letter_dict[num] = char num = num + 1 for char in strin...
true
126f12b64e6b63454b5843e73dc6dc87ed0e0e45
akashgkrishnan/simpleProjects
/calc/app.py
760
4.125
4
from calc.actual_calc import ActualCalulator repeat = 'y' print(''' Enter the operation you are interested in : 1) Enter 1 for performing addition of 2 numbers 2) Enter 2 for performing subraction on 2 numbers 3) Enter 3 for perforiming multiplication on 2 numbers 4) Enter 4 for performing division on 2 numbers 5) Ente...
true
1ebaa91a786113a75d78c6e9f46c0f02e3cd0787
beyzabutun/Artificial-Intelligence
/MonteCarlo/mcs.py
1,864
4.125
4
#!/usr/bin/python3 import random # Evaluate a state # Monte Carlo search: randomly choose actions def monteCarloTrial(player,state,stepsLeft): if stepsLeft==0: return state.value() ### Randomly choose one action, executes it to obtain ### a successor state, and continues simulation recursively ### from that s...
true
46e72161442c45fa2a5e6dbc580bd86db5202a85
EzraBC/CiscoSerialNumGrabber
/mytools.py
1,581
4.375
4
#!/usr/bin/env python """ INFO: This script contains functions for both getting input from a user, as well as a special function for handling credentials (usernames/passwords) in a secure and user-friendly way. AUTHOR: zmw DATE: 20170108 21:13 PST """ #Make script compatible with both Python2 and Python3. from __fu...
true
e794133843ab561393b55627675f3f419884527b
rembrandtqeinstein/learningPy
/pp_e_11.py
342
4.125
4
num = input("Enter a number to check if it's a prime: ") try: num = int(num) except: print("Not a number") def prime(x): div = range(1, x) lis = [y for y in div if x % y == 0] if len(lis) == 1: print(x, "is a prime number") else: print(x, "is not a prime number, it's divisible ...
true
327b2644b39d5364ca15d8eed74c8f2e7945902a
rembrandtqeinstein/learningPy
/coursera_test.py
343
4.1875
4
#import pandas as pd hours = input("How many hours you work: ") rate = input("How many you are payed per hour: ") try: hrs = float(hours) fra = float(rate) except: print("That is not a number") quit() if hrs >= 40: pay = 40 * fra pay = pay + ((hrs - 40) * 1.5) else: pay = hrs * fra print(p...
true
9af4f4db42d1ee0ed61b0a8ab99ba76d7fbf803f
joshey-bit/Python_Projects
/2-D Game/alien.py
1,544
4.15625
4
''' A program to create alien class ''' import pygame from pygame.sprite import Sprite class Alien(Sprite): '''A class to create an alien and draw it on the screen''' def __init__(self,alien_settings,screen): super().__init__() self.alien_settings = alien_settings self.screen...
true
92c0d35d31f7727ac542ad1d5661a15e4e2bc64c
ChengzhangBai/Python
/LAB10/task2.py
700
4.5
4
# Write a python program that prompts the user for the name of .csv file # then reads and displays each line of the file as a Python list. # Test your program on the 2 csv files that you generated in Task 1. fileName = input('Please input "boy" or "girl" to open a file: ') if fileName == "" or fileName not in('boy'...
true
acd4218bb27771db82a4796d8dd21479cf3cab5c
humblefo0l/PyAlgo
/DP/MaximumProductSubarray.py
1,261
4.1875
4
""" Maximum Product Subarray Medium 11755 362 Add to List Share Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. A subarray is a contiguous subseque...
true
cecc70dbe060dcdfd840322a2bb44a649b751ecc
humblefo0l/PyAlgo
/Recursion/Permutation.py
478
4.21875
4
""" 46. Permutations Medium Add to List Share Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Exa...
true
ffeb082d317527637ee17b7dd36c0c4f7f11ea40
trieuchinh/DynamicProgramming
/howSum.py
1,063
4.21875
4
''' Write a function called "howSum(targetSum, number)" that takes in a targetSum and an array of numbers as arguments. The function should return an array containing any combination of elements that add up to exactly the targetSum. If there is no combination that adds to the targetSum, then return null. If th...
true
c95bc18ced7fafa924d4c59a8402f14fb1d178c8
Philipotieno/Grokking-Algorithms
/02_selection_sort.py
658
4.15625
4
# Find the smallest valuein an array def findSmallest(arr): # Store the smalest value smallest = arr[0] # Store the smallest index of the smallest value smallest_index = 0 for i in range(1, len(arr)): if arr[i] < smallest: smallest = arr[i] smallest_index= i retur...
true
b3bb07853979e7dfec06b2d6c75e0c2ece5e250d
plankobostjan/practice-python
/06StringLists
238
4.3125
4
#!/usr/bin/python word = str(input("Enter a word: ")) rev = word[::-1] print word + " reversed is written as: " + rev if word == rev: print "Word you've enetered is a palidnrome." else: print "Word you've enetered is not a palidnrome."
true
6c4ba4568fe819c4401605d5080b4c885a542773
venkataramadurgaprasad/Python
/Python-For-Everybody/Programming For Everybody(Getting Started With Python)/Week-5/Assignment_3.1.py
690
4.3125
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 sho...
true
c0eeee6004b9acb0f8e6dfd61edde5a3b80e5a1d
kaustubhvkhairnar/PythonPrograms
/Lambda Functions/Assignment2.py
339
4.3125
4
#2.Write a program which contains one lambda function which accepts two parameters and return #its multiplication. def main(): value1 = input("Enter number1 : ") value2 = input("Enter number2 : ") ret=fp(value1,value2); print(ret) fp=lambda no1,no2 : int(no1)*int(no2); if __name__=="__main...
true
3abedfd55165751b0cfb93e6b2f291113af556cf
kaustubhvkhairnar/PythonPrograms
/Object Orientation/Assignment3.py
1,761
4.59375
5
#3. Write a program which contains one class named as Arithmetic. #Arithmetic class contains three instance variables as Value1 ,Value2. #Inside init method initialise all instance variables to 0. #There are three instance methods inside class as Accept(), Addition(), Subtraction(), Multiplication(), Division(...
true
952f16d1be7dcf93fbf5afd931546da2e11b027e
kaustubhvkhairnar/PythonPrograms
/Object Orientation/Assignment5.py
1,806
4.34375
4
#5. Write a program which contains one class named as BankAccount. #BankAccount class contains two instance variables as Name & Amount. #That class contains one class variable as ROI which is initialise to 10.5. #Inside init method initialise all name and amount variables by accepting the values from user. #There a...
true
bc5c6752015df561abe9e8d67a7120398eb893d0
NatTerpilowska/DailyChallengeSolutions
/Daily3.py
218
4.21875
4
min = int(input("Enter the lowest number: ")) max = int(input("Enter the highest number: ")) print("Even numbers from %d to %d are: " % (min, max)) for i in range(min, max+1): if(i%2==0): print(i, end=" ")
true
9f9c815d3a02685db5cf792468f0c96eea59a16f
penguincookies/GWSSComputerScience
/Python/AcidRain.py
880
4.125
4
# comments use pound ACID_THRESHOLD = 6.4 ALKALINE_THRESHOLD = 7.4 print("This program will take the pH of a body of water and") print("determine if it's habitable to the fish living there.") print() pH = eval(input("Enter the water's pH: ")) # instead of "else if", Python uses "elif # Python also relies on colons ...
true
bcd517d5144f761cee2ce9993dbaeff2dea939fe
AbhijitEZ/PythonProgramming
/Beginner/ClassDemo.py
1,997
4.1875
4
from abc import ABC, abstractmethod class Car: default_value = "All remain same" # static def __init__(self, wheels_count=2): self.wheels_count = wheels_count # property def __str__(self): # default function is when calling print return(f"This is default print") def __eq__...
true
d459fd0fab2c9cb4ae601dea2a57363828d70632
theinsanetramp/AnkiAutomation
/genSentenceDB.py
2,925
4.125
4
import sqlite3 from sqlite3 import Error import csv def create_connection(db_file): """ create a database connection to a SQLite database """ try: conn = sqlite3.connect(db_file) return conn except Error as e: print(e) return None def create_table(conn, create_table_sql): ...
true
bbabed6baee00637d9459da02a4339440ea8799a
avieshel/python_is_easy
/fizz_buzz.py
2,606
4.34375
4
def is_divisible_by_5(number): return number % 5 == 0 def is_divisible_by_3(number): return number % 3 == 0 def is_prime(number): for divisor in range (2, number): if (number % divisor == 0): return False return True ''' A Prime number has exactly two divisors 1 and itself. To chec...
true
5fbbabee18776cc21049d33131e117c5f32db22a
anubhav-shukla/Learnpyhton
/guessing.py
520
4.1875
4
# it is while loop program # python guessing.py print("It is a guessing game") import random random_number =random.randrange(1,10) guess=int(input("what could be tthe Number? ")) correct=False print(random_number) while not correct: if guess==random_number: print("congrats you got it") corr...
true
0afb2f0b115724f3440cf755d094fe68e6597ee2
anubhav-shukla/Learnpyhton
/some_method.py
452
4.15625
4
# here we learn some useful method #python some_method.py fruits=['mango','orange','apple','apple'] # print(fruits.count('apple')) # 2 # fruits.sort() it gives an sorted array # print(sorted(fruits)) #it just use for print or temporary sorting # fruits.clear() # it gives you an empty list fruit1=fr...
true
3c0c943512655eed6dc6e8ee92420cc6ba2f4e79
anubhav-shukla/Learnpyhton
/list_comprehension.py
1,054
4.625
5
# most powerful topic in python # list comprehension # python list_comprehension.py # today we create a list with the help o list comprehension # create a list of squares from 1 to 10 # it is a simple way to create a list square # square=[] # for i in range(1,11): # square.append(i**2) # print(s...
true
b8d1ff3381a518f89f764c2b26d1b687c3be7824
anubhav-shukla/Learnpyhton
/chapter5_exe3.py
256
4.34375
4
# here we take input as list and reverse each element # python chapter5_exe3.py def reverse_all(l): reverse=[] for i in l: reverse.append(i[::-1]) return reverse listj=['mango','apple','banana'] print(reverse_all(listj))
true
718cb952f0b24a475eee0b032ec687a8dfc0157c
anubhav-shukla/Learnpyhton
/add.py
487
4.3125
4
# here we learn how to add two list and items # python add.py # cancatenation fruits=['mango','orange','apple'] fruits1=['banana','grapes'] fruit=fruits+fruits1 # print(fruit) print all in single list # using extend method # exetnd fruits.extend(fruits1) print(fruits) # it is doing same work # appe...
true
ef4c42f4cab534e847afc7d0cbddc586797edc0f
anubhav-shukla/Learnpyhton
/check_empty_or_not.py
318
4.375
4
# here we see check empty or not # important #python check_empty_or_not.py # name="Golu" it print not empty # name='' it show empty # here you can use it name =input('Enter your name: ') # name='India' if name: print('your name is '+name) else: print("You did't enter your name")
true
7805a27b5f2e6ca6cd329c82b5242c6b6668cdda
shuxinzhang/nltk-learning
/exercises/Chapter 02/02-23.py
1,631
4.28125
4
# -*- coding: utf-8 -*- import matplotlib matplotlib.use('TkAgg') import nltk import math ''' ★ Zipf's Law: Let f(w) be the frequency of a word w in free text. Suppose that all the words of a text are ranked according to their frequency, with the most frequent word first. Zipf's law states that the frequency of a word...
true
73762233b5fc0d1de3d02a74fde9ae76b7a71cd3
jonathancox1/Python104-medium
/leetspeek.py
759
4.21875
4
#convert user input to 'leetspeak' # A -> 4 # E -> 3 # G -> 6 # I -> 1 # O -> 0 # S -> 5 # T -> 7 #ask user for input input = str(input("Give me your text: ")) user_input = input.upper() #define function to check which letter is a leet letter def convert(a): if a == 'A': return '4' elif a == 'E': ...
true
102d1dacc8b140fb06aa890ad6d866b02a0cfae5
barney1538/CTI110
/P2T1_BarneyHazel.py
446
4.28125
4
#Write a program that ask the user to enter projected total sales then will display the profit that'll be made from that amount. #February 20th, 2020 #CTI-110 P2T1-Sales Prediction #Hazel Barney #Get the projected total sales. total_sales = float(input('Enter the projected sales: ')) #Calculate the profit as 23...
true
72e9820a494760fc8146df05992c5f4684442a04
abhijit-mitra/Competitive_Programming
/7_pythagorean_triplet.py
1,070
4.25
4
''' Is pythagorean triplet exist in the given array. Pythagorean triplet means: a^2 + b^2 = c^2. a,b,c could be any elemnt in array. for array = [3,1,4,5,6], one combination is present i.e: 3^2 + 4^2 = 5^2 Optimum solution is having time complexity of n^2. **Trick** 1/Sort the given array. [1,3,4,5,6] 2/Iterate and mut...
true
60a6eb1505bb2788859387d4af931ae036e0de1f
Edmartt/canbesplitted
/tests/test_basic.py
1,816
4.125
4
import unittest from code.backend_algorithm import Splitter class BasicTestCase(unittest.TestCase): """Contiene los metodos para las pruebas unitarias.""" def setUp(self): self.splitter = Splitter() self.empty = [] # empty array for testing empty array result==0 self.array = [1, 3, 3...
true
6776f5e9be955e1f39672fa52979fa11e606856b
rfdickerson/cs241-data-structures
/A6/app/astar/priorityqueue.py
1,591
4.3125
4
import math def parentindex( curindex): return (curindex - 1) // 2 def leftchild( i ): return i*2 + 1 class PriorityQueue ( object ): """ A priority queue implemented by a list heap You can insert any datatype that is comparable into the heap. The lowest value element is kept at the root of the ...
true
324731e01eddde2390c9fef2645ec76ca9eca3d5
Rim-El-Ballouli/Python-Crash-Course
/solutions/chapter4/ex_4_10.py
305
4.3125
4
cubes = [number**3 for number in range(1, 10)] for cube in cubes: print(cube) print('The first three items in the list are:') print(cubes[:3]) print('Three items from the middle of the list are:') print(cubes[len(cubes)//2:]) print('The last three items in the list are') print(cubes[-3:])
true
534baa4384cb36ce87d60bc82c428bd7a876f532
Rim-El-Ballouli/Python-Crash-Course
/solutions/chapter4/ex_4_11.py
455
4.28125
4
pizza_names = ["Cheese", "Vegetarian", 'Hawaiian', "Peperoni"] for pizza_name in pizza_names: print('I like ' + pizza_name + 'pizza') print('I really like pizza!') friend_pizzas = pizza_names[:] pizza_names.append('Barbecue') friend_pizzas.append('Honey Mustard') print('My friend’s favorite pizzas are:...
true
dfc48b4f6feadae7923fc0dfd795258492d4f5ed
soundestmammal/machineLearning
/bootcamp/flow.py
1,915
4.125
4
# -*- coding: utf-8 -*- if 3>2: print('This is true') hungry = True if hungry: print('feed me') else: print('Not now, im full') loc = 'Bank' if loc == 'Auto Shop': print('Cars are cool!') elif loc == "Bank": print("You are at the bank") else: print('I do not know much.') name = 'Sammy'...
true
41988de645aae080c0fc964cc7656acca922f431
soundestmammal/machineLearning
/bootcamp/oop.py
970
4.40625
4
# This is part one of learning about how objects work in Python. # Python is a class based language. This is different that other languages such as javascript. # How to define a class? class car: pass car = Vehicle() print(car) # Here car is an object (or instance) of the class Vehicle #Vehicle class has 4 attrib...
true
145b40261b3506d9605fff2a67e135b9e5fc4b6a
soundestmammal/machineLearning
/bootcamp/lists.py
626
4.15625
4
# -*- coding: utf-8 -*- # Lists general version of sequence my_list = [1,2,3] # Lists can hold different object types new_list = ['string', 23, 1.2, 'o'] len(my_list) # Indexing and Slicing my_list = ['one', 'two', 'three', 4, 5] # my_list[0] returns 'one' #my_list[1:] returns 'two' , 'three', 4, 5 my_list[:3] 'hel...
true
592052a96d70f124fe17a0248b4df1f93ada8a14
yarik335/GeekPy
/HT_1/task6.py
412
4.375
4
# 6. Write a script to check whether a specified value is contained in a group of # values. # Test Data : # 3 -> [1, 5, 8, 3] : True # -1 -> (1, 5, 8, 3) : False def Check(mylist,v): return print (v in mylist) myList1 = [1, 5, 8, 3] myList2 = (1, 5, 8, 3) value = int(input("en...
true
66a9a58b8ee04c9a903a6eaacb7c3b7d2c394807
pramilagm/coding_dojo
/python/random_problems/decorator.py
970
4.3125
4
# Decorators are a way to dynamically alter the functionality of your functions. So for example, if you wanted to log information when a function is run, you could use a decorator to add this functionality without modifying the source code of your original function. def decorator_function(original_function): def...
true
6e71070883296d0f4fa69456eb390a2a788114e1
mrmoore6/Module2
/main/camper_age_input.py
463
4.1875
4
""" Program: camper_age_input.py Author: Michael Moore Last date modified: 9/5/2020 The purpose of this program is to convert years into months. """ from main import constants def convert_to_months(year): months = year * constants.MONTHS return(months) if __name__ == '__main__': age_in_years = int(in...
true
57e01f83db8e55704098bd6fe9910bbcf0643cd3
struppj/pbj-practice
/pbj.py
1,366
4.21875
4
#goal 1 peanut_butter = 1 jelly = 1 bread = 7 if peanut_butter == 1 and jelly == 1 and bread >=2: print "I can make exactly one sandwich" if peanut_butter < 1 or jelly < 1 or bread <=1: print "No sandwich for me" #goal 2 peanut_butter = 4 jelly = 6 bread = 9 if bread >= 2 and peanut_butter >= 1 a...
true
6b8b4085784cded514229f7744463d282b03563e
K-Roberts/codewars
/Greed Is Good.py
1,492
4.34375
4
''' Created on Nov 13, 2018 @author: kroberts PROBLEM STATEMENT: Greed is a dice game played with five six-sided dice. Your mission, should you choose to accept it, is to score a throw according to these rules. You will always be given an array with five six-sided dice values. Three 1's => 1000 points Three 6's...
true
4fd336444011052fc5280b737aab042cfb0ecd1c
jcjessica/Python
/test.py
738
4.25
4
# program that prints out a table with integers from decimal 0 to 255, it's hex number, and the character corresponding to the unicode with UTF-8 encoding # using a loop #for x in range(0, 256): # print('{0:d} {0:#04x} {0:c}'.format(x)) # using list comprehension #ll = [('{0:d} {0:#04x} {0:c}'.format(x)) for x...
true
4c05f6717795444de47d9c1f73332924cb41eb67
BradleyMidd/learnwithbrad
/calc.py
499
4.3125
4
# Basic Calculator action = True while action: num1 = int(input("Type a number: ")) info = input("Do you want to add, subtract, multiply or divide? \nType [+], [-], [*] or [/]: ") num2 = int(input("Type a second number: ")) if info == "+": print(num1 + num2) elif info == "-": prin...
true
eeadea36a30f7259237e2a1b35219f6bba1d2b1e
ginajoerger/Intro-to-Computer-Programming
/Homework 0/exercise2.py
524
4.28125
4
# HOMEWORK 0 - EXERCISE 2 # Filename: 'exercise2.py' # # In this file, you should write a program that: # 1) Asks the user for a number # 2) Prints 'odd' or 'even' depending on the number's parity # # Example1: # *INPUT FROM THE USER # Enter a number: 17 # *PRINTED OUTPUT # odd # # Example2: # *INPUT ...
true
cf7107f26f2531a68e5a23c9ffa51090d1d1be7b
NayoungBae/algorithm
/week_2/03_add_node_linked_list_nayoung.py
1,567
4.15625
4
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self, data): self.head = Node(data) def append(self, data): if self.head is None: self.head = Node(data) return current_node = self.head ...
true
338ae906f91e5ab7dd8a9f7df31384bb894ba409
kukaiN/Sudoku_solver
/sudoku_checker.py
1,787
4.125
4
def num_in_row(board, row_number, col): """ returns a list of values that are on the same row""" return list({board[row_number][i] for i in range(len(board)) if col != i } - set([0])) def num_in_column(board, column_number, row): """ returns a list of values that are on the same column""" return list(...
true
397ac1c9fe38ca7a4352d42e0da2e1c0e794c2b9
grayreaper/pythonProgrammingTextbook
/futval.py
1,131
4.125
4
# futval.py # A program to compute the value of an investment # carried 10 years into the future ###This is not working properly!! ###This is not working properly!! ###This is not working properly!! ###This is not working properly!! ###This is not working properly!! ###This is not working properly!! ###T...
true
a3ed36e4bdedfb614019876ac85e1071883a9625
grayreaper/pythonProgrammingTextbook
/feetToMilesConvert.py
333
4.25
4
# feetToMilesConvert.py # This program converts feet to miles # BY: Gray Reaper def main(): print("This Program converts a distance in feet to miles") feet = eval(input("Enter the distance in feet: ")) miles = feet / 5280 print("The distance in miles is", miles) input("Press ENTER to e...
true
92614454c9999c233b15ab0632e1979a0bf12ab9
rajesh-06/p243_assignment_2
/A2_q1b.py
1,351
4.46875
4
#To get the distance between 2 points def distance(x1, x2, y1, y2): if((x2-x1)>=0 and (y2-y1)>=0): return ((x2-x1)+(y2-y1)) elif((x2-x1)<=0 and (y2-y1)>=0): return ((x1-x2)+(y2-y1)) elif((x2-x1)<=0 and (y2-y1)<=0): return ((x1-x2)+(y1-y2)) elif((x2-x1)>=0 and (y2-y1)<=0): return ((x2-x1)+(y1-y2)) sum=0 n...
true
5d9715b4afdbfaa7d627b2cb89012aa4a6e30f2f
codingtrivia/PythonLabs
/Intermediate/Lab3/Lab3.py
323
4.3125
4
# Using recursion, print only even numbers in descending order. For e.g. if I say, print_down(10), output would be: # 10 # 8 # 6 # 4 # 2 # You will need to do a slight modification in the code we wrote for print_up_down in our class today. # Hint: Use % operator def print_down(n): #<your code here> print_down(1...
true
614fdacddcea190226dedcb8fb9b30843d69f916
khadak-bogati/python_project
/LAB3.py
1,930
4.46875
4
print('When we set one variable B equal to A;\n both A and B are referencing the same list in memory:') # Copy (copy by reference) the list A A =["Khadak Bogati",10,1.2] B = A print('A:',A) print('B:',B) print('Initially, the value of the first element in B is set as hard rock. If we change the\n first element in A ...
true
7dbfb9f5fbeaf8bc2dafd2003f3c0403140858db
khadak-bogati/python_project
/TypeerrorAndValueError.py
350
4.34375
4
myString = "This String is not a Number" try: print("Converting myString to int") print(1/0) print("String # " + 1 + ": "+ myString) myInt = int(myString) print(myInt) except (ValueError, TypeError) as error: print("A ValueError or TypeError occureed.") except Exception as error: print("Some other type of error...
true
396bdb1c3d00ef1c113ee7195ef1a754320b1a7b
khadak-bogati/python_project
/Function.py
2,605
4.5625
5
print("===========================================") print('An example of a function that adds on to the parameter a prints and returns the output as b:') def add(a): b = a + 1 print(a, 'if you add one', b) return(b) add(2) ........................ output =========================================== An example of a...
true
4e2481ad72e8ecb600b9df438b9bda347be000e4
GabrieleMaurina/workspace
/python/stackoverflow/calculator.py
581
4.34375
4
print("Welcome to my calculator programme!") while True: # try: operator = input("Enter a operator (+,-,* or /): ") num_1 = int(input("Enter the first number: ")) num_2 = int(input("Enter the second number: ")) q = input('Press Q to quit to the programme...') if operator ==...
true
29c5b22e47aee010b7c4cb60cf8e66d8a72feb77
otomobao/Learn_python_the_hard_way_
/ex3.py
670
4.46875
4
#Showing what i am doing print "I will now count my chickens:" #Showing hens and caculate the number print "Hens", 25.0+30.0/6.0 #Showing roosters and the caculate the number print "Roosters",100.0-25.0*3.0%4.0 #Showing what i am going to do next print "Now I will count the eggs:" #Caculate the number and print prin...
true
bc5980fdfcd37b51dd917a31fd2ba10aba46cc04
SayantaDhara/project1
/printPositiveNo.py
261
4.15625
4
list1 = [] n = int(input("Enter number of elements : ")) print("Enter list terms") for i in range (0,n): elem = int(input()) list1.append(elem) print("Positive numbers are:") for num in list1: if num >= 0: print(num, end = " ")
true
4a890456ce83401f6e3408d5c75d5f839a064ece
ConquestSolutions/Conquest-Extensions
/GetStarted/01-BasicCodeSamples/1.1-BasicCodeSamples.py
1,119
4.34375
4
########## # # THIS SCRIPT IS A LITTLE BASIC PYTHON IN THE CONTEXT OF THE CONQUEST EXTENSIONS CONSOLE # Copy this code into a console bit by bit from the top down to see how it all works. # ########## #Declare variable (change to your favourite number!) variable = 37 #Return variable print 'Variable: ' + str(variable...
true
e609a51428b4d0526be7f16f6c11132035c38ff7
jwebster7/sorting-algorithms
/merge_sort.py
2,009
4.4375
4
def mergeSort(lst): ''' 1. Split the unsorted list into groups recursively until there is one element per group 2. Compare each of the elements and then group them 3. Repeat step 2 until the whole list is merged and sorted in the process * Time complexity: The worst-case runtime is O(nlog(n)) ...
true
0895e45d8c44983ac75833f7c051ec28f26d32e4
mlopezqc/pymiami_recursion
/exercise1.py
1,364
4.59375
5
""" Exercise 1: Write a recursive function count_multiples(a, b) that counts how many multiples of a are part of the factorization of the number b. For example: >>> count_multiples(2, 4) # 2 * 2 = 4 1 >>> count_multiples(2, 12) # 2 * 2 * 3 = 12 2 >>> count_multiples(3, 11664) 6 >>> This send the stat...
true
bcf713e9bbad134c881bf7f1ce293a46a1b3725c
idristuna/python_exercises
/in_out_exercise/q8.py
325
4.25
4
#! /usr/bin/python3 #using string.format to dispaly the data below totalMoney = int(input("Enter totalMoney")) quantity = int(input("Enter quantitiy")) price = int(input("Enter price")) statement1 = "I have {0} dollars so I can buy {1} football for {2:.2f} dollars " print(statement1.format(totalMoney, quantity, pri...
true
04422bb36c79b62d156c21baf162e166a39e0222
pratyushagnihotri03/Python_Programming
/Python Files/14_MyTripToWalmartAndSet/main.py
202
4.125
4
groceries = {'cereal', 'milk', 'starcrunch', 'beer', 'duct tpe', 'lotion', 'beer'} print(groceries) if 'milk' in groceries: print("You have already a milk") else: print("Oh yea, you need milk")
true