blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
c052d1bdbab67f90d16cada85d8e90cfd74b84b9 | Neminem1203/Puzzles | /DailyCodingProblem/47-hindsightStockTrade.py | 723 | 4.125 | 4 | '''
Given a array of numbers representing the stock prices of a company in chronological order, write a function that calculates the maximum profit you could have made from buying and selling that stock once. You must buy before you can sell it.
For example, given [9, 11, 8, 5, 7, 10], you should return 5, since you c... | true |
b66b7a2364ee0a85b1a02312ca6612663033a4ff | Kellytheengineer/Plotting-Graphs-in-Python | /function.py | 547 | 4.15625 | 4 | #Functions in Python
#Like in mathematics where a function takes an arguement and produces a result
#does so in Python as well !
#The general form of a Python function is:
#def function name(arguments):
# {Lines telling the function what to do to produce the result}
# return result
#Let's consider produci... | true |
55b0801451db7915d07c2a094f462bdb969583c9 | DamienOConnell/MIT-600.1x | /Final_Exam/print_without_vowels.py | 522 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 4 14:20:57 2019
@author: damien
"""
def print_without_vowels(s):
"""
s: the string to convert
Finds a version of s without vowels and whose characters appear in the
same order they appear in s. Prints this version of s.
Does n... | true |
3b8c172962321c61a644fabab4e24362e64fb679 | DamienOConnell/MIT-600.1x | /Problem_Set_5/build_shift_dict.py | 1,222 | 4.34375 | 4 | #!/usr/bin/env python3
#
# -*- coding: utf-8 -*-
import string
# A = 65
# Z = 90
# a = 97
# z = 122
# ORD() IS THE REVERSE OF CHR()
def build_shift_dict(shift: int):
""" return a dictionary that maps all upper and lower alphabet letters
mapped to their Caesar cipher, shift by... | true |
974f14fface0264a97a219c23bd5311f3fb39420 | DamienOConnell/MIT-600.1x | /Week_1/int_to_binary.py | 428 | 4.25 | 4 | #!/usr/bin/env python3
entered = int(input("enter a number to convert to binary: "))
num = entered
if num < 0:
isNeg = True
else:
isNeg = False
num = abs(num)
result = ""
if num == 0:
result = 0
while num > 0:
result = str(num % 2) + result
num = num // 2
print("num so far: ", result, " num... | true |
311587a8db2c28f9d850ee7c86425ea61b95cc00 | DamienOConnell/MIT-600.1x | /MidTerm_Exam/sumDigits.py | 324 | 4.21875 | 4 | #!/usr/bin/env python3
#
# -*- coding: utf-8 -*-
def sumDigits(N):
"""
recursive Python function, return the sum of its digits.
"""
if N >= 10:
return N % 10 + sumDigits(N // 10)
else:
return N % 10
print(sumDigits(1))
print(sumDigits(11))
print(sumDigits(126))
print(sumDigits(... | true |
5237a567cc0af876fcaf45507fb62019039dc19d | ryanthomasdonald/python | /week-2/lectures/stack.py | 2,491 | 4.25 | 4 | # RECURSION
# It's an algorithm.
# It's a function that calls itself.
# Call Stack:
# Global frame is its native/idle state
# Functions get "stacked" on top
# class Stack():
# def __init__(self):
# self.data = []
# self.length = 0
# def push(self, value):
# self.data.append(value... | true |
afbc0f86cf05352e5a3510e6c7939e343b132318 | micmor-m/Calculator | /main.py | 1,129 | 4.1875 | 4 | from art import logo
# Add
def add(n1, n2):
return n1 + n2
# Subtract
def subtract(n1, n2):
return n1 - n2
# Multiply
def multiply(n1, n2):
return n1 * n2
# Divide
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide,
}
def calculator(... | true |
e5ee0988bbe6350dbb9b7a7743e6f80c2d8a1071 | teoespero/PythonStuff | /Chapter-04/tuples-01.py | 767 | 4.28125 | 4 | # Python and tuples
# Teo Espero
# GIST I
# BOF
# defining a Tuple
my_tuple = ('leonard', 'westbrook', 'davis', 'james', 'curry', 'harden')
print('defining a Tuple')
print(my_tuple)
# creating a list
my_list = []
# initialize the list from the Tuple
print('initialize the list from the Tuple')
ctr = 0
for element in... | true |
c8895aa4821f9a9785fc06f4d9378709831ffff9 | teoespero/PythonStuff | /Chapter-06/dictionaries-04.py | 925 | 4.21875 | 4 | # A list of dictionaries
# Teo Espero
# GIST I
# BOF
# define our list
alien_0 = {
'color': 'green',
'points': 5,
'power': ['telepathy', 'time travel']
}
alien_1 = {
'color': 'red',
'points': 10
}
alien_2 = {
'color': 'yellow',
'points': 15,
'power': ['invisibility', 'fly']
}
alien_... | true |
331f2c8ebad4e9dc377e682d6c0c976d904500a3 | 121910314005/lab-1 | /l6.Node of list.py | 2,114 | 4.40625 | 4 | class Node:
def _init_(self,data):
self.data = data;
self.next = None;
class CreateList:
#Declaring head and tail pointer as null.
def _init_(self):
self.head = Node(None);
self.tail = Node(None);
self.head.next = self.tail;
self.tail.next = se... | true |
a944d1fb9cc85f1761202598fe81c7f71ba9aec8 | Mojo2015/PythonFun | /Beginning Python for Dummies Practice/Lists/Sorting a list.py | 501 | 4.53125 | 5 | Colors = ["Red", "Orange", "Yellow", "Green", "Blue"] #Creates a list to the variable Color
for Item in Colors:
print(Item, end=" ") #This will print the list in the order they occur, end=" " makes sure the list prints to one line
print()
Colors.sort() #Simple, sorts the list in alphabetical order
Colors.revers... | true |
ea2e2c52133d5968d0e074a11de742ff8098b382 | candytale55/Practice_Makes_Perfect_Py_2 | /get_rid_of_vowels.py | 564 | 4.6875 | 5 | # function anti_vowel takes one string "text", as input and returns the text with all of the vowels removed.
# For example: anti_vowel("Hey You!") should return "Hy Y!". Donβt count Y as a vowel. Make sure to remove lowercase and uppercase vowels.
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
def anti_... | true |
ab6df2284ed54f5a91eb512a13ffc4f4a54c76ad | candytale55/Practice_Makes_Perfect_Py_2 | /censor_a_word.py | 1,166 | 4.5 | 4 | # function _censor_ takes two strings, _text_ and _word_, as input.
# It should return the text with the word you chose replaced with asterisks.
# For example: censor("this hack is wack hack", "hack") should return "this **** is wack ****"
# Assume your input strings wonβt contain punctuation or upper case letters... | true |
4ffdba4441ca471d09e4b000db4860db828dd700 | JKinsler/lists_trees_graphs | /hash_table.py | 682 | 4.21875 | 4 | """Implement a hash table using only arrays."""
table = [None]*5
lst = ["hi", "amber", "yellow", "stone"]
pairs = {"hi": "a", "amber": "b", "yellow":"c", "stone":"d"}
def make_hash_table(pairs):
"""add values to the hash table"""
for item in pairs:
code = hash(item)
arr_val = code % len(... | true |
122d72efd4e5722f965f75fd5c05c6fcc1d299fe | golubot/python_tutorial | /tutorial/tests/oop/DogsTestCase.py | 1,195 | 4.28125 | 4 | import unittest
from tutorial.solutions.oop.Dog import Dog
class MyTestCase(unittest.TestCase):
def test_dogs(self):
"""
Create dog class that will be used to instantiate different dog objects.
"""
my_schnauzer = Dog(breed="Schnauzer", name="Fido", spots=False)
type(my_sch... | true |
20f31409fb94f05979ed4f8f19f6c86b989eaeaa | consumerike/Fundamental_warm_ups | /dictionary_warmup.py | 876 | 4.46875 | 4 | #looping through all key-value pairs:
user_0 = {
'username': 'efermi',
'first': 'enrico',
'last': 'fermi',
}
for key, value in user_0.items():
print(key)
print(value)
#loop through all key-value pairs and print keys:
for key in user_0.keys():
print(key)
#looping through the keys only is the def... | true |
4ffdf17b7982e04916e4af3b31195aa07dc61311 | ToddBenson/sample | /kata/exercise.py | 2,137 | 4.3125 | 4 | """
Create an object that returns the positions and the values of the "peaks"
(or local maxima) of a numeric array.
For example, the array arr = [ 0 , 1 , 2 , 5 , 1 , 0 ] has a peak in position 3
with a value of 5 (arr[3] = 5)
The output will be returned as an object with two properties: pos and peaks.
Both of these ... | true |
87415d8088973f0aeed3bb5576edfc535602510f | Darrenrodricks/IntermediatePythonNanodegree | /ObjectOrientedProgramming/CustomInit.py | 1,062 | 4.25 | 4 | class House:
def __init__(self, size, color='white'):
self.size = size
self.color = color
home = House(1000, color='red')
print(home.size)
print(home.color)
mansion = House(25000)
print(mansion.size)
print(mansion.color)
# ******************* MINI QUIZ **************************
# Define a class... | true |
6554f52d20b731d419580eb7a1b736e2581a61a4 | Reena-Kumari20/Files | /demofile.py | 667 | 4.125 | 4 | #To open the file, use the built-in open() function.
def demo(file):
with open(file,'r') as filename:
words=filename.read()
print(words)
filename.close()
demo("demofile.txt")
#use of read
f=open("demofile.txt","r")
a=f.read()
print(a)
f.close()
#use of readline
x=open("demofile.txt","r")
b=x.readl... | true |
56b7d63145f03b95046c82896ef6fd9fc9c40513 | mbarbachov/alexGIT | /stuff for aops/week4/week4_problem7.py | 1,094 | 4.53125 | 5 | # ask for birth year,month, and day
year = int(input('What is the year the person was born? '))
month = int(input('What is the month the person was born? '))
day = int(input('What is the day the person was born? '))
# ask for current year,month, and day
year2 = int(input("What is the current year? "))
month2 = int(inpu... | true |
4cb0316e7e5931647ac0c8324024dc956c5d6639 | theech/python-2018 | /strings/StringOperations.py | 2,614 | 4.6875 | 5 | # Python String Operations
# There are many operations that can be performed with string which makes it one of the most used.
# 1. Concatenation of Two or More Strings
# Joining of two or more strings into a single one is called concatenation.
#The + operator does this Python. Simply writing two string litera... | true |
3134207e30f642ef3c49c8fdacb2373ecf7a7beb | RLeary/little_things | /Python/is_square.py | 530 | 4.21875 | 4 | # is an integer square?
import math
def is_square(n):
# positive integers only
if n < 0:
return False
# math.sqrt returns a float, and squaring this value may not be accurate
# int() takes the floor of a number, and adding 0.5 to it should mean
# that we get the value we are looking for if... | true |
ca1319a3987b737536749470c02603b1e8c00c50 | brenmcnamara/coding-challenges | /src/middle-of-linked-list/solution.py | 1,216 | 4.34375 | 4 |
def find_middle(list):
"""Find the middle element of a linked list
Args:
- list: A linked list. Assuming this is a valid linked list, and not nil
Returns:
The middle element of the linked list.
"""
ptr1 = list
ptr2 = list['next'];
while ptr2:
ptr1 = ptr1['next']
a... | true |
daca21300d4d012c53b6b0c13132e55150f9d0e0 | sandeeppalakkal/Algorithmic_Toolbox_UCSD_Coursera | /Programming_Challenges_Solutions/week4_divide_and_conquer/1_binary_search/binary_search.py | 1,728 | 4.125 | 4 | # Uses Python3
'''Binary Search
In this problem, you will implement the binary search algorithm that allows searching
very efficiently (even huge) lists, provided that the list is sorted.'''
'''Problem Description:
Task. The goal in this code problem is to implement the binary search algorithm.
Input Format. The first... | true |
bf8125ebb2a628c2cd8cea13e7fddf0b2f01feec | sandeeppalakkal/Algorithmic_Toolbox_UCSD_Coursera | /Programming_Challenges_Solutions/week5_dynamic_programming1/1_money_change_again/money_change_dp.py | 1,291 | 4.125 | 4 | # Uses Python3
'''Money Change Again
As we already know, a natural greedy strategy for the change problem does not work correctly for any set of
denominations. For example, if the available denominations are 1, 3, and 4, the greedy algorithm will change
6 cents using three coins (4 + 1 + 1) while it can be changed usin... | true |
458c0bf0b0dd0d4230f3d3cde4f30ebad6f369c4 | Ricky-Millar/100-days-of-python | /CoffeeMachine/main.py | 2,791 | 4.15625 | 4 | from menu import MENU
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
# TODO 1 : Prompt user by asking βWhat would you like? (espresso/latte/cappuccino):β
def orderFunc():
order = input("What would you like? (espresso/latte/cappuccino):")
if order == "espresso" or order == "latte" or or... | true |
e859bd0384a1d2e71d8ae14e00a66612e6f5bc0f | FightForDobro/itea_python_basics | /Basov_Dmytrii/03/Task_3_2_v3.py | 1,854 | 4.46875 | 4 | def custom_map(func, *arguments):
"""
This is the 2nd version of custom map function. It can handle with multiple input arguments.
:param func: Any input function.
:param arguments: iterable collections, where the 1st is the smallest.
:type func: class 'function'
:type arguments: type depends on... | true |
f07aee08b4afa3f6dfdb34bf85f188989cf35c5f | FightForDobro/itea_python_basics | /Yurii_Kilochyk/Task3/3.1.py | 988 | 4.25 | 4 | '''
Task 3.1 Array difference
Implement a difference function, which subtracts one list from another and returns the result.
It should remove all values (all of its occurrences) from list a, which are present in list b.
Examples:
call: array_diff([1, 2], [1])
return: [2]
call: array_diff([1, 2, 2, 2, 3], [2])
retu... | true |
1f20e37e80a147a89140a3c7bb6ae6ff98cea609 | FightForDobro/itea_python_basics | /pavlenko_dmitryi/05/Task51.py | 813 | 4.15625 | 4 | def sum_function(first_input, second_input):
"""
This function sums two numbers or displays an error when entering text.
:param first_input: first input
:param second_input: second input
:type first_input: int
:type second_input int
:return: amount of inputs
:rtype: int
"""
tr... | true |
8f5e4f33fface4ac28119ac4af034baa40b17a3c | FightForDobro/itea_python_basics | /Aleksandr_Bondar/Task_3.2/map_func.py | 603 | 4.28125 | 4 |
def cmap(func,iterable):
"""
This function works like standard map function, with only difference that it
returns list instead of map object
:param func: function what need to be applied to iterable
:param iterable: iterable data, which need to be processed by function
:type func: function, known to interpreter
:... | true |
d85c61e392efea8d08392b6bca1a2bd4bb10966f | cs-fullstack-2019-spring/python-review2-cw-cierravereen24-1 | /classwork.py | 1,346 | 4.375 | 4 | # Point of entry.
# The main function calls the problem fucntion within its scope.
def main():
problem1()
# Create a task list. A user is presented with the text below.
# Let them select an option to list all of their tasks,
# add a task to their list, delete a task, or quit the program.
# Make each option a diffe... | true |
7190cc8ca6ba51ff09e9cca528b88b749a93e5ec | leonardourbinati/Exam | /Exam/miscellaneous.py | 2,245 | 4.1875 | 4 | # miscellaneous.py
# For the following exercises, pseudo-code is not required
# Exercise 1
# Create a list L of numbers from 21 to 39
# print the numbers of the list that are even
# print the numbers of the list that are multiples of 3
print('exercise_1')
l= range(21,40)
print('l= %s' %l)
for i in l:
if i%2==0:
pri... | true |
5b990055d37e4cac6aec93806a9469ff6a202e58 | nabilatajrin/python-programs | /string-manipulation/check-string.py | 423 | 4.1875 | 4 | #String Length
a = "Hello, World!"
print(len(a))
#Check String
txt = "The best things in life are free!"
print("free" in txt)
txt = "The best things in life are free!"
if "free" in txt:
print("Yes, 'free' is present.")
#Check if NOT
txt = "The best things in life are free!"
print("expensive" not in txt)
txt = "Th... | true |
fe5c5486c8f38ca4515f94042bca534a5822e4cd | nabilatajrin/python-programs | /append-new-line.py | 470 | 4.3125 | 4 | x = 3
print(x) # Trailing comma suppresses newline in Python 2
print(x, end=" ") # Appends a space instead of a newline in Python 3
print(x, end=" ") # Appends a space instead of a newline in Python 3
y = 5, #',' keeps () in next prints
print(y) # Trailing comma suppresses newline in P... | true |
4045918e2597ba940d9c680c87bfd82b80ab5a06 | nabilatajrin/python-programs | /string-manipulation/reverse-string.py | 2,875 | 4.3125 | 4 | class ReverseString:
#Solution 01: using for loop
#Time Complexity: O(n)
#Auxiliary Space: O(1)
def reverse(s):
str=""
for i in s:
str = i+str
return str
s = 'Geeks'
print('output: ', reverse(s))
# Solution 02: using for loop
#Pseudocode:
#run a ... | true |
860e06ea7ed1d0ec699c1821be2bc727a6db77bf | nabilatajrin/python-programs | /pythonprograms/break/Break_1.py | 331 | 4.1875 | 4 | #find out if any specific fruit exist in the list
fruits = ["apple", "orange", "banana", "jambura",
"mango", "cherry"]
found = "no"
for fruit in fruits:
if fruit == "jambura":
found = "yes"
print("found it!")
break
if found == "yes":
print ("we have jambura!")
else:
print... | true |
46abd7a77174d5dcfe53e20b355862ab97be2233 | gauriindalkar/function | /perfect number.py | 681 | 4.21875 | 4 | # 7.Write a function βperfect()β that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000.
# [An integer number is said to be βperfect numberβ if its factors, including 1(but not the number itself), sum to the number. E... | true |
6dab29b52007232f5c9e8dafef441083576fa6b7 | joestone51/ff-scraper | /ff_scraper/output/output.py | 581 | 4.125 | 4 | def write_output(file_name: str, outputs: list) -> None:
""" Writes each row in :outputs to :file_name.csv as its own line
Will write the CSV of each row of outputs to the provided file name.
Args
file_name (str): The name you want the csv file to have
outputs (list): A list of lists to be... | true |
d0ed761598e1a4fe63f3fd65054018927e14dfd0 | 18zgriffin/SoftwareDev | /Functions/Lists.py | 757 | 4.25 | 4 | def listsort(arg_list):
arg_list.sort()
listlen = len(arg_list)
print("The sorted list is", arg_list)
print("The largest value in the list is", arg_list[listlen-1])
def listreverse(or_list):
rlist = []
for i in or_list:
rlist.insert(0, i)
print("The reverse list is", rlist)
def ele... | true |
2b3ef91cb4a5c6e35e0ec62686e3181b59c20342 | Michael-Zagon/ICS3U-Unit4-03-Python | /squared.py | 729 | 4.25 | 4 | #!/usr/bin/env python3
# Created by: Michael Zagon
# Created on: Oct 2021
# This program squares each number from 0 up to the users number
def main():
# This function squares each number from 0 up to the users number
counter = 0
answer = 0
# Input
integer_s = input("Enter an integer >= 0: ")
... | true |
adf9f035200be58fd6bc5b8e11b47686349afc5f | kloayza23/PythonLearning | /DataStructuresAndFunctions/assignments/Asgn3.2.py | 1,286 | 4.125 | 4 | def add(a,b):
return a+b
def subtract(a,b):
return a-b
def multiply(a,b):
return a*b
def divide (a,b):
if(a == 0 or b== 0):
return "Not a number"
else:
return a/b
def calculator(choice, num1, num2):
operationList = [("Sum","+",add), ("Difference",'-', subtract), ("Pro... | true |
780ad0c2f549d08738b4cd604e2e5adfb4d904b5 | SandipaniDey/FSSDP_2020 | /infinite.py | 461 | 4.125 | 4 | num_list = []
sum = 0
count = 0
while True:
num = input("Enter a Number: ")
if len(num) < 1:break
try:
num = int(num)
except:
print("Enter a valid number")
quit()
sum = sum + num
count += 1
num_list.append(num)
print("Sum of the given numbers are: ",sum)... | true |
76efca6943bc0faba55e1afd00fba908ccd2f19e | lyndsiWilliams/Data-Structures | /test.py | 1,491 | 4.21875 | 4 | # Print out each element of the following array on a separate line:
# ["Joe", "2", "Ted", "4.98", "14", "Sam", "void *", "42", "float", "pointers", "5006"]
# You may use whatever programming language you'd like.
# Verbalize your thought process as much as possible before writing any code. Run through the UPER problem s... | true |
fff313fc54e07c39cb8abc51d2547c09b7db1ac6 | RajaomalalaSendra/a-byte-of-python | /input_output_python.py | 381 | 4.1875 | 4 | class Palindrome:
def __init__(self, text):
self.text = text
print("({} is created)".format(self.text))
def reverse(self):
return self.text[::-1]
def is_palindrome(self):
return self.text == self.text[::-1]
something = input("Enter text: ")
pal = Palindrome(something)
if pal.is_palindrome():
print("Yes, it... | true |
efbb23813871276fc74bb653a37b88e863acc850 | someshj5/bridgelabz_programs | /Data structures/program1.py | 2,608 | 4.21875 | 4 | class Node: # creating a node class for linked list head
def __init__(self, value):
self.value = value
self.next = None
class LinkedList: # creating a class linked list
def __init__(self):
self.head = None # ass... | true |
dc00fc1e9c558b7367085c10415228d331662faf | someshj5/bridgelabz_programs | /Data structures/program3.py | 1,476 | 4.21875 | 4 | class Stack: # creating a class Stack
def __init__(self): # function to initialize the stack as empty
self.items = []
def is_empty(self): # function to check if the stack is empty
return self.items == []
def push(self, data): ... | true |
82ceaa2fd5fe09f74c05b52b79a3ed0714f03e76 | Samdayem/VirtualPetandCropClass | /VirtualPet.py | 2,055 | 4.125 | 4 | class VirtualPet:
"""An implementation of a virtual pet"""
def talk(self):
print("Hello, I am your new pet and i have been called {0}".format(self.name))
if self.hunger<50:
print("please feed me, I'm hungry")
def __init__(self,name):
self.... | true |
d9194911e933fefb1c4a6e4e3c418f7c6901aed5 | samuelhe83/collection | /sorts/Isort.py | 2,276 | 4.28125 | 4 | #Simple Sort #3: The Insertion Sort.
#Time-complexity: W [O(n^2)], Avg [O(n^2)], B [O(n)],
#Notes: While this sort does share the same time-complexities as bubble sort, it has some very unique attributes that make it actually useful (lol). The Worst case for this algorithm is an already-sorted-reversed list. The Bes... | true |
a4d273cf5688e43ae2bf75c229711c0fe8e5b6b9 | enxicui/Python | /PythonAssignments/p9/p9p3.py | 416 | 4.28125 | 4 |
'''
pseudocode
Prompt the user for an integer as x
if x==0:
fa==1
elif:
fa==1
elif x<0:
fac = 1
for every integer between 1 and x
fa = fa * i
print(fa)
'''
x=int(input('please enter a number:'))
fa=0
if x==0:
fa==1
elif x==1:
fa==1
elif x<0:
print('sorry, the number must greater than 0')... | true |
9c42f6cce9f1884e71139088f3d52c8b7bab48ff | jjjchens235/daily_leetcode_2021 | /arrays/intersection_of_two_arrays.py | 1,263 | 4.125 | 4 |
def intersect(nums1, nums2):
return set.intersection(set(nums1), set(nums2))
def intersect(nums1, nums2):
"""
two pointer solution
i corresponds to nums1 index
j corresponds to nums2 index
if nums1[i] > nums2[j], then j+=1
elif nums1[i] < nums2[j], then i+=1
else: it's an intersection,... | true |
08d22c74ba9070c07eebf9e3240b334ba305c509 | jcorn2/Project-Euler | /prob19.py | 463 | 4.125 | 4 | from datetime import timedelta,date
#date durations used to calculate number of Sundays
week = timedelta(days=7)
dayDuration = timedelta(days=1)
begin = date(1901,1,1)
day = begin
end = date(2000,12,31)
#find first Sunday after begin
while(day.weekday() != 6):
day = day + dayDuration
count = 0
#loops through ever... | true |
f1e65032c653aeb6b6a9a1e9af1f99403504e217 | sametypebonus/Basic-Python-Codes | /loancalc.py | 521 | 4.1875 | 4 | # Get the loan details from the user
money_owed=float(input("How much money do you owe?\n"))
apr = float(input("What is the yearly percentage rate?\n"))
monthly = float(input("What is the monthly payment amount?\n"))
months = int(input("How many months do you want to see the results for?\n"))
monthlyapr = apr/12... | true |
30e432d3fde4e13f1e65d8e867a1ba600fcdfbd0 | ghoshmithun/problem_solving | /permutation.py | 1,656 | 4.25 | 4 | # Write an algorithm for permutation of digits of a number
from typing import List
# def permutation_number(number:int)-> List[str]:
# if not isinstance(number,int):
# try:
# number=int(number)
# except ValueError:
# return 'input is not a number'
# else:
# digits... | true |
825539b1a7af02d131ff4ae7fe0a7309648ec977 | taiyrbegeyev/Advanced-Programming-In-Python | /Assignment 5/2/appropiparam.py | 1,393 | 4.125 | 4 | # JTSK-350112
# appropiparam.py
# Taiyr Begeyev
# t.begeyev@jacobs-university.de
from graphics import *
from random import randrange
from sys import *
def main():
print("Enter the length of the window")
d = int(input())
if d > 1000:
print("Window size shouldn't exceed 1000")
sys.exit()
... | true |
bb7074f0a55d7383a219547cabc75aad08d12fad | ehsansaira/GirlsWhoCode | /Jigsaw.py | 208 | 4.125 | 4 | #a = [1, 2, 3, 4, 5, 6]
#a[1:4]
#[2, 3, 4]
numeros = [5,13,19,23,29,37]
slice = slice(-1,-4, -1)
print("List the numeros before the slice")
print("The List after negative values for slice:" ,numeros[slice])
| true |
9f00445153fcb93da59ea44e25a94d818d97cf84 | bhardwajaditya113/python | /multipleStringFormatting.py | 201 | 4.125 | 4 | name = input("Enter your name:")
surname = input("Enter your surname:")
when = "today"
#message = "Hello! %s %s" % (name, surname)
message = f"Hello! {name} {surname}. What's up {when}?"
print(message) | true |
c3398477a1496b6e2b46976ddbec19d54b2612b3 | reymon359/machine-learning | /2 - Regression/1 Simple linear regression/simple_linear_regression.py | 2,340 | 4.375 | 4 | # Simple Linear Regression
# Importing the libraries
import numpy as np # To work with mathematical numbers.
import matplotlib.pyplot as plt # To work with plots
import pandas as pd # To import and manage datasets
# Importing the dataset
dataset = pd.read_csv('Salary_Data.csv')
# We separate the dependent and the i... | true |
2ad7d9a66e33dd105970de44152471f32d15c145 | luhn/pizzeria | /pizzeria.py | 2,662 | 4.125 | 4 | import math
import pickle
import os.path
def add_pizza(pizzas):
"""Gather user input and add pizza to list"""
print 'Enter a pizza'
dm = input('Diameter (inches): ')
price = input('Price: $')
notes = raw_input('Notes (brand, toppings, etc.): ')
pizzas.append(Pizza(dm, price, notes))
def print... | true |
178a8ad116a5e813e64490e829947f32d4ac09d0 | ManishBhojak/Python-Projects | /password_validity(prac 24).py | 644 | 4.25 | 4 | #Check Validity of a Password
import re
p=input("Enter your Password ")
x=True
while x:
if(len(p)<6 or len(p)>12):
break
elif not re.search("[a-z]",p):
break
elif not re.search("[A-Z]",p):
break
elif not re.search("[0-9]",p):
break
elif not re.search("[$#... | true |
e5d9ef664c58c91d581cf01bc9157d75034e8256 | AshZhang/2016-GWC-SIP-projects | /python/pygame/doc_scaven_hunt_2.py | 2,696 | 4.15625 | 4 | """
Pygame base template for opening a window
Sample Python/Pygame Programs
Simpson College Computer Science
http://programarcadegames.com/
http://simpson.edu/computer-science/
Explanation video: http://youtu.be/vRB_983kUMc
"""
import pygame
import random
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 25... | true |
010c3949f762aca30451e7a93486c3e17df83254 | Joycrown/Wave4 | /match_flower_name.py | 1,330 | 4.4375 | 4 | #For the following practice question you will need to write code in Python in the workspace below. This will allow you to practice the concepts discussed in the Scripting lesson, such as reading and writing files. You will see some older concepts too, but again, we have them there to review and reinforce your understan... | true |
5f2190b522a2829703180911d43d66960ca257c4 | vskemp/madlib | /madlib.py | 715 | 4.4375 | 4 | # Prompt the user for the missing words to a Madlib sentence using the input function. You will make up your own Madlib sentence, but here's an example:
# ____(name)____'s favorite subject in school is ____(subject)____.
# With the above given sentence, this is what a user session might look like:
# $ python madlib.p... | true |
bd58b4661743f116fbdd4c7ec7851dc5a4bea621 | MMGit64/Anagram | /Anagram.py | 948 | 4.34375 | 4 | def Anagram(str1, str2):
count1 = [0] * 26 #To count frequency of each character
count2 = [0] * 26
i = 0
while i < len(str1): #Counts frequency of each character for str1
count1[ord(str1[i])-ord('a')] += 1 # 'ord' refers to the unic... | true |
c3d1e0a7b00ea851fb30caa67b0e688ac35f9066 | MrChrisLia/Udemy_Learning | /milestone_2_self_written/utils/database.py | 1,801 | 4.3125 | 4 | import json
"""
Concerned with storing and retrieving books from a list.
"""
books = []
def add_book(title, author):
for b in books:
if title == b['Title'] and author == b['Author']: #check if the book is already in the list
print('This book already exists!')
break
else:
... | true |
144c8e706e8f6e67e48b4b60f85ed46492931c01 | luchang59/leetcode | /246_Strobogrammatic_Number.py | 737 | 4.28125 | 4 | # A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
# Write a function to determine if a number is strobogrammatic. The number is represented as a string.
# Example 1:
# input: "69"
# output: True
# Example 2:
# input: "962"
# output: False
class Solutio... | true |
074779d4cdaa2081db1f1c1edb69269a5d167d97 | luchang59/leetcode | /998_Maximum_Binary_Tree_II.py | 998 | 4.21875 | 4 | # Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def insertIntoMaxTree(self, root: TreeNode, val: int) -> TreeNode:
"""
for recursion, if no root or root.val < val, create a new no... | true |
95adac0322f95d99e2b2c19a2413778750c6a501 | DanFreemantle/code-club | /2019-08-21/a-square-loop.py | 672 | 4.28125 | 4 | '''
Task: "A square loop"
Difficulty: Intermediate
Description: Write a program that asks the user to input an integer between 2 and 20.
Output every number squared up to and including the number they entered. Each square should be on a separate line.
For instance, if the user enters "5" the expected output will be the... | true |
7c8351f67b3b715babd4b7981338c3c849eafbb6 | JakeNat/cos125 | /labs/lab01/task04.py | 1,173 | 4.1875 | 4 | # File: task04.py
# Author: Jake Natalizia
# Date: September 17th, 2019
# Section: B
# Email: jacob.natalizia@maine.edu
# Description: Calculates your distance from home and your average walking speed, based on the distance of your two paths.
# Collaboration: I did not collaborate with anyone.
pathOne = input("How far... | true |
4bc44618c0101e0e64e7fb33c1124a64a85009b7 | JakeNat/cos125 | /homework/hw05/hw5a.py | 1,426 | 4.53125 | 5 | # File: hw5a.py
# Author: Jake Natalizia
# Date: October 30th, 2019
# Section: B
# Email: jacob.natalizia@maine.edu
# Description: Simulates up and down movement of a hailstone in a storm.
# Collaboration: I did not collaborate with anyone.
def oddHeight(height):
# While height is odd
while height % ... | true |
8b25ed749a2bd930259f8cecf2bab4e1411bd9a2 | psamvatsar/Mathematics-Machine-Learning-Linear-Algebra-Codes | /Echelon form.py | 1,190 | 4.21875 | 4 | def fixRowTwo(A) :
# Insert code below to set the sub-diagonal elements of row two to zero (there are two of them).
A[2] = A[2]- A[2,0]*A[0]
A[2] = A[2]- A[2,1]*A[1]
# Next we'll test that the diagonal element is not zero.
if A[2,2] == 0 :
# Insert code below that adds a lower row ... | true |
5f8a3007076b1a517fe0c6a14e54e25ee228a6fe | webdevajf/Learn-Python-The-Hard-Way | /ex33.py | 2,126 | 4.28125 | 4 | # This line creates var 'i' and give it a value of
# int 0.
i = 0
# This line creates var 'numbers' and gives it a value
# of an empty braket "[]"
numbers = []
# This line creates a while loop and give it the
# condition that it's code will run as long as the
# value of var 'i' is less than int 6.
while i < 6:
# T... | true |
852f3829c188f6f1158b7ee7a4fde58c094e2696 | cotrat/UBUNTU-FILES | /pyprac/prac.py | 366 | 4.125 | 4 | shoppinglist = [] # empty list
item = input("Enter an item or type -1 to exit ")
while item != -1:
shoppinglist.append(item) # put the item in the array
item = input("Enter an item or type -1 to exit ") # reprompt the user
print ("The customer needs to purchase ")
print (len(shoppinglist))
print (... | true |
09f7f06234cb9a745c837fae051255c2ab1163a6 | addy96/edx | /MITx/6.00.1x/Week-6/Lecture-12/genPrimes.py | 561 | 4.125 | 4 | """Prime number generator"""
__author__ = 'Nicola Moretto'
__license__ = "MIT"
def genPrimes():
'''
Generate prime numbers, one at the time
Use the next() method to get the next prime number
:return: Increasing sequence of prime numbers
'''
primes = []
number = 2
isPrime = True
whi... | true |
c0f1837e8e8f8a2904a6ac96bd8d57dd56ea2c70 | addy96/edx | /MITx/6.00.1x/Week-2/Lecture-3/dec2bin.py | 1,252 | 4.15625 | 4 | """Convert decimal numbers - integer or fractional - to binary"""
__author__ = 'Nicola Moretto'
__license__ = "MIT"
def dec2bin(x):
"""
Convert a decimal number - integer or fractional inside the interval [-1, 1] - to binary
:param x: Decimal number (integer or fractional inside the interval [-1, 1])
... | true |
88b31c61a9a618cba66dc7e62fba7337a7b7cb6e | Pradhvan/assignment | /problem.py | 2,028 | 4.21875 | 4 | """
Write a function that takes an array of integers given a string
as an argument and returns the second max value from the input array.
If there is no second max return -1.
1. For array ["3", "-2"] should return "-2"
2. For array ["5", "5", "4", "2"] should return "4"
3. For array ["4", "4", "4"] should return β-1β
... | true |
137b8462db6ebccb0a52726b0a9991190bc06718 | jaytparekh7121994/PythonProjects | /DataStructure_nestedList.py | 1,392 | 4.125 | 4 | combs = []
for i in [1, 2, 3]:
for j in [3, 2, 1]:
combs.append((i, j))
# combs.append(i,j) shows error that append can take only one argument.
# Add parantheses to i,j -> (i,j) ,it makes it a tuple.
# Hence, its just one object passed in append()
print(combs)
print("loop... | true |
50cf7e665eb97396300d7997e05409f2088f6f8c | Babkock/python | /6 - Functions/Module6/more_functions/string_functions.py | 640 | 4.3125 | 4 | #!/usr/bin/python3
"""
Tanner Babcock
October 1, 2019
Module 6, topic 3: Function parameters
"""
"""
This function multiples the string 'message' 'n' number of times,
and returns the resulting string
:param message: The message to be multiplied
:param n: Number of times to be multiplied
:returns: 'message' multiplie... | true |
e6d075f3d7d81ded2c68623ce11a0ff9f5a17609 | Babkock/python | /3 - Strings, Basic IO, Operators/io/average_scores/average_scores.py | 814 | 4.21875 | 4 | #!/usr/bin/python3
"""
Tanner Babcock
September 10, 2019
Module 3, topic 2: Basic input and output
"""
def average():
# get 3 scores from the user
score1 = input("Enter the first score: ")
score2 = input("Enter the second score: ")
score3 = input("Enter the third score: ")
# convert all input stri... | true |
322273e2bc3695a8506040d40255fa38f479a503 | Babkock/python | /13 - Database/number_guess/number_guess.py | 1,820 | 4.28125 | 4 | #!/usr/bin/python3
"""
Tanner Babcock
November 19, 2019
Module 13, topic 1: GUI and Data Visualization
"""
import tkinter
import random
class NumberGuesser:
def __init__(self):
self.guessed_list = []
self.the_number = random.randint(1,8)
def add_guess(self, guess):
self.guessed_list.ap... | true |
bb7100d826b86cbaf1723886492e8bbd839a914a | DanielDavisCS/SYSNETIIPROJ | /MyPython/compute_stats.py | 2,038 | 4.4375 | 4 | #!/usr/bin/env python
'''
Name: Thomas Cole Amick
Course:COP3990C
Assignment:hw03
Run: python compute_stats.py <file_name.csv>
Description: Takes in input from a csv file and calculates the mean, and variance of each line.
For each line of the input file, the mean, variance and number of columns are writen to the out... | true |
a7cbac6baff8a617eec8b53ab63253c3526dd547 | codevscolor/codevscolor | /python/python-count-words-characters-string/example1.py | 381 | 4.1875 | 4 | # https://codevscolor.com/python-count-words-characters-string
# 1
word_count = 0
char_count = 0
# 2
usr_input = input("Enter a string : ")
# 3
split_string = usr_input.split()
# 4
word_count = len(split_string)
# 5
for word in split_string:
# 6
char_count += len(word)
# 7
print("Total words : {}".format(w... | true |
f5e70061ea969230ca0b72d43acc5459c548cee9 | AnaBVA/pythonCCG_2021 | /Tareas/PYTHON_2021-[9] Regiones ricas en AT-2984/Daianna GonzΓ‘lez Padilla_10042_assignsubmission_file_/AT_regions.py | 2,086 | 4.28125 | 4 | '''
NAME
AT_regions.py
VERSION
[1.0]
AUTHOR
Daianna Gonzalez Padilla <daianna@lcg.unam.mx>
DESCRIPTION
This programs gets a dna sequence and returns the AT rich regions of it.
CATEGORY
DNA sequence analysis
USAGE
None
ARGUMENTS
None
INPUT
The dna sequence g... | true |
e841af2b2db3fc2f7a91c8ae267ceae7268eb141 | NeelimaNeeli/Python3 | /own_functions.py | 777 | 4.4375 | 4 | #function = this executes the block of code only WHEN IT IS CALLED .....
#this is a very logical concept....see below example.
def weapon(knife): #Here,weapon is a function that i have created.and knife inside the weapon brackets will acts as a variable like
print(knife) #its acts an empty variable.so i... | true |
17827795eec9743900550ffb86737cb29db1fc49 | NeelimaNeeli/Python3 | /nested_func.py | 614 | 4.46875 | 4 | #nested function calls = function calls inside other functions
# innermost function calls are resolved first
# returned value is used as argument for the next outer function
# for example:
#num = input("enter the whole positive number : ")
#num = float (num)
#num = i... | true |
25cf94797599d2066238c175a0e9298e0713296f | jakeportra/python-challenge | /PyBank/main.py | 1,219 | 4.15625 | 4 | #Import modules
import pandas as pd
#Read CSV file, put in dataframe
bank_data = "../../../ClassRepo6/UofM-STP-DATA-PT-11-2019-U-C/03-Python/Homework/PyBank/Resources/budget_data.csv"
bank_df = pd.read_csv(bank_data)
#The total number of months included in the dataset
total_months = len(bank_df.index)
#The net tot... | true |
e4a240b0eadc6a6674bc13051d07a539413ea3b5 | LoriImbesi/learning-python | /ex8.py | 709 | 4.3125 | 4 | # This is function called "formatter". It is assigned four {} which will turn
# the formatter variable into four strings.
formatter = "{} {} {} {}"
# Take the formatter string defined on line 3 and call its format function.
# Pass the four arguments, 1, 2, 3, 4 to it.
# The result of calling format on formatter is a n... | true |
75f877520d5b9b707bbad5c806c4a89cdbc8ae79 | realpython/materials | /python-self-type/accounts_string.py | 1,632 | 4.15625 | 4 | import random
from dataclasses import dataclass
@dataclass
class BankAccount:
account_number: int
balance: float
def display_balance(self) -> "BankAccount":
print(f"Account Number: {self.account_number}")
print(f"Balance: ${self.balance:,.2f}\n")
return self
def deposit(self,... | true |
2bfd0586871bba39fc96587898e04f7dee2d7098 | realpython/materials | /python-eval-mathrepl/mathrepl.py | 2,317 | 4.1875 | 4 | #!/usr/bin/env python3
"""MathREPL, a math expression evaluator using Python's eval() and math."""
import math
__version__ = "1.0"
__author__ = "Leodanis Pozo Ramos"
ALLOWED_NAMES = {
k: v for k, v in math.__dict__.items() if not k.startswith("__")
}
PS1 = "mr>>"
WELCOME = f"""
MathREPL {__version__}, your Py... | true |
ba0411d1ae1c613c1fc873874b1f5ad75b21b178 | realpython/materials | /python-interview-problems-parsing-csv/full_code/test_weather_v1.py | 2,189 | 4.25 | 4 | #!/usr/bin/env python3
""" Find the day with the highest average temperature.
Write a program that takes a filename on the command line and processes the
CSV contents. The contents will be a CSV file with a month of weather data,
one day per line.
Determine which day had the highest average temperature... | true |
a3c29fde281eabaee5de097cfa3a392e630f0201 | darylchionh/Calc-test- | /calculator/not_as_easy.py | 625 | 4.34375 | 4 | # function returns a reversed value of arg1's digits
def reverse_digits(arg1):
#========================================#
# input: integer arg1 #
# return: integer or string #
# eg. input: 632527 => return: 725236 #
#========================================#
return 0
# fu... | true |
6a277bc9690523eddf7948a1ec0f92b17529c66e | cmidler/CrackingTheCodingInterview | /CTCI-Python/Chapter8/Question6.py | 1,301 | 4.25 | 4 | '''
Towers of Hanoi: In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of
different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order
of size from top to bottom (Le., each disk sits on top of an even larger one). You have the following
constraints:
(... | true |
e2aa65a105f7a61d3c18b7a7b2d5585da4678d79 | Chandrahas-Soman/General-Python-Programming | /sorting_based_on_frequency.py | 1,716 | 4.34375 | 4 | '''
Problem statement: Given an array sort that array in a fashion that
1. The number with the highest frequecy comes first.
2. If there are multiple numbers with the same frequency (>= 2) then they should be sorted in descending order.
3. If there are multiple numbers with frequency = 1 then they should get sorted in ... | true |
bea3c381adb0b93097800f8295de3e696d621bb1 | loveingenioustech/demo | /python-demo/demo/RandomDemo.py | 925 | 4.15625 | 4 | import random
def roll_dice(numbers=3, points=None):
print('<<<<< ROLL THE DICE! >>>>>')
if points is None:
points = []
while numbers > 0:
point = random.randrange(1,7)
points.append(point)
numbers = numbers - 1
return points
def roll_result(total):
isBig = 11 <=tot... | true |
4653c497aba08dc5d5d8a6ca75a4366a67b40195 | jalfred911/WeJapaLabs | /while_example2.py | 940 | 4.34375 | 4 | #Count By Check
#Suppose you want to count from some number start_num by another number count_by until you hit a final number end_num, and calculate break_num the way you did in the last quiz.
#Now in addition, address what would happen if someone gives a start_num that is greater than end_num.
# If this is the case, ... | true |
9e3249e14d4b6e24e32b6ed50e3fd538ff4653b4 | caliskanbulent/Class4-PythonModule-Week5 | /Society.py | 1,922 | 4.6875 | 5 | '''
Create the class Society with following information:
society_name, house_no, no_of_members, flat, income
Methods :
An __init__ method to assign initial values of society_name, flat, house_no, no_of_members, income
input_data() To read information from members
allocate_flat() To allocate flat according to inco... | true |
cd95fc5f0e2de264fabd071288ef291550a5ee43 | chris-r-harwell/HackerRankPython | /itertools-combinations/ans.py.0 | 788 | 4.25 | 4 | #!/bin/env python3
#
# combinations: for groups and order doesn't matter.
# permutations: for lists and order does matter.
# Given string S print all possible combinations
# of size k of the string in lexicogaphic sorted order.
#
# INPUT:
# S k
# where S is a string
# and k is an integer
# space separated
#
# OUTPUT:
... | true |
1095afa377c97cfde55b1ca793334177af45b8bc | chris-r-harwell/HackerRankPython | /pythonModDivmod.py | 489 | 4.40625 | 4 | #!/bin/env python3
"""
https://www.hackerrank.com/challenges/python-mod-divmod
divmod(a, b)
returns tuple ( a//b, a%b )
where a//b is the integer division and
a%b is the modulo operator getting remainder
INPUT: two lines
int a
int b
OUPUT: three lines
result of integer division a//b
result of mod... | true |
eb4d336f5aab543811b8a547e289a1017584ca0d | chris-r-harwell/HackerRankPython | /decoratorsNameDirectory.py | 1,653 | 4.34375 | 4 | #!/bin/env python3
"""
https://www.hackerrank.com/challenges/decorators-2-name-directory
Let's use decorators to buid a name directory! You are given some
information about N people. Each person has a first name, last name,
age and sex. Print their names in a specific format sorted by their
age in ascen... | true |
241ceaf180f9a725985945dda077dd31af98843b | chris-r-harwell/HackerRankPython | /doListComprehensions-2.py | 2,369 | 4.1875 | 4 | #!/bin/env python3
#
# hackerrank.com
# https://www.hackerrank.com/challenges/list-comprehensions
#
# INPUT: four lines each with an integer
# specifying dimensions of cube X,Y,Z and
# constraint N
# OUTPUT: list of all possible coordinates (i,j,k) on 3D grid
# where the sum of i+j+k != N
# 0 <= i <= X
# ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.