blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
d1656696811a0a9d02b392c66583e2ef9c01712b | KurskiySergey/Python_Algos | /Урок 1. Практическое задание/task_7.py | 1,709 | 4.53125 | 5 | """
7. По длинам трех отрезков, введенных пользователем,
определить возможность существования треугольника,
составленного из этих отрезков. Если такой треугольник существует,
то определить, является ли он разносторонним, равнобедренным или равносторонним.
"""
try:
LENGTH_1 = float(input("Введите длину первого отре... | false |
7f32e5b9b10dc2808100d1375870e20a731584c4 | yyogeshchaudhary/PYTHON | /4oct/defaultArrgumet.py | 557 | 4.25 | 4 | # /usr/bin/python
'''
Default Arrgument:
def functionName(var1, var2, var3=10)
var3=10 : is called as default arrgument and we can call function with 2 or 3 parameters
if we call the function with 3 parameter then it will override the value of var3 with given value
every default parameter should be trailing param... | true |
35bf8abfac68432e60f458c2797b7457216e84f1 | 1907cloudgcp/project-0-MasterKuan | /src/main/python/com/revature/client/controller/settingsmenu.py | 1,512 | 4.125 | 4 | HIDE = 0
# Run until exit
def run_settings_menu():
while True:
print("Hide is " + str(HIDE))
action = settings_menu()
if action == 0:
return 0
elif action == 1:
change_hide_password()
def get_hide():
global HIDE
return HIDE
# Get user input until... | false |
2cdf3ee23e4db1ec39810a47d712c50e4cf479ba | iconoeugen/swe | /sorting/select.py | 810 | 4.3125 | 4 | #!/usr/bin/python
"""Selection sort
Time complexity:
Big-Oh: O(n^2)
Big-Omega: O(n^2)
Big-Theta: O(n^2)
Space complexity:
O(1)
"""
def sort(list):
l = len(list)
steps = 0
for i in range(0, l-1):
min_idx = i
for j in range(i+1, l):
if list[min_idx] > list[j]... | false |
12cb04c632d16225961d5c466e49d7ec10c0c1a6 | mtbottle/mts_project_euler_exercises | /ex9.py | 563 | 4.34375 | 4 | # -*- coding: utf-8 -*-
from math import *
#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.
if __name__ == "__mai... | false |
1d63d6434cdcacf5cbde78f8be2dbfc2799362d9 | ciaocamilo/ejemplos-python | /condicionales1.py | 1,426 | 4.4375 | 4 | numero = 57
# if numero > 0:
# print("El número es positivo")
# else:
# if numero < 0:
# print("El número es negativo")
# else:
# if numero == 0:
# print("El numero es cero")
# if numero > 0:
# print("El número es positivo")
# elif numero < 0:
# print("El número es nega... | false |
9f574d8b2d828a1a8fb24e8c1b67e58216280c0a | ramon-ortega/codigo-python | /CodigoDePractica/CodigoPython/condicionales.py | 1,157 | 4.1875 | 4 | ##x = input('escoge x: ')
##y = input('escoge y: ')
##if x > y:
#print x, "es mas grande que", y
## print('{x} es mas grande que {y}'.format(x=x, y=y))
#otra forma de hacerlo es por posicion, example: print('{0} es mas grande que {1}'.format(x,y))
##else:
## print y, "es mas grande que ", x
##print('-------... | false |
e0c552546a75f7badedb0dfb01dc15aeae9e24fc | Omega97/Learning-Python | /_B_Simple/Copy.py | 1,275 | 4.25 | 4 | """
The difference between assignation, shallow copy and deep copy
"""
from utils import title
@title
def no_copy():
""" no copy """
a = [['a', 'a'], ['a', 'a']]
print('old a =', a)
b = a
b[0] = ['b']
b[1][0] = 'b'
b[1][1] = 'b'
print('new a =', a)
print(' b =', ... | false |
e68a23472e159c441441ea14858974259091d9ab | Harshsa28/CLRS_exercises_codes | /22_1_3.py | 280 | 4.1875 | 4 | x = {}
x[1] = [2]
x[2] = [4]
x[3] = [1,2]
x[4] = [3]
print(x)
def transpose(adj_list):
y = {}
for i in adj_list:
for j in adj_list[i]:
if j in y:
y[j].append(i)
else:
y[j] = [i]
print(y)
transpose(x)
| false |
d4604f0b95fbedcb2fcec35b8f60974177a84235 | Eraydis/Test-tasks | /test_task1.py | 812 | 4.25 | 4 |
# '''Имеется функция StringChallenge(strArr), использующая параметр StrArr, который содержит только один элемент,
#Возвращая строку true, если это валидное число, которое содержит только цифры с правильно расставленными разделителями и запятыми, а обратном случае возвращает строку false'''
import re
def Strin... | false |
6470c1ac40bdb0694f525f3796da2cd29e6f0950 | yunusarli/Quiz | /questions.py | 1,717 | 4.21875 | 4 | #import sqlite3 module to keep questions in a database.
import sqlite3
# Questions class
class Questions(object):
def __init__(self,question,answer,options=tuple()):
self.question = question
self.answer = answer
self.options = options
def save_question_and_answer(self):... | true |
d4bb5a83bf83ed0f3b9b427a45c77dbdd2cf733a | emilypng/python-exercises | /Packt/act11.py | 253 | 4.28125 | 4 |
def fib_recursive(n):
if n<2:
return n
else:
return fib_recursive(n-2)+fib_recursive(n-1)
user_input = eval(input("Enter a number to take the factorial of: "))
input_factorial = fib_recursive(user_input)
print(input_factorial)
| false |
30ed215f931ffdcde9dc2e8853f15a00a66b6e00 | Wajahat-Ahmed-NED/WajahatAhmed | /harry diction quiz.py | 253 | 4.1875 | 4 | dict1={"set":"It is a collection of well defined objects",
"fetch":"To bring something",
"frail":"weak",
"mutable":"changeable thing"}
ans=input("Enter any word to find its meaning")
print("The meaning of ",ans,"is",dict1[ans]) | true |
fd38fc531606f37eb343d17e9ddf100667ea508c | Reena-Kumari20/Dictionary | /w3schoolaccessing_items.py | 870 | 4.28125 | 4 | #creating a dictionary
thisdict={
"brand":"ford",
"model":"mustang",
"year":1964
}
print(thisdict["brand"])
print(thisdict.get("brand"))
#dictionary_length
#to determine how many items a dictinary has,use the len()function.
print(len(thisdict))
#dictionary items-data types
thisdict={
"brand":"ford",
"ele... | true |
ff6f7c387ee332af8b00b5a819a8572c86750790 | tanglan2009/mit6.00 | /FinalExam/P6.py | 1,336 | 4.34375 | 4 | class Frob(object):
def __init__(self, name):
self.name = name
self.before = None
self.after = None
def setBefore(self, before):
# example: a.setBefore(b) sets b before a
self.before = before
def setAfter(self, after):
# example: a.setAfter(b) sets b after a
... | false |
50dd82e6795ef4d215f1da9025bba21609bdedbd | HarshPonia/Python_Programs | /Numbers.py | 782 | 4.4375 | 4 | # In python We have Three numbers
# 1. int
# 2. float
# 3. Complex
# Ex 1:-
a= 25
print(type(a)) #int
b = -30
print(type(b)) #int
# Ex 2:-
c = 1.0
print(type(c)) #float
d = -20.25
print((type(d))) # float
# Ex 3:-
e = 2j
print(type(e)) # complex
f = -4+5j
print(type(f)) # complex
# Convert Numb... | false |
790354fe9432f1cf7a4a6aa7d9db3f68ed2b41b0 | HarshPonia/Python_Programs | /Pattern/Apattern.py | 261 | 4.15625 | 4 | n = 8
for i in range(0,n):
if i == 0:
print(" ",end = "")
print("@",end = "")
print("\r")
for i in range(0,n//2):
print("@ @")
for i in range(0,n+2):
print("@",end = "")
print("\r")
for i in range(0,n//2):
print("@ @") | false |
4f9aab2c40c2bfd8ccae05264fc3243efd3da3f4 | KrShivanshu/264136_Python_Daily | /ProgramsForSubmission/ListIntoNestedDict.py | 221 | 4.125 | 4 | """
Write a Python program to convert a list into a nested dictionary of keys
"""
my_list = ['a','b','c','d','e']
my_dict = current = {}
for ele in my_list:
current[ele] = {}
current = current[ele]
print(my_dict) | false |
3044aa9396d2a3481d652a64f99db78253d88d71 | KrShivanshu/264136_Python_Daily | /Collatz'sHypothesis.py | 420 | 4.125 | 4 | """ Write a program which reads one natural number and executes
the above steps as long as c0 remains different from 1.
We also want you to count the steps needed to achieve the goal.
Your code should output all the intermediate values of c0, too.
"""
c0 = int(input("Enter a number: "))
step = 0
while c0!=1:
if ... | true |
0f46661eb4208c064f2badee1a0322bae583b6fa | johnsogg/play | /py/tree.py | 1,997 | 4.34375 | 4 | class Tree:
"""A basic binary tree"""
def __init__(self):
self.root = None
def insert(self, node):
if (self.root == None):
self.root = node
else:
self.root.insert(node)
def bulk_insert(self, numbers):
for i in numbers:
n = Node(i... | true |
53b033db25faa95074a34e44b1fc095a5abd7824 | ltoshea/py-puzzles | /lowestprod.py | 805 | 4.1875 | 4 | """Create a function that returns the lowest product of 4 consecutive numbers in a given string of numbers
This should only work is the number has 4 digits of more. If not, return "Number is too small".
lowest_product("123456789")--> 24 (1x2x3x4)
lowest_product("35") --> "Number is too small"
lowest_product("1234111")-... | true |
625b5c1642c07a17d591b3af07c99cb65ab2070c | DipanshKhandelwal/Unique-Python | /PythonTurtle/turtle_circle/turtle_circle.py | 1,053 | 4.3125 | 4 | import turtle
''' this moves turtle to make a square
even tells us how to configure our turtle like changing its speed ,color
shape etc'''
def turtle_circle():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
''' Inputs be like :
turtle... | true |
ac0b9c7cbd00ba13b6f5409556cafaf60460ba96 | Tabsdrisbidmamul/PythonBasic | /Chapter_9_classes/02 three_restaurant.py | 1,260 | 4.40625 | 4 | class Restaurant:
"""a simple to stimulate a restaurant"""
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
"""will define what the restaurant is"""
print(self.restauran... | true |
35d6f1f370cdf61b6bf1f496e08d0ea329d64995 | Tabsdrisbidmamul/PythonBasic | /Chapter_8_functions/15 import_modules.py | 301 | 4.1875 | 4 | import math as maths # import maths module
def area_of_a_circle(radius):
"""finds area of a circle, argument is radius"""
area = round(pi * radius, 2)
return area
pi = maths.pi
# call function, which will give me the area of a circle
circle_0 = area_of_a_circle(50)
print(circle_0)
| true |
c17a03c48b288270bf1bb671f8dca1fa6fbace24 | Tabsdrisbidmamul/PythonBasic | /Chapter_10_files_and_exceptions/01 learning_python.py | 766 | 4.34375 | 4 | # variable to hold file name
file = 'learning_python.txt'
# use open function to open file, and print the contents three times
with open(file) as file_object:
content = file_object.read()
print(content, '\n')
print(content, '\n')
print(content, '\n')
print('indent\n')
# open the file and read through each line a... | true |
0ac565e0d4d3b948dcf0d8767039d6ccb2d9f71d | Tabsdrisbidmamul/PythonBasic | /Chapter_10_files_and_exceptions/04 guest_book.py | 448 | 4.1875 | 4 | # program that asks the user name, once entered print a prompt to say it was
# accepted and append the string onto the file
filename = 'programming.txt'
while True:
userName = str(input('What is your name? '))
print('Welcome ', userName)
with open(filename, 'a') as file_object:
# the \n is required, as the write... | true |
3c5b8e6838f2ebead83149f9e35c12f3c7a9b96c | Tabsdrisbidmamul/PythonBasic | /Chapter_7_user_inputs_and_while_loops/08 dream_vacation.py | 819 | 4.28125 | 4 | # set an empty dictionary to be filled up with polling later
responses = {}
# make a flag set to true
polling_active = True
while polling_active:
# prompt for user's name and their destination
name = input('\nWhat is your name: ')
dream_vacation = input('What place is your dream vacation? ')
# store ... | true |
24c95a3ab3e6b6e6a6cfa4ab1fbfc0f43dbf9409 | GudjonGunnarsson/python-challenges | /codingbat/warmup1/9_not_string.py | 884 | 4.40625 | 4 | #!/usr/bin/python3
""" This challenge is as follows:
Given a string, return a new string where
"not" has been added to the front. However,
if the string already begins with "not",
return the string unchanged.
Expected Results:
'candy' -> 'not candy'
'x' -> 'not x'
'n... | true |
915deca3aed8bb835c8d915589a91e5f02cf3f49 | DocAce/Euphemia | /dicey.py | 2,108 | 4.1875 | 4 | from random import randint
def roll_die(sides):
return randint(1, sides)
def flip_coin():
if randint(0, 1) == 0:
return 'Heads'
else:
return 'Tails'
def generate_coin_flip_output(args):
numflips = 1
# just use the first number we find as the number of coins to flip
for arg in ... | true |
fc27b4861ef7c7fcd503acac082b04843a94c665 | Ascarik/PythonLabs | /Ch06/Lab08.py | 638 | 4.21875 | 4 | # Converts from Celsius to Fahrenheit
def celsiusToFahrenheit(celsius):
return (9 / 5) * celsius + 32
# Converts from Fahrenheit to Celsius
def fahrenheitToCelsius(fahrenheit):
return (5 / 9) * (fahrenheit - 32)
print(
format("Celsius", "20s"), "Fahrenheit",
" | ", format("Fahrenheit", "20s"),
f... | false |
6e0ddb0412a5f38c233d513c26492d9ddb5d2a1b | Ascarik/PythonLabs | /Ch04/Lab36.py | 644 | 4.1875 | 4 | import turtle, random
NUM = 200
x1, y1 = 0, 0
radius = random.randint(50, NUM)
x2, y2 = random.randint(-NUM, NUM), random.randint(-NUM, NUM)
# Pull the pen down
turtle.circle(radius)
turtle.penup()
turtle.goto(x2, y2)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.circle(3)
turtle.end_fill()
# Displ... | false |
71adcc544a902e71d283a4ffefb069622b2a03c6 | vesteinnbjarna/Forritun_Vesteinn | /Lestrarverkefni/Kafli 2/simple_while.py | 251 | 4.15625 | 4 | #simple while
x_int = 0
#test loop-controled variable at the start
while x_int < 10:
print(x_int, end =' ') # print x_each time it loops
x_int = x_int + 1 # changing x_int while in loop
print ()
print ('Final value of x_int: ', x_int)
| true |
94a919169f98db4d533b7b186c3c2c4a49dc491c | vesteinnbjarna/Forritun_Vesteinn | /Lestrarverkefni/Kafli 5/celius_to_farenheit.py | 347 | 4.1875 | 4 |
def celsius_to_farenheit(celsius_float):
""" Convert Celsius to Fahrenheit. """
return celsius_float * 1.8 + 32
print("Convert Celsius to Fahrenheit.")
celsius_float = float(input('Enter degrees in celsius:'))
fahrenheit_float = celsius_to_farenheit (celsius_float)
print(celsius_float," converts to ", fahre... | false |
e5dbd401cbb63acdd259b185a02eeee98498734e | vesteinnbjarna/Forritun_Vesteinn | /Hlutapróf 2 undirbúningur/longest_word.py | 682 | 4.40625 | 4 |
def open_file(filename):
file_obj = open(filename, 'r')
return file_obj
def find_longest(file_object):
'''Return the longest word and its length found in the given file'''
max_length = 0
longest_word = ""
for word in file_object:
word = word.strip()
length = len(word)
... | true |
e9b16fba6e3a93f03f9e0b4950b9f3692f2a8cc8 | vesteinnbjarna/Forritun_Vesteinn | /Tímaverkefni/Assignment 12/Q4.py | 606 | 4.5 | 4 |
def merge_lists(first_list, second_list):
a_new_list = []
for element in first_list:
if element not in a_new_list:
a_new_list.append(element)
for element in second_list:
if element not in a_new_list:
a_new_list.append(element)
a_new_list = sorted(a_new_li... | true |
e0b0f0b3ec6cfe4adb826d78aadaf9496db112ad | vesteinnbjarna/Forritun_Vesteinn | /Tímaverkefni/Assignment 7/A7.5.py | 699 | 4.1875 | 4 |
import string
# palindrome function definition goes here
def is_palindrom (imported_string):
original_str = imported_string
modified_str = original_str.lower()
bad_chars = string.whitespace + string.punctuation
for char in modified_str:
if char in bad_chars:
modified_str = modi... | true |
17f31ab18c5d3f2d100c967bb88ca7b399d28278 | vesteinnbjarna/Forritun_Vesteinn | /Tímaverkefni/Assignment 7/A7.3.py | 353 | 4.15625 | 4 | # The function definition goes here
def is_num_in_range(number):
if number > 1 and number < 555:
answer = str(number) + " is in range."
else:
answer = str(number) + " is outside the range!"
return answer
num = int(input("Enter a number: "))
result = is_num_in_range(num)
print (resu... | true |
d4321a075f9540f36673bc598bfc9f1990598094 | vesteinnbjarna/Forritun_Vesteinn | /Skilaverkefni/Skilaverkefni 5/project.py | 1,683 | 4.5625 | 5 | # The program should scramble each word in the text.txt
# with the following instructions:
# 1.The first and last letter of each word are left unscrambled
# 2. If there is punctuation attached to a word it should be left unscrambled
# 3. The letter m should not be scrambled
# 4. The letters between the first an... | true |
c55af45dee5dd8861b67840741f798d791302b35 | AHoffm24/python | /Chapter2/classes.py | 999 | 4.40625 | 4 | #
# Example file for working with classes
#
#methods are functions in python
#self argument refers to the object itself. Self refers to the particular instance of the object being operated on
# class Person: #example of how to initalize a class with variables
# def __initialize__(self, name, age, sex):
# s... | true |
58b14b436e842442e92a12cab3f08992e5f6acb2 | XTremeRox/AI-Lab | /Day1/prog1.py | 405 | 4.21875 | 4 | #!/usr/bin/python3
def print_list_elements(l):
for element in l:
print(element, end=' ')
print()
if __name__=="__main__":
l = []
l = ("Make me wanna say").split()
print_list_elements(l)
#insertion
l.insert(4, "like")
print_list_elements(l)
#appending
l.append("oh")
... | false |
e22f5ff5265d5073eeac203c5a6c8e017babdf23 | rodrigo9000/PycharmProjects | /PlayingWithSeries/Mission3_RollTheDice.py | 513 | 4.34375 | 4 | # User should be able to enter how many dices he wants to roll: 1 ,2 or 3. He should pass this value as a parameter in the
# function RollTheDice(num). Dices should show random numbers from 1 to 6.
import random
def main():
def RollTheDice(num):
if num in [1, 2, 3]:
for turns in range(1, (num + ... | true |
b410db6a9ea07a05b7e80afad10bfed4a7d643b6 | 95subodh/Leetcode | /116. Populating Next Right Pointers in Each Node.py | 1,266 | 4.28125 | 4 | #Given a binary tree
#
#struct TreeLinkNode {
# TreeLinkNode *left;
# TreeLinkNode *right;
# TreeLinkNode *next;
#}
#pulate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
#
#itially, all next pointers are set to NULL.
#
#te:
#
#u may only use c... | true |
93149f960c8b7d342dde0ea643b3977b3ae35bd3 | 95subodh/Leetcode | /326. Power of Three.py | 240 | 4.34375 | 4 | #Given an integer, write a function to determine if it is a power of three.
from math import *
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
return True if n>0 and 3**20%n==0 else False | true |
33fa289bf90d66af8fb90cedcf7d52a4a3613baf | kphillips001/Edabit-Python-Code-Challenges | /usingternaryoperators.py | 380 | 4.34375 | 4 | # The ternary operator (sometimes called Conditional Expressions) in python is an alternative to the if... else... statement.
# It is written in the format:
# result_if_true if condition else result_if_false
# Ternary operators are often more compact than multi-line if statements, and are useful for simple conditiona... | true |
36a0f49179f1135a619d1d694fa71974e0ffb71b | jbulka/CS61A | /hw2_solns.py | 2,545 | 4.15625 | 4 | """Submission for 61A Homework 2.
Name:
Login:
Collaborators:
"""
# Q1: Done
def product(n, term):
"""Return the product of the first n terms in a sequence.
We will assume that the sequence's first term is 1.
term -- a function that takes one argument
"""
prod, k = 1, 1
while k <= n... | true |
215aed3bd3d66a69c49bc841e6dc9011cc8bf156 | QinmengLUAN/Daily_Python_Coding | /wk4_findNumbers.py | 860 | 4.28125 | 4 | """
1295. Find Numbers with Even Number of Digits
Given an array nums of integers, return how many of them contain an even number of digits.
Example 1:
Input: nums = [12,345,2,6,7896]
Output: 2
Explanation:
12 contains 2 digits (even number of digits).
345 contains 3 digits (odd number of digits).
2 contains 1 digi... | true |
9261b5b8c174058a10632b6cbe2a580c0a5e9cba | QinmengLUAN/Daily_Python_Coding | /DailyProblem20_maximum_product_of_three.py | 651 | 4.375 | 4 | """
Hi, here's your problem today. This problem was recently asked by Microsoft:
You are given an array of integers. Return the largest product that can be made by multiplying any 3 integers in the array.
Example:
[-4, -4, 2, 8] should return 128 as the largest product can be made by
multiplying -4 * -4 * 8 = 128.
... | true |
99845dad934230a83a99d4e8ac1ab96b24cd0c3f | QinmengLUAN/Daily_Python_Coding | /DailyProblem19_findKthLargest.py | 653 | 4.125 | 4 | """
Hi, here's your problem today. This problem was recently asked by Facebook:
Given a list, find the k-th largest element in the list.
Input: list = [3, 5, 2, 4, 6, 8], k = 3
Output: 5
Here is a starting point:
def findKthLargest(nums, k):
# Fill this in.
print findKthLargest([3, 5, 2, 4, 6, 8], 3)
"""
import he... | true |
5ff35f6f7a920113cec07c88e253ad06a9bdcfec | QinmengLUAN/Daily_Python_Coding | /LC354_maxEnvelopes_DP.py | 2,042 | 4.40625 | 4 | """
354. Russian Doll Envelopes
Hard
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope.
What is the maximum number of envelopes... | true |
dc33830a1d3708345a5d77f6f9dfd86017137e31 | QinmengLUAN/Daily_Python_Coding | /wk2_sqrt.py | 609 | 4.125 | 4 | # Write a function to calculate the result (integer) of sqrt(num)
# Cannot use the build-in function
# Method: binary search
def my_sqrt(num):
left_boundary = 0
right_boundary = num
if num <= 0:
return False
elif num < 1:
return 0
elif num == 1:
return num
while (right_boundary - left_boundary) > 1:
m... | true |
7dab89ca1ef40d80b0ea0728cca5126bd021f291 | QinmengLUAN/Daily_Python_Coding | /wk2_MoeList.py | 1,106 | 4.28125 | 4 | # To understand object and data structure
# Example 1: https://www.w3schools.com/python/python_classes.asp
# Example 2: https://www.tutorialspoint.com/python_data_structure/python_linked_lists.htm
# write an object MyList with many methods: MyList, append, pop, print, node
class MyNode:
def __init__(self, value):
s... | true |
c48afae5e64ef91588c53ce962ea8c326a529d1b | QinmengLUAN/Daily_Python_Coding | /LC1189_maxNumberOfBalloons_String.py | 858 | 4.125 | 4 | """
1189. Maximum Number of Balloons
Easy: String, Counter, dictionary
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
You can use each character in text at most once. Return the maximum number of instances that can be formed.
Example 1:
... | true |
24b60cb185dcf1770906a0b042b297aa7ea0784b | QinmengLUAN/Daily_Python_Coding | /LC326_isPowerOfThree_Math.py | 420 | 4.25 | 4 | """
326. Power of Three
Easy: Math
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
Follow up:
Could you do it without using any loop / recursion?
"""
c... | true |
ea27a81da0146733e81e51b59fcb87622e5f8cea | QinmengLUAN/Daily_Python_Coding | /DailyProblem04_isValid_String.py | 1,649 | 4.21875 | 4 | """
Hi, here's your problem today. This problem was recently asked by Uber:
Leetcode 20
Imagine you are building a compiler. Before running any code, the compiler must check that the parentheses in the program are balanced. Every opening bracket must have a corresponding closing bracket. We can approximate this using s... | true |
7e4c89bc3812a0bf3707b3de2183ca661b693f3d | QinmengLUAN/Daily_Python_Coding | /LC207_canFinish_Graph.py | 2,214 | 4.1875 | 4 | """
207. Course Schedule
Medium: Graph
There are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.
Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]
Given the total number of courses and a list of prere... | true |
f27497e9a8acc603807d738e36b3937ad47f1b77 | NkStevo/daily-programmer | /challenge-003/intermediate/substitution_cipher.py | 1,260 | 4.125 | 4 | import json
def main():
with open('ciphertext.json') as json_file:
ciphertext = json.load(json_file)
print("----Substitution Cipher Program----")
choice = input("Input 1 to encode text and 2 to decode text:\n")
if choice == '1':
text = input("Input the text you would l... | true |
505816e71a2df217a36b6dc74ae814e40208b26d | zszinegh/PyConvert | /pyconvert/conversions.py | 1,068 | 4.375 | 4 | """A module to do various unit conversions.
This module's functions convert various units of measurement.
All functions expect a 'float' as an argument and return a 'float'.
'validate_input()' can be used before running any function to
convert the input to a 'float'.
"""
def validate_input(incoming):
"""Conve... | true |
61c0658f4299a3175b50d3d2c680ad8ea52d2d4c | cadbane/python-dojo | /tricks/iterating.py | 279 | 4.1875 | 4 | # iterating over list index and value pairs
a = ['Lorem', 'ipsum', 'dorem', 'kolorem']
for i, x in enumerate(a):
print(f'{i}: {x}')
# iterating over dictionary
b = {'apple': 3, 'banana': 7, 'orange': 0}
for f, q in b.items(): # iteritems() for python2
print(f'{f}: {q}') | false |
82be926a6549078edf9b27ea2e56c0993d5e6b3a | isaiah1782-cmis/isaiah1782-cmis-cs2 | /Assignment_Guessing_Game.py | 950 | 4.25 | 4 | import math
import random
Minimum_Number = int(raw_input("What is the minimum number? "))
Maximum_Number = int(raw_input("What is the maximum number? "))
print "I'm thinking of a number from " + str(Minimum_Number) + " to " + str(Maximum_Number) + "."
Guess = str(raw_input("What do you think it is?: "))
def Correc... | true |
27d4d41ca785afa105f59b8420637948d29ea9b0 | kammariprasannalaxmi02/sdet | /python/Activity14.py | 538 | 4.3125 | 4 | #Write a program that asks the user how many Fibonnaci numbers to generate and then generates them.
fibo_num = input("Enter the number to get Fibonnaci numbers: ")
def fibonnaci_Num(fib_num):
n1 = 0
n2 = 1
i = 1
n = int(fib_num) - 2
fiba_list = [0,1]
if(int(fib_num)==1):
pri... | false |
77069ee92fcb26ff76619058b379d05e8c177153 | kammariprasannalaxmi02/sdet | /python/Activity12.py | 264 | 4.21875 | 4 | #Write a recursive function to calculate the sum of numbers from 0 to 10
def calculate(i):
if i <= 1:
return i
else:
return i + calculate(i-1)
num = int(input("Enter a number: "))
print("The sum of numbers: ", calculate(num))
| true |
26343c2e7d1a57463b71faee58c204afd426b5b8 | noemiko/design_patterns | /factory/game_factory.py | 2,774 | 4.75 | 5 | # Abstract Factory
# The Abstract Factory design pattern is a generalization of Factory Method. Basically,
# an Abstract Factory is a (logical) group of Factory Methods, where each Factory
# Method is responsible for generating a different kind of object
# Frog game
class Frog:
def __init__(self, name):
... | true |
5f20f80abf87e9a9b32d0f5b32da197e75b18655 | NeonMiami271/Work_JINR | /Python/Kvadrat_yravn.py | 551 | 4.125 | 4 | #Решение квадратного уравнения
import math
print("Решим квадратное уравнение")
a = float(input("а = "))
b = float(input("b = "))
c = float(input("c = "))
D = b**2 - (4*a*c)
if D < 0:
print("Корней нет")
elif D == 0:
x = -b/(2*a)
print("Корень равен:" + str(x))
elif D > 0:
x1 = (-b - math.sqrt(D))... | false |
cc59404f7b10f79ddbf44dc265083c99c32ad4be | phpdavid/python-study | /home-study/study-code/python-code/ten/one.py | 760 | 4.625 | 5 | # 使用类枚举的方式(python中没有枚举类型)为元祖每个元素命名,提高程序可读性
# 在python中没有真正的枚举类型,我们可以定义一些常量代替
Student = ('david', 19, 'male')
# # 通过下标读取值,可读性很差,时间久了,不知道是什么了
# # name
# Student[0]
# # age
# Student[1]
# # gender
# Student[2]
#
# # 定义常量
# # NAME = 0
# # AGE = 1
# # GENDER = 2
# NAME, AGE, GENDER = range(3)
# Student[NAME]
# Student[AGE]
... | false |
95a9f4e25127241ba07696dacca17dfe3740c930 | vladflore/py4e | /course3/week6/extract-data-json.py | 1,396 | 4.40625 | 4 | # In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/json2.py. The
# program will prompt for a URL, read the JSON data from that URL using urllib and then parse and extract the comment
# counts from the JSON data, compute the sum of the numbers in the file and enter the sum... | true |
597416454b410742bc4ac70d165389cd73093c56 | PKpacheco/exec_roman_numerals | /main.py | 826 | 4.1875 | 4 | from int_roman import *
from roman_int import *
def decision_method(number_choice):
if (number_choice == 1):
N = int(input("Input integer number (between 1 and 3000: "))
if (N == 0):
print ("Please enter a number greater than 0")
elif (N > 3000):
print ("Please enter... | false |
f7f87810b50c50b2828e2c404763cdb3f44b08a0 | alindsharmasimply/Python_Practice | /seventySecond.py | 307 | 4.21875 | 4 | def sumsum():
sum1 = 0
while True:
try:
a = input("Enter a valid number to get the sum ")
if a == ' ':
break
sum1 = sum1 + a
print sum1, "\n"
except Exception:
print "Enter a valid number only "
sumsum()
| true |
3a50f698d6a65fafa0c72bfc75b8ec175896b9d8 | SimonFromNeedham/Project_Euler_Problems | /euler16.py | 1,072 | 4.125 | 4 | # 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
# What is the sum of the digits of the number 2^1000?
# I'm aware that this approach is more complex than necessary and that I could just use a long to store the number,
# But I honestly find it a lot more interesting to work through the problem tryi... | true |
c0bdf60e9dd878b032e2372faf6babe022ee1201 | littlejoe1216/Daily-Python-Exercise-01 | /#1-Python-Daily-Exercise/Daily Exercise-1-02082018.py | 290 | 4.1875 | 4 | #Joe Gutierrez - Python Daily Exercise - 2/16/18
# 1. Write a statement that concatenates at least two variables (you can have more than 2 for this practice).
name = input('Enter First name:')
sna = input('Enter Last name:')
joe = name + sna
print ('Is your name ' + str(joe))
| true |
43c9ee7ba7e074a0d37c44e7391d8181d706193d | CSSBO/websystem | /算法分析/fenxingtree.py | 1,203 | 4.28125 | 4 |
import turtle
#画分形树,用的是创建二叉树的算法
def treeoface(length):
#如果枝干长度小于15就不画
if length<15:
return 0
turtle.forward(length)#往前画
turtle.up()#在回退的时候关闭画笔的工作
turtle.backward(length * (1 / 3))#回退到三分之一的地方
turtle.down()#重新打开画笔工作
turtle.left(60)
#time.sleep(1)#画左枝干,长度为主枝干的... | false |
518087b3406afc65b712cee808f5849e98d40197 | palepriest/python-notes | /src/ex32.py | 635 | 4.1875 | 4 | # -*- coding:utf-8 -*-
t_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'bananas', 'Blueberries', 'oranges']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
# print a integer list
for number in t_count:
print "The number is %d." % number
# print a string list
for fruit in fruits:
print "The fruit type is %s.... | true |
ca03996c06e344c39557e27a53fd7a4b8d243471 | Nasir1004/assigment-3-python-with-dahir | /lopping numbers from one to ten.py | 235 | 4.1875 | 4 | '''
numbers=1
for i in range (1,10):
print(i)
#this is example of for loop numbers from one to ten
'''
# the whileloop example is
current_number = 1
while current_number <=10:
print(current_number )
current_number += 1
| true |
db42b6acb7d451e412f58c2837e4d1c309a412dc | wbluke/python_dojang | /01_input_output.py | 649 | 4.15625 | 4 | # if you divide integer by integer, result is float.
num = 4 / 2
print(num) # 2.0
# convert float to int(int to float)
num = int(4/2)
print(num) # 2
num = float(1+3)
print(num) # 4.0
# delete variable
del num
# if you want to know class' type
print(type(3.3)) # <class 'float'>
# when save input data on variable... | true |
1c5ae131528b6e48953212686c066c5a9736a334 | brandonkbuchs/UWisc-Python-Projects | /latlon.py | 2,073 | 4.5 | 4 | # This program collects latitude and longitude inputs from the user and returns
# Information on the location of the quadrant of the coordinate provided
def latlon(latitude, longitude): # Defines function
# Latitude logic tests.
if latitude == 0: # Test if on equator
print "That location is on the ... | true |
5eea14c56271bb0034e0d80744730fe9bf2ea3ae | vishaldhateria/100daysofcode | /18-August-2020/changedimensions.py | 523 | 4.1875 | 4 | # my__1D_array = numpy.array([1, 2, 3, 4, 5])
# print my_1D_array.shape #(5,) -> 5 rows and 0 columns
# my__2D_array = numpy.array([[1, 2],[3, 4],[6,5]])
# print my_2D_array.shape #(3, 2) -> 3 rows and 2 columns
# change_array = numpy.array([1,2,3,4,5,6])
# change_array.shape = (3, 2)
# print change_array
... | false |
659e981c2f135e1ae4e3db3d62d90d359c787e71 | 21eleven/leetcode-solutions | /python/0673_number_of_longest_increasing_subsequence/lsubseq.py | 1,203 | 4.125 | 4 | """
673. Number of Longest Increasing Subsequence
Medium
Given an integer array nums, return the number of longest increasing subsequences.
Example 1:
Input: nums = [1,3,5,4,7]
Output: 2
Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].
Example 2:
Input: nums = [2,2,2,2,2]
... | true |
6a52d60f15ef338e27b8c62ce8c034653c0a0f2f | 21eleven/leetcode-solutions | /python/0605_can_place_flowers/three_slot.py | 1,411 | 4.15625 | 4 | """
605. Can Place Flowers
Easy
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be... | true |
a3f61908d09cba128724d0d6a533c59075156091 | 21eleven/leetcode-solutions | /python/1631_path_with_minimum_effort/bfs_w_heap.py | 2,594 | 4.125 | 4 | """
1631. Path With Minimum Effort
Medium
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, ... | true |
0790ccdc036798bf7ce9d542345f784dd6009d39 | makhmudislamov/leetcode_problems | /microsoft/arr_and_str/set_matrix_zeroes.py | 2,465 | 4.46875 | 4 | """
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
Example 1:
Input:
[
[1,1,1],
[1,0,1],
[1,1,1]
]
Output:
[
[1,0,1],
[0,0,0],
[1,0,1]
]
Example 2:
Input:
[
[0,1,2,0],
[3,4,5,2],
[1,3,1,5]
]
Output:
[
[0,0,0,0],
[0,4,5,0],
... | true |
27a566d6f5312cf2b427d42c1e542d53a1384c21 | makhmudislamov/leetcode_problems | /microsoft/arr_and_str/trapping_rain_water.py | 1,224 | 4.28125 | 4 | """
Given n non-negative integers representing an elevation map where the width of each bar is 1,
compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1].
In this case, 6 units of rain water (blue section) are being trapped.
Thanks Marcos f... | true |
6842fe3c8db077be3e54baab2058ec882cd7c597 | guyimin/python-tutorial-by-Vamei | /3.5包裹传递.py | 456 | 4.1875 | 4 | # coding=utf-8
#!/usr/bin/env python
#包裹传递用于用户不知道参数个数的情况
def func(*name):
print type(name)
print name
# 按照位置传入tuple
func(1,4,6)
func(5,6,7,1,2,3)
def func1(**dict):
print type(dict)
print dict
#按照关键词传入dic
func1(a=1,b=9)
func1(m=2,n=1,c=11)
#difference between * and **
def func2(a,b,c):
print a,... | false |
1e0225bc030d7c718fe15296109c28a0d9c4134b | zhibosheng/6212algorithms | /chapter1/insertionsert.py | 294 | 4.125 | 4 | #Uses python3
def InsertionSert(arr):
length = len(arr)
for j in range(1,length):
key = arr[j]
i = j - 1
while i >= 0 and arr[i] > key:
arr[i+1] = arr[i]
i -= 1
arr[i+1] = key
return arr
if __name__ == "__main__":
arr = [5,6,8,2,3]
result = InsertionSert(arr)
print(result) | false |
5b2f5770e980ebeca8a5944726065bb3dee8c0aa | karandevgan/Algorithms | /RadixSort.py | 971 | 4.125 | 4 | def get_nth_digit(num, n):
'''
This function returns the nth digit of a number num
n = digit which is required
num = number
'''
divisor = 10 ** n
dividend = num
new_dividend = dividend % divisor
return new_dividend / (divisor / 10)
def counting_sort(A, n):
count = [0... | false |
ff83309a29010223b289355195fad25ac86d36c7 | karandevgan/Algorithms | /LargestNumber.py | 779 | 4.28125 | 4 | def compare(number, number_to_insert):
str_number_to_insert = str(number_to_insert)
str_number = str(number)
num1 = str_number + str_number_to_insert
num2 = str_number_to_insert + str_number
if num1 > num2:
return -1
elif num1 == num2:
return 0
else:
return 1
def la... | true |
6b3c9e414503f3b249e372f690c97e6f8cd52d78 | Keikoyao/learnpythonthehardway | /Ex20.py | 881 | 4.25 | 4 | # -- coding: utf-8 --
from sys import argv
script, input_file = argv
#read() 每次读取整个文件,它通常用于将文件内容放到一个字符串变量中
def print_all(f):
print (f.read())
#seek() 移动文件读取指针到指定位置
def rewind(f):
f.seek(0)
#readline() will read the file line by line as if there is a for next loop automatically vs readlines()一次读取整个文件
def prin... | true |
1a0260d0313bdf1d6c79434f2916383d54670312 | yusufcimenci/programlama_lab | /uzaktan_eğitim_hafta_4.py | 2,216 | 4.125 | 4 | #min_heapyfy(array,i) : bir dizinin i indeksindeki elemanı ile o elemanın sağındaki ve solundaki elamanlan büyüklük kıyaslaması yapar. Küçük olanı üste çıkartır. diziyi heap yapısına çevirir
#build_min_heapy(array) : aldığı dizinin yarısından itibaren geriye doğru kontrol edee ve bütün diziyi MinHeap düzenine sokar.
... | false |
33e1e11d95b94d22e1fc939c716cd8251d04b034 | TwoChill/Learning | /Learn Python 3 The Hard Way/ex34 - Accessing Elements of Lists.py | 2,096 | 4.21875 | 4 | # Remember, if it says "first," "second," then it's using ORDINAL, so subtract 1.
# If it gives you CARDINAL, like "The animal at 1", then use it directly.
# Check later with Python to see if you were correct.
animal = ['bear','python3.7', 'peacock', 'kangaroo', 'whale', 'platypus']
# Q1. The animal at 1. ... | true |
2ffa957733ffcd46c2fd448b75f6bbe9c64043ec | TwoChill/Learning | /Learn Python 3 The Hard Way/ex32 - Loops and Lists.py | 1,770 | 4.5625 | 5 | hair = ['brown', 'blond', 'red']
eye = ['brown', 'blue', 'green']
weights = [1, 2, 3, 4]
the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
# this first kind of for-loop goes through a list
for number in the_count:
print(f'This is c... | true |
545cbfef3ca36549f96c421a54fafc0c0c92d318 | TwoChill/Learning | /Learn Python 3 The Hard Way/ex15 - Reading Files.py | 1,845 | 4.625 | 5 | # This line imports the variable argument argv from the sys module.
from sys import argv
# These are the TWO command line arguments you MUST put in when running the script.
script, filename = argv
# This line opens the filename argument and puts it content in a variable.
txt = open(filename)
print("\n\nTHIS IS THE ... | true |
4c7fdd6fe35f53ac8a12e8b3a3c69a64e08b3b28 | cazzara/mycode | /random-stdlib/use-random.py | 2,112 | 4.65625 | 5 | #!/usr/bin/env python3
import random
## Create a random number generator object
# This can be used to instantiate multiple instances of PRNGs that are independent of one another and don't share state
r = random.Random()
## Seed random number generator
# This initializes the state of the PRNG, by default it uses the... | true |
8068f6de2b10e0d0673a0d96f8a62135223624f7 | cazzara/mycode | /if-test2/if-test2.py | 380 | 4.1875 | 4 | #!/usr/bin/env python3
# Author: Chris Azzara
# Purpose: Practice using if statements to test user input
ipchk = input("Set IP Address: ")
if ipchk == '192.168.70.1':
print("The IP Address was set as {}. That is the same as the Gateway, not recommended".format(ipchk))
elif ipchk:
print("The IP Address was se... | true |
5eca3115baaf3a1f4d09a92c3e8bef73b5e655e8 | cazzara/mycode | /datetime-stdlib/datetime-ex01.py | 931 | 4.28125 | 4 | from datetime import datetime # required to use datetime
## WRITE YOUR OWN CODE TO DO SOMETHING. ANYTHING.
# SUGGESTION: Replace with code to print a question to screen and collect data from user.
# MORE DIFFICULT -- Place the response(s) in a list & continue asking the question until the user enters the word 'quit'
... | true |
1ed15bd4d250bfc4fc373c26226f84f83c40cdcd | shishir7654/Python_program-basic | /listcomprehension1.py | 513 | 4.375 | 4 | odd_square = [x **2 for x in range(1,11) if x%2 ==1]
print(odd_square)
# for understanding, above generation is same as,
odd_square = []
for x in range(1, 11):
if x % 2 == 1:
odd_square.append(x**2)
print( odd_square)
# below list contains power of 2 from 1 to 8
power_of_2 = [2 ** x f... | true |
c084419e361233b87f85c9a688e29f6471376579 | brennanmcfarland/physics-class | /18-1a.py | 1,469 | 4.125 | 4 | import matplotlib.pyplot as plt
import math
def graphfunction(xmin,xmax,xres,function,*args):
"takes a given mathematical function and graphs it-how it works is not important"
x,y = [],[]
i=0
while xmin+i*xres<=xmax:
x.append(xmin+i*xres)
y.append(function(x[i],*args))
i+=1
... | true |
65a294810e1afc9d10fa24f84d8a4d60b5ec02c3 | jle33/PythonLearning | /PythonMasterCourse/PythonMasterCourse/GenetratorExample.py | 1,494 | 4.25 | 4 | import random
#Generator Example
def get_data():
"""Return 3 random integers between 0 and 9"""
print("At get_data()")
return random.sample(range(10), 3)
def consume():
"""Displays a running average across lists of integers sent to it"""
running_sum = 0
data_items_seen = 0
print("At top of ... | true |
218254f6a4c1152326423160bebdb9d8461d05a2 | jodaz/python-sandbox | /automate-boring-stuff-python/tablePrinter.py | 1,093 | 4.34375 | 4 | #! python3
# tablePrinter.py - Display a list of lists of strings in
# a well-organized table.
table_data = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
def print_table(main_arr):
col_widths = [0] * len(main_... | true |
b3bba5c4526cff24bd9b71a60aadddcf6e623228 | jodaz/python-sandbox | /automate-boring-stuff-python/strongPassword.py | 424 | 4.34375 | 4 | #! python3
# strongPassword.py - Find is your password is strong.
import re
password = input('Introduce your password: ')
find_upper = re.compile(r'[A-Z]').findall(password)
find_lower = re.compile(r'[a-z]').findall(password)
find_d = re.compile(r'\d').search(password)
if find_upper and find_lower and find_d and le... | true |
98f72a0486ba5cc22b42028c6bb0cd5e79ca2597 | Peterbamidele/PythonDeitelChapterOneExercise | /2.3 Fill in the missing code.py | 394 | 4.125 | 4 | """(Fill in the missing code) Replace *** in the following code with a statement that
will print a message like 'Congratulations! Your grade of 91 earns you an A in this
course' . Your statement should print the value stored in the variable grade :
if grade >= 90"""
#Solution
grade = 90
if grade >= 90:... | true |
201a2cbfa51168e159fae14bf438adb71c2b129e | cmdellinger/Code-Fights | /Interview Practice/01 Arrays/isCryptSolution.py | 1,213 | 4.1875 | 4 | """
Codefights: Interview Prep - isCryptSolution.py
Written by cmdellinger
This function checks a possible solution to a cryptarithm. Given a solution as a list of character pairs (ex. ['A', '1']), the solution is valid of word_1 + word_2 == word_3 once decoded.
See .md file for more information about cryptarithm... | true |
b3ea4b626b6afb470c37d082edd5a451c4601ae3 | LilCharles/ExamenLP | /EAEXAMEN.py | 254 | 4.15625 | 4 | lista = []
n = int(input(print("ingrese el largo de la lista: ")))
while n < 1:
n = input(print("ingrese el largo de la lista: "))
for i in range(2, n*2, 2):
numero = i**3
lista.append(int(numero))
print(lista[0])
print(lista[1:-1])
print(lista[-1])
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.