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 |
|---|---|---|---|---|---|---|
f3cc6009181b93e904fea42e9dd3e1ff0da18c80 | Moebutla/Engr-102-Class | /Lab5B/Lab5B_Butler.py | 1,987 | 3.75 | 4 |
# Disclaimer for approximation
print("DISCLAIMER: All calculations are approximated as points are approximated from stress diagram.")
# Input Variable needed:
strainValue = float(input("Please enter your stress value from 0 - 0.30: ")) #(this will be from 0.0 – 0.30)
## Additional Variables:
# Input point val... |
5ebcd75ddcb3355004b2d58795b05079fae76d16 | Moebutla/Engr-102-Class | /Lab3B/Lab3B_Prog1C.py | 794 | 3.875 | 4 | # By submitting this assignment, I agree to the following:
# “Aggies do not lie, cheat, or steal, or tolerate those who do”
# “I have not given or received any unauthorized aid on this assignment”
#
# Name: Mose Butler
# UIN: 128004413
# Section: 535
# Assignment: Lab 3b-1c
# Date: 09/... |
f7bd0ab9a90fb23b727cfa28c28669608f99c24d | AdithyaK243/AlgosTask3 | /Task3-2.py | 511 | 3.921875 | 4 |
def strengthOfWall(wallLength, noOfBricks):
brickStrengths = []
brickStrengths = list(map(int, input().split()))
brickStrengths.sort()
i = noOfBricks
while i > wallLength:
brickStrengths[1] += brickStrengths[0]
brickStrengths.pop(0)
i -= 1
return min(bric... |
cdc9e8e9c10825c3a8d358f6ff44ec46b874d4e7 | monopsony/Cluster-Error | /descri.py | 1,398 | 3.546875 | 4 | import numpy as np
from scipy.spatial.distance import pdist
def toDistance(R):
'''
This function takes a numpy array containing positions and returns it as distances.
Parameters:
-R:
numpy array containing positions for every atom in every sample
Dimensions: (n_samples,... |
cbaa96783a1860b74f3a22a4f3f2ad495c7446ba | pykafe/notas | /topic/strings/test_strings.py | 695 | 4.09375 | 4 | # Strings
def hello_world():
''' This function returns 'Hello World' '''
return 'Hello World'
def test_hello_world():
assert hello_world() == 'Hello World'
def string_to_list(my_string):
''' This function takes a string and returns that string as a list.
If a the given value is not a string... |
10d19ad833fa57a55b596f33f0a9c167992f5e8d | vikas711106/tathastu_week_of_code | /day1/2.py | 66 | 3.734375 | 4 | import math
n=int(input("enter the number:"))
print(math.sqrt(n))
|
02c061c81fabfed12ad331925cdc517e49377eb8 | tanu1208/Python | /Kattis/NastyHacks.py | 348 | 3.84375 | 4 | iterations = int(input())
for i in range(iterations):
numbers = list(map(int,input().split()))
diff = numbers[1]-numbers[2]
revenue = numbers[0]
if diff > revenue:
output = "advertise"
elif diff == revenue:
output = "does not matter"
elif diff < revenue:
output = "do not ... |
39af01979aa3774e8a8b692061c4e8b9d4b6901c | tanu1208/Python | /INF4331 assignments/assignment5/highlighter.py | 4,223 | 3.78125 | 4 | import re
import argparse
def parse_arguments():
"""
Parse commandline arguments
:return:
"""
parser = argparse.ArgumentParser(description='Usage: python3 highlighter.py <syntaxfile> <themefile> <sourcefile>')
# Set up arguments
parser.add_argument('syntaxfile', type=str,
... |
5d7766b05672d2616b0c73590acbda324e747a1f | YellowTulipShow/PythonScripts | /case/practice_questions/collect.024.py | 344 | 3.609375 | 4 | # coding: UTF-8
print(r'''
【程序24】题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
''')
# 5134
# 4
# 4 3 1 5
number = 5134
print(number, len(str(number)), "位数")
for i in range(1, len(str(number)) + 1):
print(number % 10)
number = int(number / 10)
|
e159217d2903bbabb0f7415b03072ea3def5f275 | YellowTulipShow/PythonScripts | /case/practice_questions/collect.018.py | 1,243 | 3.578125 | 4 | # coding: UTF-8
print(r'''
【程序18】题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
''')
import random
# random.randint(0, 2)
def isCanGame(Jname, Yname):
if Jname == 'a' and Yname == 'x':
return False
if Jname == 'c' and Yname == 'x':
return Fals... |
c650fa4e2638d7ae9a5d426f2808a1b74849218b | YellowTulipShow/PythonScripts | /basics/4.Number.1.init.py | 801 | 3.828125 | 4 | # coding: UTF-8
print('''
Python 三种数值类型:
Int: (整形)
通常被称为是整型或整数,是正或负整数,不带小数点。Python3 整型是没有限制大小的,可以当作 Long 类型使用,所以 Python3 没有 Python2 的 Long 类型。
Long integers(长整型)
无限大小的整数,整数最后是一个大写或小写的L。
float: (浮点型)
浮点型由整数部分与小数部分组成,浮点型也可以使用科学计数法表示(2.5e2 = 2.5 x 102 = 250)
complex: (复数)
... |
995387a6094ee7e60e10838b0c2478e5dd9214e9 | YellowTulipShow/PythonScripts | /case/practice_questions/collect.016.py | 274 | 3.828125 | 4 | # coding: UTF-8
print(r'''
【程序16】题目:输出9*9口诀。
程序分析:分行与列考虑,共9行9列,i控制行,j控制列。
''')
for x in range(1, 10):
for y in range(1, x + 1):
print("{}x{}={}\t".format(x, y, x*y), end='')
print('')
|
ae26703dfcedabc8df30327b1e820fcc18614ad6 | YellowTulipShow/PythonScripts | /basics/~.Method.range.py | 621 | 4.09375 | 4 | # coding: UTF-8
numlist = range(0, 5)
print(numlist)
print(type(numlist))
print(list(numlist))
print("\nSet step number: ")
print(list(range(0, 5, -2)))
try:
print(list(range(0, 5, 0)))
except Exception as e:
print(e)
print(list(range(0, 5, 1)))
print(list(range(0, 5, 2)))
print(list(range(0, 5, 3)))
print(li... |
109d6c73aa89a65b0fe17114a34cc3bb4acb9096 | YellowTulipShow/PythonScripts | /basics/3.Control.4.break.py | 349 | 3.796875 | 4 | # coding: UTF-8
testStr = "Python"
print("\nprint testStr => {}".format(testStr))
for nowchar in testStr:
if nowchar == 'h':
break
print("now char: {}".format(nowchar))
varint = 10
print("\nwhile varint => {}".format(varint))
while varint > 0:
print("now intvalue: {}".format(varint))
varint -= 1
... |
e0b744254a0b9cb102bd9ac29967927e1299b43d | FalseF/Algorithms-and-Problem-Solving-with-Python | /BijectionMethod.py | 270 | 3.6875 | 4 | def BisectionMethod(x):
return ((x**3)-9*x+1)
a=2
b=4
for i in range(1,20):
x0 =(a+b)/2
print(x0)
print()
fx0=BisectionMethod(x0)
fa=BisectionMethod(a)
fb = BisectionMethod(b)
if fa*fx0<0:
b=x0
else:
a=x0 |
3a47f530d3967f60e3f9aedf78f389ee9e35e612 | ruthaleks/hackerank | /repeated_string/main.py | 864 | 3.828125 | 4 | #!/bin/python3
import sys
from collections import Counter
from itertools import accumulate
from functools import reduce
def read_input():
n = int(sys.stdin.readline())
data = sys.stdin.readlines()
return data[0].strip(), n
def repeat_string(n, s):
print("n = ", n)
print("string = ", s)
c = ... |
a849e330e63bdf9c08eb1df6f68f3e0cf4759621 | WilliamMcCann/holbertonschool-higher_level_programming | /splitting_tasks_to_be_faster/h_store.py | 650 | 3.546875 | 4 | '''manages a store class and how many customers and items it has'''
from random import randint
from time import sleep
import threading
class Store():
def __init__(self, item_number, person_capacity):
self.item_number = item_number
self.person_capacity = person_capacity
self.semaphore = thr... |
d5af7c56bda22cef4a6855838d23b33ade9ef340 | WilliamMcCann/holbertonschool-higher_level_programming | /divide_and_rule/h_fibonacci.py | 520 | 4.21875 | 4 | '''prints out the Fibonacci number for a given input'''
import threading
class FibonacciThread(threading.Thread):
def __init__(self, number):
threading.Thread.__init__(self)
try:
val = int(number)
except ValueError:
print("number is not an integer")
self.numb... |
99404a1779bafb555a76438b98cc523baec7caa0 | asamn/javathehardway | /environment/chapter6/sentimental/caesar.py | 1,618 | 4.03125 | 4 | # include <stdio.h>
# include <cs50.h>
# include <string.h> //for strlen
# include <ctype.h> //for toupper
# strlen = string length
# http://www.asciitable.com/
# python caeser.py 4
import cs50
import sys # command prompts for python, len(sys.argv) !=2 is (argc != 2)
def main():
if len(sys.argv) != 2:
... |
5ed3875dee928cc5a1b65ad7d9f1f582e2358660 | ShruKin/Pre-Placement-Training-Python | /WEEK-3/1.py | 215 | 4.625 | 5 | # 1. Write a python program to check if a user given string is Palindrome or not.
n = input("Enter a string: ")
if(n == n[::-1]):
print("Its a palindrome string")
else:
print("Its not a palindrome string") |
9663393bb56c77a277bc1b62c44a3c6ae3b8b4ee | ShruKin/Pre-Placement-Training-Python | /WEEK-3/2.py | 364 | 4.46875 | 4 | # 2. Write a python program to take Firstname and lastname as input.
# Check whether the first letter of both strings are in uppercase or not.
# If not change accordingly and print reformatted string.
fn = input('Firstname: ')
ln = input('Lastname: ')
if not fn[0].isupper():
fn = fn.title()
if not ln[0].isupper(... |
ab18dab7224b07ea43eca35afcb8862953441e8d | alvin562/Codility-Solutions | /MaxProductOfThree.py | 1,031 | 3.828125 | 4 | # you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def swap(i, j, A):
temp = A[i]
A[i] = A[j]
A[j] = temp
def partition(l, r, A):
pivot = A[r]
wall = l
for i in range(l, r):
if A[i] < pivot:
swap(i... |
ceaf2f949eb9840fbeed64d74c0cd37b808f5816 | kb7664/Fibonacci-Sequence | /fibonacciSequence.py | 673 | 4.3125 | 4 | ##############################
# Fibinacci Sequence
#
# Author: Karim Boyd
##############################
# This program demonstrates one of the many ways to build the Fibonacci
# sequence using recursion and memoization
# First import lru_cache to store the results of previous runs to
# memory
from functools i... |
d44b7e922f7088558a2ff967bb20139c7c77e91a | namedots/aoc | /2018/18/main.py | 3,023 | 3.796875 | 4 | import fileinput
from collections import Counter
def show(board):
for row in board:
print(''.join(row))
print()
def count(board):
return Counter(''.join(''.join(row) for row in board))
def score(board):
counts = count(board)
return counts['#'] * counts['|']
def adjacent(board, y, x):... |
556a169da45a749589614ef5dcdb98dedcff26af | ChiranjeebNayak/OpenCV-Python | /basic_image.py | 682 | 3.5 | 4 | import cv2 as cv
import numpy as np
#img = np.zeros([512, 512, 3], np.uint8) #it will give a black image using numpy.
img = cv.imread('lena.jpg', 1) # it will give an image(given image inas parameter).
img = cv.line(img, (0, 0), (255, 255), (233, 0, 0), 5)
img = cv.arrowedLine(img, (0, 255), (255, 255), (0, 33, 0), 5)... |
cde69d8926d35ca4c5163366e6aecbfe867db612 | punoqun/multioutput-gbm | /examples/early_stopping.py | 1,593 | 3.671875 | 4 | """This example illustrates early-stopping to avoid overfitting.
Early stopping is performed on some held-out validation data, or on the
training data if validation_split is None.
"""
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from pygbm im... |
ce4af2076896709886b5772f8436d6a80fc78e1c | Thinguyen23/Election_Analysis | /PyPoll.py | 3,544 | 4.03125 | 4 | # The data we need to retrieve.
# 1. The total number of votes cast
# 2. A complete list of candidates who received votes
# 3. The percentage of votes each candidate won
# 4. The total number of votes wach candidate won
# 5. The winner of the election based on popular vote
# Add dependencies
import os
import csv
# Ass... |
75f7e3671f64a3273e2c368dc2667aefeabe1833 | kmy6270/algorithm-study | /hyeonjun/3step_for/2739.py | 88 | 3.765625 | 4 | num=int(input())
for a in range(1, 10):
print("{} * {} = {}".format(num, a, num*a)) |
2c8bc2533d2f798ea21309fe4d8e26c67dee1258 | brad2205229/python20210713_brad | /day08/HighDefDemo1.py | 279 | 3.796875 | 4 | # 高階函式
# 將函式做為參數帶入
def add(x):
return x + 1
def sub(x):
return x - 1
def calc(func, x):
result = func(x)
return result
if __name__ == "__main__":
print(add(2))
print(sub(2))
print(calc(add, 5))
print(calc(sub, 5))
|
e069dc55aa8270457c0a15b7713f45243c50276f | brad2205229/python20210713_brad | /day02/ChickenAndRabbit.py | 675 | 3.75 | 4 | # 1. 使用者輸入雞+兔的總數
# 2. 使用者輸入雞腳+兔腳的總數
# 則系統會自動算出雞兔各有幾隻
if __name__ == '__main__':
sum = int(input('輸入雞+兔的總數: '))
# 奇數, 負數, 不是數字資料(try-catch處理)...都會造成都會造成sum錯誤
# 檢查 sum 是否是奇數或負數
# homework
min, max = sum * 2, sum * 4
feet = int(input('輸入雞腳+兔腳的總數( %d ~ %d ): ' % (min, max)))
if(min <= feet <= m... |
a610c289b2a2c967435b7bcd8b79933637f1adb8 | brad2205229/python20210713_brad | /day01/calc_area.py | 550 | 3.84375 | 4 | import math
if __name__ == '__main__':
print("pi", 3.14)
print("pi", math.pi)
print("1.計算圓面積")
r = 35
area = r**2 * math.pi
print("半徑: %d 圓面積: %.2f" % (r, area))
print("半徑: %d 圓面積: %s" % (r, format(area, ",")))
print("半徑: %d 圓面積: %s" % (r, format(int(area*100)/100, ",")))
print("2.計... |
f6472ba74db6db513cdb581963015a4c8d9dddd6 | hintermeier-t/projet_3_liberez_macgyver | /graph/guard.py | 805 | 3.578125 | 4 | # -*coding: UTF-8-*
"""Module containing the GuardSprite Class."""
import pygame as pg
from . import gdisplay
class GuardSprite(pg.sprite.Sprite):
"""Class displaying the ennemy sprite.
Gathering all we need to display the ennemy Sprite (position,
source picture etc...). Inherit the pygame Sprite class... |
d48b59a7708afea878e06c1d910ff304e2772316 | hintermeier-t/projet_3_liberez_macgyver | /graph/maze.py | 1,601 | 4.125 | 4 | # -*coding: UTF-8-*
"""Module containing the MazeSpriteClass."""
import pygame as pg
from . import gdisplay
class MazeSprite (pg.sprite.Sprite):
"""Class displaying the maze sprite.
Gathering all we need to display the walls sprites,
and the path sprites. (position, source picture etc...).
Inherit ... |
51019d2f30134b636f0a394ca0ea7fedea3d532b | lupini-beans/Algorithms-and-Algorithm-Analysis | /LinkedList.py | 3,243 | 3.984375 | 4 | class LinkedList(object):
class node(object):
def __init__(self, value, next_node=None):
self.value = value
self.next_node = next_node
def __init__(self, head_node = None, head=None, next=None, prev=None,
tail=None, length=0):
self.head_node = head_node... |
57f97aac127c4d8533606efacbd6d62090362336 | talimenti/Import-modules | /operacioneslista.py | 270 | 3.609375 | 4 | def cargar_datos():
lista=[]
for x in range(5):
lista.append(int(input("Ingrese un valor: ")))
return lista
def verificar_mayor(lista):
return max(lista)
def verificar_suma(lista):
suma=0
for i in range(len(lista)):
suma += lista[i]
return suma |
d43ba1858b9eb6fc2b6afa1352859e1c85e233a0 | riaz4519/python_practice | /programiz/_52_array_set_1.py | 285 | 3.953125 | 4 | #create array
import array
arr = array.array('i',[1,2,3])
print(arr[1])
#add new array
arr.append(2)
print(arr)
#add with position
arr.insert(2,5)
print(arr)
#remove with pop
arr.pop()
arr.pop(1)
#remove with remove
arr.remove(5)
print(arr.index(1))
print(arr.reverse()) |
84c3a069035e2ad50dca56055fce252ae8378749 | riaz4519/python_practice | /programiz/_66_split_3_input.py | 125 | 3.9375 | 4 | x,y,z = input("enter three value: ").split()
#print(x,y,z)
#print with format
print("x : {} y: {} and z : {}".format(x,y,z)) |
be80b0aea58b2005699f667c15102be2d2398d42 | riaz4519/python_practice | /programiz/_6_list.py | 922 | 4.375 | 4 | #list
#create list
myList = [5,6,7,8]
print(myList)
#mixed data type list
myList = [5,8,'data',3.5]
print(myList)
#nested list
myList = ['hello',[5,6]]
print(myList)
#accessing the list
myList = ['p','r','o','b','e']
#by index
print(myList[0])
#nested
n_list = ["Happy", [2,0,1,5]]
print(n_list[1][1])
print(n... |
27d55e94a8092bc4d057da84afe277d03869be45 | riaz4519/python_practice | /programiz/_24_list_methods.py | 165 | 3.734375 | 4 |
num = list(range(5))
print(num)
# getting the length
print(len(num))
name = "python basic"
name_list = list(name)
print(name_list)
print(name_list.count('p')) |
3bbc624bb9b536c08f8bced15908961f5b8b88a8 | riaz4519/python_practice | /programiz/_33_basic_palindrome.py | 111 | 3.796875 | 4 |
new_list = 'bob'
if(new_list == new_list[::-1]) :
print('palindrome')
else:
print('not a palindrome') |
7be5d30cda7b2fea9dda47792dd011c530ebe639 | riaz4519/python_practice | /problem_solving/_4_swap_case.py | 305 | 4.15625 | 4 | def swap_case(s):
new_string = ""
for lat in s:
if lat.isupper() == True:
new_string += (lat.lower())
else:
new_string += (lat.upper())
return new_string
if __name__ == '__main__':
s = input().strip()
result = swap_case(s)
print(result) |
1e64a561788cc865ef8be88230c8b185564b8c0b | JonoHansen/summer_python | /lesson2.py | 638 | 4.0625 | 4 | # Guess the number game
import random
guessesTaken = 0
myName = raw_input("What is your name? >>")
number = random.randint(1,10)
print "I'm thinking of a number between 1 and 10."
while guessesTaken < 3:
guess = raw_input("Guess what number >>")
guess = int(guess)
guessesTaken += 1 #this means guessesTak... |
fc6d3e8b0774327e0da39521b66d2f5304d6d924 | ritz301/opensoft | /wikiminer.py | 869 | 3.78125 | 4 | """ Using wikiminer API to extract wikipedia articles from an input text """
import requests
import sys
from lxml import etree
def main():
sys.stdout.write("Enter your string:\n")
input = sys.stdin.readline()
r = requests.get("http://wikipedia-miner.cms.waikato.ac.nz/services/wikify", params={"source":input})
con... |
8cb198d2da6bf3f96a54d51eaa78c2cc175bfc3c | DisappearedCat/Graduation-work | /Task 2/NeuralNetowork.py | 5,480 | 3.59375 | 4 | """
This document implement feed forward NN
"""
import numpy
class NeuralNetwork:
def __init__(self, amount):
"""
:param amount: amount of inputs
"""
self.__size_input_layer = amount + 1
self.__hidden_layers = []
self.__output_layer = None
... |
51f2c24e0e2b4ad463e375fc22baacd392c8cc84 | julianakcm1/Minicurso-de-Python_Katie | /7.py | 561 | 3.765625 | 4 | #print("Digite uma lista de números:")
lista = (input("Digite uma lista de números:\n")).split()
"""
maior = -99999
menor = 99999
soma = 0
for i in range(len(lista)):
lista[i] = int(lista[i]) #Cast
if lista[i] > maior:
maior = lista[i]
if lista[i] < menor:
menor = lista[i]
soma += l... |
1dcdf054550e15868068fa68c006e447e50840ae | michaelwan/euler | /p4/p4.py | 857 | 3.9375 | 4 | def _is_palindromic(n):
length = len(str(n))
digits = [0] * (length+1)
remaining = n
for i in reversed(range(1, length+1)):
mod = 10 ** (i-1)
digits[length - i] = remaining // mod
remaining = remaining % mod
for i in range(1,length+1):
if digits[i-1] != digits[length ... |
267fff543e29449b7729e00b23578acb9604d247 | jefftocco21/AlgorithmsClass | /Exercise Files/2 Data Structures/Stacks/stacks_start.py | 354 | 3.90625 | 4 | # try out the Python queue functions
# TODO: create a new empty deque object that will function as a queue
stack = []
# TODO: add some items to the queue
stack.append(1)
stack.append(2)
stack.append(3)
stack.append(4)
# TODO: print the queue contents
print(stack)
# TODO: pop an item off the front of the queue
x = ... |
2726e87867938ae5c36d7437bdf1cb29a239b136 | mandulaj/Python-Tests | /Python/untitled text.py | 350 | 3.640625 | 4 | import random
questions = ["Are you ok?","Are you playing?","You know what I mean?","Hi"]
while True:
ran = random.randint(0,len(questions)-1)
print questions[ran]
ans = raw_input()
ans = ans.upper()
if ans == "YES" or ans == "NO" or ans == "" or ans == "YEAH" or ans == "OK":
n = 0
while n < 10000000000000000... |
ea362ebcf3165fcd8067e733dca39fffa8adafb3 | mandulaj/Python-Tests | /Python/isPrime.py | 365 | 4.09375 | 4 | import math
def isPrime(num):
primet = True
sq = math.sqrt(num)
x = 2
while(x <= sq):
if num%x == 0:
primet = False
break
x += 1
return primet
n = True
while n:
prime = int(input("Is prime? "))
print (isPrime(prime))
x = input(... |
aa541ec944924cac304a5b9205efee06b50fd18e | mandulaj/Python-Tests | /Python/timetable.py | 132 | 3.734375 | 4 | low = input("low b")
up = input("up b")
tab = input("tab")
print (" ")
for i in range(low,up + 1):
print (i,"*", tab,"=",i*tab)
|
abe274c9611147b4def3b7124e6fdb63e38dab5d | GAYATHRY-E/python-programme | /list2.py | 250 | 3.890625 | 4 | >>> list=[1,2,5,1,6,2,1]
#count of a number in a list
>>> list.count(1)
3
#copying a list
>>> list.copy()
[1, 2, 5, 1, 6, 2, 1]
#reversing a list
>>> list.reverse()
>>> list
[1, 2, 6, 1, 5, 2, 1]
#clearimg a list
>>> list.clear()
>>> list
[]
|
75ce5f3337c8fe5d4fa16f9931ff3424a4f889b0 | GAYATHRY-E/python-programme | /swapping2numbers.py | 211 | 3.71875 | 4 | #using an external variable
>>> a=8
>>> b=9
>>> temp=a
>>> a=b
>>> b=temp
>>> a
9
>>> b
8
#withput an external variable
>>> a=a+b
>>> b=a-b
>>> a=a-b
>>> a
9
>>> b
8
#easiest way
>>> (a,b)=(b,a)
>>> a
9
>>> b
8
|
c454186351f94ad243bb9b258abfce8fc6424bb9 | GAYATHRY-E/python-programme | /mathfunction.py | 393 | 3.921875 | 4 | #importing math module
>>> import math
>>> print(math.sqrt(25))
5.0
>>> import math as m
>>> x=m.sqrt(36)
>>> x
6.0
>>> x=int(m.sqrt(36))
>>> x
6
>>>
>>> print(m.floor(2.6))
2
>>> print(m.ceil(2.6))
3
>>> print(m.pow(2,3))
8.0
>>> print(int(m.pow(2,3)))
8
>>> print(m.pi)
3.141592653589793
>>> print(m.e)
2.718281828459... |
5a31d84be0300a1f25b23eac298764eb724dd134 | GAYATHRY-E/python-programme | /sum of natural num.py | 124 | 4.09375 | 4 | n=int(input("enter the number:"))
sum=0
for i in range(1,n+1):
sum=sum+i
print("sum of first",n,"natural numbers is",sum)
|
51eb5831e885cff30bdefa175b7ba153222156ac | CupidOfDeath/Algorithms | /Bisection Search.py | 402 | 4.15625 | 4 | #Finding the square root of a number using bisection search
x = int(input('Enter the number which you want to find the square root of: '))
epsilon = 0.01
n = 0
low = 1
high = x
g = (low+high) / 2
while abs(g*g-x) >= epsilon:
if (g*g) > x:
high = g
elif (g*g) < x:
low = g
g = (low+high) / 2
n += 1
print('The ... |
cfcc6b14f9ae21b76afa29d1974cb55733b720f0 | dragos296marin/web-crawler | /web_crawler.py | 3,372 | 3.59375 | 4 | # Description: Simple web crawler
# Author: Dragos Petrut Marin
# Version: 1.0
import re
import requests
import urllib.request
from pywebcopy import save_webpage
from urllib.parse import urlparse
class SimpleCrawler:
"""Simple web crawler. It downloads webpages in the current folder.
Attributes:
sou... |
58ec034396e1f75444e605ffce84288e69040005 | umesha-D/Tic_Tok | /Tic_tok.py | 2,995 | 4.03125 | 4 |
board = ["_", "_", "_",
"_", "_", "_",
"_", "_", "_"]
game_still_going = True
winner = None
current_Player = "x"
def display_board():
print(board[0] + "| " + board[1] + "|" + board[2])
print(board[3] + "| " + board[4] + "|" + board[5])
print(board[6] + "| " + board[7] + "|" + board[8]... |
9137a33d1c915793c81cb9f0535326e816c350d9 | mightymax/uva-inleiding-programmeren | /Game/Game.py | 2,842 | 3.578125 | 4 | import tkinter
from tkinter import Label, Button
import sys
import os
import random
from Tools import Keyboard
from Ocean import Fish, Plankton, Shark
class Game:
canvas_width = 1000
canvas_height = 800
avr_plankton_time = 20
avr_fish_time = 11
title = "Small Shark, Big Pond!"
def __init__(sel... |
42a8dcd380e302595f43a72bea8eb5c0c0a1fff3 | mightymax/uva-inleiding-programmeren | /module-1-numbers/sequence.alt.py | 1,530 | 4.25 | 4 | highestPrime = 10000
number = 1 #Keep track of current number testing for prime
nonPrimes = []
while number < highestPrime:
number = number + 1
if (number == 2 or number % 2 != 0): #test only uneven numbers and 2
#loop thru all integers using steps of 2, no need to test even numbers
for x in ra... |
ed906660c3dbd15130149e98435231ba64e1444b | mightymax/uva-inleiding-programmeren | /module-1-numbers/coprime.py | 2,731 | 4.0625 | 4 | # Name: Mark Lindeman
#
# program that calculates the chance that two random whole numbers do not have a common divisor. Such a pair of numbers is called a coprime.
# see https://progbg.mprog.nl/numbers/co-primes
import random, math, sys
def prime_factors(number):
factors = []
i = number
while i > 1:... |
8fe60cf438fcc3d7c53787297ff9156ce21c57f8 | atriadhiakri2000/Project-Euler | /Distinct powers.py | 331 | 3.5625 | 4 | def Remove(duplicate):
final_list = []
for num in duplicate:
if num not in final_list:
final_list.append(num)
return final_list
n=int(input())
l=[]
for i in range(301,n+1):
for j in range(301,n+1):
x=i**j
l.append(x)
print(l)
l.sort()
y=Remove(l)
print(y)
u=len(y)
... |
48a4387958ade9e179ced68feb40b6b7b066c14f | atriadhiakri2000/Project-Euler | /Reciprocal cycles.py | 157 | 3.5 | 4 | def f(n,d):
x=n*9
z=x
k=1
while(z%d):
z=z*10+x
k=k+1
return(k,z/d)
x=0
z=0
k=0
for d in range(1,10):
n=1
print(f(n,d))
|
4d2b6cc7e235e95c8b4167c49162aea07273c2bc | k4g4/python-group | /group.py | 3,742 | 3.625 | 4 | '''This module provides the Group class, which models
finite groups from group theory.'''
from inspect import signature
from itertools import product
from functools import total_ordering, reduce
from math import gcd
__author__ = 'kaga'
@total_ordering
class Group:
'''Create and model a finite group w... |
0bca3a56b899c73b9f63201d6eb1cb0070976972 | lasj00/Python_project | /OOP.py | 1,965 | 4.1875 | 4 | import math
class Rectangle:
# the init method is not mandatory
def __init__(self, a, b):
self.a = a
self.b = b
# self.set_parameters(10,20)
def calc_surface(self):
return self.a * self.b
# Encapsulation
class Rectangle2():
def __init__(self, a, b):
self.__... |
36b585cb0372c121c7307bb04ecc3a1b220ad0a6 | lasj00/Python_project | /abstract.py | 917 | 4.59375 | 5 | from abc import ABC
import math
# by inheriting from ABC, we create an abstract class
class Shape(ABC):
def __init__(self, a=0, b=0):
self._a = a
self._b = b
def get_a(self):
return self._a
def get_b(self):
return self._b
def __str__(self):
return "{0}: [{1},... |
215bfabf36b7990ae201193cef6765817e076788 | dvasavda/Tech-Interview-Preparation | /LeetCode - 30 Day Challenge/GroupAnagrams.py | 1,026 | 4 | 4 | '''
Day 6
Group Anagrams
Given an array of strings, group anagrams together.
Example:
Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
All inputs will be in lowercase.
The order of your output does not matter.
'''
class Solution(object):
... |
a0b036cf7a071f874f5b9bcfac1b12d6d6dc16e3 | dvasavda/Tech-Interview-Preparation | /Individual Questions/SingleNumber.py | 826 | 3.84375 | 4 | """
136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4... |
5f22df37ad5b68f660448cc59cf09d8ea47ee421 | andregalvez79/Intro_to_Python | /4/hw4.py | 3,387 | 3.953125 | 4 | ####################HW 4###################
#ANDRE VARGAS
#### STRINGS
##2
prefixes = "JKLMNOPQ"
suffix = "ack"
for p in prefixes:
if p == "O" or p == "Q":
print(p + "u" + suffix)
else:
print(p + suffix)
#3
def count(p):
lows = "abcdefghijklmnopqrstuvwxyz"
ups = "A... |
47e6f4a562e433b70379b9f3b37e3edb6f22df00 | andregalvez79/Intro_to_Python | /3/hw3.py | 5,174 | 3.796875 | 4 | ############ HW3 andre vargas
### DART/PI
import turtle
import math
import random
fred = turtle.Turtle()
fred.speed(10)
wn = turtle.Screen()
wn.setworldcoordinates(-1,-1,1,1)
def drawCircle(someturtle):
someturtle.up()
someturtle.goto(0, -1)
someturtle.down()
someturtle.circle(1, ... |
b451055efe0de3395b4c49beb4d67ee77694bece | KaylaBaum/astr-119-hw-1 | /variables_and_loops.py | 706 | 4.375 | 4 | import numpy as np #we use numpy for many things
def main():
i = 0 #integers can be declared with a number
n = 10 #here is another integer
x = 119.0 #floating point nums are declared with a "."
#we can use numpy to declare arrays quickly
y = np.zeros(n,dtype=float) ... |
2179eedc29163426d5854f324082164759b81504 | KaylaBaum/astr-119-hw-1 | /functions.py | 618 | 4.0625 | 4 | import numpy as np
import sys
#define a function that returns a value
def expo(x):
return np.exp(x) #return the np e^x function
#define a subroutine that does not return a value
def show_expo(n):
for i in range(n):
print(expo(float(i))) #call the expo function
#define a main function
def main():
n... |
f96e800b78f089bf704840a876e265fdbde4d29b | ch1huizong/study | /lang/py/pylib/01/re/re_flags_multiline.py | 460 | 3.8125 | 4 | #!/usr/bin/env python
# -*- coding:UTF-8 -*-
import re
text = 'This is some text -- with punctuation.\nA second line.'
pattern = r'(^\w+)|(\w+\S*$)'
single_line = re.compile(pattern)
multiline = re.compile(pattern,re.MULTILINE)
print'Text:\n %r' % text
print'Pattern:\n %s' % pattern
print'Single Line:'
for match in... |
5efd61227df86747207f8494528b1e45b92ce2de | ch1huizong/study | /lang/py/rfc/07/descriptor_7_8.py | 787 | 3.828125 | 4 | # -*- coding:utf-8 -*-
# 描述符对象
class TypedProperty(object):
def __init__(self, name, type, default=None):
self.name = "_" + name
self.type = type
self.default = default if default else type()
def __get__(self, instance, cls):
return getattr(instance, self.name, self.default)... |
8053b42c5deda023d29ab5a261b23c3f4f9212e8 | ch1huizong/study | /lang/py/rfc/theme/yield/generators/04/retuple.py | 480 | 3.5 | 4 | #!/usr/bin/env python
# -*- coding:UTF-8 -*-
#
# retuple.py
#
# 元组序列
# Read a sequence of log lines and parse them into a sequence of tuples
loglines = open("access-log")
import re
logpats = r'(\S+) (\S+) (\S+) \[(.*?)\] ' \
r'"(\S+) (\S+) (\S+)" (\S+) (\S+)'
logpat = re.compile(logpats)
groups = ... |
2a7ea9a7509019b371cca964095209f20943f643 | ch1huizong/study | /lang/py/rfc/07/property.py | 846 | 3.609375 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
# 老版本
class Foo1(object):
def __init__(self,name):
self.__name = name
def getname(self):
return self.__name
def setname(self,value):
if not isinstance(value,str):
raise TypeError("Must be a string!")
self.__name... |
33a65fd11b2939aa3015c5613f994ffbbc37b2cb | ch1huizong/study | /lang/py/pylib/03/operator/operator_classes.py | 485 | 3.78125 | 4 | #!/usr/bin/env python
from operator import *
class MyObj(object):
def __init__(self,val):
super(MyObj,self).__init__()
self.val = val
def __str__(self):
return"MyObj(%s)"%self.val
def __lt__(self,other):
print'Testing %s < %s'%(self,other)
return self.val < other.val
def __add__(self,other):
print'A... |
5b39bf7c68b7d184ee5850568bc5889e01abc869 | ch1huizong/study | /lang/py/pylib/03/functools/functools_partial.py | 857 | 3.59375 | 4 | #!/usr/bin/env python
import functools
def myfunc(a,b=2):
"""Docsting for myfunc()."""
print' called myfunc with:',(a,b)
def show_details(name, f, is_partial=False):
"""Show details of a callable object."""
print'%s:'%name
print' object:',f
if not is_partial:
print' __name__:',f.__name__
if is_partial:
pr... |
ffd30c12501fa4d33fea5f381d1b82ca41e39c12 | ch1huizong/study | /lang/py/rfc/12345/numlist_1-2.py | 331 | 3.625 | 4 | #!/usr/bin/env python
# -*- coding:UTF-8 -*-
import sys
if len(sys.argv) != 2 :
print "Please supply a filename"
raise SystemExit(1)
f = open(sys.argv[1])
lines = f.readlines()
f.close()
fvalues = [ float(line) for line in lines ]
print"The minimum value is", min(fvalues)
print"The maximum value is", ma... |
e2b2f45cff690c1d4f736e47a119e75665ba179e | ch1huizong/study | /lang/py/cookbook/v2/05/nsort.py | 1,013 | 3.546875 | 4 | #! /usr/bin/env python
# -*- coding:UTF-8 -*-
import random
def select(data, n):
"""
取的排名第n的最小元素,最小的是第0号元素
序列很长,而且比较操作比较耗时,新方法时间复杂度O(n)
"""
data = list(data)
if n < 0:
n += len(data)
if not 0<= n < len(data):
raise ValueError, "can'nt get rank %d out for %d" % (n, len(data... |
5fd79aec14f570b55d10153e52c7d67e751d5877 | ch1huizong/study | /lang/py/cookbook/v2/19/merge_source.py | 1,096 | 4.1875 | 4 | import heapq
def merge(*subsequences):
# prepare a priority queue whose items are pairs of the form
# (current-value, iterator), one each per (non-empty) subsequence
heap = []
for subseq in subsequences:
iterator = iter(subseq)
for current_value in iterator:
# subseq is not empty, therefor... |
fe892a92619afea490db9ded4f5b990c3207f03c | WeedViks/Python | /2.5 cal_tel.py | 489 | 3.6875 | 4 | def cal_tel(city,t):
if city == 343:
return t * 15
if city == 381:
return t * 18
if city == 473:
return t * 13
if city == 485:
return t * 11
return('Код города не существует! 0')
city = int(input('Введите код города: '))
t = int(input('Введите время раз... |
fb215eb499fde7b847cee0956255479c8375ef98 | Deanomatic/python-exercises | /classes/bangazon-classes/employee.py | 1,501 | 3.8125 | 4 | import random
from bangazon import Department
class Employees(Department):
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
self.email = first_name + '.' + last_name + '@bangazon.com'
# def eat(self, food=None, companions=None):
# ... |
5eef6ffd0fce2969545576254bbd157fe247cf8f | Deanomatic/python-exercises | /kill_nickleback/kill_nickleback.py | 445 | 3.75 | 4 | songs = {
("Nickleback", "How You Remind Me"),
("Led Zeppilin", "Whole Lotta Love"),
("Mumford and Sons", "Winter Winds"),
("Needtobreathe", "Washed By the Water"),
("Nickleback", "Animals")
}
no_more_nickleback = [band for band in songs if band[0] != "Nickleback"]
print(no_more_nickleback)
# words = ['big', 'r... |
b06d281591336364ee1ba09d8707683c2f1572de | nataliasouza1306/Prog20192 | /Aula05.py | 3,280 | 4.375 | 4 | '''
lista = ["carro", "peixe", 123, 111] # ordem dos elementos: 0, 1, 2, 3.
novalista = ["pedra", lista]
#print(novalista)
#print(lista[1])
#print(novalista[1][2]) #o segundo operador vai respoder ao primeiro. Ou seja, acessar o local 2 da lista.
#print(lista[-1]) #lista ao contrário.
#print(len(lista)) #tamanho d... |
60e870ddcd3085f24d34c2422573426a8e7c7a90 | AaronWxy/Hercules | /io_control/txt_input_handler.py | 545 | 3.65625 | 4 | """
Author: Aaron W.
"""
def read_file_and_convert_to_list(file_path, ignore_comment=True, ignore_empty=True):
try:
trans = []
with open(file_path) as f:
lines = f.read().splitlines()
for line in lines:
if not line and ignore_empty:
conti... |
f20ffcabd15bcf275a055f00a45e16d6515b3dfd | shawnrc/cshvote | /models.py | 1,828 | 3.59375 | 4 | #! /usr/bin/env python
"""
models.py - Database model definitions
author: shawn chowdhury [shawnrc@csh.rit.edu]
date: 2015-03-01
:credits: None
"But why male models?"
"Are you serious? I just told you that a moment ago."
--
"""
from peewee import *
from vote import database as db
class BaseModel(Model):
"""
... |
50d0aa09dc64f8b43c4f5b5be695d659fcd898ec | fali007/basic-programming | /tree/tree_height.py | 1,453 | 3.875 | 4 | class node:
def __init__(self):
self.data=None
self.right=None
self.left=None
class tree:
def __init__(self,val):
self.root=node()
self.root.data=val
def insert(self,val):
q=[]
q.append(self.root)
new=node()
new.data=val
while ... |
0da918651a58b885a682bc80eb9170f24d0738f0 | fali007/basic-programming | /graph/graph.py | 1,815 | 3.875 | 4 | # # raw implementation
# class graph:
# def __init__(self,num):
# self.list=[[]for i in range(num)]
# def add_edge(self,parent,node):
# self.list[parent].append(node)
# print(self.list)
# def disp(self,a):
# ans,visited,q=[],[],[]
# q.append(a)
# while(len(q))... |
697adc257c569a52800a235f995356357c1dbfee | harshkakaria/python_examples | /functions.py | 3,422 | 3.90625 | 4 | def wish():
print("hello this is user define function")
wish()
wish()
def wish(name):
print("hello",name,'good morning')
wish('jai')
wish('veera')
# Return statements:
def add(x,y):
return x+y
result = add(1,20)
print('the sum of :',result)
print('the sum of ',add(20,40))
def f1():
print('hello')
... |
0af7db6e6c453850c6574e2c4a2e36bdc328023d | harshkakaria/python_examples | /set.py | 1,847 | 3.703125 | 4 | # s= {10,20,30,40}
# print(s)
# print(type(s))
# l = [10,20,30,40,10,20,30,10]
# s=set(l)
# print(s)
# # inside set duplicate not allowed and sequence doesn't matter
#
# s= set(range(5))
# print(s)
# s= {}
# print(s)
# print(type(s))
#
# s = set()
# print(s)
# print(type(s))
# Imp functions of set :
# s = {10,20,30... |
127b0917f97c67dca4f5e42d5428b21c4ec59c01 | Oliunin/Djbootcamp | /12-Python_Level_One/ex15/func.py | 519 | 3.796875 | 4 | def my_func(par1="awesome"):
"""
DOCSTRING
"""
return "my_func"+par1
def addNum (num1=1,num2=2):
if type(num1)==type(num2)==int:
return num1+num2
else:
return "need integers"
my_func()
print(type(addNum(2,4)),addNum(2,4))
#lambda expression
#filter
mylist = [1,2,3,4,5,6,7,8]
... |
1874cf8c2d8eb251aa4d48afe309f572a2884764 | hcutler/nets213-finalproj | /analysis/printer.py | 181 | 3.53125 | 4 | import csv
with open('countries.csv') as data:
reader = csv.reader(data)
for row in reader:
if not row[2]:
row[2] = 0
print "['{}',{},{}],".format(row[0], row[1], row[2])
|
378ae7bb7712b2fe575ab91f5842d6cddd085a81 | xVIIIx/Codewars | /7kyu/Sum of numbers from 0 to N/solution.py | 172 | 3.5625 | 4 | def show_sequence(n):
if n==0:
return '0=0'
return '+'.join(str(i) for i in range(0,n+1))+' = '+str(int((n*(n+1))/2)) if n>0 else str(n)+'<0'
|
d2927ea18a60a732f9c69fd29cfce7ca23e6f4f7 | Deyht/ASOV_2020 | /Python/mlp/ext_module.py | 6,631 | 3.53125 | 4 |
# Neural networks pedagogical materials
# The following code is free to use and modify to any extent
# (with no responsibility of the original author)
# Reference to the author is a courtesy
# Author : David Cornu => david.cornu@utinam.cnrs.fr
import numpy as np
from numba import jit
#uncoment numba lines to exp... |
700c1765dd216e08efc66625d013d4ef99a71077 | ednussi/Intro-to-CS | /Ex5/GetToTheZero.py | 1,507 | 4.0625 | 4 | #############################################################
# FILE: GetToTheZero.py
# WRITER: Eran Nussinovitch a.k.a ednussi
# EXERCISE : intro2cs ex5 2013-2014
# Description:
# A function which checks a given row with numbers
# represnting the amount of jumps i can do to a previous or next
# cell in the board, if i... |
ba8177181cd2ed82ec284a50929e041fe105c8c9 | ednussi/Intro-to-CS | /Ex3/ex3.py | 12,356 | 4.5 | 4 | #############################################################
# FILE: ex3.py
# WRITER: Eran Nussinovitch a.k.a ednussi
# EXERCISE : intro2cs ex3 2013-2014
# Description:
# Containing 6 diffrent function of calculating retirement pension.
# Each one is fitted for a specific calculation5 differnet functions which
#######... |
1663965cf445d7c1280efc5f255af8da8f0bb2d9 | ChrisDickson/TwigTest | /chunk_list.py | 816 | 3.9375 | 4 | def split_list(lst, n):
# Gets the number of elements in each 'chunk'
size = round(len(lst)/n)
# List comprehension - if len(list) = 5 and n = 3
# loops through to get all but the final chunk
# starting at 0 and incrementing i by 3 each time until the 4th element
# gets a slice of th... |
c7c2681a6ca8de03dc17e2fc584bc5a85db1de04 | Jasbeauty/Learning-with-Python | /assn0/test3.py | 2,967 | 4.1875 | 4 | # -*- coding=utf-8 -*-
# 获取对象信息
class MyObject(object):
def __init__(self):
self.x = 9
def power(self):
return self.x * self.x
obj = MyObject()
print('hasattr(obj, \'x\') =', hasattr(obj, 'x')) # 有属性'x'吗?
print('hasattr(obj, \'y\') =', hasattr(obj, 'y')) # 有属性'y'吗?
setattr(obj, 'y', 19) # 设... |
9b514f867c3d0cf91ab27c1ebec460f6916215b0 | erifo/advent-of-code-2020 | /day03/main.py | 533 | 3.578125 | 4 | import re
from slope import Slope
def load(filename):
f = open(filename, "r")
lines = f.readlines()
data = [line.strip() for line in lines]
return Slope(data)
def solve_a(data):
return data.trees_in_slope(3,1)
def solve_b(data):
routes = [(1,1), (3,1), (5,1), (7,1), (1,2)]
answer = 1
... |
a7ed304f5cadf166cb3f5815795d79e96eda12cd | erifo/advent-of-code-2020 | /day03/slope.py | 765 | 3.625 | 4 | class Slope():
def __init__(self, data):
self.lines = data
self.width = len(data[0])
self.height = len(data)
def get_char_at(self,x,y):
line = self.lines[y]
char = line[x % self.width]
return char
def is_tree(self,x,y):
char = self.get_char_at(x,y)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.