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 |
|---|---|---|---|---|---|---|
4845518002b77820d57bef40ee0aa1fd90db39c3 | skolicki/snake-cube | /snake.py | 1,066 | 3.6875 | 4 | # A simple recursive code to solve putting together https://en.wikipedia.org/wiki/Snake_cube
# Reformatted a few times aiming at brevity :)
# Hint: if you want to actually follow the result, it's physically easier going backwards
import copy
def move(cube, pos, dir, sgn, legs, path):
if not legs:
print(pa... |
c832558562b45c77f2b0d255d885d3a348fa675b | jakeyap/pytorch | /example_simpleNN.py | 4,352 | 3.765625 | 4 | #!/usr/bin/env python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 17:07:22 2020
@author: jakeyap
"""
"""example_simpleNN.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Orpn_6WutNzgh8y561Yzhk_C5VxnOG4l
# Creating... |
196350bd2a49931e76ed1ac49d3f46c59e54edaf | pitmanm2/BIO439_Exam4 | /BIO439_Exam4.py | 4,457 | 3.75 | 4 | import sys
import pandas as pd
def find_possible(line):
"""
Function to find all Possible Kmers:
Takes in a single line as an argument and outputs the possible kmers for each value k
Computes this by finding the minimum of the length of the string minus k plus 1, and 4^k
Returns a list... |
694c9b48393eae40e143dce167c9cc2e1f1335b4 | paulined314/comp110-21f-workspace | /exercises/ex01/numeric_operators.py | 528 | 3.78125 | 4 | """polite_calculator."""
__author__ = "730390549"
input_one: str = input("Left-hand side: ")
input_two: str = input("Right-hand side: ")
math_one = int(input_one)
math_two = int(input_two)
print(str(input_one + " ** " + input_two + " is ") + str(int(math_one ** math_two)))
print(str(input_one + " / " + input_two + " i... |
d1baf2335243c89b21bc4cda2d0a7f558474ee62 | paulined314/comp110-21f-workspace | /exercises/ex03/happy_trees.py | 207 | 3.671875 | 4 | """Drawing forests in a loop."""
__author__ = "730390549"
Tree: str = '\U0001F332'
depth: str = input("Depth: ")
x = int(depth)
y = 0
while y <= x:
if y > 0:
print(Tree * int(y))
y = y + 1
|
75385be21843c2ae642a50569553fb44313f7ad5 | nfarnan/cs001X_examples | /lists/MW/09_process_grades.py | 488 | 3.8125 | 4 | NAME = 0
MIDTERM = 1
FINAL = 2
PROJECTS = 3
def read_file(fname):
main_list = []
with open(fname) as infile:
for line in infile:
clean_line = line.strip()
main_list.append(clean_line.split(","))
# method 1
#return main_list[1:]
# method 2
main_list.pop(0)
return main_list
def print_midterms(grades):
... |
b2c4bb3420c54e65d601c16f3bc3e130372ae0de | nfarnan/cs001X_examples | /functions/TH/04_main.py | 655 | 4.15625 | 4 | def main():
# get weight from the user
weight = float(input("How heavy is the package to ship (lbs)? "))
if weight <= 0:
print("Invalid weight (you jerk)")
total = None
elif weight <= 2:
# flat rate of $5
total = 5
# between 2 and 6 lbs:
elif weight <= 6:
# $5 + $1.50 per lb over 2
total = 5 + 1.5 ... |
b5dd5d77115b2c9206c4ce6c22985e362f13c15e | nfarnan/cs001X_examples | /exceptions/MW/03_input_valid.py | 529 | 4.21875 | 4 | def get_non_negative():
valid = False
while not valid:
try:
num = int(input("Enter a non-negative int: "))
except:
print("Invalid! Not an integer.")
else:
if num < 0:
print("Invalid! Was negative.")
else:
valid = True
return num
def get_non_negative2():
while True:
try:
num = int(i... |
98dd2df13227c80e407e62798ceb2f07e8936077 | nfarnan/cs001X_examples | /loops/TH/01_while.py | 187 | 3.765625 | 4 | count = 0
ans = "y"
while ans == "y":
count += 1
print("on loop", count)
# needed to avoid infinite loops
ans = input("Keep going? ")
cur = 50
while cur > 0:
print(cur)
cur -= 1
|
280f1e324fcef72822e34d97666f8a12be901400 | nfarnan/cs001X_examples | /decision_structures/TH/01_if.py | 268 | 4 | 4 | an_int = 7
if an_int < 10:
# do this
print("value is less than 10!")
print("this will also get printed in first if block")
if an_int > 5:
print("value is also greater than 5!")
print("this is printed from second (nested) if block")
print("out of block(s)")
|
02b2bdd0403717cfb416b255524f7a7a68262d19 | nfarnan/cs001X_examples | /loops/MW/10_Mtriangle.py | 377 | 4.09375 | 4 | # get height from user
height = int(input("Enter height of M triangle: "))
# iterate through each row
for i in range(1, height + 1):
# print out spaces
for k in range(height - i):
print(" ", end="")
# print out stars (part 1)
for j in range(i):
print("*", end="")
# print out the stars (part 2)
for l in ran... |
c931f9d7962933a52f327240ce416c06cb76c548 | nfarnan/cs001X_examples | /lists/MW/04_list_methods.py | 256 | 3.65625 | 4 | a = []
a.append("a")
a.append("b")
a.append("b")
a.append("b")
a.append("b")
a.append("C")
print(a)
a.remove("b")
print(a)
a.append("b")
print(a)
a.remove("b")
print(a)
a.pop()
print(a)
a.pop(0)
print(a)
a.pop(1)
print(a)
a.clear()
print(a)
|
ecccf72dd7cbd0f47025721ac6c84505d22927dd | nfarnan/cs001X_examples | /oo/TH/04_class_vars.py | 735 | 3.765625 | 4 | class Dog:
# shared by all instances of Dog
__tricks = []
def __init__(self, name):
self.__name = name
#self.__tricks = []
def addTrick(self, trick):
self.__tricks.append(trick)
def __repr__(self):
rv = "Dog(" + self.__name
rv += ", " + str(self.__tricks)
rv += ")"
return rv
class Cat:
__tricks... |
cdff465634e057b82d3ae3f576b11ea809d5f9f3 | nfarnan/cs001X_examples | /lists/TH/05_lists_loops.py | 151 | 3.9375 | 4 | a = ["a", "b", "c", "d", "e"]
print("while:")
c = 0
while c < len(a):
print(a[c])
c += 1
print()
print("for:")
for item in a:
print(item)
print()
|
8de2bc539d281108957b3790fc0ffec2fd1ed326 | nfarnan/cs001X_examples | /loops/TH/08_range.py | 146 | 3.59375 | 4 | for i in range(1, 6):
print(i)
print()
for another_var in range(1, 20, 2):
print(another_var)
print()
for c in range(10, 2, -4):
print(c)
|
e3c9a8600edd3f7178a94a990e725254e5607f66 | nfarnan/cs001X_examples | /files/TH/04_multiline.py | 387 | 3.6875 | 4 | print("for approach:")
inf = open("name.txt")
for line in inf:
clean_line = line.strip()
print("Hello,", clean_line)
inf.close()
print()
print("while approach:")
inf = open("name.txt")
cur_line = inf.readline()
for i in range(2):
cur_line = inf.readline()
while cur_line != "":
cur_line = cur_line.strip()
... |
c1d825716a2c9b68e5e247420ebd50cef03fef07 | AnastasisKapetanis/mypython | /askhseisPython/askhsh9.py | 260 | 4.1875 | 4 | num = input("Give a number: ")
num = int(num)
def sum_digits(n):
s = 0
while n:
s += n % 10
n //= 10
return s
while(len(str(int(num)))>1):
num = num*3 + 1
num =sum_digits(num)
print("The number is: " + str(num))
|
269083e794d9a2f137ffcbeb1d526c1c5b7ec30f | JordanKulzer/Beginner-Python-Projects | /Heads or Tails.py | 587 | 4 | 4 | import random
user_wins = 0
options = ["heads","tails"]
while True:
user_input = input("Types Heads/Tails or Q to quit: ").lower()
if user_input == "q":
break
if user_input not in options:
continue
random_number = random.randint(0,1)
coin_flip = options[random_n... |
8491691bef8b6f56870bb8f9d5ef56e2a795b1d9 | MonteChristo46/Recommender-System | /rs_helper/core/LabelMap.py | 1,583 | 3.90625 | 4 | import json
class LabelMap:
"""
A class which represents a label map. It loads a json - label map, where keys are label names. The method provides
two methods to get the label name as string and one to get the label names as int.
"""
def __init__(self, path_to_json: str) -> None:
self.labe... |
b01def477158ca6ce59a580418033a250066c5a7 | mehmetakifdevops/assignments | /sort_without_sortmethod.py | 216 | 3.5 | 4 | elements_of_list = [999, 333, 2, 8982, 12, 45, 77, 99, 11]
list2 = []
while elements_of_list != []:
a = min(elements_of_list)
list2.append(a)
elements_of_list.remove(a)
print(list2)
|
d0410d0788621701d56ad8b56e6f49cb048c227b | mhashilkar/Python- | /2.1if_statment.py | 238 | 4.25 | 4 | """
THIS IS A BASIC IF STATMENT IN PYTHON
tuna = "fish"
if tuna == "fish":
print('this is a fish alright', tuna)
"""
tuna = "fish"
if tuna == "fish": # IF THE STATMENT IS TRUE THE IT WILL PRINT THE STATMENT
print('allright')
|
3c7b27f33408b3a2b1545c1cbc89a0653fd611f2 | mhashilkar/Python- | /2.6_break_statment.py | 142 | 4 | 4 | # HOW TO USED BREAK STATMENT
count = 3
while count <= 10:
print("Count :", count)
if count == 8:
break
count = count + 1
|
b862f9fd6aad966de8bd05c2bfcb9f9f12ba61f5 | mhashilkar/Python- | /2.9.7_Variable-length_arguments.py | 590 | 4.5 | 4 | # When you need to give more number of arguments to the function
# " * "used this symbol tho the argument that means it will take multiple value
# it will be a tuple and to print that args you have to used the for loop
def printinfo(args1, *vartuple):
print("Output is: ")
print(args1)
for var in vartuple:... |
021a2a187b909c0f9477720692d1b4fb83e1c89d | mhashilkar/Python- | /2.9.4_function.py | 544 | 3.578125 | 4 | # Function defination is here
def printme(str):
print(str)
return
printme("This is first call to the user defined functions")
# In Python parameter pass bye refrense only
def changeme(mylist):
# id() is default function in python which give unique id
print(id(mylist))
print("Value inside the funct... |
d93ead75f6ee6fa3198d0a243b063a4a5795544b | OscarMCV/Monomials-Python | /main.py | 2,954 | 4.125 | 4 | """Main program."""
from monomial import Monomial
def test_monomial_string_representation():
"""Prints monomials to test __str__ method."""
print(Monomial(0, 0))
print(Monomial(0, 1))
print(Monomial(0, 5))
print(Monomial(1, 0))
print(Monomial(1, 1))
print(Monomial(1, 5))
print(Monomia... |
f47c328513f197dc7d243034e0faaf9d96209717 | pavel-malin/gg_wp | /scraping.py | 996 | 3.71875 | 4 | from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.vk.com")
bsObj = BeautifulSoup(html)
nameList = bsObj.findAll(text="prince")
for name in nameList:
print(len(nameList))
# keyword пример
# allText = bsObj.findAll(id="text")
# print(allText[0].get_text())
# проверяет то... |
e0dc21365c28f6f162c860a9ca6c845af57d81c8 | rkkirpane/dsmp-pre-work | /Creative_prework_dsmp/code.py | 1,091 | 3.78125 | 4 | # --------------
# Code starts here
class_1=['Geoffrey Hinton','Andrew Ng','Sebastian Raschka','Yoshua Bengio']
class_2=['Hilary Mason','Carla Gentry','Corinna Cortes']
new_class=(class_1+class_2)
print(new_class)
new_class.append('Peter Warden')
print(new_class)
new_class.remove('Carla Gentry')
print(new_class)
# Code... |
639be96c43561393ccbcd29912bb5f1444cd67c4 | Arunsai/KeyLogger | /gui.py | 2,158 | 3.703125 | 4 | #!/usr/bin/env python
#This program is intended to retrieve the data from a local file and display the contents on the GUI. This program asks for the filename to be displayed and if the requested file exists, it displays the file on a window.
#This program presents a simple GUI for the client to request a file and rea... |
6f92d75468e99445c071c26daf00dc7392c95ba2 | badilet/Task21 | /Task21.py | 251 | 4.15625 | 4 | # Напишите функцию которая будет суммировать введенные три случайные цифры.
def multiply(num1, num2, num3):
answer = num1 * num2 * num3
return answer
print(multiply(2, 2, 2))
|
fdb161c98be8c8cef91c9f4dedf7ecbacc4f6758 | ezeakeal/gliderV2 | /raspberry/tests/haversine.py | 1,584 | 3.703125 | 4 | from math import radians, cos, sin, asin, sqrt
Aaltitude = 2000
Oppsite = 20000
lat1 = 53.32055555555556
lat2 = 53.31861111111111
lon1 = -1.7297222222222221
lon2 = -1.6997222222222223
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1... |
b0c57e4bbcfa9a9e6283ebceeca1a0a5594a28c5 | ramyashah27/chapter-8-and-chapter-9 | /chapter 9 files are op/03write.py | 382 | 4.15625 | 4 | # f = open('another.txt', 'w')
# f.write("this file is created through writing in 'w'")
# f.close()
# this is to make/open file and will add (write) all data in it, it will overright
f = open('another.txt', 'a')
f.write(' and this is appending')
f.close()
#this is to add data in the end
# how many times we r... |
8cc09fbae4fcc4df5f1abb06711856b9d996f59a | TheSpeedX/codex | /python/problem_10.py | 614 | 3.96875 | 4 | #!/usr/bin/env python
""" Provides the sum of all the primes below two million"""
def is_prime(num):
"""is_prime checks for the number "num"
if the number "num" is prime it returns true
if not prime returns false"""
if (num<=1):
return False
for i in range(2,int (num**0.5)+1):
if (num%i =... |
8bfb967ece863bbf17d26f01aa7f421bef2f3b4a | TheSpeedX/codex | /python/problem_9.py | 399 | 4.0625 | 4 | #A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
#
#a2 + b2 = c2
#For example, 32 + 42 = 9 + 16 = 25 = 52.
#
#There exists exactly one Pythagorean triplet for which a + b + c = 1000.
#Find the product abc.
total = 1000
for a in range(1, total+1):
for b in range(a+1, total+1):
c = tot... |
3d8e5de1a7ca6b34845db173264e42c4dbbe3fd2 | TheSpeedX/codex | /python/problem_55.py | 1,312 | 3.890625 | 4 | from time import time
def is_palindrome(number):
"""returns True for a palindrome, False otherwise."""
to_str = str(number)
return to_str == to_str[::-1]
def add_reverses(number, count):
"""makes a list of reverses for a number at a maximum iteration of count, breaks if palindrome found below count.... |
a3c4626ed5309753b7225ae11d9c9b0b989eaabb | TheSpeedX/codex | /python/problem_27.py | 651 | 3.765625 | 4 | import math
def isPrime(n):
if n <= 1:
return False
if n == 2:
return True
for i in range(3, math.floor(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
primes = []
for i in range(1000):
if isPrime(i):
primes.append(i)
longest = 0
largestA... |
5d6c78f23caad3175c2c1f91a959e20128e8bbcf | michelalejo/holbertonschool-higher_level_programming | /0x0B-python-input_output/2-read_lines.py | 237 | 3.5 | 4 | #!/usr/bin/python3
def read_lines(filename="", nb_lines=0):
j = 0
with open(filename, encoding='utf-8') as s:
for i in s:
j += 1
if nb_lines <= 0 or j <= nb_lines:
print(i, end="")
|
9d22215bc3423aca807307a13e267928c6b18fda | michelalejo/holbertonschool-higher_level_programming | /0x10-python-network_0/6-peak.py | 218 | 3.765625 | 4 | #!/usr/bin/python3
""" Find the Peak"""
def find_peak(list_of_integers):
if list_of_integers == []:
return
max = 0
for n in list_of_integers:
if n > max:
max = n
return (max) |
97fe3a00533a277034e7b020add820f0aee96dc3 | CodeDem/mlprac | /Practical2.py | 272 | 3.6875 | 4 | import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame()
df['color'] = ['Red','Green','Yellow','Black','Orange']
df['count'] = [5,8,6,2,9]
df['pmf'] = df['count']/df['count'].sum()
print(df['pmf'])
plt.bar(df['color'],df['pmf'])
plt.show() |
c0157c528c3be5063752056ab9ba54e14d050494 | haseltan/-dev | /odev.py | 2,302 | 3.875 | 4 | print(" Bu program bir basketbol oyuncusuna ilişkin girdiğiniz bilgileri işleyip yeni bilgiler üretir.")
print("")
print(" Oyuncunun girdiği toplam maç sayısını, başarılı ve başarısız serbest, ikilik, üçlük atış sayısını ")
print("girdikten sonra program atış çeşitlerindeki başarı oranlarını, toplam atış s... |
b2c09cf42fa22404a0945b1746176a1b847bd260 | dobtco/beacon | /beacon/importer/importer.py | 974 | 4.125 | 4 | # -*- coding: utf-8 -*-
import csv
def convert_empty_to_none(val):
'''Converts empty or "None" strings to None Types
Arguments:
val: The field to be converted
Returns:
The passed value if the value is not an empty string or
'None', ``None`` otherwise.
'''
return val if va... |
31d79ed21483f3cbbc646fbe94cf0282a1753f91 | OceanicSix/Python_program | /parallel_data_processing/data_parition/binary_search.py | 914 | 4.125 | 4 | # Binary search function
def binary_search(data, target):
matched_record = None
position = -1 # not found position
lower = 0
middle = 0
upper = len(data) - 1
### START CODE HERE ###
while (lower <= upper):
# calculate middle: the half of lower and upper
middle = int((lowe... |
0b6c239f76fb3b7690c87f51e645b1345256286b | OceanicSix/Python_program | /Gavin_Code/Joono/deck1.py | 3,406 | 4.21875 | 4 | # import Card class from card file
from Gavin_Code.Joono.card1 import Card
# import random to use shuffle
import random
# define a class which is called Deck used to store 52 disorder cards
class Deck:
# define a __init__ method, which contain self.value_start, self.value_end, self.number_of_suits and self.cards
... |
46d9c3d6260091b4dac1468ac32be2738508475b | OceanicSix/Python_program | /Study/Search_and_Sort/Module 4/Sort_runtime.py | 2,074 | 3.953125 | 4 | import time
import random
import Study.Search_and_Sort.Bubble_sort
import Study.Search_and_Sort.Selection_sort
import Study.Search_and_Sort.merge_sort
import Study.Search_and_Sort.quick_sort
import string
import Study.Search_and_Sort.Insertion_sort
import numpy as np
import matplotlib.pyplot as plt
ranlist=[]
# for i ... |
bb038374444865f884a7ace87906baa6597e6168 | OceanicSix/Python_program | /Study/ADT/list.py | 4,057 | 4.125 | 4 | # list.py: implementation of the List ADT using an array structure
class List:
# creates a new list
def __init__(self):
self.the_list = [] # represent the list as a Python's list
self.count = 0 # indicate the current size of the list
# returns the number of items in the list
def __len... |
0d2d1d308263330b662a05d1f6d7ca8121fd4bcd | OceanicSix/Python_program | /Study/testing/unit_test_code.py | 593 | 3.734375 | 4 |
import unittest
import calculator
class TestForSum(unittest.TestCase):
# all function must start with test
#valid test case
def test_sum_valid(self):
self.assertEqual(calculator.test_add_sum(1, 2), 3)
def test_sum_invalid(self):
self.assertEqual(calculator.test_add_sum('a','b'),-1... |
1929abfa4e7d2e10f0583ed471321fda6ebbfdd0 | OceanicSix/Python_program | /Gavin_Code/Chess/board.py | 1,622 | 3.9375 | 4 | class Board:
def __init__(self,n,the_empty=0):
self.theBoard = []
self.size = n
self.empty = the_empty
i = 0
while (i < n):
self.theBoard.append([self.empty]*n)
i += 1
def __str__(self):
new_string = ""
for row in self.theBoar... |
0201b62746affdd34276f19f523f5a8866ffd937 | OceanicSix/Python_program | /My_founction/Turtle_code/Fractals.py | 398 | 3.953125 | 4 | import turtle
def fractals(turtle_object,order,length):
if order==0:
turtle_object.forward(length)
else:
for angle in [60,-120,60,0]:
fractals(turtle_object,order-1,length/3)
turtle_object.left(angle)
a=turtle.Screen()
a.bgcolor('lightgreen')
b=turtle.Turtle()
b.shape('b... |
33e560583b1170525123c867bb254127c920737f | OceanicSix/Python_program | /Study/Search_and_Sort/Insertion_sort.py | 840 | 4.34375 | 4 | # sorts the list in an ascending order using insertion sort
def insertion_sort(the_list):
# obtain the length of the list
n = len(the_list)
# begin with the first item of the list
# treat it as the only item in the sorted sublist
for i in range(1, n):
# indicate the current item to be posit... |
ba24b42e01210fe495014bc812dd950f816ff256 | OceanicSix/Python_program | /My_founction/random_func/ran_int.py | 532 | 3.609375 | 4 | import random
def ran_int(start_value,end_value):
length=end_value-start_value+1
value_list=range(start_value,end_value+1)
ran_number=random.random()
#devide value 1 into $length part, e.g devide 1 into 10 part, if the 0/10=<ran_number<=
#1/10, then return the first value in the value_list.
for ... |
522c41a97cefaa9f087cc0f0e6c2e9eab65275ce | OceanicSix/Python_program | /My_founction/converter.py | 876 | 3.828125 | 4 |
def bin_to_dec(binary):
str_binary=str(binary).strip('b')
power=0
sum=0
for i in reversed(str_binary):
sum+=int(i)*(2**power)
power+=1
return sum
stop=False
while stop==False:
input_number=input('please input a number ')
try:
if input_number=='q':
stop=... |
9982e8d147441c02f3bc24a259105ae350477485 | OceanicSix/Python_program | /test/deck.py | 322 | 4.15625 | 4 | def recursive_addition(number):
if number==1:
return 1
else:
return recursive_addition(number-1)+number
print(recursive_addition(4))
def recursive_multiplication(n,i):
if n==i:
return i
else:
return recursive_multiplication(n-1,i)*n
print(recursive_multiplication(5,2... |
03272f1a275e5055054b9131b205949b00458f4e | OceanicSix/Python_program | /Assignment/Freecell/card.py | 1,594 | 3.703125 | 4 | #Card class
class Card:
def __init__(self,card_face,card_suit):
self.card_face=card_face
self.card_suit=card_suit
self.the_card=(self.card_face,self.card_suit)
#Red color card is represented by 0, black card by 1
if self.card_suit=='H' or self.card_suit=='D':
self... |
40f6c1e65788b29ca9d58abf957d8e10ea44ced7 | OceanicSix/Python_program | /My_founction/Class point/Class point.py | 1,479 | 4.0625 | 4 |
class Point:
number=0
def __init__(self, x, y):
self.x = x
self.y = y
Point.number+=1
def get_x(self):
return self.x
def get_y(self):
return self.y
def set_x(self, x):
self.x = x
def set_y(self, y):
self.y = y
def distance_from_or... |
f23588e2e08a6dd36a79b09485ebc0f7a59ed6b7 | chiragkalal/python_tutorials | /Python Basics/1.python_str_basics.py | 930 | 4.40625 | 4 | ''' Learn basic string functionalities '''
message = "it's my world." #In python we can use single quotes in double quotes and vice cersa.
print(message)
message = 'it\'s my world.' #Escape character('\') can handle quote within quote.
print(message)
message = """ It's my world. And I know how to save this ... |
d37bf899b3b9c1b26697edd7f5a8bddaf9fa0fb7 | chiragkalal/python_tutorials | /Python Basics/7.functions.py | 2,030 | 4.0625 | 4 | # def hello():
# pass
# print(hello()) #It will print None because nothing is mentioned in hello function.
def hello_world():
return 'hello world'
print(hello_world())
print(hello_world().upper()) #It will print return values and convert it into upper case
def hello_func(greetings):
return '{} ... |
6f0fd2a0d4a53a30736625b314b2a9f88ec9736e | reroes/ejemploSiete | /c3/condicinal_if_else.py | 111 | 3.5625 | 4 | edad = 18
if(edad >= 18)
print("Felicidades eres mayor de edad")
else
print("Aun no tienes edad para beber") |
02216bc3b470b8ba1220e0c19bd96950683c71b0 | htlcnn/pe_solutions | /12.py | 412 | 3.59375 | 4 | #!/usr/bin/env python3
from functools import reduce
def num_of_divisor(n):
return len(set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def solve(input_):
n = 5000
while True:
num = int(n*(n+1)/2)
if num_of_divisor(num) > 500:
... |
652684003063a4ec9e23a19bb86fde5e4d13b107 | htlcnn/pe_solutions | /53.py | 329 | 3.828125 | 4 | #!/usr/bin/env python3
def fact(n):
if n <= 0:
return 1
return n * fact(n-1)
def solve():
counter = 0
for n in range(23, 101):
for r in range(1, n+1):
if fact(n)/(fact(r) * fact(n-r)) > 10**6:
counter += 1
return counter
if __name__ == '__main__':
... |
c8c8b2a091aed7e454b076289428eb533f26aa30 | htlcnn/pe_solutions | /42.py | 682 | 3.8125 | 4 | #!/usr/bin/env python3
import string
def word_point(word):
point = 0
for c in word:
if c in string.ascii_uppercase:
point += string.ascii_uppercase.find(c) + 1
return point
def is_triangle_num(n):
for i in range(n+1):
if i * (i+1) / 2 == n:
return True
ret... |
275814608ca5174f1f81f1a3f1c8bcc69add551b | anyabear/python-challenge | /PyBank/main.py | 2,697 | 4 | 4 | # Py Bank
# Doug Watola
import os
import csv
import operator
#Average function that takes a list of numbers
def average(list):
return sum(list)/len(list)
#Set the path for input budget file
budgetpath = ("./Resources/budget_1.csv")
outPath = ("./Resources/budgetanalysis.txt")
#==================================... |
a49b4bd0a52ebca69706c6e7a32913e35ef50bd5 | EfranH25/COVID-Neural-Net | /src/Tensor Flow Practice/keras_first_network.py | 1,235 | 3.703125 | 4 | from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
# Tutorial Link:https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/
if __name__ == '__main__':
# Step 1) Load data
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')
X = data... |
c84ef9ba9437b95067078a2d23b425f797f1f9c7 | Dakotap08/mentalHealth | /webpage.py | 2,393 | 3.65625 | 4 | a1 = ("Nothing...")
b2 = ("Hello")
c3 = ("Hello, I'm in need")
d4 = ("...")
e5 = ("Some days I feel empty") #yellow
f6 = ("I am having suicidal thoughts/tendencies") #red
g7 = ("")
h8 = ("")
choices = (a1, b2, c3, d4, e5,f6, g7, h8)
e6 = ("my family")
e7 = ("my Job")
e8 = ("school")
choices2 = (e6, e7, e8)
e1 = ("goo... |
cabd4dcaac3474b7cc3daa4711a56a4fdebade38 | Muchtrix/Ai | /Pracownia_pythonowa/zadanie5.py | 626 | 3.65625 | 4 | #coding=utf8
import itertools as it
def evaluate(text):
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
ops = {'v': ' or ', '^': ' and ', '~': ' not '}
letters = tuple(set(text.translate(None, 'v^()~ ')))
for tr in it.product(... |
b22ab7316aa34c25d23e265e5a09ee05b6f6b032 | gyjoo/efp57 | /6_Retirement_Calculator/6_Retirement_Calculator.py | 263 | 3.890625 | 4 | age = eval(input("What is your current age? "))
retire_age = eval(input("At what age would you like to retire? "))
print("You have %d years left until you can retire." % (retire_age - age))
print("It's 2017, so you can retire in %d" % (retire_age - age + 2017))
|
da47dc4201cdcb2129769eb322f004a52570d709 | gyjoo/efp57 | /5_Simple_Math/5_Simple_Math.py | 308 | 3.921875 | 4 | fnum = eval(input("What is the first number? "))
snum = eval(input("What is the second number? "))
print(" %d + %d = %d " % (fnum, snum, fnum + snum))
print(" %d - %d = %d " % (fnum, snum, fnum - snum))
print(" %d * %d = %d " % (fnum, snum, fnum * snum))
print(" %d / %d = %f " % (fnum, snum, fnum / snum))
|
d07d9272e35fa12d5c9f124962b800a1b4492c50 | gyjoo/efp57 | /1_Saying_Hello/1_Saying_Hello.py | 81 | 3.828125 | 4 | name = input("What is your name? ")
print("Hello, %s, nice to meet you!" % name)
|
d5a422cae556235ef47d0534a1e247913acc82b5 | jianboma/Find_RentPrice | /create_postcode_table.py | 3,185 | 3.5625 | 4 | #!/usr/bin/env python
# coding=utf-8
import pymysql
from pandas import read_csv
def close_connection(connection, cursor):
connection.close
cursor.close
def delete_database(query, connection, cursor):
cursor.execute(query)
connection.commit()
close_connection(db, cursor)
def create_database(db_na... |
3933ba1a53fc587cdfa10a48e006d7ccadd3fc16 | noobdboon/small-projects | /20171012/reverse.py | 66 | 3.59375 | 4 | #!python3
person = input('Enter the name: ')
print(person[::-1])
|
68fcd1df5e042b31ee9541bdbb57274757b3cf4e | jbjjbjjbj/eittek651 | /antenna_diversity/diversity_technique/selection.py | 5,076 | 4.03125 | 4 | import numpy as np
import typing as t
def selection_from_h(signal: np.ndarray,
channel_h: np.ndarray) -> t.Tuple[t.Any, int]:
"""
Signal is a N x M signal where N is the number of branches and M is the signal places,
such for example that the signal[1] gives a array of M eleme... |
0e6203ec46b907c6d62c54b0c9819c07b3da24de | wangbin0227/BasicStudy | /python/code/operator_func.py | 3,273 | 3.5625 | 4 | # -*- coding:utf-8 -*-
# @Author: wangbin
# @Time: 2020-05-24 14:18:00
# @FileName: operator_func
import os
import sys
from operator import *
def logical_operations():
a = -1
b = 5
print ('a =', a)
print ('b =', b)
print ()
print ('not_(a) :', not_(a))
print ('truth(a) :', truth(a... |
2ee037c1fc28eb456f843d1a8470a88cb1aa8c77 | YXY980102/YXY980102 | /2,标识符.py | 263 | 3.734375 | 4 | '''
第一个字符必须是字母表中字母或下划线 _ 。
标识符的其他的部分由字母、数字和下划线组成。
标识符对大小写敏感。
注:不能以数字开头
'''
# 1_2=12
a=12
_12='a'
_12asghs='s'
print(_12asghs) |
a267ce733dae7638beee46d181d5e4d81a81747e | YXY980102/YXY980102 | /11,运算符-比较运算符.py | 831 | 4.125 | 4 | '''
运算符 描述 实例
== 等于 - 比较对象是否相等 (a == b) 返回 False。
!= 不等于 - 比较两个对象是否不相等 (a != b) 返回 True。
> 大于 - 返回x是否大于y (a > b) 返回 False。
< 小于 - 返回x是否小于y。所有比较运算符返回1表示真,返回0表示假。这分别与特殊的变量True和False等价。注意,这些变量名的大写。 (a < b) 返回 True。
>= 大于等于 - 返回x是否大于等于y。 (a >= b) 返回 False。
<= 小于等于 - 返回x是否小于等于y。 (a <= b) 返回 ... |
ab9128fd1ee9e40ccdcbb7b21ba1056d749f8173 | YXY980102/YXY980102 | /1,简介.py | 3,632 | 3.65625 | 4 | '''
Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。
Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结构。
Python 是一种解释型语言: 这意味着开发过程中没有了编译这个环节。类似于PHP和Perl语言。
Python 是交互式语言: 这意味着,您可以在一个 Python 提示符 >>> 后直接执行代码。
Python 是面向对象语言: 这意味着Python支持面向对象的风格或代码封装在对象的编程技术。
Python 是初学者的语言:Python 对初级程序员而言,是一种... |
c0e3411d9f998d99eff349aaf124106506997f42 | peterashwell/python-dpath | /dpath.py | 2,008 | 3.9375 | 4 | def dpath(dikt):
"""Helper to create a DPath that is nice to read e.g. dpath(my_dict)['a', 'b']
:param dikt: Dictionary to wrap in DPath
:return: A DPath object
"""
return DPath(dikt)
class DPath:
"""dpath is a tool for navigating multidimensional map structures easily
>>> from pprint imp... |
2fc059ad6499249eae161eede4d36fcb32ad4fae | thedhruvn/py-utils | /StoppableLoopingThread.py | 3,754 | 3.71875 | 4 | import threading
import ast
import inspect
from typing import Callable
import warnings
import textwrap
class StoppableLoopingThread(threading.Thread):
"""
Extension of the Thread Object that performs a task repetitively
at a given frequency until the thread is stopped
## TODO: handle Thre... |
b6aab86007f5be62d4b6db1574799cce7d208d39 | mboos/advent-of-code | /2020/day/8/loop.py | 1,651 | 3.515625 | 4 | # Lint as: python3
"""Find value of accumulator at start of loop
Solution to https://adventofcode.com/2020/day/8
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_string("input"... |
c7a27ce14ef122a2603a40afe0908410135e4842 | TheBlueJeans/Array-Practice-Questions | /Qn11.py | 130 | 3.765625 | 4 | repeat = []
for value in A:
if value not in repeat:
repeat.append(value)
else:
print(value)
break
|
66048d949881398ba225ca5d3c72d4fabce7ced6 | TheBlueJeans/Array-Practice-Questions | /Qn12.py | 88 | 3.6875 | 4 | for i in range(len(A)):
if value not in A[i+1:]:
print(value)
break
|
0d79c38a9add557c83ee303f20ce5dc1da9be594 | gean-costa/exercism-io | /raindrops/raindrops.py | 362 | 3.96875 | 4 | def convert(number):
raindrop_sound = ''
if number % 3 == 0:
raindrop_sound = 'Pling'
if number % 5 == 0:
raindrop_sound += 'Plang'
if number % 7 == 0:
raindrop_sound += 'Plong'
if raindrop_sound == '':
raindrop_sound = str(number)
return raindrop_sound
if __na... |
be83f2c448015ca8108ba665a057ce30ef3e7ed0 | Lucchese-Anthony/MonteCarloSimulation | /SimPiNoMatplotlib.py | 885 | 4.21875 | 4 | import math
import random
inside = 1
outside = 1
count = 0
def inCircle(x, y):
#function that sees if the coordinates are contained within the circle, either returning false or true
return math.sqrt( (x**2) + (y**2) ) <= 1
while True:
count = count + 1
#random.uniform generates a 'random' number betw... |
d966305c712a454b9012c356d7b6bb831f9f4ce3 | MajidAli44/WebScraping | /ScrapingRevision.py | 584 | 3.515625 | 4 | from bs4 import BeautifulSoup
with open("Index.html",'r') as html_file:
content=html_file.read()
# print(content)
soup=BeautifulSoup(content, 'lxml')
# print(soup.prettify())
# tags=soup.find_all('h5')
# print(tags)
# courses_html_tags=soup.find_all('h5')
# for course in courses_html_... |
adf32d0f002debd783a0a3b30f1d06e0af37f0ec | Shawk1998/practiceFolder | /python数据类型/运算符.py | 435 | 3.859375 | 4 | # 加减乘除取余
print(3 + 4)
print(3 - 4)
print(3 * 4)
print(3 / 4)
print(3 % 4)
print(10 % -4) # 10 = -4 * -4 + -2
# 整除,运算结果只保留整数部分
print(7 // -4)
print(9 // -4) # 9 = -4 * -3 +-3所以结果为-3
# 幂运算
print(3 ** 4)
print(pow(3 , -2))
# 布尔运算 与或非(and or not)
# 只针对布尔值进行运算
# 比较运算
# < <= > >= == != is is not
# 赋值运算
a = 'niconiconi'... |
5dcbae137b6566304326ba48e0f48795cd444642 | brisvn/Turing355 | /turingmachine.py | 1,948 | 4.0625 | 4 | """This is the Turing Machine Module it has the turing machine class and program"""
class TM:
"""This class is the turing machine class it initiates here"""
def __init__(self):
self.state = None
self.program = {}
def read(self, program):
"""This method reads in and stores into mem... |
b4ed0b4329d24d9708c97eeebff1df4d74ad67ed | juanvicfer/PythonHeap | /MyHeapTests.py | 1,986 | 3.5 | 4 |
import unittest
from MyHeap import MyHeap
class TestHeap(unittest.TestCase):
def test_empty_after_construction(self):
a = MyHeap()
self.assertTrue(a.empty())
def test_not_empty_after_adding_one_element(self):
a = MyHeap()
a.add(5)
self.assertFalse(a.empty())
def ... |
55523137b3c7512970dae0dccc030208dc2bd9d1 | 16aburnett/Advent-Of-Code-2019 | /day2b.py | 1,754 | 3.734375 | 4 | # Advent of Code 2019 day 2 part B
# By Amy Burnett
# IntCode computer
import sys
import math
# opcodes
OPCODE_ADD = 1
OPCODE_MULT = 2
OPCODE_HALT = 99
# read in memory
init_memory = list(map(int,input().split(",")))
# loop on inputs to find answer
for a in range(99):
for b in range(99):
... |
ed0c000b2a6ad204338e348c79cf25b3a923751e | 16aburnett/Advent-Of-Code-2019 | /day6b.py | 2,301 | 3.96875 | 4 | # Advent of Code 2019 day 6 part B
# Universal Orbit Map
# By Amy Burnett
import sys
import math
# node to represent a planet related to their children planets
class node:
def __init__(self, name):
self.parent = 0
self.children = []
self.name = name
def add_child(self, chil... |
84328f12dd87c7434237c7ec85694bf3f5ff0218 | kartikxisk/python_program | /test.py | 1,523 | 3.671875 | 4 | # x = int(input())
# y = int(input())
# z = int(input())
# # n = int(input())cls
# for i in range(x):
# for j in range(y):
# for k in range(z):
# print([i, j, k])
# X = int(input())
# Y = int(input())
# Z = int(input())
# N = int(input())
# lis = [[x, y, z]
# for x in ran... |
5140b283f2c4d2eb149f7d4c9febeb27434b3fd5 | gvutukuri88/MyCodes | /getDataFramFromHbaseTable.py | 1,577 | 3.53125 | 4 | import happybase
import pandas as pd
connection = happybase.Connection('localhost', autoconnect=False)
connection.open()
def retriveDataFrame(connection,tableName):
try:
data = connection.table(tableName) #get the table with tableName and connection
data=list(data.scan()) #gives the list to tupl... |
8b308573cbc5452876711b7b24c5e84dd1377204 | dreamuming/Leetcode | /UniqueWord.py | 922 | 3.78125 | 4 | class ValidWordAbbr(object):
def __init__(self, dictionary):
"""
initialize your data structure here.
:type dictionary: List[str]
"""
self.dic = {}
for word in dictionary:
abb = word if len(word) <= 2 else word[0] + str(len(word) - 2) + word[-1]
... |
c7120a77b641360108050058a720c2b4b48d2eb4 | dreamuming/Leetcode | /Number.py | 293 | 3.921875 | 4 | from __future__ import print_function
num = 25 # a number greater than 2 and less than 100
for test in range(2, num):
if num % test == 0 and num != test:
print( num, 'equals', test, '*', num/test)
print( num, 'is not a prime number')
break
else:
print(num, 'is a prime number')
|
d58579e0abe5bcbca17441830387be0a47b4b6a6 | rgelmediler07/python-baslangic | /yerDegistirme.py | 314 | 3.734375 | 4 | print("----------------SAYILARIN YERLERİNİ DEĞİŞTİRME-----------------")
sonuc=[]
sayi1=int(input("İlk Sayıyı Gir ="))
sayi2=int(input("İkinci Sayıyı Gir ="))
sonuc=[sayi1 , sayi2]
print("1.Sayı ={} \t 2.Sayı ={}".format(sonuc[1] , sonuc[0]))
sayi1 , sayi2 = sayi2 , sayi1
print(sayi1 , sayi2)
|
209c616fe9c622b4269bddd5a7ec8d06d9a27e86 | paula867/Girls-Who-Code-Files | /survey.py | 2,480 | 4.15625 | 4 | import json
import statistics
questions = ["What is your name?",
"What is your favorite color?",
"What town and state do you live in?",
"What is your age?",
"What year were you born?"]
answers = {}
keys = ["Name", "Favorite color", "Hometown","Age", "Birthye... |
1fc60dae4e64ace935d1ce43b2d466aaca6a8674 | paula867/Girls-Who-Code-Files | /ramdomlibrary.py | 338 | 3.765625 | 4 | import random
print ("Random number with seed 30")
random.seed( 30 )
print ("first - ", random.randint(25,50))
#will generate a same random number as previous
random.seed( 25 )
print ("Second - ", random.randint(25,50))
#will generate a same random number as previous
random.seed( 15 )
print ("Third - ", rand... |
44fe58b4894c8bc4509ef48d279a9c6f709e9920 | muthu-gokul/guvi | /set1h.py | 99 | 3.5625 | 4 | r=int(input())
if r<0:
print()
else:
a=0
while(r>0):
a+=r
r-=1
print("",a)
|
649cd037b21e46e5d1a79e0f7d8d08190c36da48 | jclingensmith/yubioath-desktop | /py/qr/qrdecode.py | 12,061 | 3.546875 | 4 | """
Given a 2D matrix of pixel data from a QR code, this module will decode and
return the data contained within. Note that error correction is not
implemented, and the input will thus have to be without any errors. Only
supports numeric, alphanumeric and byte encodings.
"""
from __future__ import division
def decod... |
004ff23485e029c3a80a5d577c100f222e186ed3 | Topspin26/retailhero-shelf-allocation | /py/base.py | 300 | 3.734375 | 4 | from typing import NamedTuple, List
class Item(NamedTuple):
ind: int
cat: int
brand: int
c: int
class Rectangle(NamedTuple):
w: int
h: int
def create_empty_matrix(h: int, w: int) -> List[List[Item]]:
return [[Item(0, -1, -1, 0) for _ in range(w)] for _ in range(h)]
|
1bfba993cdca41c12f554293a8a319623be84dd8 | jfsawyer88/CodeEval | /3-Hard/051-ClosestPair/ClosestPair.py | 934 | 3.6875 | 4 | ## CodeEval
## Closest Pair
import sys
import bisect
if 1 != len(sys.argv):
f = open(sys.argv[1], 'r')
else:
import os
f = open(os.getcwd() + '/test.txt')
def dist(p, q):
'''returns the euclidian distance
between the two given points'''
return ((p[0] - q[0])**2 + (p[1] - q[1])**2)**0.5
d... |
03c8954804f8b0c1ea98e8a8548992406a758d70 | jfsawyer88/CodeEval | /2-Moderate/070-OverlappingRectangles/OverlappingRectangles.py | 517 | 3.65625 | 4 | ## CodeEval
## Overlapping Rectangles
import sys
def overlaps(L1, L2):
return not L1[1] < L2[0] or L1[0] > L2[1]
f = open(sys.argv[1], 'r')
for line in f:
line = line.strip()
if line:
line = [int(n) for n in line.split(',')]
X1 = sorted([line[0], line[2]])
Y1 = sorted([line[1], ... |
92d69cc9d69ffa986c1500254d67ec4edaa4490d | jfsawyer88/CodeEval | /1-Easy/004-SumofPrimes/SumOfPrimes.py | 1,582 | 3.6875 | 4 | ## CodeEval
## Sum of Primes
import sys
import math
def prime_pi(n):
"count primes below n"
r = int(n ** 0.5)
V = [n//i for i in range(1,r+1)]
V += list(range(V[-1]-1,0,-1))
S = {i:i-1 for i in V}
for p in range(2,r+1):
if S[p] > S[p-1]: # p is prime
sp = S[p-1] # sum of... |
f56135f84857e126ad60397b890401aafefc4a80 | jfsawyer88/CodeEval | /1-Easy/021-SumofDigits/SumOfDigits.py | 332 | 3.546875 | 4 | ## CodeEval
## Sum of Digits
import sys
def sum_of_digits(n, b=10):
res = 0
while 0 < n:
d = n % b
n = (n - d)/b
res += d
return res
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
sys.stdout.write(str(sum_of_digits(int(test))))
sys.stdout.write("\n")
test_ca... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.