blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
e6421c4d66bdc42d0ea5dd1c1906c0d7e7f97f43
LucLeysen/python
/pluralsight_getting_started/loops.py
255
4.15625
4
student_names = ['Jeff', 'Jessica', 'Louis'] for name in student_names: print(name) x = 0 for index in range(10): x += 10 print(f'The value of x is {x}') x = 0 for index in range(5, 10, 2): x += 10 print(f'The value of x is {x}')
true
ac20bc5e55fe2193c57ffc1f724ad2d9a10aadc9
yxpku/anand-python
/chapter2/pro31-map.py
292
4.1875
4
# Python provides a built-in function map that applies a function to each element of a list. Provide an implementation for map using list comprehensions. def square(num): return num*num print square(2) def map(function,list): print [function(x) for x in list] print map(square,[1,2,3,4,5])
true
167d3db677427717e3002141037727da46947493
MischaBurgess/cp1404practicals
/Prac_05/state_names.py
1,016
4.125
4
""" CP1404/CP5632 Practical State names in a dictionary File needs reformatting Mischa Burgess """ # TODO: Reformat this file so the dictionary code follows PEP 8 convention CODE_TO_NAME = {"QLD": "Queensland", "NSW": "New South Wales", "NT": "Northern Territory", "WA": "Western Australia", "ACT": "Aus...
true
6b33c6e9dc6d599f687331aa9934b329f91814e0
MischaBurgess/cp1404practicals
/Prac_09/sort_files_2.py
1,617
4.15625
4
"""sort files in FilesToSort, version 2""" import os import shutil FOLDER_TO_SORT = 'FilesToSort' def main(): os.chdir(FOLDER_TO_SORT) files_to_sort = get_files_to_sort() extensions = get_extensions(files_to_sort) get_categories(extensions, files_to_sort) def get_files_to_sort(): """Gets a list...
true
82a835c4a7ef3ff39ab91815f5da8d7eb0652ba9
harofax/kth-lab
/bonus/övn-2/övn-2-krysstal.py
1,838
4.46875
4
# exercise 1 def rectangle_area(height, width): """ :param height: height of rectangle :param width: width of rectangle :return: area of a rectangle with the specified width and height """ assert isinstance(width, int) or isinstance(width, float), "Width has to be a number!" assert isinsta...
true
c02807420cb24aa6153d051f927e70d79e42aa61
pasqualc/Python-Examples
/rotatearray.py
450
4.4375
4
# This program will take an array and a size of rotation as input. The Output # will be that array "rotated" by the specified amount. For example, if the Input # is [1, 2, 3, 4, 5] and size of rotation is 2, output is [3, 4, 5, 1, 2] while 1: array = input("Array: ") list = array.split() size = int(input("...
true
d53a41cff07f6ebbf0d2c890c6b984b5c3075dce
gladiatorlearns/DatacampExercises
/Adhoc/Packages.py
431
4.125
4
# Definition of radius r = 0.43 # Import the math package import math # Calculate C C = 2*math.pi*r # Calculate A A = math.pi*r**2 # Build printout print("Circumference: " + str(C)) print("Area: " + str(A)) # Definition of radius r = 192500 # Import radians function of math package from math import radians # T...
true
3f66c64d2cae9031fc7b0c9e326f8c8b1f2150e8
Dipson7/LabExercise
/Lab3/question_no_7.py
367
4.34375
4
''' WAP that accepts string and calculate the number of upper case and lower case letters. ''' def UPPERLOWER(sentence): u = 0 l = 0 for i in sentence: if i >= 'A' and i <= 'Z': u += 1 elif i >= 'a' and i <= 'z': l += 1 print(f"Uppercase: " + str(u)) print(f"L...
true
b8e5d8bc58770e0550a59f79acd8aa5ac5881416
Dipson7/LabExercise
/Lab3/question_no_2.py
485
4.28125
4
''' WAP called fizz_buzz that takes that takes a number. If it is divisible by 3, it should return fizz. If it is divisible by 5 return buzz. It it is divisible by both return fizzbuzz. Otherwise it should return the same number. ''' def div(): a = int(input("Enter any number: ")) if a/5 == a//5 and a/3 == a//3...
true
a86cebe421426649f4850db1f33bde0d85a11bdf
skye92/interest_cal
/InterestCal_v.2.py
1,455
4.34375
4
def account_balance():# def function/ what is function name, how many params. starting_balance = float(input("what is the starting balance? ")) # ask user for input for starting_balance stock_cost = float(input("how much does the stock cost? "))# ask user how much the stock cost stock_owned = starting_bal...
true
c9d4210f3e39ee89cc3cb7816caf920e22f32513
kalyansikdar/ctci-trees
/check_subtree.py
1,195
4.1875
4
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None # Algorithm: # 1. If the structure matches with the root, return true. # 2. Else check if it's a subtree of left subtree or right # Note: While...
true
c47a4043bdf87c41ac6081184473778996b750c4
vigjo/mdst_tutorials
/tutorial1/python_exercises.py
1,247
4.21875
4
""" Intro to python exercises shell code """ from collections import Counter def is_odd(x): if x % 2 != 0: return false return true """ returns True if x is odd and False otherwise """ def reverse(s): str = "" for i in s: str = i + str return str def is_palindrome(word): if word == ...
true
671b9b5777df9c755c8ee396c3cd7c21e187e7e5
olliepotter/Python_Scripts
/Python_Scripts/Coursework_1/fibonacci.py
1,297
4.78125
5
""" This file contains various functions to compute a given number of fibonacci terms """ def fibonacci(number, next_value=1, prev_value=0): """ Calculates the 'nth' number in the fibonacci sequence :param number: The 'nth' term in the fibonacci sequence to be returned :param next_value: The next valu...
true
66104e9f2bdb1175ad28f4ef81f1835eb449138d
FerruccioSisti/LearnPython3
/Conditionals Examples/ex36.py
1,668
4.25
4
#This exercise is basically the previous one, except it is meant to be short and entirely on our own from sys import exit #red room option from starting room def redRoom(): print("Everything in this room is red. You can't see any objects other than the outline of the door.") print("Do you try and go out the do...
true
b331aff61366b16861907d9466bd1c26e9945f66
FerruccioSisti/LearnPython3
/Tests/ex24.py
1,308
4.4375
4
#This is a longer exercise where we practice everything from the previous 23 examples print("Lets practice everything.") print('You\'d need to know \'bout escapes with \\ that do: ') print('\n newlines and \t tabs') poem = """\t the lovely world with logic so firmly planted cannot discern \n the needs of love nor com...
true
ead6245978ad7c23674e14b472457eeafa099330
franckess/Python-for-Everybody-Coursera-
/Python Data Structures/Scripts/Assignment_84.py
859
4.5
4
## Assignment 8.4 # Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. # The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. # When the progra...
true
df64b21d85348ac280397effe3d8cd576a73f52d
Rutujapatil369/python
/Assignment1_2.py
621
4.21875
4
# Write a program which contains one function named as ChkNum() which accept one parameter as number. #If number is even then it should display “Even number” otherwise display “Odd number” on console. #Input : 11 Output : Odd Number #Input : 8 Output : Even Number def ChkNum(No): if(No%2==0): ...
true
38360af0cefbce3fea4b9e03931bdee92fd822aa
ZTMowrer947/python-number-guess
/guessing_game.py
2,284
4.40625
4
""" Python Web Development Techdegree Project 1 - Number Guessing Game ----------------------------------------------------------------------- This project implements a simple version of the number guessing game. The user is prompted to guess a random number between 1 and 10, and does so until they guess correctly. At...
true
e249538c94d2b2c6d8a3dfece71adb4be5d187f4
SamuelLeeuw/mypackage
/mypackage/sorting.py
1,052
4.28125
4
def bubble_sort(items): '''Return array of items, sorted in ascending order''' for passnum in range(len(items)-1,0,-1): for i in range(passnum): if items[i]>items[i+1]: temp = items[i] items[i] = items[i+1] items[i+1] = temp r...
true
57174e710e1cd8d871ce605f4dd7bf5d8f8a21d8
deepakdas777/think-python-solutions
/Classes-and-functions/16.1.py
476
4.375
4
#Exercise 16.1. Write a function called print_time that takes a Time object and prints it in the form hour:minute:second . Hint: the format sequence '%.2d' prints an integer using at least two digits, including a leading zero if necessary. class time: hour=0 minut=0 second=0 def print_time(t): print('The time ...
true
48723d15b68caa2942c2add79890be28816fa6ea
amudwari/hangman
/game.py
1,191
4.1875
4
import random def get_random_word(): small_file = open("small.txt", "r") words = small_file.readlines() random_word = random.choice(words) print(random_word) return random_word def start_game(): print(''' You'll get 3 tries to guess the word. Lets START...''') random_word = g...
true
b0dfd9e4aed10b3cfc9f6931290c485e1f566482
slubana/GuessTheNumber
/guessmynumber.py
1,057
4.125
4
import math import random import time print("Welcome to the Guess the Number Game! \nThe goal of the game is to guess the number I am thinking!") choice = input("Do you want to play? Enter 'No' to quit and 'Yes' to play!") if choice=="No": print("Ok! Have a good day!") exit() else: print("You have chos...
true
21ef5a2af4468d11bf7b1cf85f5cc861f486a912
Krushnarajsinh/MyPrograms
/InnerClass.py
1,237
4.6875
5
#class inside a antother class is called as inner class class Student: class_name="A" #Inner class can access class variable but not instance variable of outer class def __init__(self,no,name): self.no=no self.name=name self.lap=self.Laptop("HP","i8") def show(self): print(s...
true
78a7a815b07f7d0e38d74d6958e94bb35d0cbec7
Krushnarajsinh/MyPrograms
/OneTryBlockWithManyExceptBlock.py
1,031
4.28125
4
#suppose i perform some operation with database and i need to open a connection to connect the detabase #when our task is over then we must close that connection #fa=int(input("Enter the number A:")) a=int(input("Enter the number A:")) b=int(input("Enter the number B:")) try: print("open connection") a=int(inp...
true
81a9ace06a898dce5d7ad77592e79ba2ae394cc5
Krushnarajsinh/MyPrograms
/ConstructorINInheritance.py
953
4.25
4
class A: def __init__(self,a): print("This is A class Constructor","value is:",a) def display1(self): print("This is display1 method") class B(A): def __init__(self,a): super().__init__(5) print("This is B class Constructor","value is:",a) def display2(self): prin...
true
ee198677e75c5bdac38a13c76c34c9de2ab7ad7e
Krushnarajsinh/MyPrograms
/ListAsArgumentInFunction.py
462
4.21875
4
def odd_even(list): even=0 odd=0 for i in list: if i%2==0: even+=1 else: odd+=1 return even,odd list=[] num=int(input("Howmay values you want to enter in the list:")) i=1 while i<=num: x=int(input("Enter the {}th value in list:".format(i))) list.append(x) ...
true
6e07b9cbfa479441ad03df261c47822ec6159ef4
Krushnarajsinh/MyPrograms
/GeneratorDemo.py
1,183
4.53125
5
#In iterator we need to face some issues like we need to define to functions iter() and next() #hence instead of using iterator we can use Generator #lat's do that def toptan(): yield 5 #yield is the keyword that make your method as generator now this is not normal method it is Generator #yield also similar t...
true
0f4b63cdb1224d2c5c86a2e75dcd9b8db925c5c9
Edrasen/A_Algoritmos
/Divide&Conquer2_QuickSort/quickLast.py
1,406
4.375
4
#Practica 4 #Ramos Mesas Edgar Alain #quicksort by pivot at last element #By printing every iteraction with partition function we will be able to see #how many iterations there are on the algorithm, in this case it takes only 6 iterations. contador = 0 comparaciones = 0 def partition(arr,low,high): ...
true
22bf6c6cd2472d712e0749844c8041f11213deec
headHUB/morTimmy
/raspberrypi/morTimmy/bluetooth_remote_control.py
2,281
4.125
4
#!/usr/bin/env python3 import remote_control # Controller driver and command classes import pybluez # Bluetooth python libary class RemoteController(ControllerDriver): """ Remote control morTimmy the Robot using bluetooth This class will be used to control the Raspberry Pi using e...
true
bad07650cf04085300eb252fccbbec7c345587f3
impiyush83/expert-python
/decorators.py
1,751
4.21875
4
# DECORATORS WITH ARGUMENTS : def trace(func): def wrapper(*args, **kwargs): print(f'TRACE: calling {func.__name__}() ' f'with {args}, {kwargs}') original_result = func(*args, **kwargs) print(f'TRACE: {func.__name__}() ' f'returned {original_result!r}') ...
true
dedb545a4c77ff1d065cb5815b585737f6b3293a
gadepall/IIT-Hyderabad-Semester-Courses
/EE2350/Coding Assignment-1/2.1.1g.py
1,080
4.15625
4
# Code for Moving Average System import numpy as np import matplotlib.pyplot as plt n = int(input("No.of Elements in signal: ")) x = np.ones(n) time = np.arange(n) for i in range(n): # Generating the input x[i] = 0.95 ** i def Signal_Ideal_Delay(signal,d = 2): # Function to generate ideal del...
true
a2e5abd26ff8ebe066c20741ec54f14400942a59
uh-bee/Balakrishnan_Story
/addSix.py
203
4.40625
4
""" This program will take the input of the user and return that number plus 6 in a print statement """ x= float(int(input('please enter a number'))) print("the number" + x + "plus 6 is:" + str((x+6)))
true
d5546cf9190ec318bbb90a4af97b4f46d76e5a02
unites/code_library
/python/comparison.py
1,757
4.53125
5
# Python 3 code # check if list are equal # using set() & difference() # initializing list and convert into set object x = set(['x1','rr','x3','y4']) y = set(['x1','rr','rr','y4']) print ("List first: " + str(x)) print ("List second: " + str(y)) # take difference of two lists z = x.difference(y) ...
true
8d27d8e9695d6316a6316194b04b792edfff183b
treelover28/Tkinter-Learning
/grid.py
644
4.59375
5
from tkinter import * # create root window root = Tk() # define Label widget on top of the Root widget label = Label(root, text="Hello World") label2 = Label(root, text="My name is Khai Lai") label3 = Label(root, text="---------------") # instead of automating the placement using .pack() # we can specify the position...
true
5b834fef771547925b2e9fdf7b37a8a2c54dd4ef
AmirQadir/MITx-6.00.1x
/Week2/Prob1.py
501
4.34375
4
balance = int(input("Enter the current balance:")) annualInterestRate = float(input("Enter the annualInterestRate")) monthlyPaymentRate = float(input("monthlyPaymentRate")) for i in range(12): mir = annualInterestRate / 12.0 # Monthly Interest Rate mmp = monthlyPaymentRate * balance # Minimum Monthly Payme...
true
76f61ae21e0d1747e82e42188ed61421d2dad483
jivid/practice
/cracking/Chapter 4 - Trees and Graphs/q4_5.py
596
4.21875
4
""" Implement a function to check if a binary tree is a binary search tree """ import sys # Assume here that values in the tree are positive (i.e. > 0) so as to # not worry about -1 being the base case for min and max def is_binary_search_tree(root, max=-1, min=-1): if root is None: return True if m...
true
ad3082500a9dd68294a70036a4799d03ebf86045
siddharth20190428/DEVSNEST-DSA
/DI015_Diameter_of_a_binary_tree.py
741
4.125
4
""" Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. The length of a path between two nodes is represented by the number of edges between them...
true
7b425622ed0ea1745ebabc7407082b09b1cb4e2d
siddharth20190428/DEVSNEST-DSA
/DI016_Maximum_width_of_a_binary_tree.py
1,209
4.125
4
""" Given a binary tree, write a function to get the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in the level, where the null nodes between the end-n...
true
ef367ea0d700846d6103154c1e6d92e97489c933
thumbimigwe/nipy
/snippets/5th feb/Number based brainteasers/Digit Grouping.py
748
4.34375
4
#!/usr/bin/python3 # When displaying numbers it is good practice to group digits together and use the comma to separate groups of three digits. For instance 100000000 is easier to read when it is displayed as 100,000,000. # Ask the user to enter any large number (e.g. at least 3 digits long). The program should displa...
true
c38069122b4b78fcb3092018d9e93bdbe55223e9
thumbimigwe/nipy
/snippets/Math Quiz/mathQuiz.py
2,311
4.28125
4
#!/usr/bin/python3 # ********************* PROBLEM STATEMENT ********************* # A primary school teacher wants to test her students mental arithmetic by making them complete a test with 10 questions in which they complete operations like; adding, subracting and multiplying. # Complete the following tasks; # 1....
true
7c620e8a40994c5dcf6f1a140ded402cff04b910
GIT-Ramteja/project1
/string2.py
1,801
4.40625
4
str = "Kevin" # displaying whole string print(str) # displaying first character of string print(str[0]) # displaying third character of string print(str[2]) # displaying the last character of the string print(str[-1]) # displaying the second last char of string print(str[-2]) str = "Beginnersbook" # displaying w...
true
c612c428f14af37f07d412303b80302040f8516f
Paavni/Learn-Python
/Python project/pythonex8.py
330
4.125
4
#print "How are you today?" #answer = raw_input() #print "Enter age" #age = raw_input() #print "Your age is %s" %age print "This will print in", print "one line.", print "One line it is!" name = raw_input("What is your name? ") print "Your name is: %s" %name age = raw_input("What is your age? ") print "Your age is...
true
75bab9cc50495b3f50749278e02fe7e54e126c50
timorss/python
/24addRemoveItem.py
616
4.28125
4
letters = ['a', 'b', 'c', 'd'] # add item in the beginning letters.append('e') print(letters) # ['a', 'b', 'c', 'd', 'e'] # add item in specific location letters.insert(3, '--') print(letters) # ['a', 'b', 'c', '--', 'd', 'e'] # remove item in the end letters.pop() print(letters) # ['a', 'b', 'c', '--', 'd'] # r...
true
8010ee6122f45866fd1a3dbffac29a039ceff938
ajpiter/CodeCombat
/Desert/SarvenSavior.py
753
4.125
4
"""My pet gets left behind everytime :( """ # An ARRAY is a list of items. # This array is a list of your friends' names. friendNames = ['Joan', 'Ronan', 'Nikita', 'Augustus'] # Array indices start at 0, not 1! friendIndex = 0 # Loop over each name in the array. # The len() function gets the length of the list. whi...
true
9ba06c2ab12388b1ffe5596089dbd34c681d3c95
AnthonyWalton1/ARBI
/Raspberry Pi/Raspberry Pi Code/Arbi GUIs/GUI Tutorials/Tutorial1.py
350
4.125
4
#!/usr/bin/env python from Tkinter import * # Start a GUI (object) from Tkinter class root = Tk() # Create a label (text box widget) called theLabel and set what text it shows theLabel = Label(root, text = "Python GUI") # Place the text box in the first available space and display it theLabel.pack() # Keep the G...
true
7c92766f99e3dff17ed5426962aca10f1bac7890
Environmental-Informatics/building-more-complex-programs-with-python-avnika16
/amanakta_Exercise_6.5.py
460
4.1875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Solution for Exercise 6.5 Avnika Manaktala """ def gcd(a,b): #Defining GCD function if b!=0: #Setting up recursion return gcd(b, a%b) else: return a #When b=0 recursion stops def user_gcd(): #Defining user input for GCD function ...
true
e013ee6c78fef1df17b4f1879b49d628c0386c30
jonathangjertsen/classmemo
/classmemo/__init__.py
2,039
4.125
4
""" A `Memoizer` can be used as a factory for creating objects of a certain class. It exposes a constructor and 2 methods * `memoizer = Memoizer(SomeClass)` * `memoizer.get(*args, **kwargs)` * If `memoizer` has never seen the given arguments, it creates `SomeClass(*args, **kwargs)` and returns it. * If `memoiz...
true
b8980a7259eb8cb5f01f156e0d053f0b74e8f758
dwhdai/advent_of_code
/2020/day3.py
2,826
4.4375
4
def import_map(filepath): """Given a filepath, import the map object as as a nested list. Returns: list: a 2D nested list, representing the rows of the map as individual list objects """ with open(filepath) as f: map = f.read().splitlines() return map def traverse_step(s...
true
47fb7a15721f699fdf2703ec25bea5afe020b90a
sam943/Python2.7
/Python_301/sqlite_database_connections.py
937
4.25
4
import sqlite3 # default db module available with python conn = sqlite3.connect('dem3d.db') # here is the db doesn't exist the database is created c = conn.cursor() # cursor is a handle to execute our queries c.execute('''CREATE TABLE users(username text,email text)''') c.execute("INSERT INTO users VALUES ('Sam', 'me@m...
true
8195a360629e12c4efec9d2086466e6f15e0cfe2
josefren/numpy-scipy-exercises
/exercise-7-numpy-practice.py
1,748
4.65625
5
""" Start up Python (best to use Spyder) and use it to answer the following questions. Use the following imports: import numpy as np import scipy.linalg as la import matplotlib.pyplot as plt 1 Choose a value and set the variable x to that value. 2 What is command to compute the square of x? Its cube? 3 Choose an...
true
d6d79f72a837978a1244c929b26270b76845030f
DreamXp/cse210-student-hilo
/hilo/game/Guesser.py
1,999
4.25
4
import random class Guesser: """The responsibility of this class of objects is to play the game - choose the card, add or subtract points from the total, guess whether the next card will be lower or higher, and determine whether the player can guess again. Attributes: points (number): The number o...
true
be56e882bbb827a1e40a1d6c06333292627ab9a8
artsalmon/Think-Python-2e---my-solutions
/07 - Exercises/7.2 - Module 2.py
1,083
4.5
4
""" Exercise 7.2. The built-in function eval takes a string and evaluates it using the Python interpreter. For example: >>> eval('1 + 2 * 3') 7 >>> import math >>> eval('math.sqrt(5)') 2.2360679774997898 >>> eval('type(math.pi)') <class 'float'> Write a function called eval_loop that iteratively prompts the user, takes...
true
a3748d80579b19cf572f07a9dac445457895f749
theecurlycoder/CP_PWP
/1. Python/control_flow.py
551
4.25
4
# if/then statements # boolean values likes_pizza = True likes_cats = False print(True) print(False) is_john_killer = True is_bob_killer = False if is_bob_killer == True: print("Bob is the killer") if is_john_killer == True: print("John is the killer") print() #Equality Operators print(5 == 5) print(5 > ...
true
7130c34b6e9b7cabc479c49e8bb118b9130b7220
yudhapn/OCBC-H8-Python
/Session3/function.py
2,413
4.1875
4
# case 1 def my_function(p, l): '''Function to calculate area of a square''' print(p * l) def printme(str_input): print(str_input) printme("I'm first call to user defined function") printme("Again second call to do the same function") print("\n===processing input and return it===") def changeme(myList): ...
true
c33e1014f0b877dbec5dc4c129c9c8d8b1934c0d
raj-andy1/mypythoncode
/samplefunction14.py
282
4.15625
4
""" sampleprogram14 - class 4 while loop example - type a """ looping = True while looping == True: answer = input("Type letter a") if answer == 'a': looping = False else: print ("TYPE THE LETTER A") print ("Thanks for typing the letter A")
true
5bc78f4f6b0a5f48ebae15a7cc5db65e6dbdc386
irakowski/PY4E
/03_Access Web Data/ex_12_3.py
945
4.5
4
"""Exercise 3: Use urllib to replicate the previous exercise of (1) retrieving the document from a URL, (2) displaying up to 3000 characters, and (3) counting the overall number of characters in the document. Don’t worry about the headers for this exercise, simply show the first 3000 characters of the document con...
true
4ca87c9e82ed461cf2a0192c354493279d0ec224
irakowski/PY4E
/01_Getting Started with Python/ex_3_1.py
403
4.1875
4
""" Exercise 1: Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours """ hours = float(input("Enter Hours: ")) rate = float(input("Enter Rate: ")) standart_time = 40 if hours > standart_time: overtime_rate = rate * 1.5 * (hours - standart_time) pay = (stan...
true
f93df966be9f9c9c4121154d0e014840b95cc70b
irakowski/PY4E
/02_Data Structures/ex_7_1.py
759
4.3125
4
"""Exercise 1: Write a program to read through a file and print the contents of the file (line by line) all in upper case. Executing the program will look as follows: python shout.py Enter a file name: mbox-short.txt FROM STEPHEN.MARQUARD@UCT.AC.ZA SAT JAN 5 09:14:16 2008 RETURN-PATH: <POSTMASTER@COLLAB.SAKAIPROJECT....
true
2ad39ba81a7e59fd6f49d809279ed67bfcb3f419
Jdothager/web-caesar
/caesar.py
1,271
4.25
4
def encrypt(text, rot): """ receives a string, rotates the characters by the the integer rot and returns the new string """ if type(rot) != int: rot = int(rot) # if text is not a string, return text if type(text) is not str: return text # encrypt and return the new strin...
true
5a25d8f5cf6f8bee0c6d43b8f591480946ed07a3
SahRieCat/python
/02_basic_datatypes/2_strings/02_10_most_characters.py
754
4.5625
5
''' Write a script that takes three strings from the user and prints them together with their length. Example Output: 5, hello 5, world 9, greetings CHALLENGE: Can you edit to script to print only the string with the most characters? You can look into the topic "Conditionals" to solve this challenge. '''...
true
b3f95c536d87d27d1a37ec0df9e47050b2c0e0d3
y0ssi10/leetcode
/python/symmetric_tree/solution.py
1,338
4.28125
4
# Problem # # Given a binary tree, # check whether it is a mirror of itself (ie, symmetric around its center). # For example, this binary tree [1,2,2,3,4,4,3] is symmetric: # 1 # / \ # 2 2 # / \ / \ # 3 4 4 3 # import queue class TreeNode: def __init__(self, x): self.val = x self.l...
true
b7755ffbc6242a2098ff4a99d4623e24b7fc3d25
y0ssi10/leetcode
/python/diameter_of_binary_tree/solution.py
1,031
4.21875
4
# Problem: # Given a binary tree, you need to compute the length of the diameter of the tree. # The diameter of a binary tree is the length of the longest path between any two nodes in a tree. # This path may or may not pass through the root. # # Note: # The length of path between two nodes is represented b...
true
3b922b231dd58ac97104bb606bd44afae63e2393
noozip2241993/homework4
/task1.py
671
4.34375
4
import random def generating_defining_prime_number(): """Checking whether the argument is a prime number or not""" for j in range(6): #generating six random numbers num = random.randrange(1,101) if num > 1: #prime numbers are greater than 1 for i in range(2,num): #check for factors ...
true
ab4612f127ea1205fddf615ea520a2dbab9821dc
cishocksr/cs-module-project-algorithms-cspt9
/moving_zeroes/moving_zeroes.py
566
4.1875
4
''' Input: a List of integers Returns: a List of integers ''' def moving_zeroes(arr): positive = [] negative = [] zero = [] for i in range(len(arr)): if arr[i] > 0: positive.append(arr[i]) elif arr[i] < 0: negative.append(arr[i]) else: zero....
true
1a7a5c3a0b5b5cd2858ce8c186ff63af040ed238
ashnashahgrover/CodeWarsSolutions
/practiceForPythonInterview/pythonEx6.py
519
4.34375
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. # # Examples # pig_it('Pig latin is cool') # igPay atinlay siay oolcay # pig_it('Hello world !') # elloHay orldway ! def pig_it(text): text = text.split(" ") new_text = [] for...
true
7f238c4217229748ef202dc4361832fa3211f331
ThapaKazii/Myproject
/test19.py
416
4.1875
4
# From a list separate the integers, stings and floats elements into three different lists. list=["bibek",44,'puri',288.8,'gaida',33,12.0,] list2=[] list3=[] list4=[] for x in list: if type(x)==int: list2.append(x) elif type(x)==float: list3.append(x) elif type(x)==str: list4.appen...
true
c449b076d13c203c8b3012cdc2909eac3008662b
nerugattiraju/interview-questions
/generator.py
277
4.40625
4
#generators are used to creating the iterators with the different approches from time import sleep n=int(input("enter the number")) print("contdown start") def countdown(n): while n>0: yield n n=n-1 sleep(0.3) x=countdown(n) for i in x: print(i)
true
7939224df96eb3ca863d0a6372dabed86ee25436
nerugattiraju/interview-questions
/class functions.py
448
4.125
4
class Employee: def __init__(self,name,id,age): self.name=name self.id=id self.age=age x=Employee("raju",100,24) print(getattr(x,'name'))#get the attribute of the object. setattr(x,'age',34)#set the perticular attribute of the object. print(getattr(x,'age')) #delattr(x,'id')#delete the peric...
true
808e78714e7cafbc102de51be052bd3d737c20e8
avi202020/sailpointbank
/Bank.py
358
4.125
4
from typing import Dict import Account """ Bank keeps track of users by keeping a map of user name to Account instance. Every time a new Account is created, it will add it to its map. """ class Bank: def __init__(self): self.accounts: Dict[str, Account] = {} def add_account(self, name, account): ...
true
e1a8475f8e89deecb8de69b1fc8205635c08cbdf
lamessk/CPSC-217
/Assignment2/Assignment2.py
2,143
4.25
4
#Lamess Kharfan, Student Number: 10150607. CPSC 217. #Draw a climograph displaying temperature and precipitation data for all #12 months of the year using 24 input statements, 12 for temperature and 12 for #precipitation. Line graph will be repersenative of temperature data and Bar #graph is representative of the preci...
true
2bf5f4ead2ab7718b6849f03e90f852e462d8e74
pi6220na/CapLab1
/guess.py
596
4.125
4
#Lab1 Jeremy Wolfe # Guess a number import random random_pick = random.randint(1,10) print('computer random number is : ' + str(random_pick)) guessed_number = input('Guess a number between 1 and 10: ') guessed_number = int(guessed_number) while True: if random_pick == guessed_number: prin...
true
ac72560db9c6fb4aa2861c059245eeaa979b6808
jpchato/a-common-sense-guide-to-data-structures-and-algorithms
/binary_search.py
1,471
4.375
4
def binary_search(arr, val): # first , we establish the lower and upper bounds of where the value we're searching for can be. To start, the lower boudn is the first value in the array, while the upper bound is the last value lower_bound_index = 0 upper_bound_index = len(arr) - 1 # we begin a loop i...
true
34555e8f777b09f08c25d1b4e13f693010b41064
lcsm29/MIT6.0001
/lecture_code/in_class_questions/lec2_in-class.questions.py
1,165
4.15625
4
# 1. Strings # What is the value of variable `u` from the code below? once = "umbr" repeat = "ella" u = once + (repeat+" ")*4 #umbrella ella ella ella # 2. Comparisons # What does the code below print? pset_time = 15 sleep_time = 8 print(sleep_time > pset_time) # False derive = True drink = False both = drink and deri...
true
9704dbce6358c457c123d424f1b11b89cad08452
zois-tasoulas/ThinkPython
/chapter8/exercise8_4.py
849
4.1875
4
#This will return True for the first lower case character of s def any_lowercase1(s): for c in s: if c.islower(): return True else: return False #This will alsways return True as islower() is invoked on the character 'c' def any_lowercase2(s): for c in s: if 'c'.islower(): return 'True' else: ret...
true
32c9dd2e13bf06dfc108a5cbd9d3b874f6ad54d8
zois-tasoulas/ThinkPython
/chapter6/exercise6_3.py
434
4.125
4
def first(word): return word[0] def last(word): return word[-1] def middle(word): return word[1:-1] def is_palindrome(word): if len(word) == 0 or len(word) == 1: return True elif len(word) == 2: return first(word) == last(word) else: return first(word) == last(word) and is_palindrome(middle(word)) retu...
true
04d85f17c4b854dc6822b1f33ea7993daceb38b4
drewvlaz/CODE2RACE
/SOLUTIONS/reverse-Word-Python.py
212
4.40625
4
#Get User word user_input= raw_input("Please input your word ") #reverse the user input reverse_user_input =user_input[::-1] #Print the reverse word print ("This is reverse of your word : " + reverse_user_input)
true
21663c061e8a16c3c9e56129ed778358c7625f00
annieshenca/LeetCode
/98. Validate Binary Search Tree.py
947
4.125
4
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ # Set upper...
true
47598a547fe44cea7968834b2d4c110a99cd96d8
prachichikshe12/HelloWorld
/Arithmatic.py
348
4.375
4
print(10 + 3) print(10 - 3) print(10 * 3) print(10 / 3) print(10 // 3) # print division calculation ans in Integer print(10 % 3) # prints remainder print(10 ** 3) # 10 to the power 3 #Augmented Assignment Operator x = 10 #x = x +3 #x +=3 x -= 3 print(x) # operator precedence #x= (2+3)* 10 -3 x = 2+6*2*2 print(x) ...
true
2fe7e7a8758a9a89632d255c8813a2eb2e128125
Shariarbup/Shariar_Python_Algorithm
/find_a_first_uppercase_character/find_a_first_uppercase_character.py
921
4.15625
4
#Given a String, find a first uppercase character #Solve both an iterative and recursive solution input_str_1 = 'lucidProgramming' input_str_2 = 'LucidProgramming' input_str_3 = 'lucidprogramming' def find_uppercase_iterative(input_str): for i in range(len(input_str)): if input_str[i].isupper(): ...
true
a2073aece1c27ba4c3e57612ac3fe1ab9a5913b8
shimoleejhaveri/Solutions
/solution16.py
1,475
4.4375
4
""" Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules: 1. Any left parenthesis '(' must have a corresponding right parenthesis ')'. 2. Any right parenthesis ')' must have a correspondin...
true
0aedbb6c0ea2871be312b08786599e814757f6c5
AdenRao3/Unit-6-03-Python
/movie.py
533
4.1875
4
# Created by: Aden Rao # Created on: April 7, 2019 # This program lets the user enter age and based on that it tells them what movies they can see. # imports math function import math #Input fot the user to enter their age and it tells them to myAge = int(input("Type your age: ")) # If statment to determin...
true
12d562efccfa120bf7658aa958d8d23b8e56cc44
Nate2019/python-basics
/camel.py
2,427
4.375
4
import random #Camel BASIC Game in python from 'Program Arcade Games with Python' Chapter 4: Lab exercise! #Written by Iago Augusto - plunter.com print """ Welcome to camel! You have stolen a camel to make your way across the great Mobi desert. The natives want their camel back and are chasing you down! Survive your d...
true
85ab9c2e85e5830c1671f481f828a0ab5daf1909
sneakyweasel/DNA
/FIB/FIB.py
1,049
4.15625
4
import os import sys file = open(os.path.join(os.path.dirname(sys.argv[0]), 'rosalind_fib.txt')) dna = file.read() print(dna) # dna = "5 3" n = int(dna.split(' ')[0]) k = int(dna.split(' ')[1]) population = [1, 1] def next_generation(population, k): current = population[-1] # reproductor_pairs = (population -...
true
b65a3596d0a9ab4e62564e25ce0d7e6e7debc54e
jfcarocota/python-course
/Strings.py
1,604
4.28125
4
myStr = 'Hi Friend' # restusn all options for string object #print(dir(myStr)) print(myStr) # converts strings in uppercase print(myStr.upper()) #converts string in lowercase print(myStr.lower()) #change lower to upper an viceverse print(myStr.swapcase()) # convert the first character in strings to uppercase and ...
true
2c33a2630ab625d76ac59e7a2c376c1c76f80ca6
NyntoFive/Python-Is-Easy
/03_main.py
1,197
4.34375
4
""" Homework Assignment #3: "If" Statements Details: Create a function that accepts 3 parameters and checks for equality between any two of them. Your function should return True if 2 or more of the parameters are equal, and false is none of them are equal to any of the others. Extra Credit: Modify your f...
true
2ac7a2f65c84ed64006361e1b6c3d92bd9acb2fc
shaheryarshaikh1011/HacktoberFest2020
/Algorithms/Python/sorting/bubble sort.py
406
4.375
4
#Python Implementation of bubble Sort Algorithm #Using data available in Python List temperature=[45,10,14,77,-3,22,0] #ascending Order Sort def bubble(data): n=len(data) for i in range(n-1): for j in range(i+1,n): if data[i]>data[j]: temp=data[j] data[j]=data[i] data[i]=temp print("Data Before Sor...
true
7bada2bc40f499a7e4df7809b9f5e01844224af3
rishabhnagraj02/rishabh
/PEP8.PY
458
4.125
4
#Program to show use of constuctor and destructor class Person: def __init__(self,fname,lname): self.fname=fname self.lname=lname def getFullName(self): print(fname,lname) def __del__(self): print("Destroying instance of person class") p1=Person("Emraan","Hashm...
true
45076d538b6ef92f733093861d65cc159abefbac
davidevaleriani/python
/ball.py
1,925
4.15625
4
####################################################################### # Bouncing ball v1.0 # # This program is a first introduction to PyGame library, adapted # from the PyGame first tutorial. # It simply draw a ball on the screen and move it around. # If the ball bounce to the border, the background change c...
true
34e5e6e7d7f787c615ef1f7ceb9a72a5c3d39d0d
LorienOlive/python-fundamentals
/paper-rock-scissors.py
1,205
4.21875
4
import random choices = ['paper', 'rock', 'scissors'] computer_score = 0 player_score = 0 while computer_score < 2 and player_score < 2: computer_choice = random.choice(choices) player_choice = input('What do you choose: paper, rock, or scissors? ') if computer_choice == player_choice: print('Tie...
true
07d3ce76ec05f6b1bfc4d1bdee287552e0c06aab
ledurks/my-first-portfolio
/shpurtle.py
604
4.15625
4
from turtle import * import math # Name your Turtle. t = Turtle() t.pencolor("white") # Set Up your screen and starting position. penup() setup(500,300) x_pos = -250 y_pos = -150 t.setposition(x_pos, y_pos) ### Write your code below: t.goto(500,600) pendown() begin_fill() fillcolor("LightSalmon") for sides in range(...
true
a4b554f80bca1935d4685c39c1222d486f23ddbb
aniketguptaa/python
/Strings.py
1,493
4.375
4
#strings are immutable # Different method of writing string x = "Hello My name is Carry" y = 'Hello My name is Carry' z = '''Hello My name is carry and i read in class 10 and I am smart''' print(type(x)) # TypeViewing print(type(y)) # TypeViewing print(type(z)) # TypeViewing print(x) print(y) print(z) # I...
true
e5c6517652c80dd958f26cb072055e255ce1967a
aniketguptaa/python
/Dictionary.py
966
4.1875
4
dict = {1 : "spam", 2: "spamming"} print(dict) dict1= {'name': 'Carry', 'age': 26} print(dict1['name']) print(dict1['age']) # Adding keys and value in preesxising dictionary dict1['address'] = 'Silicon valley' print(dict1['address']) print(dict1) squares = {1:1, 2:4, 3:9, 4:16, 5:25, 6:36, 7:49, 8:64, 9:...
true
677d3f159cff2060f8116447d319ffe0ff39e3a4
duncanmurray/Python2-Training-Practicals
/takepin.py
659
4.3125
4
#!/usr/local/bin/python # Page 13 of exercise quide # Emulate a bank machine # Set the correct pin correct_pin = "1234" # Set number of chances and counter chances = 3 counter = 0 # While counter is less than chances keep going while counter < chances: # Ask for user input supplied_pin = raw_input("Please ...
true
355e20ddaff58320b195720f29272a5c093b66ca
swachchand/Py_exercise
/python_small_examples/pythonSnippets/frontThreeCharacters.py
700
4.1875
4
''' Given a string, we'll say that the front is the first 3 chars of the string. . If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front. front3('Java') 'JavJavJav' front3('Chocolate') 'ChoChoCho' front3('abc') -- 'abcabcabc' front3('abcXYZ'...
true
886bdc4ecade0c75feae27d9205511a5377818c2
swachchand/Py_exercise
/python_small_examples/pythonSnippets/revStringSimple.py
362
4.40625
4
''' Print entire character stream in reverse without ---> List Comprehension Technique (simple traditional for loop) example: hello world olleh dlrow ''' word = input('Enter: ') ##The split() method splits a string into a list. w = word.split(' ') re =[] for i in w: re=i[::-1] #re.append...
true
5e63cb5efb36f2a1765446b6f9591594bf45cd4c
kevinsjung/mixAndMatchSentence
/mixAndMatchSentence.py
1,389
4.125
4
def mixAndMatchSentences(sentence): """ Given a sentence (sequence of words), return a list of all "mix and matched" sentences. We define these sentences to: - have the same number of words, and - each pair of adjacent words in the new sentence also occurs in the original sentence Example:...
true
09696fc8ccfcfad1e74b6dea56b5a067770f2549
jermailiff/python
/ex37.py
1,573
4.15625
4
import os # from math import sqrt # # # print "Hello World" # # while True: # # feelings = input("How are you feeling this morning on a scale of 1 - 10?") # # if feelings in range(1,5): # print "Pretty shitty then!" # break # elif feelings in range(6,10): # print "Pretty damn good eh" # break # else: ...
true
0090d97141e758c65615795888ee1b999d28431c
iiit-nirmal/pyhton_prac
/loops/loopControl.py
458
4.15625
4
## continue returns control the begining of loop for letteres in 'geeksgeeks': if letteres == "e" or letteres == "s": continue print('character:',letteres) ## break returns control to the end of loop for letteres in 'geeksforgkees': if letteres == "e" or letteres == "s": break print(...
true
da2d37c8ceebc6e7ac03eb30f5d472d0e7c7e1f3
joshmreesjones/algorithms
/interviews/n-possible-balanced-parentheses.py
755
4.21875
4
""" Print all possible n pairs of balanced parentheses. For example, for n = 2: (()) ()() """ def balanced_parentheses(n): if n == 0: return [""] elif n == 1: return ["()"] else: previous = balanced_parentheses(n - 1) result = [] for i in range(len(previous)...
true
3e331573d4214f4302f4124c42e74dd8f6d2c691
glennandreph/learnpython
/thirtysix.py
213
4.15625
4
name = "Glenn" age = 24 if name == "Glenn" and age == 24: print("Your name is Glenn, and you are 24 years old.") if name == "Glenn" or name == "Rick": print("Your name is either Glenn or Rick.")
true