blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
f0d149426612295f2528c73911516170229961f6 | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week3/oefening16.py | 445 | 3.859375 | 4 | import random
import string
def rand_pwd(min_lengt, max_lengt):
paswoord = ""
pwd_lengt = random.randrange(min_lengt, max_lengt + 1)
print(pwd_lengt)
for getal in range(1, pwd_lengt):
paswoord = paswoord+random.choice(string.ascii_letters)
return paswoord
min_lengt = int(input("Geef een ... |
1c1a3d0eb6f042e44ab4317d81507fa9f65b8a1c | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week1/oplossingen_labo.py | 3,396 | 3.71875 | 4 | # demo
# print("hello world")
# # Oef 1
# print("Beel")
# print("Robbe")
# print("robbebeel2001@gmail.com")
# # Oef 1.2
# print("Beel\nRobbe\nrobbebeel2001@gmail.com")
# # Oef 2
# print("Labo basic prog \n\tlabo week 1\n\t\tKennismaking\n\t\tWerken met tabs")
# # \n toevoehing in dezelfde print
# \t tab zorgt voor... |
0edafeebf37f3544293a7d94ec3d37cacf13f4cd | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week3/oefening12.py | 90 | 3.515625 | 4 | woord = input("Geef een woord > ")
for elke_letter in woord:
print(f"{elke_letter}")
|
655ef15c52119dc3db4a664a2b541c71978e4a62 | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week1/thuis3.py | 767 | 3.546875 | 4 | aantal_broek = float(input("geef aankoop aantal broeken "))
aantal_tshirt = float(input("geef aankoop aantal tshirts "))
aantal_vest = float(input("geef aankoop aantal vesten "))
prijs_broek = 70.5
prijs_tshirt = 20.89
prijs_vest = 100.3
totaal_broek = aantal_broek * prijs_broek
totaal_tshirt = aantal_tshirt * prijs... |
0158adfe868f9e31148ac089565b8de633b60eb0 | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week2/thuis2.py | 357 | 3.578125 | 4 | def exclusief_naar_inclusief(excl_btw, btw_percentage):
return (excl_btw * btw_percentage)
excl_btw = float(input("Hoeveel bedraagt het bedrag exclusief btw?"))
btw_percentage = float(input("Wat is het btw percentage?"))
incl_btw = exclusief_naar_inclusief(excl_btw, btw_percentage)
print(f"Het inclusief bedrag ... |
4674ae86d8f0a37597a073825b0205203c97e293 | forrestjan/Labos-MCT-19-20 | /2019-prog-labooefeningen-forrestjan/week2/oefening1.py | 406 | 3.734375 | 4 | #oef2
getal1 = int(input("geef getal 1 op: "))
getal2 = int(input("geef getal 2 op: "))
# het teken = kan je zien als het werkwoord word
# als je == hebt kan je dit leterlijk lezen als is gelijkaan
# vergeet noot dubbelpunt bij if______: en else_______:
#
#
#
if getal1 == getal2:
print(f"getallen {getal1} en {geta... |
f95a9efcfcaa8171f36a384c45731a3a3abe0f8b | Chumsy0725/Visual-Perception-for-Self-Driving-Cars | /Baseline Enviroment Perception/BaselinePerception.py | 10,619 | 3.90625 | 4 | """
Reference: Self Driving Cars Specialization by University of Toronto on Coursera
"""
import numpy as np
import cv2
import matplotlib.pyplot as plt
from utils import *
def xy_from_depth(depth, k):
"""
Returns x, and y coordinates of every pixel in the image using the depth map and the calibrat... |
7304664a1a8267649493a418d60b5b236e88e584 | shwesinhtay111/Python-Study-Step3 | /advance_num.py | 297 | 3.546875 | 4 | print(hex(246))
print(hex(512))
print(bin(1234))
print(bin(128))
print(bin(512))
# two arguments, equivalent to x^y
print(pow(3,4))
# three arguments it is equivalent to (x^y)%z
print(pow(3,4,5))
print(abs(-3.14))
print(abs(3))
print(round(3,2))
print(round(395,-2))
print(round(3.1415926535,2)) |
6040b3a06718d13b49ea130fb38ffb872cd9ed65 | dataiku/dss-plugin-nlp-language-detection | /python-lib/plugin_io_utils.py | 520 | 4 | 4 | # -*- coding: utf-8 -*-
from typing import List, AnyStr
def generate_unique(name: AnyStr, existing_names: List[AnyStr], prefix: AnyStr = None) -> AnyStr:
"""
Generate a unique name among existing ones by suffixing a number. Can also add a prefix.
"""
new_name = "{}_{}".format(prefix, name)
for i i... |
035ffe70a2edc5c147f25bdb8d41278dfd476ee4 | oof26/LeetCodePractice | /Easy/middleOfLinkedList.py | 561 | 4.03125 | 4 | # Given the head of a singly linked list, return the middle node of the linked list.
# If there are two middle nodes, return the second middle node.
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solu... |
c3d9032c1e9eded47128434e0202920fea3261e4 | liucheng2912/helloworld | /学习/2库/标准库/time学习.py | 618 | 4.34375 | 4 | """
time.asctime() 国外的时间格式
time.time() 时间戳
time.sleep() 等待
time.localtime() 时间戳转成时间元组
time.strftime() 将当前的时间戳转成带格式的时间
"""
import time
#国外时间
print(time.asctime())
#时间戳
print(time.time())
#时间元组
print(time.localtime())
#转换成带格式的时间 第二个参数需要是tuple
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
... |
0421e41fab7da1b2a55baae81296ce0589caf58f | liucheng2912/helloworld | /学习/1python/45数据结构-字典.py | 792 | 3.921875 | 4 | # 以关键字为索引
# 关键字可以是任意不可变类型,通常是字符串 或数字
# 如果一个元组只包含字符串、数字、或元祖,那么这个元组也可以用作关键字
a={"a":1,"b":2}
b=dict(a=1,b=2)
print(a)
print(type(a))
print(b)
print(type(b))
# key值不可变
print(a.keys())
print(a.values())
# pop 删除对应键值对 并返回对应value
print(a.pop("a"))
print(a)
# popitem 随机删除键值对 并返回被删除的键值对
print(b.p... |
5b11bc679ba9b838e13083c9140a542ae83f3680 | liucheng2912/helloworld | /学习/1python/21猜数字游戏.py | 253 | 3.671875 | 4 | import random
# 1-100的数字
x=random.randint(1,100)
while True:
y = int(input("请输入数字"))
if y<x:
print("大一点")
elif y>x:
print("小一点")
elif y==x:
print("猜对了")
break |
c6c9198fb6f40136fb4adf4a8c976acbdcdb1000 | 20c/vodka | /src/vodka/util.py | 1,762 | 4.03125 | 4 | def dict_get_path(data, path, default=None):
"""
Returns the value inside nested structure of data located
at period delimited path
When traversing a list, as long as that list is containing objects of
type dict, items in that list will have their "name" and "type" values
tested against the cur... |
2a1f981dc5e8964b3e50c9bfc65d0bc2d555e6a6 | thanatos/parser | /grammar.py | 1,905 | 4.09375 | 4 | """Classes to represent the grammar of a language."""
class Terminal(object):
"""Represents a terminal in the grammar.
A terminal is something that appears in a string generated by the grammar.
For example, in Python, the string "raise" might be a terminal. These are
the deepest nodes the the AST, an... |
6f3d6f6e07ad04e9739e0a9519fcbb314e3eaaa2 | 15179885376/Letcode | /Xuan_Ze_sort.py | 478 | 3.59375 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/5/31 0031 15:50
# @Author : Zzy
# @Site :
# @File : Xuan_Ze_sort.py
# @Software: PyCharm
def text(a):
temp=0
i=0
n=len(a)
while i<n:
flag=i
for j in range(i+1,n):
if(a[j]<a[flag]):
flag=j
... |
fa3365b4994b2a661a1b1419dbcacbe4f6806900 | jaredscarr/mail-room | /mail_room.py | 3,475 | 3.765625 | 4 | # -*- coding: utf-8 -*-
from builtins import input
MENU_DICT = {
"main_menu_prompt": """\nPlease select from the following menu options:\n
S) Send Thank You\nC) Create Report\n""",
"donation_prompt": "\nEnter 'Q' for menu or enter donation amount: ",
"name_prompt": "\nL) List of Names\nQ) Quit\nOr enter ... |
d034c93c2e0ab0da8183b7eca07c444cf4a6839d | Storeyjm/Start-up-Python-Programs | /#5.Hundreds, tens and units.py | 280 | 3.71875 | 4 | #5.Hundreds, tens and units
#User inputs number
num = int(input("Enter a number between 100 and 999"))
#Hundreds
a = num // 100
#Tens
b = (num - (a * 100)) // 10
#Units
c = num - (a * 100) - (b * 10)
#Prints output
print(a, "hundreds", b, "tens", c, "units.")
## ACS Good work |
6ce95f8200026d67d2749a225c28c1590c0b1ac1 | ricorx7/QRevPy | /Classes/MultiThread.py | 458 | 3.53125 | 4 | """
Created on Sep 28, 2017
@author: gpetrochenkov
"""
import threading
class MultiThread(threading.Thread):
def __init__(self, thread_id, function, args=None):
threading.Thread.__init__(self)
self.thread_id = thread_id
self.function = function
self.args = args
d... |
4afaf704ae98f948f2870ba468f0265a0540a221 | Residencia-Fiep-Turma-2/distribuica_pedro | /pack2/Pedro/build/lib/teste/exer01.py | 91 | 3.71875 | 4 | #!/usr/bin/python3
def imprimir(x):
for i in range(1, x):
if (i % 2 != 0):
print (i)
|
cf24c75c3a38aec29aa4bc7b8478eb75c99ed21b | welchsoft/assignment-5-3-2018 | /optional_ex/bonuschallenge.py | 704 | 4.125 | 4 | #take user input
user_input = input("please enter a word: ")
#split input string into array of words
user_words = user_input.split()
#create empty dictionary
word_bank = {}
#populate the dictionary
for words in user_words:
word_bank.update({words:0})
#check populated dictionary against user input and increment ... |
d8771aecddb4ae96fe00c958a86e40071964e8fb | LizademetionC-137/my_piton | /lesson2/get_py.py | 194 | 3.78125 | 4 | x = int(input("Введите число "))
def fun_P(x):
if x % 2 == 0:
return "четное"
else :
return "нечетное"
print("Ваше число", fun_P(x))
|
d5614e0557bb795a7853b507579e7c94b89f9de3 | LizademetionC-137/my_piton | /my_random.py | 275 | 3.65625 | 4 | import random
random_num = random.randint(1,4)
a=int(input("Угадай число!: "))
if a == random_num :
print("Победа! Ты угадал!")
else :
print("Не угадал!Я загадал {0}".format(random.choice([random_num+1,random_num-1])))
|
fe7d096c203c30ef734ccfa431e766c733b5961d | LizademetionC-137/my_piton | /lesson2/my_max.py | 182 | 3.96875 | 4 | a = int(input("Введите первое число: "))
b = int(input("Введите второе число: "))
max = a if a > b else b
print("Число", max,"больше")
|
9173422726b3b79494a9529cafaa026d51f41105 | tomerguttman/leet-sol | /py-sol/RemoveNthNodeFromEndOfList.py | 701 | 3.734375 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def removeNthFromEnd(self, head, n):
dummy = ListNode(0,None)
dummy.next = head
listLength = self.length(head)
... |
388a104997a7a3df2b10fbf2a269021ca66aafd1 | miika19200/General-Knowledge-Quiz | /Python_versions/Version_1 (user Details)/Version_1c.py | 1,060 | 4.15625 | 4 | #User Details
#Using fuctions to greet the user
def greet():#using def function so i can use mutiple times without repeating the process
global name#so name outside of def can be used
while True: #using while True loop
name = input("What is your name? : ")#ask user to input their name
#.re... |
c01c54f239cd384b0280557e5a5b6b4292427935 | wyshih/APCS | /1050305-3.py | 671 | 3.53125 | 4 | if __name__ == '__main__':
line = [] #set a list to record segments if occupied the value of that index is set to 1
segments = int(input())
for i in range(0, segments):
S, E = input().split(' ')
if int(S) > int(E):
print ('Input Error')
break
if le... |
c0ba09824867427d0d8a773c5f2f5d4255947993 | svilendobrev/svd_util | /py/yielooper.py | 2,670 | 3.609375 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
class looper( object):
'''
wrapping looper for generators to allow usual usage of "for a in gen" AND send/throw into gen
usage:
def gen( n, ofs =0): #some generator
for a in range( n):
... |
560e66484443e80975c76d326bdaae4274439bac | fhc-noodlesKing/python-c1 | /PYTHONTEST/demo1.py | 299 | 3.78125 | 4 | # b = 18
# if b >= 18:
# print("成年人")
# print("后果自负")
# else:
# print("未成年人")
# print("受保护")
# c = "的剑就是我的剑"
# d = "你的剑"
# if d in c:
# print("无极之道")
# else:
# print("error!")
a = [1,2,3,4,5]
for i in a:
print(i) |
4426161af2920b7f143beeb9ea986a7f34e360f5 | CheLcodes/leetcode_python_practice | /coda/treeSerialization.py | 1,566 | 3.859375 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Codec:
def serialize(self, root):
"""Encodes a tree to a single string.
:type root: TreeNode
:rtype: str
... |
3de28e5a780fe91c38af8637a24b6c21a37be094 | CheLcodes/leetcode_python_practice | /nuro/dotProductofTwoVectors.py | 821 | 3.78125 | 4 | """
The constructor is taking non-zero values into a dictionary,
so it is O(n) time.
And dotProduct() is just
looping over one dictionary
against the other dictionary,
multiply and sum up.
For the follow up question,
the one dictionary with shorter length
is selected as the driver for the loop in dotProduct(... |
3a909572c8d52be9a3f685107e9f4d06d96d9cb5 | CheLcodes/leetcode_python_practice | /ixl/33SearchInRotatedSortedArray.py | 696 | 3.515625 | 4 | class Solution:
@classmethod
def search(self, nums, target):
l, r = 0, len(nums) - 1
while l <= r:
mid = l + (r - l) // 2
if nums[mid] == target:
return mid
if nums[mid] < nums[r]:
if nums[mid] < target <= nums[r]:
... |
3bb9ba5b96cf6d9081ba07b97693423896002304 | piyushkashyap07/Array | /swapalternate.py | 711 | 3.625 | 4 | from sys import stdin
def swapAlternate(arr, n) :
if n%2==1:
n=n-1
for i in range(0,n,2):
arr[i],arr[i+1]=arr[i+1],arr[i]
#Taking Input Using Fast I/O
def takeInput() :
n = int(stdin.readline().rstrip())
if n == 0 :
return list(),... |
634696244a58784712aa9cbe24fe7a26e011986f | Jagan11/Devops-Demo | /Python/demo.py | 673 | 3.84375 | 4 | 5print ("Hi am Jarvis")
print("Enter your name:")
x = str(input())
print("Hello, " + x)
print ("please Enter your Age:")
y = input()
print ("Thanks for the details")
print ("To be suprised am a budding calculator program still learning to be a good one")
print (" As of now am capable of doing addi... |
e66a1863ce8a14ce6e7ccbb4fc2f4b470e13f563 | kramar42/experiments | /python/python-challange/level-4.py | 596 | 3.546875 | 4 | #!/usr/bin/env python2
# -*- coding: UTF-8 -*-
from urllib import urlopen
import re
def main():
"""
DON'T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough.
"""
base_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
nothing = 63579
... |
63dfbd027d72c62456a6d4889719fe5e1ba110d1 | seven7words/python_study | /Day4/1.py | 283 | 4.125 | 4 | from math import sqrt
end = int(input("请随便输入一个数 : "))
# end = int(sqrt(f))
# print(end)
is_can = True
for x in range(2,end+1):
if end % x == 0 :
is_can = False
break
if is_can and end != 1:
print("f是素数")
else:
print('f不是素数')
|
128b796bd726e83adcfb75d5591bb04f127287e7 | gopibchand/PythonSamples | /Scripts/argparse_oops_demo.py | 1,073 | 3.953125 | 4 | #!/usr/bin/env python
import argparse
import calculator
def parse_arguments():
"""
This method will parse arguments and returns the arguments
"""
global args
parser = argparse.ArgumentParser(description='Argument parser for accepting two numbers to perform addtions')
parser.add_argument("numbe... |
c850e3e85fca6fdb748326a529e2662067a4ddf0 | nurshahjalal/python_exercise | /Modules_Imports/timezone.py | 452 | 3.625 | 4 | import time
import pytz
print(time.tzname)
print("Epoch in this system starts at " + time.strftime("%c", time.gmtime()))
print("The Current Timezone is {0} with an offset of {1} ".format(time.tzname[0], time.timezone))
if time.daylight != 0:
print("\tDaylight saving time is in effect for this location")
pri... |
c29a7e512761834d7d965ef0de98f1c376e2365f | nurshahjalal/python_exercise | /String_Slicing/inputFunction.py | 100 | 4.09375 | 4 |
# input function
greeting = "Hello "
name = input("please enter your name")
print(greeting + name) |
b983f35db6ea4b734d5ef1d439455df1b0bf55d8 | nurshahjalal/python_exercise | /textfile/read_big.py | 421 | 3.78125 | 4 | # reading a big file : instead of reading whole file at a time, reading the 100 character at a time.
with open("big.txt", "r") as rf:
# reading 100 character at a time
size_to_read = 10000
contents = rf.read(size_to_read)
i = 1
while len(contents) > 0:
new_contents = str(i) + ") " + content... |
5f6a3a42788f5808b9a683afe5436f4f3808b28f | nurshahjalal/python_exercise | /lambda_map_filter_reduce/reduce.py | 199 | 3.75 | 4 | #Simply reduce function takes a list and return an item based the action of the function.
from functools import reduce
num = [3, 7, 8, 90, 76]
new_num = reduce(lambda x, y: x+y, num)
print(new_num) |
e4957aa45eb94331e23818d6085aa089b4752b44 | nurshahjalal/python_exercise | /regular_expression/flag_search.py | 371 | 4.25 | 4 | import re
sentence = 'Start a Sentence and start another sentence'
pattern = re.compile(r'Start') # returns only one 'Start' word as Searching with Capital 'S'
matches = pattern.findall(sentence)
print(matches)
pattern = re.compile(r'Start', re.IGNORECASE) # returns all 'Start' word as Searching with ignore case 'S'... |
d4f02da40170103f98451756005bd7d68e1ca336 | nurshahjalal/python_exercise | /textfile/write_file.py | 209 | 3.578125 | 4 | with open("new_file.txt", 'w') as wf:
new_text = wf.write("Hello I am New\n" * 10)
# Append Mode, it will append the file
with open("new_file.txt", 'a') as awf:
awf.write("Hello I am New2\n" * 10)
|
b7941beb68711b3fb5229a09aae7c1d3bd0153cf | nurshahjalal/python_exercise | /regular_expression/search_email_pattern.py | 209 | 3.625 | 4 | import re
with open("email", 'r') as f:
text_to_search = f.read()
pattern = re.compile(r'\d\d\d\.')
mathes = pattern.finditer(text_to_search)
for match in mathes:
print(match.group()) |
78f784f5b4a8277b7b960487a225f607371b1821 | nurshahjalal/python_exercise | /collections/counter.py | 600 | 3.953125 | 4 |
from collections import Counter
num = [1,2,3,4,5,6,7,8,9,0,7,8,9,5,6,67,7,7,7,7,7,7,7,7,7,4,4,4,45,5,5]
print(Counter(num))
word = 'adnvjdfkdfkflriuhkfjfksdaflsdfkdjnflsdkfnsdkfuhiureytrdkndsndinfksdmb'
print(Counter(word))
print(type(Counter(word)))
content = "I am learning python for fun so that i can automate lo... |
851927f7a0c30cc63f0667c97a2f7e5467eddbef | PymatFlow/Muller-sequence | /4.Generator/code_generator.py | 1,159 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
@author: Kazem Gheysari
"""
from fractions import Fraction
def a_iter():
"""
In this generator, we use the Miller's algorithm for finding the N-th value of the relation.
The original recurrence relation in unstable but reverse relation in stable , or
U... |
2aba353e4873adeb1c834e37f10fce250fe22b8a | annguyen88/Python | /Python2.7/Python-WIP/testPrograms/fileExists.py | 239 | 3.578125 | 4 | import os.path
import glob
check2 = glob.glob("hello*")
check = os.path.isfile("hello*")
if check2 == True:
print("File exists")
else:
print("File doesn't exists")
print glob.glob('hello*')
print check2
print os.path.isfile("hello")
|
aeed613b30863bd9b11f789bde5427065370dc19 | Aleksis1/Python | /DZ_1_5.py | 713 | 3.921875 | 4 | revenue = float(input('Выручка: '))
costs = float(input('Издержки: '))
result = revenue - costs
if result > 0:
print('Компания работает с прибылью:', '{:,}'.format(result).replace(',', ' '))
print("Рентабельность: {}%".format(result / revenue))
people = int(input('Численность сотрудников: '))
... |
fbd822f61c1a1be9ba9e7a288e6edaa8aa8fe6e7 | andrea94bs/pattern_recognizer | /code_elements/LogicalFunctions.py | 405 | 3.625 | 4 | from abc import ABC, abstractmethod
class LogicalFunction(ABC):
def __init__(self, *operands):
self.operands = operands
@abstractmethod
def getOperands(self):
pass
@abstractmethod
def getOperator(self):
pass
class OrFunction(LogicalFunction):
def __init__(self, *opera... |
8a290f77779772e50fedcdacb47df00b228b8295 | yolandaagrn/PrakAlpro | /Praktikum3.py | 958 | 3.8125 | 4 | #Nama : Yolanda Anggraini
#Universitas Kristen Duta Wacana
#Materi : Modular Programming
'''
#Membuat kalkulator BMI
input = tinggi badan
prosesnya = (tinggi - 100) - ((15/100)*(tinggi-100))
output = berat ideal seharusnya
'''
print('='*25, 'KALKULATOR BMI', '='*25)
def berat_ideal(tinggi):
ideal... |
d0bcb8e956286471332add5b037b1033cae8708e | yolandaagrn/PrakAlpro | /praktikum6.py | 653 | 3.828125 | 4 | #Nama : Yolanda Anggraini
#Universitas Kristen Duta Wacana
#Materi:Percabangan dan perulangan komplex
'''
input=angka baris
proses=for i in range
output=pola kotak, siku dan segitiga
'''
angka = int(input('Masukkan angka: '))
for i in range(angka):
for j in range(angka):
print('*',end=" ")
... |
2abe260725529c1923a7d23909d5a5577fc1e116 | JangJur/Python-Practice | /7-14(Number Baseball).py | 1,201 | 3.84375 | 4 | from random import randint
cnt = 0
num = []
while True:
answ_num = []
strike = 0
ball = 0
while len(num) < 3:
random_num = randint(0, 9)
while random_num in num:
random_num = randint(0, 9)
num.append(random_num)
print("0과 9 사이의 서로 다른 세 숫자를 랜덤한 순서로 뽑았습니다.")
... |
9b057424da494da3193ac4881a072ce807952bcf | JangJur/Python-Practice | /style.py | 624 | 3.9375 | 4 | PI = 3.14 # 원주율
# 반지름이 r인 원의 둘레 계산
def calculate_circumference(r):
return 2 * PI * r
# 반지름이 r인 원의 넓이 계산
def calculate_area(r):
return PI * r * r
#반지름이 4인 구의 부피 계산
def calculate_volume(r):
return 4 / 3 * PI * r * r *r
# 반지름이 4인 경우
radius = 4 # 반지름
print(calculate_circumference(radius))
print(c... |
7f18d164b7231d6e9c46968d71a5a1fdc33d8bf2 | JangJur/Python-Practice | /8-14(Reverse List).py | 305 | 3.796875 | 4 | numbers = [2, 4, 6, 8, 10, 12, 14]
# 리스트 뒤집기
# 코드를 입력하세요.
for index in range(int(len(numbers) / 2)):
temp = numbers[index]
numbers[index] = numbers[len(numbers) - index - 1]
numbers[len(numbers) - index - 1] = temp
print("뒤집어진 리스트: " + str(numbers)) |
1b74cee9231ff51cfef1643c3fa62c1f7ea83bea | salvador-dali/algorithms_general | /__competitions/2014/11_14_101hack19/01.py | 298 | 3.71875 | 4 | # https://www.hackerrank.com/contests/101hack19/challenges/two-strings
# just check whether at least one symbol is in both strings
def twoStrings(a, b):
if len(set(a) & set(b)):
print 'YES'
else:
print 'NO'
for i in xrange(input()):
twoStrings(raw_input(), raw_input()) |
25cf50ef4f8d001bc0734dd4f6b13857760b7a4a | salvador-dali/algorithms_general | /interview_bits/level_5/05_trees/01_simple_tree_ops/01_balanced-binary-tree.py | 373 | 3.84375 | 4 | # https://www.interviewbit.com/problems/balanced-binary-tree/
def maxd(root):
if root is None:
return 0
return 1 + max(maxd(root.left), maxd(root.right))
def is_balanced(root):
if root is None:
return True
if abs(maxd(root.left) - maxd(root.right)) > 1:
return False
retur... |
1dcd31aafb461ea2132fb8ee0e6339417eae483f | salvador-dali/algorithms_general | /interview_bits/level_4/04_backtracking/02_subsets/02_combination-sum-ii.py | 348 | 3.71875 | 4 | # https://www.interviewbit.com/problems/combination-sum-ii/
def sum_to_n(numbers, n):
numbers = [i for i in numbers if i <= n]
numbers.sort()
res = [[]]
for el in numbers:
res += [r + [el] for r in res]
real_res = list({tuple(i) for i in res if sum(i) == n})
real_res.sort()
return ... |
8c65b37becba04903bbafc5fa8e178473e3e6264 | salvador-dali/algorithms_general | /training/07_greedy/sherlock_minimax.py | 726 | 4.125 | 4 | # https://www.hackerrank.com/challenges/sherlock-and-minimax
# if you will sort all the elements and then the maximum from minimum
# will be only on between the elements or on the sides of the interval
def minimax(arr, a, b):
arr.sort()
diff = [a]
for i in xrange(1, len(arr)):
tmp = (arr[i - 1] + ar... |
101a5e139a016e5057274c750dbb9a10cc6b96d0 | salvador-dali/algorithms_general | /interview_bits/level_1/01_arrays/07_bucketing_sorting/01_hotel-bookings-possible.py | 611 | 3.5625 | 4 | # https://www.interviewbit.com/problems/hotel-bookings-possible/
import heapq
def isPossible(arr1, arr2, k):
arr = [(arr1[i], arr2[i]) for i in xrange(len(arr1)) if arr1[i] != arr2[i]]
arr.sort()
queue = []
for el in arr:
if len(queue) > k:
return 0
if len(queue) == 0:
... |
8f5cfcdb69ca4cece3b44a588ed0c29ff55d75b3 | salvador-dali/algorithms_general | /interview_bits/level_5/05_trees/03_two_trees/02_symmetric-binary-tree.py | 602 | 4.1875 | 4 | # https://www.interviewbit.com/problems/symmetric-binary-tree/
def is_symmetric(node):
values = []
def inoder(node):
if node:
inoder(node.left)
values.append(node.val)
inoder(node.right)
inoder(node)
return values == values[::-1]
def is_symmetric_recursion(... |
98211fc79da3afefe636a1b1f05335a4747adc63 | salvador-dali/algorithms_general | /__competitions/2015/09_05_booking-hackathon/01.py | 763 | 3.734375 | 4 | speed = {'metro': 20, 'bike': 15, 'foot': 5}
places = [map(float, raw_input().split()) for _ in xrange(input())]
hotels = []
for _ in xrange(input()):
e = raw_input().split()
hotels.append([float(e[0]), float(e[1]), speed[e[2]], int(e[3])])
from math import cos, asin, sqrt
def distance(lat1, lon1, lat2, ... |
3296a8e4fff21d68f4485ed41a70d1a20c0414ab | salvador-dali/algorithms_general | /interview_bits/ninja/01/01_build-identical-trees.py | 683 | 3.65625 | 4 | # https://www.interviewbit.com/problems/build-identical-trees
# http://stackoverflow.com/q/33859606/1090562
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def analysis(a, b):
if a is None and b is None:
return 0
if a is None:
... |
d6d4e5a5e895b140b72f4c23d5c67e03213bbf22 | salvador-dali/algorithms_general | /training/04_sorting/quicksort4.py | 999 | 3.84375 | 4 | # https://www.hackerrank.com/challenges/quicksort4/
# count the number of swaps in quicksort
def quick_sort(arr, left=None, right=None):
if left is None:
left = 0
if right is None:
right = len(arr) - 1
if left >= right:
return 0
lPoint = rPoint = left
pivot, count = arr[ri... |
f67284dac4fe10fcb482cbc540f9f415a160f116 | salvador-dali/algorithms_general | /interview_bits/level_5/05_trees/00_examples/01_next-greater-number-bst.py | 434 | 3.75 | 4 | # https://www.interviewbit.com/problems/next-greater-number-bst/
def getSuccessor(node, data):
successor = None
while node:
if node.val == data:
node = node.right
while node:
successor, node = node, node.left
return successor
elif node.val > da... |
9c7fffbb8c573c2372ed8f633111d9c08de9e97d | salvador-dali/algorithms_general | /interview_bits/level_3/03_linked-lists/00_examples/01_intersection-of-linked-lists.py | 571 | 3.859375 | 4 | # https://www.interviewbit.com/problems/intersection-of-linked-lists/
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def getLength(A):
length = 0
while A is not None:
A = A.next
length += 1
return length
def getIntersection(A , B, diff):
for i ... |
bafcc411d03b9389be190bb9e02bacf1d9626028 | salvador-dali/algorithms_general | /interview_bits/level_5/05_trees/03_two_trees/01_identical-binary-trees.py | 345 | 3.953125 | 4 | # https://www.interviewbit.com/problems/identical-binary-trees/
def is_identical(n1, n2):
if n1 is None and n2 is None:
return True
if (n1 is None and n2 is not None) or (n2 is None and n1 is not None):
return False
return n1.val == n2.val and is_identical(n1.left, n2.left) and is_iden... |
0a5c315ed3d5d69df97596cebca4b5fe41cc49ea | salvador-dali/algorithms_general | /training/04_sorting/countingsort4.py | 381 | 3.59375 | 4 | # https://www.hackerrank.com/challenges/countingsort4
arr = []
for i in xrange(input()):
a, b = raw_input().split()
arr.append([int(a), b, i])
# just sort the list based on the 2 columns
arr = sorted(arr, key = lambda x : (x[0], x[2]))
l = len(arr) / 2
out = []
for i in arr:
if i[2] < l:
out.append... |
92e13d1b9fbdfe9d66c4a5d097872adf47c1b070 | salvador-dali/algorithms_general | /interview_bits/level_3/03_linked-lists/00_examples/02_reverse-linked-list.py | 447 | 3.90625 | 4 | # https://www.interviewbit.com/problems/reverse-linked-list/
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def reverse(head):
new_head = None
while head:
head.next, head, new_head = new_head, head.next, head
return new_head
def reverse(head):
prev ... |
dace476ce3d6395d4824a473e0d9543a9889530c | salvador-dali/algorithms_general | /__competitions/2015/08_31_w17/02.py | 551 | 3.71875 | 4 | from datetime import datetime, date
def analyse(d1, m1, y1, d2, m2, y2):
total = 0
for i in xrange(y1 * 12 + m1 - 1, y2 * 12 + m2):
year = i / 12
month = i % 12 + 1
if date(year, month, 13).weekday() == 4:
total += 1
if d2 < 13:
total -= int(date(y2, m2, 13).we... |
6b0acd68ac3dee83af4ae26eccc50dcb4038a218 | salvador-dali/algorithms_general | /interview_bits/level_3/03_linked-lists/01_list2pointer/05_remove-nth-node-from-list-end.py | 444 | 3.65625 | 4 | # https://www.interviewbit.com/problems/remove-nth-node-from-list-end/
def remove_n_th(node, n):
start, length = node, 0
while node:
node = node.next
length += 1
if n >= length:
return start.next
pos_rem, node, curr = length - n, start, 0
while node:
curr += 1
... |
c7a6186be0a3829ced3b241dd8c224a594dff491 | salvador-dali/algorithms_general | /training/02_implementation/sherlock_and_squares.py | 304 | 3.71875 | 4 | # https://www.hackerrank.com/challenges/sherlock-and-squares
import math
def numSquares(a, b):
c = math.ceil(a**(1/2.0))
num = 0
while c ** 2 <= b:
c += 1
num += 1
return num
for i in xrange(input()):
a, b = map(int, raw_input().split())
print numSquares(a, b) |
2e62eabdd91f6ff999b4235a3312a59cb45e3807 | salvador-dali/algorithms_general | /__competitions/2015/01_06_w13/01.py | 511 | 3.796875 | 4 | # https://www.hackerrank.com/contests/w13/challenges/sherlock-and-anagrams
# the main idea is to check whether it is better to swap the element or not
# so, when you swapping, you end up paying previous price + price for the swap
# and then you need to select the smaller of them
# basically O(1)
def res(w, b, x, y, z):... |
aa022a779e9ff486c6e15421000c939f78c07dbb | salvador-dali/algorithms_general | /training/02_implementation/utopian_tree.py | 237 | 4.09375 | 4 | # https://www.hackerrank.com/challenges/utopian-tree
def height(n):
h = 1
for i in xrange(n):
if i % 2:
h += 1
else:
h *= 2
return h
for i in xrange(input()):
print height(input()) |
ac527e09e679dfc5a66a3a98e0651eeecd86d879 | salvador-dali/algorithms_general | /training/04_sorting/insertion_sort.py | 665 | 3.5 | 4 | # https://www.hackerrank.com/challenges/insertion-sort/
class BinaryIndexedTree():
def __init__(self, size):
self.size = size
self.tree = [0] * size
def update(self, idx, val):
while idx <= self.size:
self.tree[idx] += val
idx += (idx & -idx)
def read(self, ... |
522a8d4611cce17b25bfac8b4f78084efa7e6fbf | salvador-dali/algorithms_general | /interview_bits/level_5/05_trees/10_inplace_change/01_invert-the-binary-tree.py | 545 | 4.125 | 4 | # https://www.interviewbit.com/problems/invert-the-binary-tree/
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def invert(node):
if not node:
return
if not node.left:
node.left, node.right = node.right, None
invert(nod... |
f026afdff28d71a87c2060b48cb620fd95d61e1b | salvador-dali/algorithms_general | /training/05_search/sherlock_and_array.py | 423 | 3.671875 | 4 | # https://www.hackerrank.com/challenges/sherlock-and-array
def arr_partition(arr):
first, second = 0, sum(arr)
for i in xrange(len(arr)):
if i:
first += arr[i - 1]
second -= arr[i]
if first == second:
return True
return False
for i in xrange(input()):
ra... |
9ad4cfe19ccc4fd82fa94bc9f36fbb604d199c21 | salvador-dali/algorithms_general | /__library/helpers/rangeQuery.py | 8,851 | 3.5 | 4 | """
# Various algorithms that requires pre-processing of the input data to be able later to answer a lot of
# specific queries later. Algorithm run in <f(n), g(n)> time (pre-processing and each query time)
# and requires h(n) extra memory.
# http://www.spoj.com/problems/FREQUENT/
# http://www.spoj.com/problems/GSS1/
# ... |
585f627ba0a725e32cf24a0dec30309b33a7a293 | salvador-dali/algorithms_general | /interview_bits/level_4/04_backtracking/00_examples/01_modular-expression.py | 307 | 3.890625 | 4 | # https://www.interviewbit.com/problems/modular-expression/
def power(a, b, m):
if m == 1:
return 0
if b == 0:
return 1
a = a % m
curr, res = a, 1
while b:
if b % 2:
res = (res * curr) % m
b /= 2
curr = (curr * curr) % m
return res |
65fd2aa1fdd589542c55d4ec666ec5e1e2587f0c | salvador-dali/algorithms_general | /training/03_strings/palindrome_index.py | 501 | 4.09375 | 4 | # https://www.hackerrank.com/challenges/palindrome-index/
def isPalindrome(string):
return string == string[::-1]
def palindrome_index(string):
start = 0
end = len(string) - 1
while start < end:
if string[start] == string[end]:
start, end = start+1, end-1
continue
... |
74dbaa803778d84ad92afa67e20d1cb59f091ac1 | salvador-dali/algorithms_general | /interview_bits/level_2/02_strings/01_string_simulation/01_palindrome-string.py | 437 | 3.921875 | 4 | # https://www.interviewbit.com/problems/palindrome-string/
def isPalindrome(s):
if s == '':
return 1
p1, p2 = 0, len(s) - 1
while p1 <= p2:
while not s[p1].isalnum():
p1 += 1
if p1 == len(s):
return 1
while not s[p2].isalnum():
p2... |
9bbd83a4689c875ee5a6dce967abbc61e133eeb9 | salvador-dali/algorithms_general | /interview_bits/level_6/06_greedy/03_bulbs.py | 317 | 3.75 | 4 | # https://www.interviewbit.com/problems/bulbs/
def bulb(arr):
if not len(arr):
return 0
prev, arr2 = -1, []
for i in arr:
if i != prev:
arr2.append(i)
prev = i
if arr2[0] == 1:
return len(arr2) - 1
return len(arr2)
print bulb([1, 1, 1, 0, 1, 1]) |
24400a3f1012c2aaf60a1c3ec5ea797377bedf57 | salvador-dali/algorithms_general | /__library/helpers/encoding.py | 3,505 | 3.84375 | 4 | class HuffmanCode:
"""
Huffman code is a variable length encoding, which means that different symbols are encoded with different
amount of bytes. It takes into advantage the fact that different symbols can have different frequencies.
For any frequencies it produces optimal prefix-free encoding
Impo... |
e2dc57564ff7785f8e40cb541521e88d43477fb9 | salvador-dali/algorithms_general | /interview_bits/level_7/07_graphs/02_shortest_path/02_sum-of-fibonacci-numbers.py | 464 | 3.765625 | 4 | # https://www.interviewbit.com/problems/sum-of-fibonacci-numbers/
from bisect import bisect_right
def generate(n):
arr = [1, 1]
while arr[-1] <= n:
arr.append(arr[-1] + arr[-2])
return arr[:-1]
def present_as_fib(fibs, n):
res = []
while n:
pos = bisect_right(fibs, n)
res.... |
39d4c57aeb4efb5eb29eaf505fe6ff94701f0a7b | salvador-dali/algorithms_general | /interview_bits/level_2/02_two_pointers/02_multiple_arrays/01_intersection-of-sorted-arrays.py | 381 | 3.921875 | 4 | # https://www.interviewbit.com/problems/intersection-of-sorted-arrays/
def intersection(arr1, arr2):
p1, p2, res = 0, 0, []
while p1 < len(arr1) and p2 < len(arr2):
if arr1[p1] < arr2[p2]:
p1 += 1
elif arr1[p1] > arr2[p2]:
p2 += 1
else:
res.append(arr1... |
037eb90565afbdaac37814354fdfa3e820c7fe58 | salvador-dali/algorithms_general | /training/04_sorting/countingsort2.py | 337 | 3.5 | 4 | # https://www.hackerrank.com/challenges/countingsort2/
def countSort(arr):
n = 100
l = [0] * n
for i in arr:
l[i] += 1
l1 = []
for i in xrange(n):
if l[i]:
l1.extend([i] * l[i])
return l1
raw_input()
arr = list(map(int, raw_input().split()))
print ' '.join(map(str,... |
e1d724d2dc9001a5a03aa8c737375fedbb6ae861 | salvador-dali/algorithms_general | /interview_bits/level_2/02_two_pointers/02_multiple_arrays/02_merge-two-sorted-lists-ii.py | 371 | 4 | 4 | # https://www.interviewbit.com/problems/merge-two-sorted-lists-ii/
def mergeSorted(arr1, arr2):
res, p1, p2 = [], 0, 0
while p1 < len(arr1) and p2 < len(arr2):
if arr1[p1] < arr2[p2]:
res.append(arr1[p1])
p1 += 1
else:
res.append(arr2[p2])
p2 += 1... |
45fa20159317a64ad7a2ffa77da8b886c560d57d | salvador-dali/algorithms_general | /interview_bits/level_7/07_graphs/01_graph_connectivity/01_black-shapes.py | 819 | 3.578125 | 4 | # https://www.interviewbit.com/problems/black-shapes/
def grow_mold(M, i, j):
frontier = [(i, j)]
tried = set([])
while len(frontier):
y, x = frontier.pop()
tried.add((y, x))
M[y][x] = 0
for y1, x1 in [(y - 1, x), (y + 1, x), (y, x - 1), (y, x + 1)]:
if (y1, x1) n... |
18edb6c0bd87b2cec770ad3276b791dc2d1a0ac6 | salvador-dali/algorithms_general | /__competitions/2016/05_13_game_theory/13_powers-of-two-game.py | 377 | 3.84375 | 4 | # after investigation I found that you can divide all the numbers in +-i groups, where i
# is from 1 to 8. Apart from that only i = [1, 2, 4, 8] are possible
# second can win if the number of +- are the same. After some trial and error, I found that it
# happens if n % 8 == 0
for i in xrange(input()):
if input() % ... |
809344b5ad4e63163e71374cdc068c1b66b2ac8b | jentche/Emmanuel_Python_Lessons | /In class Projects/Project 4_Visualizing Monetary Policy/datlib/plots.py | 4,978 | 3.828125 | 4 | #plots.py
# os library or module allows you to access
# commandline functions from python. Such as making a new directory,
# changing or navigating between directories, copy files, change file names, etc
import os
import pandas as pd
# numpy is a math data library
import numpy as np
# matplotlib is used for plottin... |
87f40ef3f68f0fc032d84ef517d9db72b34ed2f6 | morde66/unipi_python_1 | /e12.py | 346 | 3.828125 | 4 | text = input("Enter text here: ")
x = len(text)
output = " "
for i in range(x):
c = text[x - i - 1] #pairnei ton teleutaio xarakthra
y1 = ord(c) #ton kanei se ascii arithmo
y2 = 128 - y1 #upologizei to katoptriko se ascii
output += chr(y2) #kanei ton katoptriko se xarakthra kai ton vazei sto out... |
a20743d7aa7b63d15c2caefd771eb7c1d1d0f40d | roy-sizemore/per_scholas_python_party | /homework1.py | 300 | 3.53125 | 4 | total = 0
def sum_numbers(total):
with open('homework.txt') as homework:
my_name = [name for name in homework if 'Roy' in name]
for line in my_name:
names_numbers = line.split()
total += int(names_numbers[1].strip())
print(total)
sum_numbers(total)
|
130cf8de855b8245d3310a8ef6e210cc58723ac4 | Benjamin-Watson/PokeClone | /launcher.py | 1,747 | 3.609375 | 4 | import random
import time
#Pokemon Clone Made By Hunter Levinger
class monster:
def __init__(self, attack, defence, type, lvl):
self.type = type
self.attack = attack
self.defence = defence
self.maxHealth = lvl * 65
self.health = self.maxHealth
self.lvl = lvl
de... |
0c807cbc5982cdf1295d675989db0302f0a9559c | skandamohan/Euler-Problems | /problem3.py | 556 | 3.703125 | 4 | '''https://projecteuler.net/problem=3'''
'''Please see the README document for details'''
def run(upper_bound):
if(upper_bound%2 == 0):
upper_bound = upper_bound-1
for decrementor in range(upper_bound, 0,-2):
print str(decrementor)+", ",
counter = 2
while(counter < decrementor):
if(decrementor%counter == ... |
a468482bce4b527f3bd1f8bafd39d52278b78acc | skandamohan/Euler-Problems | /problem8.py | 1,127 | 3.984375 | 4 | '''https://projecteuler.net/problem=6'''
'''Please see the README document for details'''
import math
import operator
def run(big_number, number_of_digits):
big_array = put_digits_of_number_into_array(big_number)
if len(big_array)-1 < number_of_digits:
print "Your number of digits is bigger than the BIG nu... |
b6619c471fd0fd9025bfc42b250e825a2d580479 | cmarr31/python_round_2 | /week_1/tuples_dictionaries.py | 318 | 3.84375 | 4 | # function input
my_dict = {
"Speros": "(555) 555-5555",
"Michael": "(999) 999-9999",
"Jay": "(777) 777-7777"
}
#function output
[("Speros", "(555) 555-5555"), ("Michael", "(999) 999-9999"), ("Jay", "(777) 777-7777")]
def dict_to_tuple(dictionary):
t = dictionary.items()
print t
dict_to_tuple(my_dict) |
c521bc6bc5507084b866686bc97c172c845b3351 | deyanskiq/HackBulgaria | /week8/CinemaReservationSystem/kinosalon.py | 1,609 | 3.546875 | 4 | class Map:
def __init__(self, filename):
lines = open(filename).read().split("\n")
lines = [line for line in lines if line.strip() != ""]
self.map = [list(line) for line in lines]
self.seats_availability = {}
for i in range(1, 11):
for j in range(2, 21):
... |
3a99244fd30c0f903ee040df50d64a7426efee16 | dacl010811/cursopython2021 | /Unidad1/string.py | 1,678 | 4.09375 | 4 | #Definir cadenas o String (
#
cadena_1 = "Mi pelicula favorita es :" # Tipado dinamico :
cadena_2 = "Avangers"
# Para concatenar utilizamos signo "+"
cadena_3 = cadena_1 + " " +cadena_2
print(type(cadena_3))
print(cadena_3)
# Concatenar tambien vamos utilizar ","
cadena_1 = "100"
cadena_2 = "Mazda"
cadena_... |
b28274793b40dab6a6d970e6bf97dc5c718fd71e | dacl010811/cursopython2021 | /Unidad9/encapsulamiento.py | 1,657 | 3.953125 | 4 | #Encapsulamiento
class Ejemplo():
#Atributo de clase
__atributo_privado_a = "Python A"
__atributo_privado_b = "Python B"
def __init__(self, nombre):
self.__nombre = nombre
#get de un atributo
@property
def nombre(self):
return self.__nombre
#Simular un set
@nombre... |
6fb9319f4a0d30c59ab8cf3f0081f1b985bbac23 | dacl010811/cursopython2021 | /Unidad3/estructuras_for.py | 953 | 4.1875 | 4 | # For : Iterar entre elemento y elemento
lista = [1,2,3,4,5,6,7,8,9]
# 0 1 2 ..........
print("-------------Estructura While------------")
indice = 0
while (indice < len(lista)):
print(f"{indice} : {lista[indice]}")
indice +=1
#Cambios para el estructura for
print("-------------Estructura For--------... |
3c009fc76d18edab77e7f5f4e4729175e4da576b | dacl010811/cursopython2021 | /Unidad4/funciones_parametros_defecto.py | 1,203 | 3.828125 | 4 | #Parametros por defecto.
def resta(a=None,b=None):
if a != None and b != None:
if isinstance(a,int) and isinstance(b,int):
resultado = a-b
else:
print("Error, no se pueden realizar operacion con datos que no sean Base10")
return
else:
print("Los dato... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.