blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
17308c5c65d56b64070822e1e7ae5e0c1594a5a9 | harperpack/Harper-s-Practice-Repository | /number_work.py | 670 | 4.15625 | 4 | # This is a program built to help me practice representing numbers in Python
# Explore different arithmetic in Python
import time
print(5 + 3)
print(4.0 * 2)
print(2 ** 3)
print(24 / 3)
print(9.0 - 1)
favorite_number = 8.0
print("Can you guess which is my favorite number?")
# Allow the user time to ... | true |
2d489c85552512da120bcdbb1a6b84fdc0a16b15 | malavikasrinivasan/D06 | /HW06_ch09_ex06.py | 1,478 | 4.625 | 5 | #!/usr/bin/env python3
# HW06_ch09_ex05.py
# (1)
# Write a function called is_abecedarian that returns True if the letters in a
# word appear in alphabetical order (double letters are ok).
# - write is_abecedarian
# (2)
# How many abecedarian words are there?
# - write additional function(s) to assist you
# - nu... | true |
cdfffc41e35a60ade6032f9b8522a8751e8e8821 | malavikasrinivasan/D06 | /HW06_ch09_ex02.py | 1,157 | 4.40625 | 4 | #!/usr/bin/env python3
# HW06_ch09_ex02.py
# (1)
# Write a function called has_no_e that returns True if the given word doesn't
# have the letter "e" in it.
# - write has_no_e
# (2)
# Modify your program from 9.1 to print only the words that have no "e" and
# compute the percentage of the words in the list have no "... | true |
81e3697052ce18a2c72e51ae8c8f06a6b812f8eb | pranavchandran/Automate-with-Python | /stopwatch.py | 1,324 | 4.25 | 4 | # My StopWatch
"""
Track the amount of time elapsed between presses of the ENTER key,
with each key press starting a new “lap” on the timer.
Print the lap number, total time, and lap time.
This means your code will need to do the following:
Find the current time by calling time.time() and store it as a
timestamp ... | true |
6193235aaa2f557e8e9c53d8b63ca819788be73a | ToMountainTops/MangoTest | /mango_programming_test_classes.py | 1,847 | 4.25 | 4 | """
Created on Sun Sep 29
For Mango Solutions Python test
For any questions please contact Claire Blejean: claire.blejean@gmail.com
The solution presented here relies on the random sampling function which is part of python.numpy.
A numerical solution can be coded which relies on mapping the inverse cumulative di... | true |
da3044772c9b3d4cd03151d1b177e335973dea99 | ChiranthakaJ/Google-Crash-Course-on-Python | /Python_OOP_Documenting_Functions_Classes_Methods.py | 2,451 | 4.65625 | 5 | #We can still use the Python function help to find documentation about classes and methods.
#We can also do this on our own classes, methods, and functions.
#Let's look at the below example.
class Apple:
def __init__(self, color, flavor):
self.color = color
self.flavor = flavor
def __str__(se... | true |
3473cb8474c1476efbaedd61785ada112665c321 | ColinLafferty/python_tutorials_2013 | /leap_year.py | 1,238 | 4.65625 | 5 | #!/usr/bin/env python
'''\
Leap years occur according to the following formula: a leap year is divisible
by four, but not by one hundred, unless it is divisible by four hundred.
For example, 1992, 1996, and 2000 are leap years, but 1993 and 1900 are not.
The next leap year that falls on a century will be 2400.
sour... | true |
5cd2a3acd1ef12389804180e51071ad660c84d46 | IsmailFadeli/Python-for-Probability-statistics-and-ML | /Random_Variables.py | 1,100 | 4.125 | 4 | # What is the probability that the sum of the dice equals seven?
# Step 1: associate all of the (a,b) pairs with their sum.
d = {(i,j):i+j for i in range(1,7) for j in range(1,7)}
# Step 2: collect all of the (a,b) pairs that sum each of the possible values from two to twelve.
from collections import ... | true |
1dd80cfb8fe81573fe4b5b6467ffd12feda38acb | shirishdhar/HW04 | /HW04_ex00.py | 1,270 | 4.21875 | 4 | #!/usr/bin/env python
# HW04_ex00
# Create a program that does the following:
# - creates a random integer from 1 - 25
# - asks the user to guess what the number is
# - validates input is a number
# - tells the user if they guess correctly
# - if not: tells them too high/low
# - only lets t... | true |
f77318b267a53148e75bf32c0d564a25c250db34 | Zerl1990/python_essentials | /examples/module_1/06_inputs.py | 211 | 4.40625 | 4 | # Input will show a message in the console, and return what the used types
# The return value can be store in a variable
age = input("What is your age?")
# Print the user input
print("Your age is: " + age)
| true |
d2912a4091ba27c9be145f61b5a1ce2f51c3c60f | Zerl1990/python_essentials | /examples/module_1/03_variables.py | 453 | 4.3125 | 4 | # type function return the type of the variables.
# for example, for number variable, it will return int
number = 5
print("Number Type:")
print(type(number))
decimal = 15.5
print("Decimal Type:")
print(type(decimal))
char = 'A'
print("Char Type:")
print(type(char))
string = 'My String'
print("String Type:")
print(t... | true |
72873dcfb1b9be8216663493368425738908b1ca | GuoXian88/15112_py | /fluent_py/ch08_obj_ref/ch8_obj_ref.py | 1,852 | 4.3125 | 4 | '''
garbage collection, the del command, and how
to use weak references to “remember” objects without keeping them alive.
reference variables: label attached to objects
下面可以证明赋值是先evluate右边再绑定到左边(Gizmo实例创建成功但是y并没有赋值成功)
To understand an assignment in Python, always read the right-
hand side first: that’s where ... | true |
55f6d217079a25a1bc92c94e6de29af502482c11 | mirandarevans/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/5-text_indentation.py | 474 | 4.15625 | 4 | #!/usr/bin/python3
def text_indentation(text):
if type(text) != str:
raise TypeError('text must be a string')
newline = True
for char in text:
if newline is True:
if char == ' ':
pass
else:
newline = False
if newline is False:... | true |
62c7bb6af2a4ed5fd481d5807f3f83d3ea87910a | vanithaasivakumar/Python---Hands-on | /Advanced Modules/FileIO.py | 640 | 4.125 | 4 | myfile=open('SampleText.txt')
print(myfile.read()) #displays file content
print(myfile.read()) #running it again will display empty string. Cursor is in end of the file
myfile.seek(0) #brings the cursor to the beginning of the file
print(myfile.read())
myfile.seek(0)
print(myfile.readlines()) #['Hello Wor... | true |
f9caaf9183591321cb40114dc1484fa8c27d8b6b | Sergi-Simon/INTRODUCTION-TO-PYTHON-PROGRAMMING | /Solutions to Exercises in Lecture Notes, Sections 1-6/week 3 (section 3)/vector_cosine.py | 1,455 | 4.21875 | 4 | """ vector_cosine.py
Program returnning the cosine of two vectors with recursive functions
Author: Sergi Simon
Last update: October 26, 2020 """
import math
def take_input( n, string, list0 ):
list1=list0.copy() # you can also write list1=list0 and it will still work
if len( list1 ) == n:
return list1
x = flo... | true |
ea2dc847f4175a358ebf78760f7da0537cb122a8 | Sergi-Simon/INTRODUCTION-TO-PYTHON-PROGRAMMING | /Solutions to Exercises in Lecture Notes, Sections 1-6/week 6 (sections 5, 6)/6/function_graph.py | 1,615 | 4.46875 | 4 | """ function_graph.py
Routine that checks the number of changes in sign in the graph provided in the lecture notes
Author: Sergi Simon
Last Update: November 18, 2020 """
import sys
def verify_signs ( x0, x1 ):
if x0 == -3 or x0 == 2 or x0 == 6 or x1 == -3 or x1 == 2 or x1 == 6:
string = "you have chosen interva... | true |
9e950dc6b0a0f7941d5d6d1fe1fcc2f354a7495f | Alena-Ryzhko/python_algorithms | /unit_test/reverse_string.py | 478 | 4.125 | 4 | """
Unit Test –> Reverse String
"""
import unittest
class TestStringReversal(unittest.TestCase):
def test_reverse_string(self):
input = "Rosa are red and I am glad"
expected_result = "glad am I and red are Rosa"
output = self.reverse_string(input)
self.assertEqual(expected_result,... | true |
546b568c45ff86dfec09cf3ed4b2c4c8e6bce0b4 | Alena-Ryzhko/python_algorithms | /algorithms_2_num/fibonacci_sequence.py | 983 | 4.40625 | 4 | """
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,...
where F0 = 0 , F1 = 1 and Fn = Fn-1 + Fn-2
A function to Print the Fibonacci sequence:
"""
# Approach 1
n = int(input("How many numbers will be in the sequence? Enter please "))
def fibonacci(n):
# First Fibonacci number is... | true |
e5c3d33b4d20042bebdfc4ea3d637a0928948663 | Maruthi18/Python_Projects | /Calculator/calculator.py | 1,006 | 4.21875 | 4 | from replit import clear
from art import logo
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
def calculator():
""" here we are taking n1... | true |
bcf75ce80a6eb0a2115056ae7172b981dbd047e4 | xlistarer/recurse | /main.py | 2,877 | 4.34375 | 4 | # This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
'''
#############################################
# All tasks should be solved using recursion
######################... | true |
ba579d74b47eb7dc1a55a242e22701abdbb46997 | roshansinghbisht/hello-python | /day-5-using-a-simple-loop.py | 1,945 | 4.34375 | 4 | # TASK: The provided code stub reads and integer, n, from STDIN.
# For all non-negative integers i<n, print n^2 .
if __name__ == '__main__':
n = int(input("Enter a number between 1 and 20"))
for i in range(n):
print(i**2)
# A module is a file containing Python definitions and statements.
# T... | true |
8f3e26501cd9a96e8b9f4677fe3586994afd0869 | roshansinghbisht/hello-python | /day-17-data-structures.py | 1,076 | 4.28125 | 4 | print('Creating a Tuple...............................................')
dimensions = 52, 40, 100
length, width, height = dimensions
print("The dimensions are {} x {} x {}".format(length, width, height))
# Creating a set fro a list (to remove duplicates from a list).
print('Creating a set................................ | true |
a9e469a52407aa1004562ab4b212bea5c471e71a | nick-fl/projecteuler | /5.py | 480 | 4.25 | 4 | #infinitely outputs multiples of 20. there is probably and easier way
print("Finding the smallest number that has every number between 1 and 20 as a factor.")
found = 0
a = 0
while found == 0:
counter = 0
b = a + 20
for i in range(1,21):
if b%i == 0:
counter += 1
if counter ==... | true |
b4513eb73cd6683c02ad1e0d1b413785bdeece4d | BernardWong97/Collatz | /collatz.py | 399 | 4.46875 | 4 | # The number to perform the Collatz operation.
n = int(input("Enter a positive integer: "))
# Keep looping until n = 1 assuming Collatz conjecture is true.
while n != 1:
print(n) # print current value of n.
if n % 2 == 0: # if even, divide by two.
n //= 2
else: # if odd, multiply by three and ad... | true |
6936684126b9a4d76c079d0b9638d4dddc8ae96d | Steantc/SENG3110_Lab2_Python_Unit_Testing_Project | /cube.py | 886 | 4.125 | 4 | import math
def surfaceArea(ln):
area = round((6 * ln**2), 2)
return area
def volume(ln):
volume = round((ln**3), 2)
return volume
def lateral(ln):
lateral = round((4* ln**2), 2)
return lateral
def prompt():
print()
print("----------------------------------------------------------... | true |
36ae7457a749d276c36e4e71bfeac919112168d7 | ayumoesylv/draft-tic-tac-toe | /L2 Python Class 1 homework pt 2.py | 260 | 4.125 | 4 | #write a program to count the number of elements in a list.
FruitIndex = ["apple", "orange", "banana", "kiwi", "blueberry", "grape"]
fruitNum = len(FruitIndex)
for i in range(0, len(FruitIndex)):
print(FruitIndex[i], end = " ")
print("total:", fruitNum) | true |
da4b5f37095f003305bbda58c149b0afe8f255e7 | sharma-arpit/cs50 | /Random/stud.py | 245 | 4.28125 | 4 | from student import Student
students = []
for i in range(3):
name = input("name: ")
dorm = input("dorm: ")
students.append(Student(name, dorm))
for student in students:
print("{} is in {}.".format(student.name, student.dorm))
| true |
13d3bc182e07027e3fef6dea8094e3976e55e7eb | paua-app/Python-Stuff | /functional programming/mylen.py | 2,111 | 4.34375 | 4 | """
Task:
Write a function that calculates the length of a list.
Example:
#>>> print(len([1,2,3,4,5]))
5
"""
from auxfuncs import cdr
from auxfuncs import build_list as bl
from auxfuncs import curry
__author__ = 'Aurora'
def my_len_imp(lst):
temp = 0
i = 0
while lst[i] != None:
... | true |
89fc0701e224e24bc764f31de5d01efbd59d633b | arsh771/assignment16 | /MONGODB.py | 857 | 4.3125 | 4 | #Q.1- Write a python script to create a databse of students named Students.
import pymongo
client=pymongo.MongoClient()
database=client['Students']
print('STUDENTS DATABASE CREATED')
collection=database['Student Data']
print('STUDENTS DATA TABLE CREATED')
#Q.2- Take students name and marks(between 0-100) as inpu... | true |
861757dc22878e5535c974eb49104a1195beba6f | kshannoninnes/hyprfire | /hyprfire_app/utils/file.py | 534 | 4.34375 | 4 | from pathlib import Path
def get_filename_list(path):
"""
get_filename_list
Helper function to retrieve a list of non-hidden filenames from a directory
Parameters
path: a path to a directory containing files
Return
A list of non-hidden filenames in the directory
"""
file_list = ... | true |
13365a83cff07ae5eab820f17d288d5f86bc4afc | ujaani/python | /max.py | 373 | 4.125 | 4 | first = input("give me a number")
second = input("give me another number")
first_int = int(first)
second_int = int(second)
if first_int > second_int:
max = first_int
elif first_int == second_int:
print("both no. are equal. the equal no. is " + first)
exit(0)
else:
max = second_int
max_s... | true |
6a8f1ff7ce2492d3c963e3d8d75a1162b5c4ccf5 | huzefa53/python-learning | /python-learning/dict.py | 779 | 4.21875 | 4 | #!/usr/bin/python
'''Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and
consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings.
Values, on the other hand, can be any arbitrary Python object.
Dictionari... | true |
5a6585d058c0dcf1f27f984fc6e436206bd3e90f | AfroHackology/OOP | /coreyS_classes/emp.py | 1,379 | 4.15625 | 4 | class Employee:
num_of_emps = 0
raise_amount = 1.04
names = input([])
tardies = bool(False)
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + '.' + last + '@company.com'
Employee.num_of_emps += 1
... | true |
0dac3948778f6524def5952f7112c5ca80303b63 | w23023030/sc-projects | /stanCode-Projects/boggle_game_solver/anagram.py | 2,363 | 4.1875 | 4 | """
File: anagram.py
Name: Jasmine Tsai
----------------------------------
This program recursively finds all the anagram(s)
for the word input by user and terminates when the
input string matches the EXIT constant defined
at line 19
If you correctly implement this program, you should see the
number of anagrams for ea... | true |
dc9f2e3e4b34a603913683da5a0d79cc7944cfd0 | nlkek/CodewarsProgs | /SimplePigLatin.py | 475 | 4.1875 | 4 | def pig_it(text):
res = ''
lst = text.split(' ')
for word in lst:
if word.isalnum():
res += word[1:] + word[0] + 'ay '
else:
res += word
return res.rstrip()
"""
Move the first letter of each word to the end of it, then add "ay" to the end of the word.... | true |
0eecdc646a3b101f41ddf1b4580f5cf571849d2a | gahakuzhang/PythonCrashCourse-LearningNotes | /6.dictionaries/6.4.1 a list of dictionaries.py | 320 | 4.21875 | 4 | # 6.4.1 a list of dictionaries 字典列表
aliens=[]
# 创建30个绿色外星人
for alien_number in range(30):
new_alien={'color':'green','points':5,'speed':'slow',}
aliens.append(new_alien)
for alien in aliens[:5]:
print(alien)
print('...')
print("The total number of aliens: "+str(len(aliens))) | true |
57cd761fc481808c38c9994b6eb73ac579a0fb77 | gahakuzhang/PythonCrashCourse-LearningNotes | /9.classes/9.3.3 define attributes and methods for the child class.py | 1,205 | 4.34375 | 4 | # 9.3.3 define attributes and methods for the child class 为子类定义属性和方法
class Car():
def __init__(self,make,model,year):
self.make=make
self.model=model
self.year=year
self.odometer_reading=0
def get_descriptive_name(self):
long_name=str(self.year)+' '+self.make+' '+... | true |
2323d1575e0e3299b67bddaa9c88ac80332a23f3 | YaYaChen827/Udacity_Intro_to_Computer_Science | /Quiz/Lesson5_Quiz_Empty_Hash_Table.py | 1,186 | 4.1875 | 4 | # Creating an Empty Hash Table
# Define a procedure, make_hashtable,
# that takes as input a number, nbuckets,
# and returns an empty hash table with
# nbuckets empty buckets.
def make_hashtable(nbuckets):
hashtable = []
for i in range(0, nbuckets):
hashtable.append([])
return hashtable
#Testing right make_hasht... | true |
802e97f5333bb818ff099bcbbcfa7bc204b67dec | robgoyal/CodingChallenges | /CodeWars/7/complementaryDNA.py | 437 | 4.125 | 4 | # Name: complementaryDNA.py
# Author: Robin Goyal
# Last-Modified: March 15, 2018
# Purpose: Return the complement of a DNA string
def DNA_strand(dna):
"""
(str) -> str
Return the DNA complement of dna as a string.
Examples:
>>> DNA_strand("ACTGTAC")
"TGACATG"
"""
complements = {"A"... | true |
0d85a27d4679d367cf451ab98124bf3722701614 | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/21-to-30/jumpingOnTheCloudsRevisited.py | 884 | 4.375 | 4 | # Name: jumpingOnTheCloudsRevisited.py
# Author: Robin Goyal
# Last-Modified: November 23, 2017
# Purpose: Calculate the remaining energy level after jumping over clouds
def jumpingOnTheCloudsRevisited(n, k, clouds):
'''
n -> int: number of clouds
k -> int: jump size
clouds -> list: clouds of value 0 ... | true |
35bb652c0f240421bfa70a6199e254096aebbefa | robgoyal/CodingChallenges | /Exercism/python/reverse-string/reverse_string.py | 236 | 4.375 | 4 | def reverse(text):
"""
str -> str
Reverse a string.
Examples:
>>> reverse("")
""
>>> reverse("hello")
"olleh"
>>> reverse("What's your name?")
"?eman ruoy s'tahW"
"""
return text[::-1]
| true |
9663daead070165822cbb191d30fbd4eaa73be25 | robgoyal/CodingChallenges | /CodeFights/Arcade/Intro/darkWilderness/knapsackLight.py | 574 | 4.125 | 4 | # Name: knapsackLight.py
# Author: Robin Goyal
# Last-Modified: July 21, 2017
# Purpose: Check the total weight your knapsack can hold from
# the weight of two different items
# Note: Forced solution
def knapsackLight(value1, weight1, value2, weight2, maxW):
if (weight1 + weight2) <= maxW:
retur... | true |
0cef65ad00a794aee620f23d9c13faaf878bb46c | robgoyal/CodingChallenges | /FireCode/Level_1/missingNumberFrom1To10.py | 474 | 4.375 | 4 | # Name: missingNumberFrom1To10.py
# Author: Robin Goyal
# Last-Modified: August 7, 2017
# Purpose: Find the number missing in the order of 1 to 10
# Note: Found other solutions where the sum of 1 to 10 minus the sum of the list
# returned the missing number
def find_missing_number(list_numbers):
# Check if ... | true |
8e40c15622ed0abbf7e635e3941f2d05b93dec83 | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/11-to-20/betweenTwoSets.py | 1,186 | 4.15625 | 4 | # Name: betweenTwoSets.py
# Author: Robin Goyal
# Last-Modified: November 12, 2017
# Purpose: Count the number of times a value is a multiple of all elements
# in list A and a factor of all elements in list B
def main():
n, m = list(map(int, input().strip().split(' ')))
a = list(map(int, input().str... | true |
14977d9de6c198fd7492ed70decde4d6c4f9144c | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/21-to-30/electronicsShop.py | 1,516 | 4.21875 | 4 | # Name: electronicsShop.py
# Author: Robin Goyal
# Last-Modified: November 21, 2017
# Purpose: Calculate the amount of money spent at an electronics shop
def getMoneySpent(keyboards, drives, s):
'''
The maximum amount of money that can be spent on a single keyboard
and drive without exceeding her budget
... | true |
0d8df21193abb042e99156135f5896754e8c4f86 | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/41-to-50/flatlandSpaceStations.py | 1,027 | 4.4375 | 4 | # Name: flatlandSpaceStations.py
# Author: Robin Goyal
# Last-Modified: January 31, 2018
# Purpose: Determine the maximum distance an astronaut will
# have to travel to a space station
def flatlandSpaceStations(n, c):
'''
(int, list: int) -> int
n is the number of cities and c is the indices at ... | true |
51cae524f60d055e449dca4873941206325d4d5d | robgoyal/CodingChallenges | /CodeWars/7/numberPeopleInBus.py | 557 | 4.40625 | 4 | # Name: numberPeopleInBus.py
# Author: Robin Goyal
# Last-Modified: June 7, 2018
# Purpose: Calculate the remaining number of people
# on the bus after the last stop
def number(bus_stops):
"""bus_stops
Return the remaining number of people
on the bus after the last stop.
Examples:
>>> n... | true |
1e189ea6efb35bf1d8f0ab74b3f558a83fc5ab98 | robgoyal/CodingChallenges | /CodeFights/Arcade/Intro/throughTheFog/circleOfNumbers.py | 269 | 4.25 | 4 | # Name: circleOfNumbers.py
# Author: Robin Goyal
# Last-Modified: July 13, 2017
# Purpose: Given a circular radius n and an input number,
# find the number which is opposite the input number
def circleOfNumbers(n, firstNumber):
return (firstNumber + n / 2) % n | true |
806b3371f326efcbfa503d157529e9431dadef74 | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/41-to-50/sherlocksAndSquares.py | 775 | 4.375 | 4 | # Name: sherlocksAndSquares.py
# Author: Robin Goyal
# Last-Modified: December 14, 2017
# Purpose: Calculate the number of squares in between a range
import math
def sherlocksAndSquares(A, B):
'''
A -> int: start of range
B -> int: end of range
return -> int: number of squares in between [A, B]
... | true |
722582520522b4fa825ad4ecb6b21c860aa2f7f3 | robgoyal/CodingChallenges | /CodeWars/6/sortTheOdd.py | 663 | 4.4375 | 4 | # Name: sortTheOdd.py
# Author: Robin Goyal
# Last-Modified: March 17, 2018
# Purpose: Implement solution to Sort the Odd
def sort_array(arr):
"""
(list: int) -> list: int
Return an array of the odd numbers in sorted order
while the even numbers remain in place.
Examples:
>>> sort_array([5, ... | true |
d25f598c24122cf9cf1544bfc27c383d8dfe4aba | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/41-to-50/encryption.py | 1,234 | 4.40625 | 4 | # Name: encryption.py
# Author: Robin Goyal
# Last-Modified: February 16, 2018
# Purpose: Encrypt a string
import math
def encryption(s):
"""
(str) -> str
Return a string by encrypting a string s using
the following encryption scheme.
Split s into rows (floor(sqrt(s)) and cols (ceil(sqrt(s))).
... | true |
81b86a6268ff3d043cfe3fe95bbbbe419c1b6307 | robgoyal/CodingChallenges | /CodeWars/7/sumNNumbers.py | 422 | 4.375 | 4 | # Name: sumNNumbers.py
# Author: Robin Goyal
# Last-Modified: March 13, 2018
# Purpose: Return the sum of the first n numbers
def f(n):
"""
(int) -> int or None
Return None if n is a positive integer, else
return the sum of the first n numbers.
Examples:
>>> f(100)
5050
>>> f(-5)
... | true |
d4ce245927f33fc5f58140997a35c756a86d0800 | robgoyal/CodingChallenges | /HackerRank/Algorithms/Implementation/11-to-20/catsAndMouse.py | 858 | 4.15625 | 4 | # Name: catsAndMouse.py
# Author: Robin Goyal
# Last-Modified: November 17, 2017
# Purpose: Determine which cat will reach the mouse first
def catAndMouse(a, b, c):
'''
a: position of cat A
b: position of cat B
c: position of mouse C
result: "Cat A" if cat A reaches mouse first
"Cat B... | true |
606e46df077d834a86a684b4bb6bc0bf9542cdac | kranz912/Algorithms | /Problems/5-CheckPangram.py | 606 | 4.3125 | 4 | '''
Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.
Examples :
"The quick brown fox jumps over the lazy dog" is a Pangram [Contains all the characters from 'a' to 'z']
"The quick brown fox jumps over the dog" is not a Pangram [Doesn't contains all... | true |
527ffee1162fb0545368a799e3763483ccb6d093 | krsnvijay/prime | /prime_consecutive_check.py | 2,155 | 4.25 | 4 | import sys
from functools import cache
import primesieve
@cache
def sum_digits(number):
"""
Sums all the digits of a number recursively to a single digit number
eg: 192 = 1 + 9 + 2 = 12
=> 12 = 1 + 2 = 3
so 192 will turn to 3
"""
result = sum(int(digit) for digit in str(number))
#... | true |
379af50325a45d8a599fd3d89f6a9268f02fcd95 | dhillonfarms/core-python-scripts | /NumericalProjects/fibonacci.py | 1,764 | 4.15625 | 4 | """
Discussing various approaches for generating fibonacci sequences
Using Python timeit module to find most efficient approach
"""
__author__ = 'https://github.com/dhillonfarms'
import timeit
# Using classic loop approach to get fibonacci series
def get_fibonacci_classic(num):
a = 1
b = 1
output = []
... | true |
9001e276ee0c12d82c392afaea05438824a6b6de | onahirniak/algorithms | /app/main/lists/linked_list.py | 2,335 | 4.15625 | 4 | from app.main.base.node import Node
class LinkedListNode(Node):
def __init__(self, val):
Node.__init__(self, val)
self.next = None
class LinkedList:
def __init__(self):
self.root = None
def push(self, val):
node = LinkedListNode(val)
node.next = self... | true |
4066bbd2c27a2c2b5fa65d35e55e6eb6104e8279 | modcomlearning/pythonOnline | /Lesson4.py | 637 | 4.65625 | 5 | # Today , we do while loop
# While Loop repeats a task n-times
# With while a loop you can do an infinite loop(loops forever)
# There are three steps you need to do:
# 1. Create a variable to start your loop i.e x = 0
# 2. Set a condition, loop will run only if this condition is true
# The loop will not run if ... | true |
c825f98e03cecae1489ff35b61f8f868677efca5 | jorjilour/python_files | /queues.py | 2,395 | 4.5 | 4 | from queue import Queue
import sys
# Initializing a queue
q = Queue(maxsize=3)
# qsize() give the maxsize
# of the Queue
print(q.qsize())
# Adding of element to queue
q.put('a')
q.put('b')
q.put('c')
# Return Boolean for Full
# Queue
print("\nFull: ", q.full())
# Removing element from queue
... | true |
e69fc704dceb397e33194a91bf85b96f2607913a | idaks/explanation-visualization | /prime-or-composite/prime-or-composite.py | 2,120 | 4.28125 | 4 | #!/usr/bin/env python3
import sys
print("### Running", *sys.argv, "###") # a bit of logging
N = int(sys.argv[1]) # number N > 2 to test
assert N > 2
d = 2 # trial divisor d = 2,3, ...
c = 0 # count 'composite... | true |
4f8bebc809322aa2d144bcc9b1837934939076ce | SunnyVikasMalviya/Python | /Sockets/Sockets_Intro.py | 2,321 | 4.34375 | 4 | import socket
#Sockets aid in communication between 2 entities
#For example, a client and a server are 2 entities and the client requests a \
#url. Servers have their ports open that they use to serve different kinds of \
#requests. So the client generates a socket that plugs into the port of the \
#server and h... | true |
347c04e45398da2ca4ea23a7ce9e544afa970696 | SunnyVikasMalviya/Python | /HackerRank-Solutions/Count-SubString.py | 453 | 4.40625 | 4 | def count_substring(string, sub_string):
'''
Function to count number of times a substring occurs in a string.
'''
n = len(string)-len(sub_string)+1
cnt = 0
for _ in range(n):
if string[_:_+len(sub_string)] == sub_string:
cnt = cnt+1
return cnt
if __name__ == '__main__':... | true |
b873309e52739c7f8f3b79c73d6dd3ebf2d0259a | SunnyVikasMalviya/Python | /Intermediate Python/Generators.py | 2,416 | 4.25 | 4 | '''
Generators
'''
#Generators don't return things, they yield it.
#We will create our own simple generator
def gen_func():
"""
Simple example of our own generator.
"""
yield 'Corona Corona'
yield 'Corona Corona'
yield 'Corona Corona'
yield 'Me hun ek Corona'
def normal_func... | true |
9c42e5d7f60f1e531877044fc08f7344a06b766e | SunnyVikasMalviya/Python | /Prime_In_List.py | 510 | 4.15625 | 4 | from Prime_Check import is_prime
def prime_in_list(list_):
"""
The prime_in_list function takes a list argument, iterates through all the
elements in the list, and returns a list of all the prime numbers in the
list.
"""
lst = []
for x in list_:
if is_prime(x):
... | true |
807628db2cf3320fb368c29a8297cd4bd81012e0 | SunnyVikasMalviya/Python | /Mersenne_Prime.py | 710 | 4.375 | 4 | from Prime_Check import is_prime
def Mersenne_prime(n):
"""
In mathematics, a Mersenne Prime is a prime number that is one less than a
power of 2 i.e. M(n) = 2^n - 1 should be prime for some n.
The Mersenne_prime function takes a integer argument which is n in M(n) and
returns a list of Mer... | true |
d66f9d41acb3608bfe1ab2735c1649254bbc33e5 | SunnyVikasMalviya/Python | /Intermediate Python/Multiprocessing.py | 2,138 | 4.375 | 4 | import multiprocessing
"""
CPUs have different number of processors i.e.the number of cores in your CPU.
All the programs not using multiprocessing will be allocated only a single core
to work with. So at a time you will only be using a fraction of what your whole
CPU is capable of. Say, you have a quad core proce... | true |
773f7f6dafb220d32fb023cae1363e1eba50b742 | jeetpatel242/turtlebot3_astar | /scripts/utils.py | 1,964 | 4.15625 | 4 | #!/usr/bin/env python3
import numpy as np
import math
# Function to check if the given point lies outside the final map or in the obstacle space
def check_node(node, clearance):
# Checking if point inside map
offset = 5.1
if node[0] + clearance >= 10.1 - offset or node[0] - clearance <= 0.1 - offset or n... | true |
3a7778a7a96577c76dde47bed0dc1c41bc649d4f | sarahdactyl71/lpthr | /exercises/ex33.py | 402 | 4.28125 | 4 | def while_loop(times, increment):
i = 0
numbers = []
while i < times:
print(f"At the top i is {i}")
numbers.append(i)
i += increment
print("Numbers now: ", numbers)
print(f"At the bottom i is {i}")
print("The numbers: ")
for num in numbers:
print... | true |
91178a5ee27fa127d03c2b8f6db73673f6735c37 | ancylq/leetcode | /detect_capital.py | 840 | 4.46875 | 4 | # coding:utf-8
'''
Given a word, you need to judge whether the usage of capitals in it is
right or not.
We define the usage of capitals in a word to be right when one of the
following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
... | true |
cf7d3496fa7bd37aecdd0268bfd6628f5e5f7034 | florin-postelnicu/PythonFlorin01 | /IfElseElif/Multiplication4.py | 1,244 | 4.21875 | 4 |
import random
yesno = True
correct = 0
incorrect = 0
while(yesno):
print(" This program helps you to learn the multiplication table!")
a = random.randint(1, 10)
b = random.randint(1, 10)
print("Find the product of the numbers :", a , " * ", b)
product = a*b
print("Please Enter you... | true |
1915944dbe1b4a252697b765a26087e65c8102b9 | michaelbenninghoven-sparks/PythonPrograms | /3a) Map+ReverseMap.py | 1,264 | 4.4375 | 4 | import time
#Asking for first name
name1=input("Enter a name.\n")
name1=name1.rstrip()
#Asking for first number
number1=input("Enter their phone number.\n")
number1=number1.rstrip()
#Asking for second name
name2=input("Enter a name.\n")
name2=name2.rstrip()
#Asking for second number
number2=input("Ente... | true |
ee0a8c14349e16c6ed4f4dd3cc710c53f009eb29 | SACHSTech/ics2o1-livehack2-practice-StephanieHCTam | /problem2.py | 720 | 4.21875 | 4 | """
-------------------------------------------------------------------------------
Name: problem2.py
Purpose: This program determines if a triangle is a right angle triangle.
Author: Tam.S
Created: 12/02/2021
------------------------------------------------------------------------------
"""
print(" ****** S... | true |
7331f3222ce90576e93745e90e3755b82d095266 | tjhobbs1/python | /Module7/fun_with_lists/search_sort_list.py | 1,300 | 4.625 | 5 | """
Program: search_sort_list.py
Author: Ty Hobbs
Last Day Modified: 10/08/2019
The purpose of the program is to create a list of numbers and return it to the user. It will be used for testing
Basic List Exceptions
"""
def make_list():
# This function will run a for loop calling the get_input function to get t... | true |
67a015f1f98a9724eec728c7cfe5442bc3bda742 | tjhobbs1/python | /Module11/override_test.py | 1,095 | 4.125 | 4 | class Shape:
"""Shape class"""
colors = ['BLUE', 'GREEN', 'ORANGE', 'PURPLE', 'RED', 'YELLOW']
def __init__(self, color='BLUE'):
self._color = color
def change_color(self, new_color):
if new_color not in self.colors:
raise InvalidColorError
self._color = new_color
... | true |
5d46e5cd5da5caa8cad966d40f214d32cc537e0f | tjhobbs1/python | /Module6/payroll_calc.py | 1,769 | 4.40625 | 4 | """
Program: payroll_calc.py
Author: Ty Hobbs
Last date modified: 09/30/2019
The purpose of this program is to take an employees name, the number of hours they work and their rate of pay.
It will then return the total amount of pay that employee will receive.
"""
def hourly_employee_input():
# This function wil... | true |
cdbb311a8c65ef52b6a37a35e182b636a7ba3c43 | nitin2149kumar/INFYTQ-Modules | /Data Structure/Day-4/Ex_11.py | 1,384 | 4.25 | 4 | #DSA-Exercise-11
import random
def find_it(num,element_list):
#Remove pass and write the logic to search num in element_list using linear search algorithm
#Return the total number of guesses made
guesses=0
for i in element_list:
guesses+=1
print(guesses)
if num==i:
... | true |
65b1767df2e775cdf12f28362e0a552647793684 | nitin2149kumar/INFYTQ-Modules | /Data Structure/Day-5/Ex_19.py | 902 | 4.125 | 4 | #DSA-Exer-19
def swap(num_list, first_index, second_index):
#Remove pass and copy the code written earlier for this function
num_list[first_index],num_list[second_index]=num_list[second_index],num_list[first_index]
def find_next_min(num_list,start_index):
#Remove pass and copy the code written earlier fo... | true |
49dd1f1a4ac77bb1c3a8c6c0d3e9500514fd2cca | rchicoli/ispycode-python | /Data-Types/Numbers/Booleans.py | 383 | 4.15625 | 4 |
# True behaves like 1
print( int(True) )
# False behaves like 0
print( int(False) )
# non zero numbers evaluates to True
print( bool(99) )
# 0 evaluates to False
print( bool(0) )
# boolean expressions using the logical operators
print "not True :" , not True
print "not False :" , not False
print "True and False :... | true |
c0805de1cd404c8258fb5e91a7408de33db58f81 | Carter0/learningPython | /vector.py | 1,150 | 4.375 | 4 | #!/usr/local/bin/python3
from math import hypot
# Also another example from the book. This time about vectors.
class Vector:
# What is interesting to note here is that...
# We have created 6 special methods and most are not called by the user. Most are called by the python interpreter.
def __init__(self... | true |
4383772d34f8f68671a65e594e6775143f8337c0 | kuldeeparyadotcom/coding_interview | /sum_target/SumTarget.py | 2,941 | 4.1875 | 4 | #!/usr/bin/env python
# vim: tabstop=8 expandtab widthsize=4 softtabstop=4
"""
Problem - A list of numbers is given. A target number (integer) is given. Write a function that returns a boolean value if any two numbers in list sum up the given target number.
Input -
List of integers
target integer
Output -
True if a... | true |
11a092e1eea851c85df75938bc0f2df28fce8f71 | kuldeeparyadotcom/coding_interview | /q004/prime_classification.py | 1,157 | 4.125 | 4 | #!/usr/bin/env python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
def classify_list(l):
"""
Purpose - function classifies prime numbers vs non-prime numbers
Input - a list of positive integers
Ouput - For each number in list, program confirms whether it is prime or not
"""
... | true |
42fda741883c2092888795118c130777edaf9448 | abi-oluwade/engineering-48-Mr-Miyagi-Game | /mr_miyagi_sensei_edition.py | 1,501 | 4.28125 | 4 | print ("Hello young grasshopper,")
# The 'while True' here means that the whole loop will run on forever/infinitely it will always be a true condition ,
# but can be broken with the use of the 'break' keyword after a condition has been met and will print the statement
# at the end outside the loop.
while True:
user... | true |
ea36fe328a8653132ddf456d18745196bea80a84 | SMinTexas/phone_book_console_app | /phonebook.py | 2,049 | 4.59375 | 5 | # You will write a command line program to manage a phone book.
# When you start the phonebook.py program, it will print out a menu
# and ask the user to enter a choice:
# $ python3 phonebook.py
# Electronic Phone Book
# =====================
# 1. Look up an entry
# 2. Set an entry
# 3. Delete an entry
# 4. Li... | true |
d7b2c4dd0a7b106730e4731819dbbe31b4dc18db | Arun-07/python_100_exercises | /Question_2.py | 395 | 4.34375 | 4 | # Question 2
# Write a program which can compute the factorial of a given numbers.
# The results should be printed in a comma-separated sequence on a single line.
# Suppose the following input is supplied to the program: 8 Then, the output should be:40320
n = int(input('Enter a number: '))
result = 1
for i in range(1,... | true |
44a5e5d629980e316a750c26037d41be1ae1a74b | Arun-07/python_100_exercises | /Question_12.py | 435 | 4.1875 | 4 | # Write a program, which will find all such numbers between 1000 and 3000 (both included)
# such that each digit of the number is an even number.
# The numbers obtained should be printed in a comma-separated sequence on a single line.
import re
odd_pattern = re.compile(r"['1', '3', '5', '7', '9' ]")
for num in rang... | true |
cfaf8e864df4eb7d0a30e03466184abd33f3c2d3 | Arun-07/python_100_exercises | /Question_35.py | 315 | 4.3125 | 4 | # Define a function which can generate a list where
# the values are square of numbers between 1 and 20 (both included).
# Then the function needs to print the last 5 elements in the list.
def sqrd_list():
num_list = [i**2 for i in range(1, 21)]
for j in num_list[:-6:-1]:
print(j)
sqrd_list()
| true |
15d687c7ae68b28c20e713ae165c59576cb1690c | schase15/cs-module-project-hash-tables | /applications/word_count/word_count.py | 2,328 | 4.3125 | 4 | # Already did this with the histo.py example
# Only works on 3 out of 5 test with the special characters if statement
# I think the test is wrong, based on the Readme. It says if no special characters are
# removed it should return a blank dictionary.
# In the second one, "Hello hello", there are no... | true |
496109a8720fd12f0aaf8065423224ce46097081 | SR-Sunny-Raj/Hacktoberfest2021-DSA | /33. Python Programs/binconversion.py | 204 | 4.1875 | 4 | '''Problem Statement : Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. '''
n=int(input("Enter Number : "))
print(bin(n)[2:])
| true |
0cd1dd82c16e2fc272087e3c55578aa107a3b44c | SR-Sunny-Raj/Hacktoberfest2021-DSA | /05. Searching/BinarySearch.py | 1,266 | 4.3125 | 4 | # Binary Search: Search a sorted array by repeatedly dividing the search interval in half.
# Begin with an interval covering the whole array.
# If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half.
# Otherwise, narrow it to the upper half. Repeated... | true |
2f836eba2f03aa2af3d26029f16f760624e144bd | SR-Sunny-Raj/Hacktoberfest2021-DSA | /33. Python Programs/create_sublist.py | 2,113 | 4.1875 | 4 | Python3 program to find a list in second list
class Node:
def __init__(self, value = 0):
self.value = value
self.next = None
# Returns true if first list is
# present in second list
def findList(first, second):
# If both linked lists are empty/None,
# return True
if not first and not second:
return True
... | true |
3b4d75e13e90c3f80307badb1fe07be84aaee4f5 | SR-Sunny-Raj/Hacktoberfest2021-DSA | /20. Dynamic Programming/rod_cutting.py | 1,423 | 4.34375 | 4 | """
Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces.
Example:
If length of the rod is 8 and the values of different pieces are given as following, then the maximum obta... | true |
6d3a0183b835bed116980eab41cd43df8bd54c46 | Hanu-Homework/SS1 | /week02/hw_ex05_vowels_and_consonants.py | 796 | 4.28125 | 4 | def count_vowels_and_consonants(string: str) -> tuple:
# A constant tuple holding all of the vowels
all_vowels = ('a', 'e', 'i', 'o', 'u')
vowels_count = 0
consonants_count = 0
# Convert all the characters of the string to lowercase
string = string.lower()
# Iterate through each character... | true |
e2ff807c46dafdfe5ca57a85cba6c52f3fdab478 | Hanu-Homework/SS1 | /week02/tut_ex01_digits_sum.py | 647 | 4.3125 | 4 | # Get the input number from the user
num = int(input("Enter a number: "))
def calculate_digits_sum(number: int) -> int:
"""
Return the sum of all digits in a number
Args:
number (int): the input number
Returns:
(int): the sum of all digits of the input number
"""
# Return val... | true |
c86a4161ca43e6fad5387ba5c8aa795480549a08 | dbrgn/projecteuler | /python/0009/9.py | 769 | 4.28125 | 4 | """
Problem 9
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
import sys
def triplet(m, n):
"""Euclid's formula. Generate... | true |
8b2094f561c9088f0da99fe268820fd59f4fd93e | thomasren681/MIT_6.0001 | /ps4/ps4a.py | 2,481 | 4.3125 | 4 | # Problem Set 4A
# Name: Thomas Ren
# Collaborators: None
# Time Spent: x: About a quarter to an hours
def get_permutations(sequence):
'''
Enumerate all permutations of a given string
sequence (string): an arbitrary string to permute. Assume that it is a
non-empty string.
You MUST u... | true |
a2650327ea1d4d9e989e94bf082e0801899cd5ba | Katarzyna-Bak/Coding-exercises | /Triangle area.py | 766 | 4.21875 | 4 | """
Task.
Calculate area of given triangle. Create a function t_area that will take a string which will represent triangle, find area of the triangle, one space will be equal to one length unit. The smallest triangle will have one length unit.
Hints
Ignore dots.
Example:
.
. .
. . . -... | true |
aeb77a185e0947f5eb2e7d95884cdf6b11697dc9 | Katarzyna-Bak/Coding-exercises | /Right to Left.py | 1,761 | 4.46875 | 4 | """
"For centuries, left-handers have suffered unfair discrimination in a world designed for right-handers."
Santrock, John W. (2008). Motor, Sensory, and Perceptual Development.
"Most humans (say 70 percent to 95 percent) are right-handed, a minority (say 5 percent to 30 percent) are left-handed, and an indetermi... | true |
bae89e5416fca377bce925552209a6c3eb97bf23 | Katarzyna-Bak/Coding-exercises | /Filling an array (part 1).py | 468 | 4.15625 | 4 | """
We want an array, but not just any old array, an array with
contents!
Write a function that produces an array with the numbers 0
to N-1 in it.
For example, the following code will result in an array
containing the numbers 0 to 4:
arr(5) // => [0,1,2,3,4]
Note: The parameter is optional. So you have to... | true |
8d02064e8feb688e01ece44ce2921f23b79b758c | Katarzyna-Bak/Coding-exercises | /Double Char.py | 502 | 4.125 | 4 | """
Given a string, you have to return a string in
which each character (case-sensitive) is repeated once.
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
Good Luck!
"""
def double_char(s):
output = ''
f... | true |
657a70dba9da3ec8793d9a4116f0d737775643eb | Katarzyna-Bak/Coding-exercises | /BASIC Making Six Toast.py | 857 | 4.6875 | 5 | """
Story:
You are going to make toast fast, you think that you
should make multiple pieces of toasts and once. So,
you try to make 6 pieces of toast.
Problem:
You forgot to count the number of toast you put into
there, you don't know if you put exactly six pieces
of toast into the toasters.
Define a funct... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.