blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 545k | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 545k |
|---|---|---|---|---|---|---|
8af6afe0c13b9b7e332f9c02ca54ca564f60256f | xcnwf/AdventOfCode2020 | /day 1/d1-algo.py | 948 | 3.5 | 4 | import numpy as np
Numbers = []
with open("d1-input.txt", 'r') as f:
for l in f:
Numbers.append(int(l.strip()))
## PART 1
print("## Day 1 - Part 1 ##")
for i in range(len(Numbers)):
for j in range(len(Numbers)):
if i != j and Numbers[i] + Numbers[j] == 2020:
print("Solution found : a = {} and b = {}. a + b = ... |
8ef46addf3ff00c698eee105bbc8b149cb68f1f6 | anthony2446/test-py | /videolesson/odd_even.py | 243 | 3.921875 | 4 | #coding:utf-8
'''
lesson 19-04
filename: odd_even.py
'''
lst = [1,2,3,4,5,6,7,8,9,10]
odd = []
even = []
for i in lst:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
print("odd: ", odd)
print("even: ", even) |
8b9602b07e32de9035895e366b7cce91117ed483 | christinerose/python_projects | /MadLibs.py | 482 | 3.765625 | 4 | noun = input("Give me a noun: ")
noun2 = input("Give me another noun: ")
celebrity = input("Give me celebrity's name: ")
verb = input("Give me an action verb: ")
verbing = input("Give me an -ing verb: ")
animal = input("Name an animal that starts with a consonant: ")
print("That", noun, "is singing to a big", noun2 + ... |
7e53a35ce5df8873d540fe708e0c110af0d51eeb | nyccowgirl/text_wrapper | /text_wrap.py | 5,021 | 3.515625 | 4 | """
Write a generator that lazily rewraps text so that it fits an 80 column window
without breaking words, and a consumer function that demonstrates same using the
contents of the filename passed on the command line, as follows:
$ python3 text_wrap.py <filename>
"""
import sys
def get_data(infile):
"""Lazy fun... |
fc1453ee6d2deecd858a5669cfe28926f97a3e78 | mns4al/ChIDE-Code | /NightLight.py | 485 | 3.578125 | 4 | #Night Light - dimming version
#Required a photocell connected between pins 0 and 3v
from microbit import *
all_on = Image() #create empty image
pin0.read_digital() #Setup Pin0
while True:
# read pin0: returns 0=dark to 1023=bright
value = pin0.read_analog()
# Convert value to a 0-9 "Lamp_Level"
... |
c7e1424764351fdef37a7fc79856318b8872673a | Miri-Hwang/Web_Scraping_Challenger | /check_url.py | 1,804 | 3.640625 | 4 | import requests
# url에 '.com'이 포함되는 지 확인
def dot_come(url):
if url[-4:] == ".com":
return True
else:
return False
# url에 'https://'이 포함되는 지 확인
def check_http(url):
if url[0:8] == "https://" or url[0:7] == "http://":
return True
else:
return False
# URL이 유효한 값인 지 확인... |
22b36ae23d2d5ffeb264ab4acb27e229939ba6f2 | sevas/fastpython_sandbox | /pylib/mynumeric.py | 186 | 3.5625 | 4 | def sum(lo: int, hi: int) -> int:
i = lo # type: int
out = 0 # type: int
while True:
out += i
i += 1
if i == hi:
break
return out
|
3581eafdd034ac79ae8446a461f062b56ffc0dc9 | pedrohdavelar/MITx-6.00.1x-Exercises | /Week 1/problem2.py | 256 | 3.796875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 15:04:41 2020
@author: Pedro
"""
s = "azcbobobegghakl"
print(len(s))
count = 0
num = 0
for letter in s:
if s[num:(3+num)] == 'bob':
count += 1
num += 1
print (count)
|
a1cdd5430752daa45f5f800831ef8a6019c166ff | Srammy/GraAlgo | /Chapter02/selection_sort_decrease.py | 707 | 3.640625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Oct 8 21:40:53 2018
@author: ASUS
选择排序-递减 时间复杂度O(n^2)
"""
def findmax(arr):
"""
寻找序列中的最大值
arr:操作的序列
return :最大值的索引
"""
max_value = arr[0]
max_index = 0
for i in range(1,len(arr)):
if arr[i] > max_value :
max_value = arr[... |
c3f64bd3ed5b26bd2a69919af01960c15b1b5e07 | EDU-FRANCK-JUBIN/exercices-sur-python-Nummytincan | /VolumeConeDroit.py | 182 | 4 | 4 | import math
print("entrer la hauteur du cone")
h = int(input())
print("entrer le rayon de la base du cone")
r = int(input())
v = r*r*math.pi
print(v)
v /= 3
print(v)
v *= h
print(v)
|
3aecd3afc0558b00aa683aeb245b1e2876f78706 | hazim/Treehouse---Python-Basic | /check_please.py | 519 | 4.21875 | 4 | import math
def split_check(total, number_of_people):
# we want to round up the number in order to make sure that the person paying is not paying the extra out of their own pocket
return math.ceil(total_due / split_among)
try:
total_due = float(input("What is the total? \n"))
split_among = int(input("How many ... |
5c13fae29c8cfabd1964a78ac57ad905ba0798fd | oops-p-creater/DSA | /duplicate Paranthesis.py | 324 | 3.703125 | 4 | from collections import deque
exp=input("enter expression")
stack=deque()
for i in exp:
if(i!=')'):
stack.append(i)
else:
if(stack[-1]=='('):
print("false")
break
while(not stack[-1]=='('):
stack.pop()
stack.pop()
print("true... |
a8e2c922a8f4503cdb5ad29a5c2c1c22b45c21cc | ysechrest/yadlf | /yadlf/neuralnet.py | 11,140 | 4.0625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Sep 22 17:02:37 2018
@author: yanceys
TODO:
- Implement Batch Normalization
"""
import numpy as np
#----------------------------------------------------------------
#Definitions of activation functions and their derivatives below.
#These are used by nnlayer to ... |
342bb962990c1007de76c11712172e4cc71d870a | fargofremling/practiceprograms | /sleepin.py | 586 | 4.09375 | 4 | day_of_week = raw_input("What day of the week is tomorrow? \n> ").lower()
weekend = [
"saturday",
"sat",
"sunday",
"sun",
"s"]
weekday = [
"monday", "mon", "m",
"tuesday", "tues", "tue", "t",
"wednesday", "wed", "w",
"thursday", "thurs", "thu",
"friday", "fri", "f"]
if day_o... |
eb19e9bba5d91fc9a2d8703e649f1c93d2e940b1 | fargofremling/practiceprograms | /sum_square_difference.py | 964 | 3.859375 | 4 | # The sum of the squares of the first ten natural numbers is,
# 1**2 + 2**2 + ... + 10**2 = 385
#
# The square of the sum of the first ten natural numbers is,
# (1 + 2 + ... + 10)**2 = 552 = 3025
#
# Hence the difference between the sum of the squares of the first ten natural numbers
# and the square of the sum is... |
6bed9547a01b75035b9f268866e2b30115e3193c | fargofremling/practiceprograms | /power_digit_sum.py | 372 | 4 | 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?
exponent = 2**1000
print "2 ^ 1000 =", exponent
split = str(exponent)
big_number = list(split)
print big_number
big_number = [ int(x) for x in big_number ]
def add(x,y): return x+y
answe... |
6c59ebb2ccef32d42ce26a1c5c641ed026732194 | fargofremling/practiceprograms | /coin_estimator.py | 3,782 | 4.25 | 4 | # Goal Create a program that allows the user to input the total weight of each type
# of coin they have (pennies, nickels, dimes, and quarters), and then print out how
# many of each type of wrapper they would need, how many coins they have, and the
# estimated total value of all of their money.
# Weight of each coi... |
fc7529146178c2b5bec177608aac796298088621 | afunesa/Mi-primer-ejercicio | /basico.py | 376 | 3.640625 | 4 | # Primeros pasos cn datos basicos
saludo= "Hola a todos!"
numero_uno = 1
numero_dos_decimales = 1.25E3
primera_letra = "A"
print(saludo)
print("Empezamos el curso" + " " + primera_letra)
print(bool(9))
print(bool(0))
print(bool("blabla"))
print(numero_uno + numero_dos_decimales)
primera_letra = "aa"
print("Empezamos... |
64dfac840a45b17371c2993075b6d0302f11b78b | xinJone/gifmaze | /gifmaze/algorithms.py | 9,059 | 3.8125 | 4 | # -*- coding: utf-8 -*-
import heapq
import random
from collections import deque
from operator import itemgetter
from .maze import Maze
def prim(maze, start):
"""Maze by Prim's algorithm."""
queue = [(0, start, v) for v in maze.get_neighbors(start)]
maze.mark_cell(start, Maze.TREE)
while len(queue) ... |
3ea712598966cdf88b26b070244d9f72df1e1e82 | PepperBrookside/TicTacToePython | /tictactoe/collatz.py | 162 | 3.59375 | 4 | import test
def collatz(n):
print(n)
if n==1: return 0
if n%2==1:
return 1 + collatz(3*n+1)
else:
return 1 + collatz(int(n/2))
|
94e1039cf02ee01fe894a1fddf75d0ad26776850 | akbb0707/The-Months | /main.py | 2,122 | 3.9375 | 4 | import random
import sys
months_raw = open("Months.txt",encoding="utf-8").readlines()
months_polish_raw = open("MonthsPolish.txt",encoding="utf-8").readlines()
months = []
months_polish = []
for element in months_raw:
months.append(element.strip())
for element in months_polish_raw:
months_polish.... |
983c937e01dd998476887933c1844d9288e4ed70 | netatch/Sudoku-solver | /solver.py | 10,208 | 3.53125 | 4 | #bo is a grid - 9x9 board game with numbers 1-9
import copy
from tests import *
#const
BOX1=(range(0,3),range(0,3))
BOX2=(range(0,3),range(3,6))
BOX3=(range(0,3),range(6,9))
BOX4=(range(3,6),range(0,3))
BOX5=(range(3,6),range(3,6))
BOX6=(range(3,6),range(6,9))
BOX7=(range(6,9),range(0,3))
BOX8=(range(6,9),... |
c6c3d36e8e94df119bd83ca6814367854604c4fd | akosasante/bioinformatics | /rosalind functions.py | 2,520 | 3.609375 | 4 | import re
import operator
def NucleotideCounter(DNA):
result = [0, 0, 0, 0]
for base in DNA:
if base == "A":
result[0] += 1
elif base == "C":
result[1] += 1
elif base == "G":
result[2... |
434137c46c2ce81aa057aa931d4d124843fb5c20 | neurodebian/fsleyes-props | /fsleyes_props/widgets_number.py | 8,911 | 3.578125 | 4 | #!/usr/bin/env python
#
# widgets_number.py - Create widgets for modifying Number properties.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""This module provides the :func:`_Number` function, which is imported into
the :mod:`widgets` module namespace. It is separated purely to keep the
``widgets`` module file... |
4c4c583509fe799d9e82d468323a5f97f8778b9d | codewitty/Python_Code-Challenges | /unique.py | 1,345 | 3.875 | 4 | import re
from collections import Counter
def take(n, iterable):
"Return first n items of the iterable as a list"
return list(islice(iterable, n))
def unique(file_name):
with open(file_name, 'r') as file:
data = re.findall(r"[0-9a-zA-Z-']+", file.read())
data = [words.upper() for words in ... |
e97c4992d812d179ed739f2bc355ffe816ad9031 | donutdaniel/Python-Challenge | /p0-9/p5/p5.py | 447 | 3.546875 | 4 | import pickle
#load data
ifile = open('data.txt', 'rb')
obj = pickle.load(ifile)
ifile.close()
#load output file
ofile = open('out.txt', 'w');
#p is a list of lists of lists..I think ascii art!
#print to console and out.txt
#O(n^2)
for i in obj:
for j in i:
char = j[0]
k = j[1]
for x in range(0, k):
print(... |
f63233131068519c68bb0fd2f53959387a3dd730 | donutdaniel/Python-Challenge | /p10-19/p15/p15.py | 482 | 3.84375 | 4 | import datetime
validDates = []
for n in range(100):
year = ""
if n < 10:
year = "10" + str(n) + "6"
else:
year = "1" + str(n) + "6"
year = int(year)
d = datetime.date(year, 1, 26)
#check for 26th falling on a thursday
if(d.weekday() == 0 and year%4 == 0):
#check for leap year
validDates.append(d)
pri... |
239d72457d3148a28479b43f20669fdf4076c84c | shanekang/pre-education | /quiz/pre_python_10.py | 309 | 3.96875 | 4 | """10. 팩토리얼을 구하는 함수를 작성하시오.
ex ) 5! = 5x4x3x2x1
print(factoral(5)) -> 120 출력
예시
<입력>
print(factorial(5))
<출력>
120
"""
def factorial(n):
fac = 1
for i in range(1, n + 1):
fac *= i
return fac
print(factorial(5))
|
0ab8514c0104788d78f244588735a33305766867 | shanekang/pre-education | /quiz/quiz5_4_hanoi.py | 242 | 3.96875 | 4 | def hanoi(n, start, end):
if n == 0:
return
middle = 6 - start - end
hanoi(n-1, start, middle)
print(f"{start}번 기둥의 {n}번 원반을 {end}번 기둥에 옮긴다.")
hanoi(n-1, middle, end)
hanoi(3, 1, 3) |
5ffd4932c42ee0aad2a4ba1f55a700db5f94726d | HarelKahani/T-Talk | /game_test/client.py | 3,404 | 3.515625 | 4 | import time
import pygame
import random
width = 700
height = 700
apple_w = 20
apple_h = 20
window = pygame.display.set_mode(size=(width, height))
pygame.display.set_caption("My Game")
class Apple:
def __init__(self, x, y):
self.x = x
self.y = y
self.width = apple_w
... |
1fbdeee095f2c6dfaab9fa9427041c279b4583f3 | RJSPEED/DB_BANK_TELLER_ | /bt_schema.py | 712 | 3.5625 | 4 | import sqlite3
import os
DIRPATH = os.path.dirname(__file__)
DBFILENAME = "bank_teller.db"
DBPATH = os.path.join(DIRPATH, DBFILENAME)
def schema(dbpath):
with sqlite3.connect(DBPATH) as conn:
cursor = conn.cursor()
SQL = "DROP TABLE IF EXISTS accounts;"
cursor.execute(SQL)
SQL =... |
a322a6c261c2b80b9c0e161d3b104e252d1c3014 | dikaa7/kripto4 | /rsa.py | 792 | 3.65625 | 4 | import random
from util import is_prime, gcd, modinv
def generate_keypair(p, q):
if not (is_prime(p) and is_prime(q)):
raise ValueError('Both numbers must be prime.')
elif p == q:
raise ValueError('p and q cannot be equal')
n = p * q
phi = (p-1) * (q-1)
e = random.randrange(1, phi... |
efff89c172521965ce1806c4d8049cdcb2aea664 | humyPro/play_python | /variable_parameter.py | 290 | 3.859375 | 4 | #!/use/bin/env python
# -*- coding: utf-8 -*-
def calc(*nums):
sum=0;
for n in nums:
sum+=n*n
return sum
print('这里定义了一个计算a^2+b^2+....+n^2的函数')
print('函数签名是calc(*nums)')
print('可以传入一个list或者tuple,这样:nums=[1,2,3] -> cale(*nums)') |
8c7de2f7120c4610d4621eefea4cf60986daca15 | PiersonGarrett/Python-Skillbuilding-Projects | /File_Projects/Code_Snippet_Organizer/Colors_ANSI.py | 993 | 3.703125 | 4 | # Colors_ANSI can add color to text using ANSI escape sequences
class Colors_ANSI:
RED = '\033[38;5;124m'
GREEN = '\033[38;5;28m'
ORANGE = '\033[38;5;202m'
PURPLE = '\033[38;5;98m'
CYAN = '\033[38;5;43m'
YELLOW = '\033[38;5;215m'
ENDCOLOR = '\033[39m\033[39m'
def get_color(self,col... |
018eba95a408fdf49382690ebbbeb4860d2769ca | PiersonGarrett/Python-Skillbuilding-Projects | /File_Projects/Code_Snippet_Organizer/Snippet.py | 1,395 | 3.59375 | 4 | # Definition of Snippet Class which will hold information of a snippet and return a modified string with syntax highlighting
# Handles the change in text color needed for syntax highlighting
from Colors_ANSI import Colors_ANSI
class Snippet(Colors_ANSI):
def __init__(self,_label,_language,_snippet_string... |
6e0312f298ea6be09851588dbd9cd1e5a4c9fcb1 | devnikhilmhatre/hacker-rank | /hacker_rank/counting_valleys.py | 387 | 3.71875 | 4 | def countingValleys(n, s):
step = 0
valley = 0
for i in s:
if step == 0:
start = i
if i == 'U':
step += 1
else:
step -= 1
if step == 0 and start == 'D':
valley += 1
return valley
# string = 'DDUUDDUDUUUD'
string = 'UD... |
7149c2015a8de5d29600b5880b4c4319651b1a05 | hadoge/simpleScripts | /Aletter.py | 250 | 3.84375 | 4 | #words count
def count(a, b):
c = 0
for i in a:
if i == b :
c = c + 1
return c
word = count("I knew you would come, but i didn't know how", "o")
print(word)
|
8700ee3c5b6427a7d546ca5e4a327a03afe072e0 | yaitouny/SMU_homework | /03-Python/Python-Challenge/PyBank/main.py | 1,936 | 3.984375 | 4 | import csv
budget_data = r"Python-Challenge/PyBank/budget_data.csv"
totalMonths = 0
netTotal = 0
averageChange = 0
newList = []
changeList = []
maxIncrease = 0
minDecrease = 0
#open and read from csv file
with open(budget_data) as csvfile:
csv_reader = csv.reader(csvfile, delimiter = ",")
csv_header = next(csvfil... |
c593de4528944eecdd6c30ddeb1d1ccc27517dec | Three-Y/MyPythonLearning | /ibbie_16_列表.py | 2,048 | 4.1875 | 4 | """
列表(list,相当于java中的数组)
格式:变量名=["hhh","xxx","jjj","aaa"]
索引值从0开始
可以存放不同类型的数据,但是通常存放类型相同的数据
"""
"""创建列表"""
name_list = ["hhh", "jjj", "jjj", "aaa"]
print(name_list)
"""根据索引取值"""
name_list[2]
# name_list[4] # IndexError: list index out of range
print(name_list[2])
"""根据内容取索引"""
name_list.index("aaa")
# na... |
84a49f93c9e05a35e7ae543e8b03dc7f9cb0a8ce | Three-Y/MyPythonLearning | /ibbie_32_父类的公有属性和方法.py | 825 | 4.34375 | 4 | """
父类的公有属性和方法
子类可以调用父类的公有属性和方法
子类对象也可以调用父类的公有属性和方法
可以通过父类的公有方法,在子类间接调用父类的私有属性和方法
"""
class A:
def __init__(self):
self.a = "父类公有属性"
self.__b = "父类的私有属性"
def test(self):
print("父类公有方法")
print("父类的公有方法中调用父类的私有属性和方法:")
print(self.__b)
self.__test2()
... |
5eddcec5b87e61fbd22e0488898f5e200ba1eeec | Three-Y/MyPythonLearning | /ibbie_19_字符串.py | 4,234 | 4.125 | 4 | """
字符串
可以用双引号或单引号定义字符串,一般使用双引号
str = "abc"
假如字符串中包含双引号,则使用单引号来定义
str = 'lalala"啦啦啦"'
可以帮字符串看成是一个列表,列表的每个元素都是一个字符
字符串的索引值从0开始
"""
"""定义字符串"""
str1 = "abc"
print(str1)
str2 = '"哈哈"'
print(str2)
"""遍历字符串"""
str3 = "abc123321cba"
for char in str3:
print(char)
"""字符串的长度"""
print(len(str3))
"... |
5839e093920e86c0a2f9fa7449540a2552311a06 | Three-Y/MyPythonLearning | /ibbie_36_多态.py | 461 | 4.125 | 4 | """
多态
不同的子类对象,调用相同的父类方法,产生不同的结果(同java,略)
"""
class Animal:
def eat(self):
print("吃东西")
class Dog(Animal):
def eat(self):
print("狗狗吃骨头")
class Cat(Animal):
def eat(self):
print("猫猫吃鱼")
class Master:
def feed(self,animal):
animal.eat()
cat = Cat()
dog = Dog()... |
ff8ea91da6694f34c8ae196a92799406a3bbe8ac | Three-Y/MyPythonLearning | /ibbie_48_编码.py | 650 | 3.84375 | 4 | """
ASCII编码
早期使用的编码,只有256个字符,每个字符占1字节
UNICODE编码
几乎涵盖了全世界所有的字符
UTF-8,是UNICODE的一种
使用1-6个字节表示一个字符
大多数汉字使用3个字节表示
Python2.X默认使用ASCII
Python3.X默认使用UTF-8
可以在文件开头指定编码
添加注释:# *-* coding:utf8 *-*
或:# coding=utf8
python2.X会将中文字符切成3个1个字节的字符输出,就会导致乱码
可以在字符串前加一个u,表示这是一个utf-8编码的字符串
"""
str ... |
72cad72c19eff98a08799bceff6811b3e71c0187 | IgnasiBosch/CodeWars | /src/sudoku_solution_validator.py | 5,687 | 3.640625 | 4 | """
###Sudoku Background Sudoku is a game played on a 9x9 grid. The goal of the game is to fill all cells of the grid with
digits from 1 to 9, so that each column, each row, and each of the nine 3x3 sub-grids (also known as blocks) contain
all of the digits from 1 to 9.
(More info at: http://en.wikipedia.org/wiki/Sudok... |
7f4dd8521d12aa3d208fa4c51d507d84b304de6b | mtaziz/python_projects | /Basic Rock Paper Scissors Game (CLI).py | 1,945 | 4.25 | 4 | import random
# Welcome text
print("ROCK PAPER SCISSORS")
# Game variables
ties = 0
wins = 0
losses = 0
# Gameloop
while True:
# Displaying game data.
print("%s Wins, %s Loses, %s Ties" % (wins, losses, ties))
# Loop for player choice.
while True:
print("Enter any one: (r)ock (p)aper (s)ciss... |
5427ab6d6cf9680ea249749d25027aff012034f9 | felixkiryowa/SendIT | /api/model/orders.py | 17,949 | 3.671875 | 4 | """This is orders class defining the orders class model constructor """
import psycopg2
from api import connection
from flask import jsonify
from flask_mail import Message
from api import mail
cursor = connection.cursor()
class Orders:
"""
Class to define the attributes of a parcel order
"""
cursor.... |
65a091c820e63e5b5458ab152ebabe0ebb681cbe | Deepakdk7/th06061 | /50.py | 92 | 3.6875 | 4 | a1=int(input())
f=0
for i in range(2,a1):
if a1%i==0:
f=1
print("yes" if f==1 else "no")
|
33f38d757a2011c1d646678d93a075ead11e2232 | Deepakdk7/th06061 | /67.py | 81 | 3.75 | 4 | aaa=int(input())
fact1=1
for i in range(1,aaa+1):
fact1=fact1*i
print(fact1)
|
1d056012ee73ea06a75019c8596d10658597e763 | PBearson/Collatz-Sequence-Analyzer | /collatz.py | 1,913 | 3.78125 | 4 | import matplotlib.pyplot as plt
import math
runs = 100 # The largest n value to be considered
stop_at_power_of_two = True # If true, termiminate the Collatz sequence when n is a power of 2.
lastSum = 0
results = []
averages = []
maxes = []
# Return True if n is a power of 2 (including 1)
def isPowerOfTwo(n):
p =... |
590e9d9a6895524c4f470177c77326380112778f | kevinywlui/CryptoProject | /stest.py | 1,825 | 3.828125 | 4 | ##### Tester function ######
#
#
# This implements the frequency test, bit switch test and the poker test
from math import floor
from time import time
def stest(rngs):
size = len(rngs) # here rngs should be a deque type
t=time()
freq = 0 # here we count the number of 1s
... |
1903f7bdb542b121b286dc6607ed9d646f847f08 | Aefsaefuddin/labspy02 | /labspy02.py | 273 | 3.625 | 4 | N=int(input("banyaknya data = "))
if N>0:
i=1
x=int(input("data ke -"+str(i)+"="))
max=x;total=x
for i in range(2,N+1):
x=int (input("data ke -"+str(i)+"="))
total+=x
if max<x:
max=x
print("bilangan terbesar =",max)
|
cca316ffdce210448db81c368a571d72ceb5a0f7 | Rediet8abere/CodePath | /reverse.py | 237 | 4.0625 | 4 | def reverseS(s):
# revS = ""
revS = []
# revS leh
# iterate over string
for i in range(len(s)):
# prepend the value to a new variable
revS.append(s[len(s)-(i+1)])
return ''.join(revS)
print(reverseS("hi, codepath"))
|
7e88fcd7ceb00336f30d56387450c1f10ba45769 | FrankTheodoloz/633-1-ALGO-TP3 | /metier/customers.py | 12,777 | 3.765625 | 4 | from domaine.customer import Customer
class CustomerTree:
def __init__(self) -> None:
self.root: Customer = None
self.size = 0
self.nb_of_customers: int = 0
self.sum_of_ages: int = 0
self.sum_of_invitations: int = 0
def build_tree(self, costumers: list, re... |
669ca8b9f0cee2c65eddfa3df53653dd5376f7fd | XxdpavelxX/Python2- | /L1 Introduction to Eclipse/helloworld.py | 590 | 3.703125 | 4 | """Here are your instructions:
Create a IntroEclipse_Homework project and assign it to the Python2_Homework working set. In the new project,
create a helloworld.py program that prints "Hello World." Hand in the finished program."""
#####################################################################################... |
0dbacaded161597e4ded3ab63e28e65e8b5de709 | boitshepo97/bank-account | /bank_account.py | 715 | 3.515625 | 4 | class BankAccount:
def __init__(self,balance,interest_rate,monthly_fee,customer):
self.balance =balance
self.interest_rate = interest_rate
self.monthly_fee = monthly_fee
self.customer = customer
def deposit(self,amount):
self.balance += amount
return self.balance... |
1af4500cbe9bf06202ddc9f07874136bc3b0fa04 | Igor-PR/Feature-System | /Backend/models.py | 2,746 | 3.515625 | 4 | from app import db
"""
This file contains all the Database models that this algorithm uses. They have the column properties and table relations
All of them implment the __init__ method as a class constructor, __repr__ method returns a string representation of the model
they also implement the serialize property. This ... |
3b34d0f068565adcf1afb86b4deccc034f27da3e | AbiTubay/Python-Basics | /py_json.py | 402 | 3.546875 | 4 | # JSON - used in data APIs.
# similar to dictionaries but with double quotes
import json
# Sample JSON
usrJson = '{"firstname" : "John", "lastname" : "Doe", "age": 30}'
# JSON to Dictionary
user = json.loads(usrJson)
print(user)
print(user["firstname"])
# Dictionary to JSON
car = {'make':'ford', 'model':'mustang','y... |
5af7a4ac6b300fee0b1e86a4eb14378eb9243279 | cgscreamer/UdemyProjects | /Python/dictionaries.py | 671 | 4.1875 | 4 | fruit = {"orange": "a sweet, orange, citrus fruit",
"apple": "good for making cider",
"lemon": "a sour, yellow citrus fruit",
"grape": "a small, sweet fruit growing in bunches",
"lime": "a sour, green citrus fruit"}
#To add to a dictionary
fruit["pear"] = "an odd shaped apple"
#To ... |
942b0ee78413c3de2e27a1dae50ed21ae971df4d | cgscreamer/UdemyProjects | /Python/whilemypythongentlyweeps.py | 116 | 3.84375 | 4 | for i in range(10):
print("i is now {}".format(i))
i=0
while i <10:
print("i is now {}".format(i))
i+=1 |
c27528b7d7d8944e04e612fb05dd75a265fe4df5 | paik11012/TIL | /StartCamp/02_DAY/text_handling/reversed_ss_text.py | 351 | 3.8125 | 4 | #change ss.txt 0 1 2 3 4 ... into 4 3 2 1...
#read file line by line
with open('ss.txt','r') as f: #context manager
lines = f.readlines() #read each lines by "list" type
#print(lines)
lines.reverse() #reverse list
with open ('reversed_ss.txt','w') as f:
for line in lines:
f.write(line)
#print... |
8a90e853cd972d08822be7ffb0f71310f2d94558 | MilanMolnar/CodeWars_solutions | /Human_Readable_Duration_Format_4kyu.py | 1,867 | 3.59375 | 4 | def format_duration(secs):
def return_s(word, time_dict):
write_word = word
if time_dict[word] > 1:
write_word += 's'
return write_word
else:
return write_word
if secs == 0: return 'now'
result = ""
time_dict = {
'year': 0,
... |
9b75c774aa4591ef27b69e594594e1f4f2a515d8 | dwjoss/project-euler | /solutions/problem_3.py | 409 | 3.734375 | 4 | # Problem 3
#
# The prime factors of 13195 are 5, 7, 13 and 29.
#
# What is the largest prime factor of the number 600851475143 ?
def largest_prime_factor(number):
current = 2
while current < number:
if number % current == 0:
number /= current
else:
current += 1
ret... |
fa82962cae016363dee794c962553a62b8a4fdc8 | andyhou2000/exercises | /chapter-6/ex_6_5.py | 1,129 | 4.125 | 4 | # Programming Exercise 6-5
#
# Program to total the value of numbers in a text file.
# The program takes no user input, but requires a text file with numbers, one per line,
# which it opens, reads line by line, and totals the numbers in a variable,
# then displays the total on the screen.
# Define the main ... |
5bd4a64c40de41eb21d95ec08c4ce5ba06d351b8 | andyhou2000/exercises | /chapter-4/ex-4-5.py | 2,173 | 4.46875 | 4 | # Programming Exercise 4-5
#
# Program to compute total and average monthly rainfall over a span of years.
# This program gets a number of years from a user,
# then uses nested loops to prompt for rainfall for each month in each year
# and calculate the total and the average monthly rainfall,
# then displays the ... |
80c8bb6fa0068c40e7417af66c9230ec5945fcfc | andyhou2000/exercises | /chapter-2/ex-2-5.py | 797 | 4.59375 | 5 | # Programming Exercise 2-5
#
# Program to calculate distances traveled over time at a speed.
# This program uses no input.
# It will calculate the distance traveled for 6, 10 and 15 hours at a constant speed,
# then display all the results on the screen.
# Variables to hold the three distances.
# be sure to in... |
ddc8b5c1c688595eb24cdebc4d594fa50faa04c6 | impradeeparya/python-getting-started | /tree/SymetricTree.py | 2,042 | 4.21875 | 4 | # Definition for a binary tree node.
class TreeNode(object):
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def is_child_symmetric(self, children):
is_symmetric = True
left_index = 0
right_ind... |
01e555636656384332367f963f239957d0918fbc | impradeeparya/python-getting-started | /array/PascalTriangle.py | 880 | 3.765625 | 4 | class PascalTriangle(object):
def binomial_coefficient(self, line, index):
# C(n r) = n!/((n-r)! * r!)
n_factorial = 1
for number in range(1, line + 1):
n_factorial = n_factorial * number
n_r_factorial = 1
for number in range(1, (line - index) + 1):
n... |
1887d83c9fcc85038a298577442c7bea72d24bcf | Clemoreau/Fenics_comp_modeshape_disk | /comp_modeshape_disk/Methods/Simulation/convert_unit.py | 638 | 3.78125 | 4 | def convert_unit(x, a="m", b="cm"):
"""
Description:
qsd
Input:
x: float
a: str input unit
b: str output unit
Output:
x: float
"""
space = {"m": 1.0, "cm": 1e-2, "mm": 1e-3, "um": 1e-6, "nm": 1e-9}
time = {"s": 1.0, "cs": 1e-2, "ms": 1e-... |
68ef0e4b3aa7bc2c4f27e924960d0fcbdd520d3a | Ocampol/PracticasCursoPython | /Curso python 2.py | 615 | 3.9375 | 4 | #Ejercicio 1
"""numero = int(input("Ingresa un numero: "))
nuevoNumero = int(input("Ingresa un numeros, que sean mayor al anterior: "))
while numero<nuevoNumero:
numero = nuevoNumero
nuevoNumero = int(input("Ingresa un numeros, que sean mayor al anterior. Para dejar de hacerlo ingresa un numero menor: "))
print("El ... |
dd24aef6bb611f05cf7e295cedd62dbdd9684cb6 | chanchalkumawat/Learn-Python-Hardway | /ex6of46.py | 520 | 4.09375 | 4 | """Define a function sum() and a function multiply() that sums and multiplies (respectively) all the numbers in a list of numbers. For example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) should return 24."""
a=[]
print"Enter elements in list"
for item in range(1,4):
num=int(raw_input())
a.ap... |
a145bda0848c345599343ef6abee82d44a11ba41 | chanchalkumawat/Learn-Python-Hardway | /ex4of46.py | 351 | 4.15625 | 4 | #Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise.
def check(c):
if c=='a'or c=='A' or c=='e' or c=='E' or c=='i' or c=='I' or c=='o' or c=='O' or c=='u' or c=='U':
return True
else:
return False
z=raw_input("Enter the charact... |
113b8960f22c48a5e4550f368b0add77a877b2ef | chanchalkumawat/Learn-Python-Hardway | /ex26of46.py | 575 | 4 | 4 | """Using the higher order function reduce(), write a function max_in_list() that takes a list of numbers and returns the largest one. Then ask yourself: why define and call a new function, when I can just as well call the reduce() function directly?"""
def max_in_list(list1):
f = lambda a,b: a if (a > b) else b... |
37cf97e762702764e936945c1651fa8b1ef25a2f | chanchalkumawat/Learn-Python-Hardway | /ex29of46.py | 389 | 4.0625 | 4 | """Using the higher order function filter(), define a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n."""
words=["byee","helllo","hkkkkkk"]
n=6
def filter_long_words(words,n):
return filter(lambda word:len(word)>n, words)
print filter_l... |
243903e845a19ea0239be3309e205643efdb84af | Rajmeet/C.S.Practical | /Q19.py | 1,240 | 3.890625 | 4 | class Queue:
def __init__(self):
self.queue = []
def isEmpty(self):
return self.queue == []
def enqueue(self, entry):
self.queue.append(entry)
def length(self):
return len(self.queue)
def application(self):
nur, kg, one = 0 , 0 , 0
fo... |
5e1b3523ee6d661471c347e1289a9f21f4f0a9c8 | hk-tech/atcoder | /problems/cf17-final/a/submit.py | 272 | 3.71875 | 4 | S = input()
if 'AA' in S:
print('NO')
exit()
else:
if S.replace('A', '') != 'KIHBR':
print('NO')
exit()
else:
for x in ['KAI', 'IAH']:
if x in S:
print('NO')
exit()
print('YES')
|
e71b9ce88e794e4fc54d9abeaeae9bba9c792714 | hk-tech/atcoder | /problems/abc188/a/submit.py | 109 | 3.65625 | 4 | X, Y= (int(i) for i in input().split())
if min(X, Y) + 3 > max(X, Y):
print('Yes')
else:
print('No') |
f053e25bc0ac585f82e112c76f352efee0d727b6 | hk-tech/atcoder | /problems/arc110/a/submit.py | 223 | 3.59375 | 4 | N = int(input())
lis = list(range(2, N+1))
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(numbers):
return reduce(lcm_base, numbers, 1)
print(lcm(lis) + 1) |
bd059e2c09650819879c4033f4a3ae7bdbb5a7b4 | boisbb/IFJ_Compiler | /final_version/tests/compilable_tests/test1.py | 80 | 3.71875 | 4 | a = 15
if a < 20:
while a != 0:
a = a - 1
else:
a = 2
print(a)
|
40586a96dad88b27a9819cead81a91bb838a5442 | liweichen8/Python | /104Reverse_reversed.py | 363 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 30 22:59:19 2020
@author: liweichen
"""
def reverse_reversed(items):
for i in range(len(items)):
if type(items[i])==list:
#print(items[i])
item=reverse_reversed(items[i])
items[i]=item
#p... |
1a233299a0242c1a4d6fe812e35d8685c99c5815 | liweichen8/Python | /37CountingSeries.py | 724 | 3.578125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 19:43:40 2020
@author: liweichen
"""
#import math
def counting_series(n):
n+=1
if n <= 9 :
return n
pre = 0
i = 0
while pre < n:
i+=1
if pre + i*9*10**(i-1) >= n:
#i-=1
#print... |
01b5d447961e436ff4ad88cf2aa3d913be5a3979 | liweichen8/Python | /70BridgeHandShape.py | 466 | 4 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 16:15:10 2020
@author: liweichen
"""
def bridge_hand_shape(hand):
suits = ['spades', 'hearts', 'diamonds', 'clubs']
shape=[]
#count=0
for suit in suits:
count=0
for card in hand:
#print(card, car... |
a5b7309e953e9db54c3314640c7656c11be9b3ea | liweichen8/Python | /48Fractran.py | 634 | 3.6875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 26 17:26:52 2020
@author: liweichen
"""
from fractions import Fraction
def fractran(n, prog, giveup=20):
new = []
i=1
l=False
new.append(n)
if not prog:
return new
while i<=giveup:
for num in prog:
... |
0a362a56360e155b731a05aff687f2dedda9f50c | liweichen8/Python | /18CountSumProducts.py | 1,194 | 3.703125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 17:56:00 2020
@author: liweichen
"""
'''
def count_distinct_sums_and_products(items):
list1 = []
i=0
nextitems = items
add = 0
mul = 0
if len(items):
for e in items:
for j in nextitems:
... |
ec824d83193793c3c24ce4d8681944b2cdfd795c | liweichen8/Python | /3onlyodd.py | 363 | 4 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 20 17:07:32 2020
@author: liweichen
"""
def only_odd_digits(n):
b = len(str(n))
for x in range(1,b+2,1):
num = n//(10**(b-x))
print(x, num)
if num%2 == 0:
break
if x <= b:
return False
el... |
bf0d61eeabe1f113096550ce3d6b1f4c6e202d8f | liweichen8/Python | /33CountAndSay.py | 469 | 3.953125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 22:26:09 2020
@author: liweichen
"""
def count_and_say(digits):
if digits == '':
return ''
num = ''
index = digits[0]
count = 1
for c in digits[1:]:
if c != index:
num += str(count) + in... |
94ac4c1969f75eb9df6dc89486de57bf48cda284 | Pujith-M/Exercism-Solutions | /python/prime-factors/prime_factors.py | 701 | 3.796875 | 4 | def find_first_prime_which_devides(natural_number):
temp = natural_number
numbers = list()
while temp:
temp -= 1
numbers += [True]
for prime in xrange(2,(long(natural_number**(0.5))+1)):
if numbers[prime]:
if natural_number % prime == 0:
print "rt",prime
return prime
j = 0
while prime*prime+... |
845b6097d47f36d315d5aab749cc9b316dde59de | Pujith-M/Exercism-Solutions | /python/word-search/word_search.py | 2,341 | 3.65625 | 4 | def search_Puzzle(puzzle, word):
for y in range(len(puzzle)):
for x in range(len(puzzle[y])):
if puzzle[y][x] == word[0]:
#search right
if word == puzzle[y][x:x+len(word)]:
return (Point(x,y),Point(x+len(word)-1,y))
#search left
elif word == puzzle[y][x-len(word)+1:x+1][::-1]:
return (Po... |
5d662e94089f426aba7cf8caf6ba8eb907f92ae6 | lostinmilkshake/PythonLessons | /Python_Step_2/2.1.3py.py | 360 | 3.65625 | 4 | class NonPositiveError(Exception):
pass
class PositiveList(list):
def append(self, number):
if number > 0:
super(PositiveList, self).append(number)
else:
raise NonPositiveError
k = PositiveList()
for i in range(5):
try:
k.append(int(input()))
except No... |
d97aa875aa410b486ee09b2909ac8349ed54c55f | naitax/PythonYT | /guessing_game.py | 394 | 3.953125 | 4 | secret_word = 'giraffe'
guess = ''
count = 0
limit = 3
out_of_guesses = False
while guess != secret_word and not(out_of_guesses):
if count < limit:
guess = input('Enter guess: ')
count += 1
print('Its your {} guess'.format(count))
else:
out_of_guesses = True
if out_of_guess... |
c5be9731c62607ed083b6ae6cf067b6e91a67ac6 | SvStranik/1st-course-in-algorithms-data | /LinkedList.py | 2,454 | 3.953125 | 4 | class Node:
def __init__(self,v):
self.value = v
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
def add_in_tail(self,item):
if self.head is None: self.head = item
else: self.tail.next = item
self.tail = i... |
57efdbe964dd07792ae3c22d76094a77662472dd | seandewar/challenge-solutions | /hackerrank/easy/ctci-array-left-rotation.py | 291 | 3.59375 | 4 | #!/usr/bin/env python2
# https://www.hackerrank.com/challenges/ctci-array-left-rotation
def array_left_rotation(a, d):
return a[d:] + a[:d]
_, d = map(int, raw_input().strip().split(' '))
a = map(int, raw_input().strip().split(' '))
print ' '.join(map(str, array_left_rotation(a, d)))
|
440b6af8757961eb7c98c94ad3ee9af992041578 | seandewar/challenge-solutions | /hackerrank/easy/find-substring.py | 411 | 3.515625 | 4 | #!/usr/bin/env python3
# https://www.hackerrank.com/challenges/find-substring
import re
if __name__ == '__main__':
sentences = [input().strip() for _ in range(0, int(input()))]
queries = [input() for _ in range(0, int(input()))]
for q in queries:
query_matches = 0
for s in sentences:
... |
c6bc0e1240d6ab2269a81f243b35fd8419338da7 | ang2536/Turtle-designs | /turtle designs/loopfun.py | 507 | 3.96875 | 4 | import turtle
bob=turtle.Turtle()
bob.speed(0)
'''
for times in range(10):
print(times)
bob.circle(100)
bob.right(36)
numbers=[106,92,87,74,43]
for d in numbers:
print(d)
bob.circle(d)
bob.left(360/5)
'''
bob.width(15)
distance=100
colors=["blue" , "green" , "purple" , ... |
aa4dfa154242936d5f20ec549bf328cf0ecdcc2f | hackermensch/das_erste | /name.py | 242 | 3.6875 | 4 | name = "ada lovelace"
print(name.title())
name = "Ada Lovelace"
print(name.upper())
print(name.lower())
print("Languages:\nPython\nC\nJavaScript")
st_name = "Peter"
surname = "Moskowicz"
fullname = st_name + " " + surname
print(fullname)
|
2572d56d214e42e189e7ae9f8319ee2ef1cf580a | taylorperkins/foobar | /test/test_prepare_the_bunnies_escape.py | 3,455 | 3.96875 | 4 | import unittest
from utils import print_time
from logic.prepare_the_bunnies_escape import answer
class TestBreadthPrepareTheBunniesEscape(unittest.TestCase):
"""Challenge 3
Prepare the Bunnies' Escape
===========================
You're awfully close to destroying the LAMBCHOP doomsday device and fr... |
b950894571ff57399763c6209f27e698021240bb | taylorperkins/foobar | /logic/solar_doomsday.py | 399 | 3.859375 | 4 | from collections import deque
def answer(area):
current_square = 0
num = 1
while current_square < area:
current_square = num**2
num += 1
squares = list()
while area != 0:
num_squared = num**2
if num_squared <= area:
squares.append(num_squared)
... |
7278e5b16a928c6764dde79d296d30e063352e93 | taylorperkins/foobar | /test/test_solar_doomsday.py | 1,916 | 4.125 | 4 | import unittest
from utils import print_time
from logic.solar_doomsday import answer
class TestSolarDoomsday(unittest.TestCase):
"""Challenge 1
Solar Doomsday
==============
Who would've guessed? Doomsday devices take a LOT of power. Commander Lambda wants to supplement the LAMBCHOP's
quantum an... |
4a48faffc796e2f7a6126ab2e78a0d24141be2d5 | sahaj2005/pythonLearning | /panda.py | 524 | 3.609375 | 4 | import pandas as pd
s1=pd.Series([2,3,4,3])
print(s1)
s1=pd.Series([2,3,4,5],index=['a','b','c','d'])
print(s1)
#pandas with dict
s1=pd.Series({'a':20,'b':40,'c':10})
print(s1)
#pandas with dict and index
s1=pd.Series({'a':20,'b':40,'c':10},index=('a','b','d','c'))
print(s1)
#pandas index
s1=pd.Series([2,3,4,3,5,6,7... |
3773b5432eda8a2532595f8f9cdabfdfb39d337d | sahaj2005/pythonLearning | /funcationlearning.py | 262 | 3.921875 | 4 | def hello():
print("hello world")
hello()
def add_10 (x):
return x+10
print(add_10(20))
def odd_even(x):
if x%2==0:
print(x,"is even number")
else:
print(x, "is odd number")
odd_even(5)
# lambda
g=lambda x:x*x*x
print(g(2)) |
c391550b6f292cb3990d758e372766a3d127d224 | sahaj2005/pythonLearning | /pythonlLibrary/pia.py | 165 | 3.5 | 4 | import matplotlib.pyplot as plt
import numpy as np
y = np.array([40, 20, 25, 15])
mylabel = ["Off", "Leg", "Straigt", "Cover"]
plt.pie(y,labels=mylabel)
plt.show() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.