blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
1a719ddedba620ec08f18633c1730f50cfc3d0e9 | the-carpnter/algorithms | /towers_of_hanoi.py | 565 | 4.1875 | 4 | def hanoi(n, rod0, rod1, rod2):
# This is the base case, we just have to move the 1 remaining plate to the target plate
if n == 1:
print('Plate 1 from {} to {}'.format(rod0, rod2))
return
# We have to first move n-1 plates to the auxiliary rod
hanoi(n-1, rod0, rod2, rod1)
# Moving th... | true |
c81a139f48b30116760c3710f5778fedcac40def | gmoore016/Project_Euler | /Complete/Problem009.py | 1,306 | 4.25 | 4 | """
Gideon Moore
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
def main():
# Solutions are defined by pairs of a and b since... | true |
2d5f0fa53d224128c6c6730cbd317decf614f72a | yashlad27/MAC-Python-basics-Jun21 | /Tuples01.py | 1,165 | 4.6875 | 5 | # TUPLE: it is a collection which is ordered and unchangeable
# tuples are written with round brackets
thisTuple = ("apple", "banana", "cherry")
print(thisTuple)
# 1. tuple items are ordered, unchangeable, and allow duplicate values
# first item has index [0] and the second item has index [1]
# 2. tuples have a defi... | true |
75b576265e6714bc87460fadd1891797cc5bbcad | yashlad27/MAC-Python-basics-Jun21 | /tupleUnpack.py | 896 | 4.75 | 5 | # UNPACKING A TUPLE:
# When we creat a tuple, we normally assign values to it. This is called "packing" tuple.
fruitsT = ("apple", "cherry", "orange")
# but in Python we are allowed to extract the values back into variables.
# this is called unpacking
(green, yellow, red) = fruitsT
print(green)
print(yellow)
print(... | true |
fa2728ce4877a73cfd46ad3dbc1ab76aba2cce5c | khabib-habib/week3 | /exercises.py | 294 | 4.15625 | 4 | phrase = input("Enter the phrase: ")
# return the vowels used in the phrase
vowels = ['e', 'u', 'i', 'o', 'a']
result = []
for letter in phrase:
if letter in vowels:
result.append(letter)
print(result)
print("".join(result))
result2 = {'e':0, 'u':0, 'i':0, 'o':0, 'a':0}
| true |
71761cf997e5ddb9fbb89a5a7e5d72906461dcb3 | mehul-clou/turtle_race | /main.py | 1,130 | 4.28125 | 4 | from turtle import Turtle, Screen
import random
is_race_on = False
screen = Screen()
screen.setup(width=500, height=400)
user_guess= screen.textinput(title="Make your bet", prompt="Which Turtle Will Win the race? Enter a race")
print(user_guess)
color = ["red", "yellow", "green", "orange", "brown", "pink", "blue"]
y_... | true |
53eac1a63bbd7eae0395d4320c0d4e521aa3cd5c | lotlordx/CodeGroffPy | /type_conversion_exception_handling.py | 764 | 4.21875 | 4 | def divide_numbers(numerator, denominator):
"""For this exercise you can assume numerator and denominator are of type
int/str/float.
Try to convert numerator and denominator to int types, if that raises a
ValueError reraise it. Following do the division and return the result.
However if ... | true |
fc58262858ac1531f14a0dda380c02c7d48d431a | muremwa/Simple-Python-Exercises | /exercise_6C_text_processing.py | 1,644 | 4.125 | 4 | # Q6c) Find the maximum nested depth of curly braces
#
# Unbalanced or wrongly ordered braces should return -1
#
# Iterating over input string is one way to solve this, another is to use regular expressions
import re
def max_nested_braces(string_):
braces = []
nesting = 0
# eliminate empty braces
if ... | true |
7728d8b1f32f2c697b3a9a72bc219c7481f5df6c | Abdirahman136896/python | /areaofcircle.py | 267 | 4.4375 | 4 | #Write a Python program which accepts the radius of a circle from the user and compute the area.
import math
radius = int(input("Enter the radius of the circle: "))
x= math.pi
#area = ((22/7) * pow(radius, 2))
area = (math.pi * pow(radius, 2))
print(area) | true |
df4ee5f6f227c883f6ee5295bebab3ccb0fafb57 | Abdirahman136896/python | /tuples.py | 418 | 4.21875 | 4 | #create tuple
coordinates = (4,5)
#prints all the values in the tuple
print(coordinates)
#prints values of the tuple at a specific index
print(coordinates[0])
print(coordinates[1])
#coordinates[1] = 6 returns an error tuple object not supporting assignment because tuples are immutable
list_coordinates = [(4,5),... | true |
e3ab63a25d5169348149a7749270a1311e54342a | badlydrawnrob/python-playground | /anki/added/lists/indexes-06.py | 1,092 | 4.625 | 5 | #
# Indexes: Sort
# - List Capabilities and Functions (9)
## sort() method
################
animals = ["cat", "ant", "bat"]
animals.sort()
for animal in animals:
print animal
#### Q: What is `sort()` doing here?
#### - Explain what it defaults to (alphabetical)
#### - Note that .sort() modifies the list rather ... | true |
a6d79d3a25e37f8ccaff2e47536d41a1ddbc0e86 | badlydrawnrob/python-playground | /flask-rest-api/05/tests/user_01.py | 2,014 | 4.15625 | 4 | '''
We're allowing the user class to interact
with sqlite, creating user mappings (similar
to the functions we created in `security.py`
`usename_mapping`, `userid_mapping`)
'''
import sqlite3
class User(object):
def __init__(self, _id, username, password):
self.id = _id
self.username = username
... | true |
954e6f9ab4770826ad54bc799a054515b8ea85e2 | HashtagPradeep/python_practice | /control_flow_assignment/Assignment- Control Flow_Pradeep.py | 886 | 4.46875 | 4 | #!/usr/bin/env python
# coding: utf-8
# ---
# ---
#
# <center><h1>π π Assignment: Control Flow π π</h1></center>
#
# ---
#
# ***Take 3 inputs from the user***
#
# - **What is your Age?** (Answer will be an Intger value)
# - **Do you eat Pizza?** (Yes/No)
# - **Do you do exercise?** (Yes/No)
#
# #... | true |
7f60171c06620157ee51f79e34750848b7ade127 | AlexandruGG/project-euler | /22.py | 1,190 | 4.15625 | 4 | # Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
# For example,... | true |
49c35742888364656b980820e7278e1634aaf576 | BioGeek/euler | /problem014.py | 914 | 4.15625 | 4 | # The following iterative sequence is defined for the set of positive integers:
#
# n -> n/2 (n is even)
# n -> 3n + 1 (n is odd)
#
# Using the rule above and starting with 13, we generate the following sequence:
#
# 13 40 20 10 5 16 8 4 2 1
#
# It can be seen that this sequence (starting at 13 and finis... | true |
ffa490bae900863d83963a5d68ef29a119852d71 | lukepeeler/lukepeeler.github.io | /docs/data_generator.py | 2,970 | 4.1875 | 4 | from graphics import *
from utility import *
import random
# Generates a random 2D points.
# meanX: mean of X-axis of the underlying normal distribution, type: int
# meanY: mean of Y-axis of the underlying normal distribution, type: int
# sigmaX: standard deviation on X-axis, type: int
# sigmaY: standard deviation on ... | true |
3e0644d2a2e4c28aa63219ce205d7d67d4af2130 | PickertJoe/algorithms-data_structures | /Chapter3_Basic_Data_Structures/palindrome_checker.py | 1,234 | 4.15625 | 4 | # A program to verify whether a given string is a palandrome - Miller and Ranum
from pythonds.basic import Deque
def main():
while True:
print("~~~Welcome to the Python Palindrome Checker!~~~")
palindrome = input("Please enter the string you'd like to test: ")
tester = palchecker(palindro... | true |
e2118826da7fd3917370b40d00f0c4199dbd93bd | PickertJoe/algorithms-data_structures | /Chapter5_Searching_Sorting/bubble_sort.py | 367 | 4.25 | 4 | # A simple function to perform a bubble sort algorithm to order a numeric list. Sourced from Miller & Ranum
def bubbleSort(alist):
for iteration in range(len(alist) - 1, 0, -1):
for i in range(iteration):
if alist[i] > alist[i + 1]:
temp = alist[i]
alist[i] = al... | true |
10e1be03e36e97d938f05566b1e464a0d2e3890e | PickertJoe/algorithms-data_structures | /Chapter3_Basic_Data_Structures/unordered_list_test.py | 2,693 | 4.25 | 4 | # A program to test the function of the unordered list class
import unittest
from unordered_list import UnorderedList
class ULTestCase(unittest.TestCase):
"""Ensures proper functioning of unordered list methods"""
def test_UL_empty(self):
"""Ensures Unordered List returns correct boolean re: existan... | true |
bf2accb1d629c86bbd82f9f6ca7f7e1aa0cb550a | t6nesu00/python-mini-projects | /guessNumber.py | 739 | 4.1875 | 4 | # number guessing game
import random
guess = 0
computers_number = random.randint(0, 9)
print(computers_number)
condition = True
while condition:
user_guess = input("Guess the number (0-9) or exit: ")
if user_guess == "exit":
print("Hope to see you again.")
condition = False
elif computers_... | true |
6f68500287c37a8c41121dba41b4ace190e8460c | cyxorenv/Test | /Numbers.py | 686 | 4.40625 | 4 | # In python there is three types of numbers:
# =----------------------------------------=
# 1) x = 1 int (Integer)
# 2) y = 1.1 float (a decimal point)
# 3) z = 1 + 2j (Complex numbers)
# Standart arithmetic in python - (and any outher programming languige).
# Addition
print(10 + 3)
# Sustruction
print(10 - 3)
# M... | true |
e782dec2b7611e67f0c732cb21fc82c077d0f81f | rajiv25039/love-calculator | /main.py | 1,073 | 4.1875 | 4 | # π¨ Don't change the code below π
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
# π¨ Don't change the code above π
#Write your code below this line π
combined_name = name1 + name2
combined_name_in_lower_case = combined_name.lower()
t = com... | true |
0b4e6205d0c646eb976e18ff1bbc97c52a018a5a | Takate/hangman | /hangman_0.1.py | 2,953 | 4.125 | 4 | import random
rerun = "Yes"
while rerun == "Yes" or "Y" or "yes" or "YES":
listOfWords = ["test"]
guessWord = random.choice(listOfWords)
guessWordList = list(guessWord)
#print(guessWordList)
letterIs = []
board = [" * " for char in guessWord]
difficulty = input("\n easy - 15... | true |
b3002a921b6eccc3c318b66b5e242279b853c02b | kvssea/Python-Challenges | /palindrome.py | 845 | 4.5 | 4 | '''Create a program, palindrome.py, that has a function that takes one string argument and prints a sentence indicating if the text is a palindrome. The function should consider only the alphanumeric characters in the string, and not depend on capitalization, punctuation, or whitespace.
If your string is a palindr... | true |
2df2ddc83610a326d4e5adbc825e12351a4cd630 | a200411044/Python_Crash_Course | /name.py | 278 | 4.21875 | 4 | #This show how to format your name in Python!
name = "simon law"
print(name.title())
print(name.upper())
print(name.lower())
first_name = "simon"
last_name = "law"
full_name = first_name + " " + last_name
print(full_name)
msg = "Hello, " + full_name.title() + "!"
print(msg)
| true |
7a2eaecdf76a8a44963109bd8fc595f5e660b7aa | mslok/SYSC3010_Michael_Slokar | /Lab-3/lab3-database-demo.py | 1,095 | 4.125 | 4 | #!/usr/bin/env python3
import sqlite3
#connect to database file
dbconnect = sqlite3.connect("mydatabase");
#If we want to access columns by name we need to set
#row_factory to sqlite3.Row class
dbconnect.row_factory = sqlite3.Row;
#now we create a cursor to work with db
cursor = dbconnect.cursor();
#execute insetr stat... | true |
f656fe862e4c13070c21cf18ecf10ea973e78681 | Ausduo/Hello_World | /french toast.py | 329 | 4.125 | 4 | print ("french toast")
bread = input ("enter bread size - thick or thin?")
bread = bread.lower ()
if bread == "thick":
print ("dunk the bread a long time")
elif bread == "thin":
print ("dunk the bread quickly")
else:
print ("don't do anything with it then")
print ("Thanks for following the help ... | true |
31f648d3a317b0c5a37d1147f04ac636121a653b | DracoNibilis/pands-problem-sheet | /weekday.py | 367 | 4.4375 | 4 | # Program that outputs whether or not today is a weekday.
# Author: Magdalena Malik
#list with weekend days
weekendDays = ["Saturday", "Sunday"]
#input for day
givenDay = input("enter a day: ")
#if statement that checking if day is weekday or weekend
if givenDay in weekendDays:
print("It is the weekend, yay!")
e... | true |
e2c211c9354e0d90ca724b4cbb5ea9d466148f29 | hclife/code-base | /lang/python/practices/var.py | 245 | 4.25 | 4 | #!/usr/bin/env python3
i=5
print(i)
i=i+1
print(i)
print('Value is',i)
s='''This is a multi-line string.
This is the second line.'''
print(s)
t='This is a string. \
This continues the string.'
print(t)
width=20
height=5*9
print(width*height)
| true |
ffddaecc11fb57681fa5ce9fa520e16c0c5c86c1 | gitter-badger/python_me | /hackrankoj/ErrorAndException/incorrectregex.py | 780 | 4.28125 | 4 | #!/usr/bin/env python
# coding=utf-8
'''
You are given a string S.
Your task is to find out whether S is a valid regex or not.
Input Format
The first line contains integer , the number of test cases.
The next lines contains the string .
Constraints
Output Format
Print "True" or "False" for each test case withou... | true |
9e4dbeae2f401eecfb50daa6f60f33ed8d53f7c7 | varun-va/Python-Practice-Scripts | /GeeksforGeeks/majority_element.py | 1,009 | 4.21875 | 4 | '''
Given an array arr[] of size N and two elements x and y, use counter variables to find which element appears most in the array, x or y.
If both elements have the same frequency, then return the smaller element.
Note: We need to return the element, not its count.
Example 1:
Input:
N = 11
arr[] = {1,1,2,2,3,3,4,... | true |
7f7c3d62a0a66664b05773bcde7c450291ad06d8 | jem441/OOP | /final.py | 1,140 | 4.34375 | 4 | print("Today we will play a number game.") #Beginning of the game.
print("You will take a guess at a number and if you are correct, you win!")
from textblob import TextBlob #importing the TextBlob Python Library
inpt = input("Enter a number between 0-10:") #giving the user the option to guess a number
text = ... | true |
1a2b9a0f8c147f10f8e376c1c70d76c4f9a4c8c0 | david2999999/Python | /Archive/PDF/Sequences/Dictionaries.py | 2,674 | 4.84375 | 5 | def main():
# When you first assign to menus_specials , you β re creating an empty dictionary with the curly braces.
# Once the dictionary is defined and referenced by the name, you may start to use this style of
# specifying the name that you want to be the index as the value inside of the square brackets,... | true |
241558933826203ee70c021dfb647c7d0fc07a35 | david2999999/Python | /Archive/PDF/Objects/Object-Basic.py | 2,414 | 4.34375 | 4 | # The methods that an object makes available for use are called its interface because these methods are
# how the program outside of the object makes use of the object. They β re what make the object usable.
# The interface is everything you make available from the object. With Python, this usually means that
# all of ... | true |
150b28dfc4fc10f049ae0c4cbbf4387e3fa85801 | david2999999/Python | /Archive/PDF/Basic/String.py | 926 | 4.1875 | 4 | # When you type a string into Python, you do so by preceding it with quotes. Whether these quotes are
# single ( ' ), double( '' ), or triple( " " " ) depends on what you are trying to accomplish. For the most part, you
# will use single quotes, because it requires less effort (you do not need to hold down the Shift ke... | true |
5aac6daec9b8beb2115fd5923584f8c1a506529c | david2999999/Python | /Archive/PDF/Decision/Comparison.py | 2,401 | 4.53125 | 5 | def main():
# Equality isn β t the only way to find out what you want to know. Sometimes you will want to know
# whether a quantity of something is greater than that of another, or whether a value is less than
# some other value. Python has greater than and less than operations that can be invoked with the ... | true |
addd83aecdb01324615304c312abed1698ce99f4 | david2999999/Python | /Archive/PDF/Function/Docstring.py | 1,651 | 4.3125 | 4 | # If you place a string as the first thing in a function, without referencing a name to the string, Python will
# store it in the function so you can reference it later. This is commonly called a docstring , which is short for
# documentation string .
# Documentation in the context of a function is anything written tha... | true |
4e7a9a3efd57c5866681b9a110af532252113c63 | Blak3Nick/MachineLearning | /venv/mulitple_linear_regression.py | 2,548 | 4.125 | 4 | # Multiple Linear Regression
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('50_Startups.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 4].values
# Feature Scaling
"""from sklearn.preprocessing import Standar... | true |
45728d1d9df3c4df2a2a5c9c2ed33272c4576839 | brucez082/Car_rental | /Car_rental.Achieved.py | 2,575 | 4.25 | 4 | #-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Bruce Zhang
#
# Created: 06/09/2021
# Copyright: (c) Bruce Zhang 2021
# Licence: <your licence>
#------------------------------------------------------------------------... | true |
83f2011c420c5044dcc1eb7d31113d6f909547b5 | harrifeng/Python-Study | /Interviews/Coin_Change.py | 788 | 4.1875 | 4 | """
#####From [Geeksforgeeks](http://www.geeksforgeeks.org/dynamic-programming-set-7-coin-change/)
Similar to CC150, just allow coin with 1, 3, 5 right now
Several ways to ask
1. How many ways?
2. What are the ways?
3. Minimum coin number?
"""
# This is same to Combination Sum I
def coin_change(value):
res = [0,... | true |
7453a346480da9046278fb4f146b14c87bd9efa3 | Triballian/simprad | /src/main.py | 2,935 | 4.1875 | 4 | '''
Created on Mar 19, 2016
insprired by Curious Cheetah and Sergio
http://curiouscheetah.com/BlogMath/simplify-radicals-python-code/
http://stackoverflow.com/questions/31217274/python-simplifying-radicals-not-going-well
@author: Noe
'''
from math import modf
from math import sqrt
#from os import system
#... | true |
a863fd271a218cd39128ad624985bf64cc22c7b1 | rogerlinh/MindXSchool.github.io | /Teachingteam/Gen12X/VuongTranLuc_8/q6.py | 351 | 4.25 | 4 | # Add number at the end of a list
numberList = [1, 2, 3, 4,5]
print('Hi there, this is our sequences: ')
for number in numberList:
print(number, end=' ')
print()
newNumber = int(input('what do you want to add: '))
numberList.append(newNumber)
print('This is our new sequence: ')
for number in numberList:
... | true |
6bd8e9904b1fc9a1573512dd73214bbf37f68ce0 | pravinherester/LearnPython | /functions/calculator/Calculator6.py | 1,147 | 4.15625 | 4 | 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
from art import logo
from replit import clear
operations={
"+":add,
"-":subtract,
"*":multiply,
"/":divide,
}
def calculator():
print (logo)
num1= float (input("Enter ... | true |
fe4aaa884307c5b8b358e25b2bb2aa8dca01d1eb | PrabhatRoshan/Daily_Practice_Python | /Daily_practice_codes/if-elif-else/user_input.py | 594 | 4.21875 | 4 | # Write a python program to check the user input abbreviation.If the user enters "lol",
# print "laughing out loud".If the user enters "rofl", print "rolling on the floor laughing".
# If the user enters "lmk", print "let me know".If the user enters "smh", print "shaking my head".
user_ip=input("Enter the user inp... | true |
73a1084037267aa353163c663ce2c6ccf22b6d1b | Bamblehorse/Learn-Python-The-Hard-Way | /ex3.py | 979 | 4.3125 | 4 | #Simple print " "
print "I will now count my chickens:"
#print "string then comma", integer
print "Hens", 25 + 30 / 6
#bidmas. Brackets, indices div, mult,
#add, sub. PEMDAS. Mult first.
#so div first 30 / 6 = 5
#then 25 + 5 = 30, simples
print "Roosters", 100 - 25 * 3.0 % 4.0
#3 % 4 = 3?, 3 * 25 = 75, 100 -... | true |
3cba62c7a9bd0ef2b0a3ee2544f0296461590d11 | Vindhesh/demopygit | /calc.py | 1,111 | 4.125 | 4 |
class Calculator:
def __init__(self):
pass
def calculate(self):
answer = 0
memory = list()
while True:
input1, operator, input2 = input("Enter your first number, operator and second number with space: ").split()
input1 = float(input1)
in... | true |
74df44cb43c3fc886f1c684aab78a5864cdc6893 | SamirDjaafer/Python-Basics | /Excercises/Excercise_106.py | 868 | 4.34375 | 4 | age = input('How old are you? ')
driver_license = input('Do you have a drivers license? Yes / No ')
if driver_license == 'Yes' or driver_license == 'yes':
driver_license = True
else:
driver_license = False
# - You can vote and drive
if int(age) >= 18 and driver_license == True:
print('Nice, you can vote ... | true |
ecf1eaf7b05d97214568ab6fc69c31a41f74fd4f | ssiddam0/Python | /Lab7/lab7-13_Sowjanya.py | 1,176 | 4.28125 | 4 | # program - lab7-13_sowjanya.py 26 April 2019
'''
This program simulates a Magic 8 Ball game, which is a fortune-telling toy
that displays a random response to a yes or no question. It performs the
following actions:
1) Reads the 12 responses from the file named 8_ball_responses.txt
2) Prompts the user to ask... | true |
d0c72888e33db08b24f9c9e0b6e089665561fc9b | JackStruthers/CP1404_Practicals | /CP1404_Practicals/week_02/average_age.py | 410 | 4.15625 | 4 | age = int(input("Please enter the age of a person (use a negative if there are no more people): "))
collective_age = 0
people = 0
while age >= 0:
people += 1
collective_age += age
age = int(input("Please enter the age of a person (use a negative if there are no more people): "))
if people == 0:
print(... | true |
7fe329824f1077f9f49f8b6595bbfbd9abe1cb75 | rahulraghu94/daily-coding-problems | /13.py | 670 | 4.125 | 4 | """
Good morning! Here's your coding interview problem for today.
This problem was asked by Amazon.
Given an integer k and a string s, find the length of the longest substring
that contains at most k distinct characters.
For example, given s = "abcba" and k = 2, the longest substring with k distinct
characters is "b... | true |
02aae668f0f2be658aefa800ad3e22eac941a801 | makoalex/Python_course | /Regular expressions/functions_RE.py | 1,084 | 4.34375 | 4 | import re
# making a function that extracts a phone number and all phone numbers in a given sequence
def extract_phone(input):
phone_regex = re.compile(r'\b\d{3} \d{4}-?\d{3}\b')
match = phone_regex.search(input)
if match:
return match.group()
return None
def extract_all_phone(input):
p... | true |
92d0d3047686d2b0f01898d074e5b585df4e1052 | makoalex/Python_course | /Iterator.py | 2,040 | 4.375 | 4 | # the for loop runs ITER in the background making the object an iterator after which it calls next
# on every single item making the object an iterable
def my_loop(iterable):
iterator = iter(iterable)
while True:
try:
it = next(iterator)
print(it)
except StopIteration:
... | true |
77164c1cfa58f37069bc368e79ab0268c12d5645 | WeikangChen/algorithm | /data_struct/tree/trie0b.py | 1,807 | 4.15625 | 4 | class TrieNode(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.value = None
self.children = {}
class Trie(object):
def __init__(self):
self.root = TrieNode()
def insert(self, word):
"""
Inserts a word ... | true |
146a08687142b1a7ed5a341541616d637b308056 | rolandoquiroz/hackerrank_coderbyte_leetcode | /list2.py | 1,260 | 4.375 | 4 | #!/usr/bin/python3
"""
Find Intersection
Have the function FindIntersection(strArr)
read the array of strings stored in strArr
which will contain 2 elements: the first element
will represent a list of comma-separated numbers
sorted in ascending order, the second element will
represent a second list of comma-separated n... | true |
8985c182f0d906b520962503eae94659bb7c6553 | dongrerohan421/python3_tutorials | /09_if_else.py | 522 | 4.15625 | 4 | '''
This program shows use of If-Else conditional statement.
1. Your condition doesn't starts with indentations or tab.
2. statment inside the condition starts with indentation or tab.
3. Once condition satisfied, next statement must starts with new line with no indentation or no tab.
'''
n = int(input("Number: "))
... | true |
baf9a7f27bbb8bb66f3565d3b3be2daf9651d090 | dongrerohan421/python3_tutorials | /06_strings.py | 686 | 4.34375 | 4 | '''
This program explains Pytho's string
'''
# Escape character usefule to jump over any character.
# Use double back slash to print back slash in your output.
a = 'I am \\single quoted string. Don\'t'
b = "I am \\double quoted string. Don\"t"
c = """I am \\triple quoted string. Don\'t"""
print (a)
print (b)
print (... | true |
675c80d6f783c90bcec8fc34cb91ddff2ebdfe61 | nmounikachowdhary/mounikan28 | /firstassignment.py | 2,373 | 4.3125 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
# Python Program - Calculate Circumference of Circle
print("Enter 'x' for exit.");
rad = input("Enter radius of circle: ");
if rad == 'x':
exit();
else:
radius = float(rad);
circumference = 2*3.14*radius;
print("\nCircumference of Circle =",circumferenc... | true |
7859e5d4e892f162c23a96dc1a7480f556f28fef | Josglynn/Public | /List Less Than Ten.py | 1,487 | 4.75 | 5 | # Take a list, say for example this one:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# Write a program that prints out all the elements of the list that are less than 13.
list_num = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
filtered_1 = [item for item in list_num if item < 13] # Comprehensions style
print(filt... | true |
0bfc7cae00049db8f2bee365c4d85001c0a92e62 | michaelschuff/Python | /DailyCodingChallenge/201.py | 499 | 4.21875 | 4 | #You are given an array of arrays of integers, where each array corresponds to a row in a triangle of numbers. For example, [[1], [2, 3], [1, 5, 1]] represents the triangle:
# 1
# 2 3
#1 5 1
#We define a path in the triangle to start at the top and go down one row at a time to an adjacent value, eventually ending wit... | true |
25cb09b0c2f6330633749615ec5264f7a8f3245d | jabedkhanjb/Hackerrank | /30-Days-of-Code/Day 26:_Nested Logic.py | 2,276 | 4.25 | 4 | """
Objective
Today's challenge puts your understanding of nested conditional statements to the test. You already have the knowledge to complete this challenge, but check out the Tutorial tab for a video on testing.
Task
Your local library needs your help! Given the expected and actual return dates for a library book,... | true |
3ca41732ad78e387b0d4eb6af55b65cbd08d19be | jabedkhanjb/Hackerrank | /Python/String/Text_Wrap.py | 570 | 4.15625 | 4 | '''
Task
You are given a string and width .
Your task is to wrap the string into a paragraph of width .
Input Format
The first line contains a string, .
The second line contains the width, .
Output Format
Print the text wrapped paragraph.
Sample Input
ABCDEFGHIJKLIMNOQRSTUVWXYZ
4
Sample Output
ABCD
EFGH
IJKL
IMN... | true |
63d0bdef7cc2dab2c6bbc15a51f3e5061485d23f | jabedkhanjb/Hackerrank | /30-Days-of-Code/Day16:_Exceptions.py | 1,756 | 4.53125 | 5 | """
Objective
Today, we're getting started with Exceptions by learning how to parse an integer from a string and print a custom error message. Check out the Tutorial tab for learning materials and an instructional video!
Task
Read a string, , and print its integer value; if cannot be converted to an integer, print Ba... | true |
3515dd6d4de9cea5f774213bc7c4bef6af4d97e5 | jabedkhanjb/Hackerrank | /Python/String/Capatilize.py | 1,250 | 4.40625 | 4 | """
You are asked to ensure that the first and last names of people begin with a capital letter in their passports.
For example, alison heck should be capitalised correctly as Alison Heck.
Given a full name, your task is to capitalize the name appropriately.
Input Format
A single line of input containing the full name... | true |
c91d3ef1c333c85daf6cfca9de9962d25675b640 | jabedkhanjb/Hackerrank | /10_Days_of_Statistics/Day0/Mean_Median_Mode.py | 2,255 | 4.375 | 4 | """
Objective
In this challenge, we practice calculating the mean, median, and mode. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given an array, , of integers, calculate and print the respective mean, median, and mode on separate lines. If your array contains more than one modal... | true |
f651b61ddacc18b64492fe337fbc3fbf0653f86a | yoginee15/Python | /venv/Conditions.py | 332 | 4.3125 | 4 | x = int(input("Enter number"))
r = x%2
if r==0:
print("You entered even number")
else:
print("You entered odd number")
if x>0:
print("You entered positive number")
elif x<0 :
print("You entered negative number")
elif x==0:
print("You entered zero")
else :
print("Please enter number. You entered... | true |
85da073031a62446c1e48e915337b04f76a268ba | numeoriginal/multithread_marketplace | /consumer.py | 2,118 | 4.25 | 4 | """
This module represents the Consumer.
Computer Systems Architecture Course
Assignment 1
March 2021
"""
import time
from threading import Thread
class Consumer(Thread):
"""
Class that represents a consumer.
"""
def __init__(self, carts, marketplace, retry_wait_time, **kwargs):
Thread.__in... | true |
bfc1b1dbc57b1f755badff44a4fee261a2d9247a | EladAssia/InterviewBit | /Binary Search/Square_Root_of_Integer.py | 990 | 4.15625 | 4 | # Implement int sqrt(int x).
# Compute and return the square root of x.
# If x is not a perfect square, return floor(sqrt(x))
# Example :
# Input : 11
# Output : 3
##########################################################################################################################################
class Solut... | true |
141a8525869b6a6f2747b61228f70224ae2fcc63 | EladAssia/InterviewBit | /Two Pointers Problems/Merge_Two_Sorted_Lists_II.py | 1,452 | 4.125 | 4 | # Given two sorted integer arrays A and B, merge B into A as one sorted array.
# Note: You have to modify the array A to contain the merge of A and B. Do not output anything in your code.
# TIP: C users, please malloc the result into a new array and return the result.
# If the number of elements initialized in A and ... | true |
38bd841245ca882be8cbade1bc9648aee3ea9073 | EladAssia/InterviewBit | /Hashing/Anagrams.py | 1,774 | 4.125 | 4 | # Given an array of strings, return all groups of strings that are anagrams. Represent a group by a list of integers representing the
# index in the original list. Look at the sample case for clarification.
# Anagram : a word, phrase, or name formed by rearranging the letters of another, such as 'spar', formed from '... | true |
c7cc0ced10bcf0bf1bb0e4da0cd97fc978ac9dd6 | zk18051/ORS-PA-18-Homework05 | /task6.py | 718 | 4.375 | 4 | """
=================== TASK 6 ====================
* Name: Typewriter
*
* Write a script that will take file name as user
* input. Then the script should take file content
* as user input as well until user hits `Enter`.
* At the end, the script should store the content
* into the file with given name. If the file... | true |
f285ba64dd8d68b96db0f7430fe2cf8a9bb111d3 | fatpat314/SPD1.4 | /Homework2/leet_code.py | 2,473 | 4.15625 | 4 | # Q1
"""Given an array of integers, return indices of the two numbers
such that they add up to a specific target"""
# restate question
'''So we have an array of ints. we want to return the position of the index
of two numbers that add to our target number'''
# clearifying questions
'''None'''
# assumptions
'''No neg... | true |
54f4b9f4d9b00e05ccf0e06ae96051cea6873fae | Chewie23/fluffy-adventure | /CodingTestForOpenGov/SortListAndOutputElement.py | 913 | 4.25 | 4 | from random import randrange
from heapq import nlargest
def organize_and_pull_K_biggest_num(num_of_elem, Kth):
if Kth <= 0 or Kth > num_of_elem:
print("That number is out of range!")
exit(0)
num_list = []
for n in range(num_of_elem):
num_list.append(randrange(-100, 100))
pr... | true |
2eea86811100bc9b0d3641ce9b31f58c503fa58d | Tweek43110/PyPractice | /Loops.py | 1,679 | 4.1875 | 4 | # There are two type of loops available FOR and WHILE
# FOR examples
simpleTest = [1,2,3,4]
for number in simpleTest:
print(number)
# another useful example
for i in range(12, 20):
print(i)
for evenNumbers in range(0,20,2):
print(evenNumbers)
# WHILE examples
x = 0
while x < 5:
print(x)
x += 1
#... | true |
46d626b6ae270bca958857b813b6baea359b8804 | hongkailiu/test-all | /trunk/test-python/script/my_exception.py | 922 | 4.1875 | 4 | #!/usr/bin/python
def kelvin_to_fahrenheit(temperature):
"""test exception"""
assert (temperature >= 0), "Colder than absolute zero!"
return ((temperature - 273) * 1.8) + 32
print kelvin_to_fahrenheit(273)
print int(kelvin_to_fahrenheit(505.78))
# will raise an exception
# print kelvin_to_fahrenheit(-5)... | true |
382861d6c759a0954249f94c18732f562183bebf | jahick/pythonSamples | /convert.py | 901 | 4.1875 | 4 | # Put your code here
decimal = int(input("Enter an integer: "));
base = int(input("Enter a base number to convert to. (2, 8, 10, 16): "));
def decimalToRep(decimal,base):
if base == 10:
return decimal;
elif base == 2:
return str(bin(decimal)[2:]);
elif base == 8:
return oct(decimal)... | true |
aacf2efce41b7894a1e69ab400e9efdffcb16758 | goosen78/simple-data-structures-algorithms-python | /bubble_sort.py | 912 | 4.4375 | 4 | #!/usr/bin/env python3
"""
Bubble Sort Script
"""
def bubble_sort(L):
"""
Sorts a list in increasing order. Because of lists are mutable
this function does not have to return something.
This algorithm uses bubble sort.
@param L: a list (in general unsorted)
"""
for i in... | true |
81c3ccbe5b8b5a1464a2244761a38c18f60e265d | imrajashish/python-prog | /heap&queu.py | 789 | 4.4375 | 4 | #Write a Python program to find the three largest integers from a given list of numbers using Heap queue algorithm
import heapq
h = [12,34,56,786,56,45,3,453]
print("Three largest number in list: ")
print(heapq.nlargest(3,h))
#Write a Python program to find the three smallest integers from a given list of numbers usin... | true |
3d7582f3f5e45f2d1819763c4e96a3b4c5e26bb8 | imrajashish/python-prog | /list2.py | 550 | 4.625 | 5 | #Write a Python program to extract the nth element from a given list of tuples.
def extract_nth_element(test_list, n):
result = [x[n] for x in test_list]
return result
students = [('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)]
print ("Original list:")
p... | true |
95bd03109ce74e6f3207be3dfa2f7ff15cd26840 | imrajashish/python-prog | /lambda2.py | 2,376 | 4.34375 | 4 | #Write a Python program to sort a list of dictionaries using Lambda.
models = [{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':'2', 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}]
print("\n originals dict in model:")
print(models)
sorted_models = sorted(models,key = lambda x:x... | true |
c0ef45938c2daadcd8095d36ef7037c502ad0fc1 | imrajashish/python-prog | /lambda3.py | 2,251 | 4.28125 | 4 | #Write a Python program to find intersection of two given arrays using Lambda
num1 = [1,2,3,4,5,6,7,8,7]
num2 = [3,4,5,6,6,8,8,9,8,7]
print("\n original arrays:")
print(num1)
print(num2)
result = list(filter(lambda x: x in num1,num2))
print("\n Intersection of the said array: ",result)
#Write a Python program to rearr... | true |
d1f0d16d6f96eeec6981e70ead1cf21d33762dd3 | brianchun16/PythonPractices | /Lecture04/practice1_while.py | 238 | 4.15625 | 4 | x = int(input('Enter an integer: '))
x = abs(x)
ans = 0
while ans**3 < x:
ans = ans+1
if ans**3 == x:
print('X is a perfect cube')
print('The X value is: ', ans)
else:
print('X is not a perfect cube')
print('The X value is:', ans)
| true |
ff0b42c3fd172deb291c9e510b3f1cff9ef61497 | nikhilgurram97/CS490PythonFall2017 | /Lab Assignment 1/gameboard.py | 611 | 4.25 | 4 | hinp=int(input("Enter Height of Board : "))
winp=int(input("Enter Width of Board : ")) #For taking input height and input width respectively
def board_draw(height,width): #Initializing a drawing function
for j in range(0,height): #In this loop, the reverse shaped '... | true |
1a4d6a0fc3ae833fa1bb09a2130c9d11eab3417a | plammens/python-introduction | /Fundamentals I/Elements of Python syntax/Statements expressions/main.py | 1,011 | 4.40625 | 4 | # ----- examples of statements (each separated by a blank line): -----
import math # import statement
my_variable = 42 # assignment statement
del my_variable # del statement
if __name__ == '__main__': # if statement
print('executing as script') #
else: #
... | true |
a2b0fd51ade7db2efafb76fab1291b73ccf516af | rduvalwa5/Examples | /PythonExamples/src/PyString.py | 2,687 | 4.21875 | 4 | '''
Created on Mar 24, 2015
@author: rduvalwa2
https://docs.python.org/3/library/string.html?highlight=string#module-string
https://docs.python.org/3/library/stdtypes.html#string-methods
This is how to reverse a string
http://stackoverflow.com/questions/18686860/reverse-a-string-in-python-without-using-reversed-or-1
'... | true |
65059eda46952316221245f7b021616acb7b7c87 | Exubient/UTCS | /Python/Assignment 4/assignment4.py | 2,830 | 4.15625 | 4 | """
Assignment 4: Metaprogramming
The idea of this assignment is to get you used to some of the dynamic
and functional features of Python and how they can be used to perform
useful metaprogramming tasks to make other development tasks easier.
"""
#Hyun Joong Kim
#hk23356
import functools
import logging
... | true |
537fc9c10ae830cd564ae892235719b048178bb3 | johncmk/cloud9 | /rec_pointer.py | 726 | 4.3125 | 4 | '''
Updating the el in the li while
traversing in recursion can effect the
changes of original value of the li in running time because
its updating the value via address.
Updating the value that is pass by value
through recursion would not change the orginal value
beause it copies the value before it goes into the
nex... | true |
2b4c15c744d01b2a58a72f47a4b9bcca85336c2c | johncmk/cloud9 | /qsort_CLRS.py | 792 | 4.125 | 4 | '''This function takes last element as pivot,
places the pivot element at its correct position in sorted array,
and places all smaller (smaller than pivot)
to left of pivot and all greater elements to right of pivot'''
def partition(arr,low,high):
i = (low-1)
pivot = arr[high]
''''''
for j in... | true |
fe0846d78614934ff88ecbe3a04dc09e9b77e9b4 | johncmk/cloud9 | /Perm_Comb.py | 1,351 | 4.3125 | 4 | '''Factorial function means to multiply
a series of descending natural number 3! = 3 x 2 x 1
Note: it is generally agreed that 0! = 1.
It may seem funny that the multiplying no numbers
together gets us 1, but it helps simplify a lot
of equation.'''
'''non-tail recursion;
waste more memory when n is big integer
... | true |
97dc89fba3c044b3da16e5fcf6468ecd45d33efb | timvan/reddit-daily-programming-challenges | /multiplication_table.py | 569 | 4.21875 | 4 | # Multiplication Table
# Request two numbers and create the multiplication table of those numbers
def start():
print ("Welcome to multiplication table emulator!")
print ("Choose two numbers to create a multiplication table!")
while True:
N1 = raw_input("Number 1:")
try:
N1 += 1
except TypeError:
... | true |
59dd3f87c0c58dc421fcf023143edc716299389c | darloboyko/py_courses | /codewars/kata_7/NegativeConnotation_04.py | 1,214 | 4.46875 | 4 | #You will be given a string with sets of characters, (i.e. words), seperated by between one and
# three spaces (inclusive).
#Looking at the first letter of each word (case insensitive-"A" and "a" should be treated the same),
# you need to determine whether it falls into the positive/first half of the alphabet ("a"-"m... | true |
46b238bee670488bed3f121c59febe2abce590c3 | darloboyko/py_courses | /codewars/kata_8/task_01.py | 1,169 | 4.28125 | 4 | '''David wants to travel, but he doesn't like long routes. He wants to decide where he will go, can you tell him
the shortest routes to all the cities?
Clarifications:
David can go from a city to another crossing more cities
Cities will be represented with numbers
David's city is always the number 0
If there isn't any... | true |
609d502011f4d6dbb5bac47aaa2f8c93a7a7819f | darloboyko/py_courses | /codewars/kata_7/comfortableWords_04.py | 1,348 | 4.1875 | 4 | #A comfortable word is a word which you can type always alternating the hand you type with
#(assuming you type using a QWERTY keyboard and use fingers as shown in the image below).
#That being said, create a function which receives a word and returns true/True if it's a
# comfortable word and false/False otherwise.
#... | true |
f6ce75e92016710e60e625e80adfb0911d7b44ec | darloboyko/py_courses | /codewars/kata_7/niceArray_03.py | 575 | 4.21875 | 4 | #A Nice array is defined to be an array where for every value n in the array, there is also an
# element n-1 or n+1 in the array.
#example:
#[2,10,9,3] is Nice array because
#2=3-1
#10=9+1
#3=2+1
#9=10-1
#Write a function named isNice/IsNice that returns true if its array argument is a Nice array, else false.
# You s... | true |
771ca2a109d51e3aa667106e3b44c071a1cb86f3 | SigmaQuan/BOOK-CODE-Learning.Python.The.Hard.Way | /lesson_13.py | 2,667 | 4.90625 | 5 | """
Exercise 13: Parameters, Unpacking, Variables
In this exercise we will cover one more input method you can use to pass
variables to a script (script being another name for you .py files). You
know how you type python lesson_03.py to run the lesson_03.py file? Well
the lesson_13.py part of the comman... | true |
308bdfde1b97e5dc0f719c1c620d257479c55464 | SigmaQuan/BOOK-CODE-Learning.Python.The.Hard.Way | /lesson_18.py | 2,333 | 4.75 | 5 | """
Exercise 18: Name, Variables, Code, Functions
Functions do three things:
1. They name pieces of code the way variables name strings and
numbers.
2. They take arguments the way your scripts take argv.
3. Using 1 and 2 they let you make your own "mini-scripts" or
"tiny comm... | true |
14626d6e41bbc14f2569725273aa3aad5210d8cf | SigmaQuan/BOOK-CODE-Learning.Python.The.Hard.Way | /lesson_20.py | 1,703 | 4.46875 | 4 | """
Exercise 20: Functions and Files
"""
from sys import argv
# get the input file name from terminal
[script, input_file] = argv
def print_all(f):
# output a whole file
print f.read()
def rewind(f):
# jump to the beginning of a file
f.seek(0)
def print_a_line(line_count, f):
# output a line... | true |
46f2a1f6ce47d9f80f71ef4250d3b3389068f2ca | SigmaQuan/BOOK-CODE-Learning.Python.The.Hard.Way | /lesson_23.py | 2,091 | 4.46875 | 4 | """
*****
Exercise 23: Read Some Code
You should have spent the last week getting your list of symbols straight
and locked in your mind. Now you get to apply this to another week of
reading code on the internet. This exercise will be daunting at first.
I'm going to throw you in the deep end for a few da... | true |
230bba3cff67045255bc24d2d6b6702a42d0fb75 | tmcook23/NICAR-2016 | /intro-to-python/part2/2_files.py | 739 | 4.15625 | 4 | # Import modules
import csv
# Write a function that accepts one file name as an argument.
# The function should print each row from a csv file as well as each row's length and its type.
def output_rows_from(file_name):
# Open the csv
csv_file = open(file_name, 'rb')
# Create the object that represents the data i... | true |
59665fb98044dc3610126dd3b08b1cc43ce0b8d7 | tmcook23/NICAR-2016 | /intro-to-python/part1/1_workingwintegers.py | 1,402 | 4.375 | 4 |
#INTEGERS
#In programming, an integer is a whole number. You can do all sorts of math on integers,
#just like you'd do with a calculator or in Excel or a database manager.
2+2
5*5
# In the command line Python interpreter, these results will always show up.
# But if you run an entire Python (.py) program, however ... | true |
51a776bb343bb4b917107e5f6009760141ed134b | akjha013/Python-Rep | /test7.py | 791 | 4.21875 | 4 | #LOOP PRACTICE EXAMPLE PYTHON
command = ""
hasStarted = False
hasStopped = True
while True:
command = input('>').lower()
if command == 'start' and hasStarted is False:
print('Car has started')
hasStopped = False
hasStarted = True
elif command == 'start' and hasStarted is True:
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.