blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
fbb5cf72b35858269f21e8fd8e0803ae966bc791 | Crolabear/record1 | /Collatz.py | 1,078 | 4.1875 | 4 | # goal: write a program that does the following...
# for any number > 1, divide by 2 if even, and x3+1 if odd.
# figure out how many steps for us to get to 1
# first try:
import sys
class SomeError( Exception ): pass
def OneStep(number, count):
#number = sys.argv[0]
if type(number) is int:
if number... | true |
1540db701ceb4907f050bef4dd59922ddd8d3e44 | connorhouse/Lab4 | /lists.py | 1,855 | 4.1875 | 4 | stringOne = 'The quick brown fox jumps over the lazy dog'
print(stringOne.lower())
def getMostFrequent(str):
NO_OF_CHARS = 256
count = [0] * NO_OF_CHARS
for i in range(len(str)):
count[ord(str[i])] += 1
first, second = 0, 0
for i in range(NO_OF_CHARS):
if count[i] < count[first... | true |
1a064c17ae1d941a9a055ad6c768d4ea78e7f9dc | anishverma2/MyLearning | /MyLearning/Advance Built In Functions/useofmap.py | 510 | 4.6875 | 5 | '''
The map function is used to take an iterable and return a new iterable where each iterable has been modified according to some function
'''
friends = ['Rolf', 'Fred', 'Sam', 'Randy']
friends_lower = map(lambda x: x.lower(), friends)
friends_lower_1 = (x.lower for x in friends) #can also be used as a generator ... | true |
b0cd65ee2540ec7abbece259639628d808672c81 | brianjgmartin/codingbatsolutions | /String-1.py | 1,158 | 4.1875 | 4 | # Solutions to Python String-1
# Brian Martin 14/04/2014
# Given a string name, e.g. "Bob", return a greeting of the form "Hello Bob!".
def hello_name(name):
return "Hello " + name + "!"
# Given two strings, a and b, return the result of putting them together in
# the order abba, e.g. "Hi" and "Bye" returns "Hi... | true |
7db18f6d7a61e5a2d802a5a417e5dbfc0acd6a6a | mcgarry72/mike_portfolio | /knights_tour_problem.py | 2,595 | 4.125 | 4 | # this is an example recursion problem
# classic: given a chessboard of size n, and a starting position of x, y
# can the knight move around the chessboard and touch each square once
import numpy as np
def get_dimension_input():
cont_processing = True
have_received_input = False
while not have_received_i... | true |
bac727960b8e93f16d210ebc60dae8e576e8aa10 | Andida7/my_practice-code | /45.py | 2,148 | 4.46875 | 4 | """Write a program that generates a random number in the range of 1 through 100, and asks
the user to guess what the number is. If the user’s guess is higher than the random number,
the program should display “Too high, try again.” If the user’s guess is lower than the
random number, the program should display “To... | true |
164a205f30278d2ca0e01cb7e38f8fd39f481ec8 | JeffGoden/HTSTA2 | /python/homework 1-8/task3.py | 742 | 4.21875 | 4 | number1= int(input("Enter 1 number"))
number2= int(input("Enter a 2nd number"))
if(number1 == number2):
print("Its equal")
else:
print("Its notr equal")
if(number1!= number2):
print("Its not equal")
else:
print("its equal")
if(number1>number2):
print("number 1 is greater than number 2")
else:
p... | true |
2f5befb1e3213da290381566175cf6e63a1f735b | DeenanathMahato/pythonassignment | /Program4.py | 593 | 4.28125 | 4 | # Create a program to display multiplication table of 5 until the upper limit is 30
# And find the even and odd results and also find the count of even or odd results and display at the end. (using do while loop,for loop,while)
# 5 x 1 = 5
# 5 x 2 = 10
# 5 x 30 = 150
e= []
o= []
for a in range(1,31):
if (a*5)%2==0:... | true |
c317b5a617d4c84d83762e8f6eafe87995ad9fba | velicu92/python-basics | /04_Functions.py | 1,301 | 4.21875 | 4 |
##############################################################################
####################### creating a basic Function ##########################
##############################################################################
def sumProblem(x, y):
sum = x + y
print(sum)
sentence = 'Th... | true |
d163ea2611bfefb44382b904d0ae992e22ca1b52 | nishantchy/git-starter | /dictionary.py | 487 | 4.3125 | 4 | # accessing elements from a dictionary
new_dict = {1:"Hello", 2:"hi", 3:"Hey"}
print(new_dict)
print(new_dict[1])
print(new_dict.get(3))
# updating value
new_dict[1] = "namaste"
print(new_dict)
# adding value
new_dict[4] = "walla"
print(new_dict)
# creating a new dictionary
squares = {1:1, 2:4, 3:9, 4:16, 5:25}
print(... | true |
9ed6b0d01e7e6329a7bf8e04ac10e426175b91f2 | Rafaelbarr/100DaysOfCodeChallenge | /day018/001_month_number.py | 2,320 | 4.15625 | 4 | # -*- coding: utf-8 -*-
def run():
# Variable declaration
months = 'JanFebMarAprMayJunJulAugSepOctNovDec'
done = False
# Starting the main loop
while done == False:
# Ask the user for a numeric input of a number
month_number = int(raw_input('Enter the number of a month ... | true |
16ff87190cf9599da27b7dc5e912cb376959f1e4 | the-mba/progra | /week 5/exercise4.py | 520 | 4.3125 | 4 | valid = False
number_of_colons = 0
while not valid:
attempt = input("Please enter a number: ")
valid = True
for c in attempt:
if c == '.':
number_of_colons += 1
elif not c.isdigit():
valid = False
break
if number_of_colons > 1:
valid = False
... | true |
e203bc43e7d2fac93785b8ad563c742084e80a6b | Dave-dot-JS/LPHW | /ex15.py | 376 | 4.125 | 4 | from sys import argv
script, filename = argv
# opens the specific file for later use
txt = open(filename)
# reads the designated file
print(f"Here's your file {filename}:")
print(txt.read())
# re-takes input for file name to open
print("Type the filename again:")
file_again = input("> ")
# opens new file
txt_again = o... | true |
1e2ea00b37d89d7763805e8a7a0a57c2f1da7d3d | Socialclimber/Python | /Assesment/untitled.py | 1,684 | 4.1875 | 4 | def encryption():
print("Encription Function")
print("Message can only be lower or uppercase letters")
msg = input("Enter message:")
key = int(input("Eneter key(0-25): "))
encrypted_text = ""
for i in range(len(msg)):
if ord(msg[i]) == 32: #check if char is a space
encrypted_text += chr(ord(msg[i])) # cocnca... | true |
50a092982e0f3182094714e2c3cf565226545900 | jerster1/portfolio | /class2.py | 1,080 | 4.28125 | 4 | #lesson 1
#firstName = raw_input("what is your name? ")
#lasttName = raw_input("what is your last name? ")
#address = raw_input("what is your address? ")
#phonenumber = raw_input("what is your phone number? ")
#age = input("How old are you? ")
#
#lesson 2
#firstname = raw_input("what is ur name? ")
#
#print "... | true |
925a2c4ad9b411c4da3704b21792a5e33a024e4d | bmarco1/Python-Journey | /yup, still going.py | 1,117 | 4.21875 | 4 | def build_person(first_name, last_name):
"""Return a dictionary of information about a person."""
person = {'first': first_name, 'last': last_name}
return person
musician = build_person('jimi', 'hendrix')
print(musician)
print("\n")
def build_person(first_name, last_name, age=''):
"""Return... | true |
a702d1f6fe1d827965529dd0fe6a6abbdbf24f7b | marianopettinati/test_py_imports | /car.py | 2,303 | 4.46875 | 4 | class Car():
"""A simple attemp to represent a car."""
def __init__(self, make, model, year):
"""Initialize attributes to describe a car."""
self.marca = make
self.modelo = model
self.año = year
self.odometro = 0
def get_descriptive_name(self):
"""Return a n... | true |
617cab393cb8f65cb4f60fb554452b00ef99f78e | Artimbocca/python | /exercises/python intro/generators/exercises.py | 865 | 4.21875 | 4 | # Write an infinite generator of fibonacci numbers, with optional start values
def fibonacci(a=0, b=1):
"""Fibonacci numbers generator"""
pass
# Write a generator of all permutations of a sequence
def permutations(items):
pass
# Use this to write a generator of all permutations of a word
def w_perm(w):
... | true |
42a836d108a4933a59e3609c40d2502919b18f11 | Artimbocca/python | /exercises/python intro/google/calculator.py | 657 | 4.4375 | 4 | # You can use the input() function to ask for input:
# n = input("Enter number: ")
# print(n)
# To build a simple calculator we could just rely on the eval function of Python:
# print(eval(input("Expression: "))) # e.g. 21 + 12
# Store result in variable and it can be used in expression:
while True:
exp = input... | true |
9483b859d50c28ecf5c0edaf4114a63b111eab8c | francisaddae/PYTHON | /FillBoard.py | 2,322 | 4.4375 | 4 | # NAME OF ASSIGNMENT: To display a tic-tac-toe borad on a screen and fill the borad with X
# INPUTS: User inputs of X's
# OUTPUTS: Tic-Tac-Toe board with X
# PROCESS (DESCRIPTION OF ALGORITHM): The use of nested for loops and while loops.
# END OF COMMENTS
# PLACE ANY NEEDED IMPORT STATEMENTS HERE:
import string
imp... | true |
649392e5c71d432b2c6dfb738f76bed0c4b90c42 | J4rn3s/Assignments | /MidtermCorrected.py | 2,166 | 4.375 | 4 | #################################################################
# File name:CarlosMidterm.py #
# Author: Carlos Lucio Junior #
# Date:06-02-2021 #
# Classes: ITS 220: Programming Languages & Concept... | true |
3f9247d1c7d9538a20aa26e1dae4736284fc6b4c | mgoldstein32/python-the-hard-way-jupyer-notebooks | /ex15.py | 483 | 4.375 | 4 | #importing arguments
#assigning variables to said arguments
print "Type the filename:"
#assigning a variable called "txt" as the file being opened
txt = raw_input("> ")
#printing out the file
print "Here's your file %r" %txt
filename = open(txt)
print filename.read()
#doing it again with a different variable... | true |
9407a8304b4a4236ddc45934aea4b91bbe7da0d4 | cloudmesh-community/sp19-222-89 | /project-code/scripts/read_data.py | 1,003 | 4.21875 | 4 | #this function is meant to read in the data from the .csv file and return
#a list containing all the data. It also filters out any rows in the
#data which include NaN as either a feature or a label
"""Important note: when the data is read using the csv.DictReader,
the order of the features is changed from the original... | true |
78ee951a2cd1745691f28bc36e674c358792a8b2 | jurentie/python_crash_course | /chapter_3/3.8_seeing_the_world.py | 420 | 4.40625 | 4 | places_to_visit = ["Seattle", "Paris", "Africa", "San Francisco", "Peru"]
print(places_to_visit)
# Print in alphabetical order
print(sorted(places_to_visit))
# Show that list hasn't actually been modified
print(places_to_visit)
# Print list in reverse actually changing the list
places_to_visit.reverse()
print(place... | true |
3a69957eac67a12c16cf6e5bb2c28eb7dc87a950 | HaoMood/algorithm-data-structures | /algds/ds/deque.py | 1,541 | 4.28125 | 4 | """Implementation of a deque.
Queue is an ordered collection of items. It has two ends, a front and a rear.
New items can be added at either the front or the rear. Likewise, existing items
can be removed from either end. It provides all the capabilities of stacks and
queues in a single data structure.
"""
from __futu... | true |
bca0941d748df7a79930774c1e57287ddbfdc8e9 | sylwiam/ctci-python | /Chapter_4_Trees_Graphs/4.2-Minimal-Tree.py | 883 | 4.125 | 4 | """
Given a sorted (increasing order) array with unique integer elements, write
an algorithm to create a binary search tree with minimal height.
"""
from binary_tree import BinaryTree
# @param li a list of sorted integers in ascending order
# @param start starting index of list
# @param end ending index of list
def c... | true |
6767de31ed8eea4e1c0489ed5a1a7ad3b0f9bca7 | sylwiam/ctci-python | /Chapter_2_Linked_Lists/2.7_Intersection.py | 2,760 | 4.15625 | 4 | """
2.7 Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the inresecting node.
Note that the intersection is defined based on reference, not value.
That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the
second list, the... | true |
76375c4530dc177c5587eeace5e53a23df692f1e | ghj3/lpie | /untitled14.py | 691 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 17 22:13:36 2018
@author: k3sekido
"""
def isWordGuessed(secretWord, lettersGuessed):
'''
secretWord: string, the word the user is guessing
lettersGuessed: list, what letters have been guessed so far
returns: boolean, True if all th... | true |
dbf9328fd348044e9dda97a75e7a0ca4312ef1e4 | augustoscher/python-excercises | /hacking/picking-numbers.py | 619 | 4.25 | 4 | #
# Given an array of integers, find and print the maximum number of integers you can select
# from the array such that the absolute difference between any two of the chosen integers is less than or equal to 1
#
# Ex:
# a = [1,1,2,2,4,4,5,5,5] -> r1 = [1,1,2,2] and r2 = [4, 4, 5, 5, 5]
# result would be 5 (length of s... | true |
ac73357099eec0d42992610677661f1ee21cea38 | pokemonball34/PyGame | /quiz.py | 1,378 | 4.59375 | 5 | # A Function that asks for the initial temperature type and converts it from Celsius to Fahrenheit or vice versa
def temperature_type_def(temperature_type):
# Conditional to check if user typed in C or c to convert from C -> F
if temperature_type == 'C' or temperature_type == 'c':
# Asks the user for t... | true |
9b5504ebd01228f23fbb55d87c0c29eb942ab25b | bwayvs/bwayvs.github.io | /Ch5_milestone.py | 2,589 | 4.15625 | 4 | print()
print("You wake up to find yourself trapped in a deep hole. How will you get out?")
print()
look = input("Type LOOK UP or LOOK DOWN for more details: ")
print()
if look.upper() == "LOOK UP":
print()
print("You see a pull string attached to the ceiling.")
pull_string = input("Maybe you shoul... | true |
3fa2cc87a45bc022d7f44fcf173dcc8b028d950e | FarnazO/Simplified-Black-Jack-Game | /python_code/main_package/chips.py | 900 | 4.1875 | 4 | '''
This module contains the Chips class
'''
class Chips():
'''
This class sets the chips with an initial chip of 100 for each chip object
It contains the following properties:
- "total" wich is the total number of chips, initially it is set to 100
It also contains the following methods:
... | true |
efd5e6e4fdaa571aea4b16c99e84e6fc3046a544 | N-SreeLatha/operations-on-matrices | /append.py | 371 | 4.375 | 4 | #appending elements into an array
import numpy as np
a=np.array(input("enter the elements for the first array:"))
b=np.array(input("enter the elements for the second array:"))
print("the first array is:",a)
print ("the second array is:",b)
l=len(b)
for i in range(0,l):
a=np.append(a,b[i])
print("the new array formed b... | true |
cc1ca54cd720e9403f2bdf20ccde569838a37ffb | siddharth952/DS-Algo-Prep | /Pep/LinkedList/basic.py | 856 | 4.34375 | 4 |
# single unit in a linked list
class Element(object):
def __init__(self,value):
self.value = value
self.next = None
class LinkedList(object):
def __init__(self, head=None):
# If we establish a new LinkedList without a head, it will default to None
self.head = head
def app... | true |
89a86ec738390178a218821719f3959213d0f1ad | R-Tomas-Gonzalez/python-basics | /list_intro_actions_methods.py | 2,863 | 4.53125 | 5 | #lists are pretty much arrays with some differences
#collections of items
#lists are Data Structures
li = [1,2,3,4,5]
li2 = ['a', 'b', 'c']
li3 = [1,2,'a',True]
# Data Structures - A way for us to organize info and data
#Shopping Cart Example
shopping_cart = [
'notebooks',
'sunglasses',
'toys',
'grapes'... | true |
a71b77d255c9db65dc6e6bd7dffb6683494eb31d | bommankondapraveenkumar/PYWORK | /code45.py | 510 | 4.21875 | 4 | def squarecolor():
letter=input("enter the letter")
number=int(input("enter the number"))
evencolum=['b','f','d','h']
oddcolum=['a','c','e','g']
evenrow=[2,4,6,8]
oddrow=[1,3,5,7]
if(letter in evencolum and number in evenrow or letter in oddcolum and number in oddrow):
print("square is black")
... | true |
b6be82f0a96114542689840b501cae39305b284f | bommankondapraveenkumar/PYWORK | /code38.py | 445 | 4.34375 | 4 | def monthname():
E=input("enter the month name:\n")
if(E=="january" or E=="march" or E=="may" or E=="july" or E=="august" or E=="october" or E=="December"):
print(f"31 days in {E} month")
elif(E=="february"):
print("if leap year 29 otherwise 28")
elif(E=="april" or E=="june" or E=="september" or E=="nove... | true |
bbe61dbdac5acdbd4baa422c303664481b308763 | mdeora/codeeval | /sum_of_digits.py | 422 | 4.15625 | 4 | """
Given a positive integer, find the sum of its constituent digits.
Input sample:
The first argument will be a text file containing positive integers, one per line. e.g.
23
496
Output sample:
Print to stdout, the sum of the numbers that make up the integer, one per line.
e.g.
5
19
"""
import sys
with open(sys... | true |
a7bcd098bef75d2226097d4d11f0a6ce957fd43c | sidduGIT/linked_list | /single_linked_list1.py | 734 | 4.1875 | 4 | class Node:
def __init__(self,data):
self.data=data
self.next=None
class LinkedList:
def __init__(self):
self.head=None
def printlist(self):
temp=self.head
while(temp):
print(temp.data)
temp=temp.next
first=LinkedList()
first.head=... | true |
7f9c06979dd778bf0313bffacd4b954fe55498aa | sidduGIT/linked_list | /linked_list_all_operations.py | 1,336 | 4.125 | 4 | class Node:
def __init__(self,data):
self.data=data
self.next=None
class LinkedList:
def __init__(self):
self.head=None
def insert_at_end(self,data):
new_node=Node(data)
if self.head==None:
self.head=new_node
return
cur=self.hea... | true |
06966d4ff9727c6eb910497e92654ad6eec68810 | sidduGIT/linked_list | /doubly_linkedlist_delete_at_first.py | 1,619 | 4.25 | 4 | class Node:
def __init__(self,data):
self.data=data
self.next=None
self.prev=None
class Doubly_linkedlist:
def __init__(self):
self.head=None
def insert_at_end(self,data):
if self.head==None:
new_node=Node(data)
self.head=new_node
... | true |
1e1b603ef227a61948ea220bbb0bf261f73ad3b9 | DarkEyestheBaker/python | /ProgramFlow/guessinggame.py | 1,290 | 4.15625 | 4 | answer = 5
print("Please guess a number between 1 and 10: ")
guess = int(input())
if guess == answer:
print("You got it on the first try!")
else:
if guess < answer:
print("Please guess higher.")
else: # guess must be greater than answer
print("Please guess lower.")
guess = int(input(... | true |
d08f70e1711874ed57fbdc089835155e4d98bd57 | beechundmoan/python | /caesar_8.py | 1,359 | 4.3125 | 4 | """
All of our previous examples have a hard-coded offset -
which is fine, but not very flexible. What if we wanted to
be able to encode a bunch of different strings with different
offsets?
Functions have a great feature for exactly this purpose, called
"Arguments."
Arguments are specific parameters that w... | true |
fbcd09f15d85456e86ac136af36b7797f730ca94 | bhushankorpe/Fizz_Buzz_Fibonacci | /Fizz_Buzz_Fibonacci.py | 1,727 | 4.3125 | 4 | #In the programming language of your choice, write a program generating the first n Fibonacci numbers F(n), printing
#"Buzz" when F(n) is divisible by 3.
#"Fizz" when F(n) is divisible by 5.
#"FizzBuzz" when F(n) is divisible by 15.
#"BuzzFizz" when F(n) is prime.
#the value F(n) otherwise.
#We encourage you to... | true |
fd0c0d40b181c03d4a0e3d1adcbe37ee69e31bbf | Polinq/InfopulsePolina | /HW_3_Task_6.2.py | 382 | 4.3125 | 4 | def is_a_triangle(a, b, c):
''' Shows if the triangle exsists or not. If it exsisrs, it will show "yes" and if it does not exsit it will show "no". (num, num, num) -> yes or (num, num, num) -> no.'''
if (a + c < b or a + b < c or b + c < a):
print('NO')
else:
print('YES')
# пример использов... | true |
5a4f54078e1a341c9107f9efec5726b869a0fc27 | Polinq/InfopulsePolina | /HW_3_Task_6.1.py | 313 | 4.40625 | 4 | def is_year_leap(a):
'''The function works with one argument (num) and shows if the year is leap. If the year is leap it shows "True", if the year is not leap it shows "False"'''
if ((a % 4 == 0 and a % 100 != 0) or (a % 400 == 0)):
print('True')
else:
print('False')
is_year_leap(4)
| true |
df1af2c50ba4f110e76c4609518c6e9e166a1fe4 | kavyan92/code-challenges | /rev-string/revstring.py | 610 | 4.15625 | 4 | """Reverse a string.
For example::
>>> rev_string("")
''
>>> rev_string("a")
'a'
>>> rev_string("porcupine")
'enipucrop'
"""
def rev_string(astring):
"""Return reverse of string.
You may NOT use the reversed() function!
"""
# new_string = []
# for char in range((len(... | true |
c2b7982dc8b822a17f9d60634888c0b3ae151884 | alvas-education-foundation/spoorti_daroji | /coding_solutions/StringKeyRemove.py | 377 | 4.28125 | 4 | '''
Example
If the original string is "Welcome to AIET" and the user inputs string to remove "co" then the it should print "Welme to AIET" as output .
Input
First line read a string
Second line read key character to be removed.
Output
String which doesn't contain key character
'''
s = input('Enter The Main String: ')
... | true |
0607f73a1d10f718b4dea2d28c7a6a64b73233af | SpiffiKay/CS344-OS-py | /mypython.py | 1,078 | 4.15625 | 4 | ###########################################################################
#Title: Program Py
#Name: Tiffani Auer
#Due: Feb 28, 2019
#note: written to be run on Python3 :)
###########################################################################
import random
import string
#generate random string
#adapted from tuto... | true |
bb797f115f513f5210013037f1cda1a86aefe6df | Phazon85/codewars | /odd_sorting.py | 673 | 4.1875 | 4 | '''
codewars.com practice problem
You have an array of numbers.
Your task is to sort ascending odd numbers but even numbers must be on their places.
Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.
'''
def sort_array(source_array):
temp = sorted([i for i in... | true |
91092e769d5b1258414d8cac0b3009a9f59b4ef3 | jk555/Python | /if.py | 1,503 | 4.25 | 4 | number = 5
if number == 5:
print("Number is defined and truthy")
text = "Python"
if text:
print("text is defined and truthy")
#Boolean and None
#python_course = True
#if python_course:
# print("This will execute")
#aliens_found = None
#if aliens_found:
# print("This will not execute"... | true |
137af1c6366d00b78500c8b111ad5e6b3bc6121e | rameshroy83/Learning | /Lab014.py | 227 | 4.15625 | 4 | #!/usr/bin/python2
'''
In this code we will talk about escape sequecnce \n is for a new line, \t for a tab.
\'' to print quote \\ to print backslash.
'''
a = input("Enter the string")
print("You entered the string as \n",a)
| true |
bffbe1b30baf3a918462905e96e3a853b96388a6 | for-wd/django-action-framework | /corelib/tools/group_array.py | 449 | 4.21875 | 4 | def groupArray(array, num):
"""
To group an array by `num`.
:array An iterable object.
:num How many items a sub-group may contained.
Returns an generator to generate a list contains `num` of items for each iterable calls.
"""
tmp = []
count = 0
for i in array:
count +=... | true |
0927f0c0882096fec39a956385abe8509ccabb38 | nashj/Algorithms | /Sorting/mergesort.py | 1,197 | 4.25 | 4 | #!/usr/bin/env python
from sorting_tests import test
def merge(left_list, right_list):
# left_list and right_list must be sorted
sorted_list = []
while (len(left_list) > 0) or (len(right_list) > 0):
if (len(left_list) > 0) and (len(right_list) > 0):
if left_list[0] < right_list[0]:
... | true |
428ae6aee6bf3d0a604320a2cabe06cb0757bf42 | nashj/Algorithms | /Sorting/quicksort.py | 588 | 4.1875 | 4 | #!/usr/bin/env python
from sorting_tests import test
def quicksort(list):
# Lists of length 1 or 0 are trivially sorted
if len(list) <= 1:
return list
# Break the list into two smaller lists by comparing each value with the first element in the list, called the pivot.
pivot = list[0]
lte... | true |
b04548acb91ff5e1a6d32b547ed68480db462f7c | TimDN/education-python | /class/basic.py | 491 | 4.34375 | 4 | class Person: # create a class with name person
first_name = "Foo" # class variable
foo = Person() # Create a Person object and assign it to the foo variable
bar = Person() # Create a Person object and assign it to the bar variable
print(foo.first_name) #prints Foo
print(bar.first_name) #prints Foo
bar.firs... | true |
7b824c269e031a2b621ee9c69f571970ccfc5ec9 | usmannA/practice-code | /Odd or Even.py | 508 | 4.3125 | 4 | '''Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user. Hint: how does an even / odd number react differently when divided by 2?
Extras:
If the number is a multiple of 4, print out a different message.'''
entered_number= int(input("Please enter any... | true |
5def7924086f2dcfd0121f7a6979fb5cbbf47e6d | standrewscollege2018/2021-year-11-classwork-padams73 | /zoo.py | 273 | 4.25 | 4 | # Zoo program
# Start by setting a constant
# This is the age limit for a child
CHILD_AGE = 13
# Get the age of the user
age = int(input("What is your age?"))
# Check if they are a child
if age < CHILD_AGE:
print("You pay the child price")
print("Welcome to the zoo") | true |
2681d86a929e491d1bc7774d9ce8f346ab5c8161 | standrewscollege2018/2021-year-11-classwork-padams73 | /madlib.py | 333 | 4.25 | 4 | # This program is a Madlib, getting the user to enter details
# then it prints out a story
print("Welcome to my Madlib program!")
# Get their details
body_part = input("Enter a body part:")
name = input("Enter a name:")
# Print the story
print("Hello {}, you have the strangest looking {} I have ever seen".format(name... | true |
aafa7894fa867811e663cf65282ece2445fe700e | standrewscollege2018/2021-year-11-classwork-padams73 | /for_user_input.py | 316 | 4.1875 | 4 | # In this program the user enters a starting
# value, stopping value, and step
# The program then counts up
# Get inputs from user
start_num = int(input("Start?"))
stop_num = int(input("Stop?"))
step = int(input("Change each time?"))
# Print the numbers
for num in range(start_num, stop_num+1, step):
print(num) | true |
c1c77ddd5cb6b430281603fcb29680c0181898be | VictorB1996/GAD-Python | /GAD-02/Homework.py | 432 | 4.28125 | 4 | initial_list = [7, 8, 9, 2, 3, 1, 4, 10, 5, 6]
ascending_list = sorted(initial_list)
print("Ascending order: ")
print(ascending_list)
descending_list = sorted(initial_list, reverse = True)
print("\nDescending order: ")
print(descending_list)
print("\nEven numbers using slice: ")
print(ascending_list[1::2])
print("\... | true |
d8cf3b2cb04b117c5ed1478384723b1df83290e8 | Jangchezo/python-code-FREE-SIMPLE- | /readReverse.py | 736 | 4.125 | 4 | # readReverse.py
#test code
"""
reverseRead(file)
->print from the end of the file
"""
file = open('c:/Users/JHLee/Desktop/test.txt', 'r')
lines = file.readlines()
for i in range(0, len(lines)):
print(lines[len(lines)-i-1][0:-1])
# Real code 1
file = open('c:/Users/JHLee/Desktop/test.txt', ... | true |
727a3fadc945279790ace65b0810de18791f0c2a | jeancarlov/python | /decisionB.py | 2,913 | 4.46875 | 4 | # ----- Design Tool - PseudoCode ---------
# Create main function and inside the main function enter the variables codes for input and output
# Display Menu options and request user to make a selection
# Enter variables with input request to the use
# print user input result
# Create if statements to check if variable ... | true |
cb56d6e59567c3713f2b9fff7efea89ed5d29c77 | atbohara/basic-ds-algo | /linkedlist/rearrange_pairs.py | 1,420 | 4.25 | 4 | """Rearrange node-pairs in a given linked list.
Demonstration of 'runner' technique.
"""
from linked_list import Node
from linked_list import LinkedList
def rearrange_pairs(orig_list):
"""Modifies the input list in-place.
O(N).
"""
slow_ptr = orig_list.head
fast_ptr = orig_list.head
while fas... | true |
b106c568098b8d4db825de07a3f6d869f4a0fc0e | abokumah/Lab_Python_02 | /solutions/extra_credit_solutions/Lab03_2.py | 828 | 4.71875 | 5 | """
Lab_Python_02
Extra Credit
Solutions for Extra Credit Question 1
"""
# getting input from the user
unencrypted = int(raw_input("Enter a number to encrypt: "))
encrypted = 0
encrypted_old = 0
while unencrypted > 0:
# multiplying both the encrypted numbers by 10
encrypted *= 10
encrypted_old *= 10
#gettin... | true |
1e3b15e3576fa57b0af51d37cf91cbf158d0a4a2 | cnluzon/advent2016 | /scripts/03_triangles.py | 2,969 | 4.15625 | 4 | import argparse
"""
--- Day 3: Squares With Three Sides ---
Now that you can think clearly, you move deeper into the labyrinth of hallways
and office furniture that makes up this part of Easter Bunny HQ. This must be a
graphic design department; the walls are covered in specifications for
triangles.
Or are they?
The... | true |
147db49069181bfd366e2975da98f704e3a7ca89 | Jetroid/l2c | /solutions/l2s_solution14.py | 674 | 4.4375 | 4 | #Write a program that will print out the contents of a multiplication table from 1x1 to 12x12.
# ie. The multiplication table from 1x1 to 3x3 is as follows:
# 1 2 3
# 2 4 6
# 3 6 9
#Hint: You'll probably want to use two for loops for each number.
#Reminder: To print something without putting a newline on the end, you... | true |
a2dcded762980962a583a58af292352dcb1185b9 | Jetroid/l2c | /solutions/l2c_solution11.py | 650 | 4.4375 | 4 | #Finish the if/elif/else statement below to evaluate if myInt is divisible by 4, else evaluate if it is divisible by 3.
#Try out myInt for several different values!
#Reminder: We can use the modulo operator to get the remainder. eg: 7 % 3 is equal to 1. (because 2*3 + 1 is equal to 7)
#Hint: If a modulo result i... | true |
3383c4a85f5db4d89293ff8e43183a4e3832be83 | wa57/info108 | /Chapter8/Chapter8Ex1.py | 1,069 | 4.25 | 4 | """a) _____ Assume “choice” is a variable that references a string.
The following if statement determines whether choice is equal to ‘Y’ or ‘y’.:
if choice == ‘Y’ or choice == ‘y’:
Rewrite this statement so it only makes one comparison and does not use the or operator.
b) _____ Write a loop that counts the number of ... | true |
98bdd82a126a576d54c51b03d9201ee1ffa22b46 | wa57/info108 | /Chapter7/AshmanLab4Problem1.py | 2,300 | 4.15625 | 4 | #Project Name: Lab 4 Homework
#Date: 4/28/16
#Programmer Name: Will Ashman
#Project Description: Lab 4 Homework
#Resource used for table formatting: http://knowledgestockpile.blogspot.com/2011/01/string-formatting-in-python_09.html
#WA - Import the math module to perform calculations
import math
def main():
#WA -... | true |
cc2e5541bc5a57ca67de5109dae3f5cc976d560d | wa57/info108 | /Lab2/TestFunctions.py | 843 | 4.21875 | 4 | #WA - Gathers a positive, negative, and inclusive number between 48-122
#WA - As well as a string from the user
posInteger = float(input('Positive integer: '))
negInteger = float(input('Negative integer: '))
myChar = int(input('Integer between 48 and 122 inclusive: '))
myString = input('String: ')
#WA - outputs absolu... | true |
730667d8c9bfd1f0883a35d85468609387b33ca7 | chenhuang/leetcode | /maxSubArray.py | 1,575 | 4.1875 | 4 | #! /usr/bin/env python
'''
Maximum Subarray
Given an array of integers, find a contiguous subarray which has the largest sum.
Note
The subarray should contain at least one number
Example
For example, given the array [−2,2,−3,4,−1,2,1,−5,3], the contiguous subarray [4,−1,2,1] has the largest sum = 6.
Maximum Subarra... | true |
9ca5bf3b0e75a993f519289bbc5b50ca7e8f5b68 | chenhuang/leetcode | /insert.py | 2,143 | 4.15625 | 4 | #! /usr/bin/env python
'''
Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
You may assume that the intervals were initially sorted according to their start times.
Example 1:
Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9]... | true |
896c390f0835370f76156d3c3de4e2997a7d7522 | sauravrana1983/Python | /Challenge/Introductory/7_Print.py | 261 | 4.1875 | 4 | # Read an integer .
# Without using any string methods, try to print the following:
# Note that "" represents the values in between.
# Input Format
# The first line contains an integer .
def printAll(value):
print(*range(1,value + 1), sep='')
printAll(10) | true |
a795f444b9265560800773b2cbd980ba6eb989e6 | Abinash-giri/mypractise | /AgeCalculator.py | 761 | 4.21875 | 4 | #Program to calculate age of a person
import datetime
def calculateAge(dob):
'''Calulate's a person age'''
today = datetime.date.today()
age = today.year - dob.year
return age
def checkDate(dob):
'''Checks if date is valid or not'''
day,month,year = dob.split('/')
isvaliddate = True
... | true |
f57eebb51e5cf1fa20b4b2fbdecf21ecc555e5dc | HoangQuy266/nguyenhoangquy-fundamental-c4t4 | /Session04/sheep.py | 580 | 4.21875 | 4 | print ("Hello, my name is Hiepand these are my sheep size: ")
sheep = [5, 7, 300, 90, 24, 50 ,75]
print (sheep)
for i in range (3):
print("MONTH", i+1)
print ("Now one month has passed and this is my flock: ")
new_sheep = [x+50 for x in sheep]
print (new_sheep)
max_sheep = max(new_sh... | true |
9839709ad5c1b281e13e9cd0cbe3e3eeb736513d | ashutoshkmrsingh/Library-Management-System-Console-based- | /faculty.py | 1,334 | 4.375 | 4 | """
faculty module contains FacultyClass and faculty_list data structure.
FacultyClass used to create faculty objects.
And, faculty_list is a list data structure which stores the faculty objects,
and used for modifying faculty data and storing it in a pickle file named as "faculty_data.pkl"
"""... | true |
c2af48a092afd6f5ea2e2080b38ebc4eb099045f | symonk/python-solid-data-structures-and-algorithms | /algorithms/searching/binary_search.py | 884 | 4.25 | 4 | import random
import typing
def binary_search(arr: typing.List[int], target: int) -> int:
"""
Performs a binary search through arr. Divide and conquer the list to achieve
o(log n) performance. Pre requisites are that `arr` must be already sorted.
:param arr: The (sorted) sequence of integers.
:p... | true |
a8ad59d9cdb2baf7d7b33188f42bdf3af7a7d0ed | GeorgeDiNicola/blackjack-game | /application/utils.py | 790 | 4.25 | 4 | from os import system, name
def get_valid_input(prompt, possible_input, error_message):
"""Retrieve valid input from the user. Repeat the prompt if the user gives invalid input.
Keyword Arguments:
prompt (string) -- the question/input prompt for the user.
possible_input (list) -- the allowable input for the pro... | true |
91f35e9fcb6f5aaaf03d1e34353a33c405c0e581 | skurtis/Python_Pandas | /Question3.py | 1,578 | 4.125 | 4 | #!/usr/bin/env python3
datafile = open("CO-OPS__8729108__wl.csv") # open the CSV file as the variable "datafile"
diffmax = 0 # starts the max difference between final and initial mean as 0
for i in datafile:
if i.startswith('Date'): # skips the first line (header) but makes sure the previous line is designated as "p... | true |
e48c040f638eda0e83d01e812c34386af253b29b | cspyb/Graph-Algorithms | /BFS - Breadth First Search (Iterative).py | 897 | 4.21875 | 4 | """
BFS Algorithm - Iterative
"""
#graph to be explored, implemented using dictionary
g = {'A':['B','C','E'], 'B':['D','E'], 'E':['A','B','D'], 'D':['B','E'], 'C':['A','F','G'], 'F':['C'], 'G':['C']}
#function that visits all nodes of a graph using BFS (Iterative) approach
def BFS(graph,start):
queue =... | true |
eb415e333c7e0db6ef2e5542b7daaf6b07813c1c | ElliotFriend/bin | /fibonacci.py | 436 | 4.15625 | 4 | #!/usr/bin/env python3
import sys
# Start the sequence. It always starts with [0, 1]
f_seq = [ 0, 1 ]
# Until the length of our list reaches the limit that
# the user has specified, continue to add to the sequence
while len(f_seq) <= int(sys.argv[1]):
# Add the last two numbers in the list, and stick
# that ... | true |
040c39b646a03fb71fbae182b336d1367ffe8d8c | agermain/Leetcode | /solutions/1287-distance-between-bus-stops/distance-between-bus-stops.py | 1,298 | 4.125 | 4 | # A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
#
# The bus goes along both directions i.e. clockwise and counterclockwise.
#
# Return the shortest distance betwee... | true |
486023ab94e7e490a5ca39bfa2224c26c469f617 | beth2005-cmis/beth2005-cmis-cs2 | /cs2quiz3.py | 1,645 | 4.75 | 5 | # 1) What is a recursive function?
# A function calls itself, meaning it will repeat itself when a certain line or a code is called.
# 2) What happens if there is no base case defined in a recursive function?
#It will recurse infinitely and maybe you will get an error that says your maximum recursion is reached.
# 3)... | true |
31f900dde317cc4b7d78cbedca4c6beb09aa5229 | swheatley/LPTHW | /ex5.2.py | 763 | 4.34375 | 4 | print "LPTHW Lesson 5.2 \n \t Python format characters"
print '% :', "This character marks the start of the specifier"
print 'd :', "Integer/decimal"
print 'i :', "Integer/decimal"
print 'o :', "Octal value"
print 'u :', "Obsolete type- identical to 'd' "
print 'x :', "Hexadecimal(uppercase)"
print 'e :', "Floating ... | true |
2a0a967462c5958e31e20cbe1cfce34be2a05a93 | pjain4161/HW08 | /fun2.py | 1,139 | 4.25 | 4 | # Borrowed from https://realpython.com/learn/python-first-steps/
##############################################################################
#### Modify the variables so that all of the statements evaluate to True. ####
##############################################################################
var1 = -588
var2... | true |
546ee390dfe4711bab61a6648daae43389ec8b4d | irsol/hacker-rank-30-days-of-code | /Day 9: Recursion.py | 446 | 4.3125 | 4 | """
Task
Write a factorial function that takes a positive integer,N as a parameter and prints the result
of N!(N factorial).
Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial,
you will get a score of 0.
Input Format
A single integer,N (the argument to pass to factorial... | true |
e07b328b02a76c8cc243bcf7002b07cf96f8b8fc | infractus/my_code | /RPG Dice Roller/rpg_dice_roller.py | 2,336 | 4.4375 | 4 | #Dice roller
import random
roll = True #this allows to loop to play again
while roll:
def choose_sides(): #this allows player to choose which sided die to roll
print('Hello!')
while True:
sides=(input('How many sides are the dice you would you like to roll?' ))
if sides.isd... | true |
5bd8b16f9adeb479b29a0970406cf62d5e4a7477 | paigeweber13/exercism-progress | /python/clock/clock.py | 1,145 | 4.125 | 4 | """
contains only the clock object
"""
class Clock():
"""
represents a time without a date
"""
def __init__(self, hour, minute):
self.hour = hour
self.minute = minute
self.fix_time()
def __repr__(self):
# return str(self.hour) + ':' + "{:2d}".format(self.minute)
... | true |
1ac9e7c54261c2c15c3856ccba743791d2e3cd41 | amacharla/holbertonschool-higher_level_programming | /0x06-python-classes/6-square.py | 2,343 | 4.3125 | 4 | #!/usr/bin/python3
class Square:
def __init__(self, size=0, position=(0, 0)):
"""
Calls respective setter funciton
Args:
size: must be int and greater than 0
position: must be tuple and args of it must be int
"""
self.size = size
self.position ... | true |
217c17718277bd9eebc936314da74581bf1c5d07 | Kevin-Rush/CodingInterviewPrep | /Python/findMissingNumInSeries.py | 617 | 4.21875 | 4 | '''
1. Find the missing number in the array
You are given an array of positive numbers from 1 to n, such that all numbers from 1 to n are
present except one number x. You have to find x. The input array is not sorted. Look at the below array
and give it a try before checking the solution.
'''
def find_missing(input):... | true |
958e8293912a6df866ea3b8821948db8dc3540e4 | Kevin-Rush/CodingInterviewPrep | /Python/TreeORBST.py | 712 | 4.25 | 4 | '''
6. Determine if a binary tree is a binary search tree
Given a Binary Tree, figure out whether it’s a Binary Search Tree. In a binary search tree, each
node’s key value is smaller than the key value of all nodes in the right subtree, and is greater than
the key values of all nodes in the left subtree. Below is an ... | true |
5f815d28e7ed7d3a54819698c3446cdfc6b146c8 | subashreeashok/python_solution | /python_set1/q1_3.py | 486 | 4.15625 | 4 | '''
Name : Subahree
Setno: 1
Question_no:3
Description:get 10 numbers and find the largest odd number
'''
try:
print "enter the numbers: "
max=0
#getting 10 numbers
for i in range(0,10):
num=int(raw_input())
#print(num)
#checking odd or not
for j in range(0,10):
if(num%2!=0):... | true |
4cbba297236116927584453cab7e9d579b93f3a1 | DeltaEcho192/Python_test | /pos_neg_0_test.py | 267 | 4.1875 | 4 | test1=1;
while test1 != 0:
test1=int(input("Please enter a number or to terminate enter 0 "))
if test1 > 1:
print("This number is positve")
elif test1 < 0:
print("This number is negative")
else:
print("This number is zero")
| true |
0c63157083ee466ff665870a7d70c3e0c09c62f6 | 15AshwiniI/PythonPractice | /Calculator.py | 570 | 4.1875 | 4 | #this is how you comment in python
print "Welcome to Calculator!"
print "Enter your first number"
a = input()
print "Enter your second number"
b = input()
print "What calculation whould you like to do?"
print "Addition, Subtraction, Multiplication, Division"
p = raw_input()
if p == "Addition":
print "Answer: "+... | true |
1d4b7b925e4c71c3bde9b6e62b7ef864f041eb33 | 2amitprakash/Python_Codes | /Grokking_Algo/quicksort.py | 494 | 4.125 | 4 | import random
def quicksort(list):
if len(list) < 2:
return list
else:
pi = random.randint(0,len(list)-1)
#pi = 0
print ("The list is {l} and random index is {i}".format(l=list,i=pi))
pivot = list.pop(pi)
less = [i for i in list if i <= pivot]
more = [i f... | true |
1b076c0cac0d11470b6ee48b998ba73b20182317 | TechyAditya/COLLEGE_ASSIGNMENTS | /Python/chapter4/list_methods.py | 395 | 4.1875 | 4 | l1=[1,8,9,5,6,6] #can have same elemnets repeatedly
l1.sort() #arranges in ascending order
print(l1)
l1.reverse() #reverse the list elements
print(l1)
l1.append(10) #adds element at the end of the list
print(l1)
l1.insert(3,69) #adds element at the index mentioned, but doesn't removes the elements
print(l1)
l1.pop(2)... | true |
c902d56fd3a438b0e7bab5d0df826422979ea800 | HarryBaker/Fuka | /cleanTxtFiles.py | 1,960 | 4.1875 | 4 | # A program that cleans text files when given raw input in the following manner:
# Remove all characters except letters, spaces, and periods
# Convert all letters to lowercase
__author__ = 'loaner'
from sys import argv
class Cleaner:
def __init__(self, input):
raw_file_name = raw_input(input);
fil... | true |
0ffbe7a1cc9c186c1043d0b683f19ba6499a1602 | onestarshang/leetcode | /validate-binary-search-tree.py | 1,814 | 4.1875 | 4 | #coding: utf-8
'''
http://oj.leetcode.com/problems/validate-binary-search-tree/
Given a binary tree, determine if it is a valid binary search tree (BST).\n\nAssume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.
The right subtree of a node contains only ... | true |
f3634048b65198301168cf657d3e7ffa463ba159 | onestarshang/leetcode | /decode-string.py | 1,719 | 4.125 | 4 | '''
https://leetcode.com/problems/decode-string/
Given an encoded string, return it's decoded string.
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
You may assume that the input strin... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.