blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
9e05dab42e7349eb6a37db194139b96c4b9cedf4 | stahv21-meet/meet2019y1lab7 | /snake_2.py | 6,274 | 4.3125 | 4 | import turtle
import random #We'll need this later in the lab
turtle.tracer(1,0) #This helps the turtle move more smoothly
SIZE_X=800
SIZE_Y=500
turtle.setup(SIZE_X, SIZE_Y) #Curious? It's the turtle window
#size.
turtle.penup()
SQUARE_SIZE = 20
START_LENGTH = 3
TIME_STEP = 100
#... |
3084ef698a1b5b123e3b6447f6498dda71d34d86 | yimej/GW_coursework | /python-challenge/PyPoll/main.py | 2,215 | 3.84375 | 4 | import csv
again = "y"
while again == "y":
print("----------------------------------------------------------")
file = input("Enter file name: ")
with open(str(file), newline="") as csvfile:
poll_list = list(csv.reader(csvfile, delimiter=","))
print("-----------------------... |
9bfe409f9fa491061a0f5f603a9b4beb6ae308a5 | GaZ3ll3/WaveBlocksND | /src/WaveBlocksND/MatrixExponential.py | 2,565 | 3.5 | 4 | """The WaveBlocks Project
This file contains several different algorithms to compute the
matrix exponential. Currently we have an exponential based on
Pade approximations and an Arnoldi iteration method.
@author: R. Bourquin
@copyright: Copyright (C) 2007 V. Gradinaru
@copyright: Copyright (C) 2010, 2011, 2012 R. Bou... |
e0ad79e8a94044ac9902b224ec1d3bd8c8329a33 | PizzaMyHeart/map.py | /map.pyw | 490 | 3.640625 | 4 | #! python3
# map.py - Launches a map in the browser using an address from the
# command line or clipboard.
import webbrowser, sys, pyperclip
from urllib import parse
if len(sys.argv) > 1:
# Get address from cmdline.
address = ' '.join(sys.argv[1:])
# URL escaping
address = parse.quote_plus(address)
els... |
843645e32b2c631a8ed12b64bf4dd5207dfc7a1d | sandeepshiven/python-practice | /function_exercises/is_greater.py | 420 | 4.21875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 21 23:08:53 2019
@author: sandeep
"""
def is_greater(a,b):
return a>b
num1,num2 = input("Enter two mumbers\n").split() # method for taking multiple input
print(f"Is {num1} greater than {num2}\n{is_greater(num1,num2)}")
num1,num2 = [input() f... |
5369eb99e5baca43d9a07fb0910da622b28e593c | sandeepshiven/python-practice | /function_exercises/Write a function that computes the volume of a sphere given its radius.py | 229 | 3.875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 27 14:08:50 2019
@author: sandeep
"""
# import math # to use pi by calling math.pi()
def vol(rad):
return ((4/3)*(3.14)*(rad**3))
# Check
print(vol(2)) |
b86e733f0ee6656eae219e954688ff56ff3ca8ca | sandeepshiven/python-practice | /decorators 2/only_int.py | 753 | 3.578125 | 4 | from functools import wraps
def only_ints(fn):
@wraps(fn)
def wrapper(*args,**kwargs):
if any([i for i in args if type(i) != int]):
print("Only ints are allowed")
return
return fn(*args, **kwargs)
return wrapper
@only_ints
def add(*args):
print( sum(args))
add(... |
722afe0f67c461be14a4128f4cefa51589d235e7 | sandeepshiven/python-practice | /advance python modules/datetime.py | 312 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 26 19:37:19 2019
@author: sandeep
"""
from datetime import datetime
#datetime object cotaining current date and time
now = datetime.now()
print("now =",now)
#dd/mm/yy H:M:S
c_time = now.strftime("%d/%m/%Y %r")
print(c_time)
|
32e32a21b72493a58d5cc475bd2b1a677772ace0 | sandeepshiven/python-practice | /functions/map,filter and lambda/lambda.py | 311 | 3.890625 | 4 | mylist = [1,2,3,4,5,6,7,8,9]
square = lambda num: num**2 # basically same as writing a function to return square of number
#using lambda with map
print(list(map(lambda num: num**2,mylist))) # taking num as a parameter and returning the value after :
print(list(filter(lambda num: num%2 == 0,mylist)))
|
c4e413b23c208f87c55c7d63effcf558310efe96 | sandeepshiven/python-practice | /iterators and generators/gen_yes_no.py | 212 | 3.578125 | 4 | def gen_yes_no():
ans = ['yes','no']
while True:
yield ans[0]
yield ans[1]
gen = gen_yes_no()
print(next(gen)) # 'yes'
print(next(gen)) # 'no'
print(next(gen)) # 'yes'
print(next(gen)) # |
b2a2618219df2e6fcab9a45dcdb81de0bd54cc8d | sandeepshiven/python-practice | /errors and exception/another.py | 616 | 4.125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 15:16:40 2019
@author: sandeep
"""
# using try except for prompting user for entering the correct input
def ask_for_int():
while True:
try:
result = int(input("Please enter a number: "))
except:
p... |
4ba01c38fa493281eae558fab0a8f3c7b7467da0 | sandeepshiven/python-practice | /object oriented programming/oops2/name_mangling.py | 630 | 4.125 | 4 | '''
_name // just a convention that tells this variable is meant for use inside the class don't acces it outside
__name // does something behind the scenes adds the class name and __name together so it can be only
accesed like this object._Class__name
___name__ // is used to ovewirte some built in methods like __len__... |
1d6ac4c9fe5c1d4ed0e859e12bd7c0c01e5410cc | sandeepshiven/python-practice | /functions/pig_latin.py | 403 | 4.03125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 23:01:25 2019
@author: sandeep
"""
def pig_latin(word):
first_word = word[0]
if first_word.lower() in 'aeiou':
pig_word = word + 'ay'
else:
pig_word = word[1:] + first_word + 'ay'
r... |
96ce9566e4808c328dc39ff9cfaae44fffb0b6d6 | sandeepshiven/python-practice | /decorators 2/really_restricting_arguments.py | 889 | 3.75 | 4 | '''
# NOT WORKING CODE!
# JUST FOR DEMO PURPOSES!
# When we write:
@decorator
def func(*args, **kwargs):
pass
# We're really doing:
func = decorator(func)
# When we write:
@decorator_with_args(arg)
def func(*args, **kwargs):
pass
# We're really doing:
func = decorator_with_args(arg)(func)
'''
from functools... |
8fc582dceb592dda48e8db91a5d024bcb33d0f8a | sandeepshiven/python-practice | /functions/map,filter and lambda/filter.py | 205 | 4 | 4 | def even(num):
return num%2 == 0
mylist = [1,2,3,4,5,6,7,8,9]
print(list(filter(even,mylist))) # filters out the false value for the elements in mylist
for item in filter(even,mylist):
print(item) |
c7e838ad067a1167a09d7034f25c8951ec5ba285 | sandeepshiven/python-practice | /functions/finding_a_substring.py | 533 | 4.09375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 22:26:08 2019
@author: sandeep
"""
def substring(string,sub):
if sub.lower() in string.lower():
return "Yes, the word is in the string"
else:
return "No, the word is not in the string"
st = input("Enter a string... |
5ef3a187a5c88ba74be42c2147822e85a22a28f6 | sandeepshiven/python-practice | /useful_operators/random_library.py | 275 | 3.90625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 17 22:49:02 2019
@author: sandeep
"""
from random import shuffle
from random import randint
list1 = [1,2,3,4,5,6,7,8,9]
shuffle(list1)
print(list1)
for i in range (100):
print(randint(1,2))
|
190b80d09699073d1722d84a89850c7354f3f2cc | sandeepshiven/python-practice | /function_exercises/Write a Python function that takes a list and returns a new list with unique elements of the first list.py | 205 | 3.9375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 27 19:53:09 2019
@author: sandeep
"""
def unique_list(lst):
return list(set(lst))
print(unique_list([1,1,1,1,2,2,3,3,3,3,4,5]))
|
a7cfc3592b2bcc82483ef981df1a51edfca8747d | sandeepshiven/python-practice | /working with csv files/writing_csv_list.py | 407 | 3.59375 | 4 | from csv import writer,DictReader
with open('writing.csv','w') as file:
csv_reader = writer(file)
csv_reader.writerow(['Name','Surname','Age'])
csv_reader.writerow(['Sandeep','Shiven',20])
csv_reader.writerow(['Yash','',19])
csv_reader.writerow(['Ansh','Shrivastava',18])
with open('writing.csv','... |
268d9ab7553a1d11b43ea522442c0a9fe4b4e571 | sandeepshiven/python-practice | /object oriented programming/inheritance.py | 939 | 4.46875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 9 22:47:50 2019
@author: sandeep
"""
class Animal(): # creating the base class
def __init__ (self):
print("Animal created")
def who_am_i(self):
print("Animal")
def eat(self):
print("Eating... |
66f764fa2b4a169b2af3c3c9defcda04faf0fbfe | sandeepshiven/python-practice | /object oriented programming/oops2/class_methods_adv.py | 1,779 | 4.03125 | 4 | class User:
active_users = 0 # class attribute it defined once and shared between all instances of the same class
@classmethod # decorator (similar to class attribute)
def display_active_users(cls): # in class methods automatically the class is going to be passed in
return f"There are curren... |
7274ecbe22fcea1866b7d110843ae47767cad103 | sandeepshiven/python-practice | /simple questions on loops and list comprehensions/Use List Comprehension to create a list of the first letters of every word in the string .py | 226 | 4 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 18 17:47:22 2019
@author: sandeep
"""
st = 'Create a list of the first letters of every word in this string'
lst = [x[0] for x in st.split() ]
print(lst) |
9e5c0663ebb2018a76c46e22f8396a0878db2603 | sandeepshiven/python-practice | /useful_operators/list_comprehensions.py | 933 | 4.09375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 18 15:49:17 2019
@author: sandeep
"""
string = "Sandeep"
my_list = []
for item in string:
my_list.append(item)
print(my_list)
# above process can be done in a single line by using list comprehensions
my_list = []
my_list = [item for ite... |
82e44c9efb4712d21e37ac8e1f0b7b7b412f3dbd | sandeepshiven/python-practice | /object oriented programming/oops2/method_resolution_order.py | 1,155 | 4.125 | 4 | class Aquatic():
def __init__(self,name):
self.name = name
def swim(self):
print(f"{self.name} is swimming")
def greet(self):
print(f"I am {self.name} of the sea!")
class Ambulatory():
def __init__(self,name):
self.name = name
def walk(self):
print(f"{... |
9bfd5724da207adec4a63125b6ed1e5818ba3285 | mehdithreem/sharifcup | /robotic_logic/Utility/testGenerator.py | 4,946 | 3.625 | 4 | import pygame
ROBOT = 0
OBSTACLE = 1
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
BLUE = ( 0, 0, 255)
GREEN = ( 0, 255, 0)
RED = (255, 0, 0)
MAG = (255, 0, 255)
BROWN = (42, 33, 9)
YELLOW = (255, 255, 0)
LBROWN = (72, 65, 45)
pygame.init()
screen = pygame.display.set_mode((350*2,350*2))
screen.fill(B... |
33e6abc896f302c18f8bd847fa156ab48cd2b5d4 | machkr/py | /Assignments/Assignment 2/common_words.py | 2,633 | 3.640625 | 4 | import collections
from functools import reduce
import string
import sys
files = collections.OrderedDict() # (K, V) = (filename, ordered dictionary of words in file)
strip = (string.whitespace + string.punctuation + string.digits + "\"'") # Strip parameters
# Reads in words from files specified in command-lin... |
f939ba059a2d9dec78674457b333c92d7480f6d2 | dalofulgence/shoppingCart | /shopping.py | 3,235 | 4.5 | 4 | import sys
# Create the main menu
def mainMenu():
while True:
print()
print('''### SHOPPING LIST ###
Select a number for the action that you would like to do:
1. View shopping list
2. Add item from store list to shopping list
3. Remove item from shopping list
... |
bfbab794f0d7d98a22694db2449a89e92fdb9d95 | LubomyrIvanitskiy/golcher | /golcher/helpers.py | 7,795 | 3.578125 | 4 | import numpy as np
import scipy.special as misc
from collections import Counter
from itertools import permutations
def get_condition_map(full_A, branching_factor, shuffle):
"""
Create a Conditional Map.
Given the predecessor letter as a key, the map will return allowed next letters.
It could be used f... |
9e95004a905af70c4489c3f45856fe0ac028883d | HappyRocky/pythonAI | /LeetCode/89_Gray_Code.py | 1,870 | 4.3125 | 4 | # -*- coding: utf-8 -*-
"""
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
格雷编码是一个二进制数字系统,其中两个相邻的编码只有一位是不同的。
给定一个非负整数... |
65ea5d0666229cd997924b3f0952fc3cfac32336 | HappyRocky/pythonAI | /LeetCode/123_Best_Time_to_Buy_and_Sell_Stock_III.py | 3,369 | 4.34375 | 4 | # -*- coding: utf-8 -*-
"""
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy... |
e0c501ee3df148a2b5a9b0d8a9d3ebe795aaefa0 | HappyRocky/pythonAI | /LeetCode/166_Fraction_to_Recurring_Decimal.py | 1,894 | 4.40625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Given two integers representing the numerator and denominator of a fraction,
return the fraction in string format.
If the fractional part is repeating, enclose the repeating part in parentheses.
给定两个整数,代表一个分式的分子和分母。
返回分式的字符串格式。
如果小数部分是无穷循环的,将重复部分用括号括起来。
Example 1:
I... |
498cb0a554686408db5e002910b85099b43558de | HappyRocky/pythonAI | /CNN/CNN_pytorch.py | 3,765 | 3.6875 | 4 | # -*- coding: utf-8 -*-
'''
pytorch版本:0.4
实现一个demo,对torch自带的minist手写数据集进行cnn分类
'''
import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.utils.data as Data
import torchvision
# 设置生成随机数的种子
torch.manual_seed(1)
EPOCH = 1
BATCH_SIZE = 50
class CNN(nn.Module): # 网络结构,继承 Module
def __i... |
e1d55bacfd416eb99f93d1224c681a7e4a6c3bb1 | HappyRocky/pythonAI | /LeetCode/21_Merge _Two_Sorted_Lists.py | 2,041 | 4.0625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 17 10:24:30 2018
@author: gongyanshang1
Merge two sorted linked lists and return it as a new list.
The new list should be made by splicing together the nodes of the first two lists.
合并两个有序链表,返回一个新链表。即合并排序。
Example:
Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4
"""
... |
de77e1bf97305644fe856f8afdce39cfbd1c835c | HappyRocky/pythonAI | /LeetCode/129_Sum_Root_to_Leaf_Numbers.py | 2,548 | 4.25 | 4 | # -*- coding: utf-8 -*-
"""
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.
An example is the root-to-leaf path 1->2->3 which represents the number 123.
Find the total sum of all root-to-leaf numbers.
Note: A leaf is a node with no children.
给定一个二叉树,只包含0-9的数字,每个从根... |
59ee3fc20bdfd31d83391ccc62b66e0e59d88c55 | HappyRocky/pythonAI | /LeetCode/5_Longest_Palindromic_Substring.py | 6,399 | 3.953125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Aug 20 09:36:15 2018
@author: gongyanshang1
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
给定一个字符串s,找到s中最长的回文字字符串。假设s的最大长度为1000.
示例:
Example 1:
Input: "babad"
Output: "bab"
Note: "aba" is also a valid ans... |
27cc887f973b33e13d19438977fa1789c199f21e | HappyRocky/pythonAI | /LeetCode/119_Pascals_Triangle_II.py | 673 | 4.03125 | 4 | # -*- coding: utf-8 -*-
"""
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
Note that the row index starts from 0.
给定一个非负索引k,k<=33,返回杨辉三角形的第k行。
行索引从0开始。
Example:
Input: 3
Output: [1,3,3,1]
"""
def getRow(rowIndex: int) -> list:
"""
按照定义,不断延长row,直至到目标行。
"""
... |
30f3631ba09d5bfd0620afcc8edd7df5f7ed73dd | HappyRocky/pythonAI | /LeetCode/87_Scramble_String.py | 3,973 | 3.9375 | 4 | # -*- coding: utf-8 -*-
'''
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
给定一个字符串 s1,我们可以将它表示成一个二叉树,方法是递归地将其划分为两个非空的子串。
Below is one possible representation of s1 = "great":
以下是对 s1='great'的一种表达方法:
great
/ \
gr eat
/ \ / ... |
df3d824b534e4d65e2aea4874bd8c57c0fa1cddf | HappyRocky/pythonAI | /LeetCode/151_Reverse_Words_in_a_String.py | 1,752 | 4.46875 | 4 | # -*- coding: utf-8 -*-
"""
Given an input string, reverse the string word by word.
Note:
A word is defined as a sequence of non-space characters.
Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
You need to reduce multiple spaces between... |
87d90b1ba2d6427954c85e0bef138e965f6e5e0a | HappyRocky/pythonAI | /LeetCode/93_Restore_IP_Addresses.py | 1,563 | 4 | 4 | # -*- coding: utf-8 -*-
"""
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
给定一个字符串,只包含数字,返回所有可能的有效IP地址组合。
Example:
Input: "25525511135"
Output: ["255.255.11.135", "255.255.111.35"]
"""
def restoreIpAddresses(s: str) -> list:
"""
深度优先遍历,回溯法
规则:I... |
65c7adf2c8284207744a61dfd947503536e43f5e | HappyRocky/pythonAI | /LeetCode/94_Binary_Tree_Inorder_Traversal.py | 2,180 | 4 | 4 | # -*- coding: utf-8 -*-
"""
Given a binary tree, return the inorder traversal of its nodes' values.
给定一个二叉树,实现其中序遍历。
Example:
Input: [1,null,2,3]
1
\
2
/
3
Output: [1,3,2]
"""
class TreeNode:
def __init__(self, x):
if isinstance(x, dict):
self.val = x['v']
sel... |
74ec2fe9a655089116995e16e7fedd5b42153087 | HappyRocky/pythonAI | /LeetCode/3_Longest_Substring_Without_Repeating_Characters.py | 1,859 | 3.890625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Fri Aug 17 09:28:48 2018
@author: gongyanshang1
最长无重复字字符串问题
Given a string, find the length of the longest substring without repeating characters.
给定一个字符串,找到最长的不包含重复字符的子字符串的长度。
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer i... |
2fabccd42b7d54b2eb882275d03780ad7fef2b60 | HappyRocky/pythonAI | /LeetCode/135_Candy.py | 4,014 | 4 | 4 | # -*- coding: utf-8 -*-
"""
There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
Each child must have at least one candy.
Children with a higher rating get more candies than their neighbors.
What is the minimum... |
23ca97c67389c0cad16a9f81a7380ddd8a37d832 | HappyRocky/pythonAI | /ABC/loopPrintHello.py | 232 | 3.953125 | 4 | def printHelloByList(L):
if type(L) == list:
for x in L:
print("Hello,{}!".format(x))
else:
print("Paramter is not a list!")
L = ['Bart', 'Lisa', 'Adam']
printHelloByList(L)
|
b82e515c96c971b6b9dac25b73c724eaee96085b | HappyRocky/pythonAI | /LeetCode/128_Longest_Consecutive_Sequence.py | 1,414 | 4.09375 | 4 | # -*- coding: utf-8 -*-
"""
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
Your algorithm should run in O(n) complexity.
给定一个乱序的整数序列,找到连续元素序列的最长长度。
算法的时间复杂度需要为 O(n)
Example:
Input: [100, 4, 200, 1, 3, 2]
Output: 4
Explanation: The longest consecutive elements seque... |
87ee827fef5240b4e99e22d7c66ce644ee5bec59 | HappyRocky/pythonAI | /LeetCode/4_Median_of_Two_Sorted_Arrays.py | 6,287 | 3.828125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 09:22:06 2018
@author: gongyanshang1
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
You may assume nums1 and nums2 cannot be both empty.
有两个已经... |
4b4f978fc82df529226d7b00261f8a2af875c728 | HappyRocky/pythonAI | /scikit-learn/DataLoading.py | 527 | 3.75 | 4 | import numpy as np
import urllib.request as ur
def load_data():
# url of dataset
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data"
# download the file
raw_data = ur.urlopen(url)
# load the CSV file as a numpy matrix
dataset = np.... |
79f3f4d92b21dd6c6ee2fe44ad8cfb6f844414e7 | HappyRocky/pythonAI | /LeetCode/101_Symmetric_Tree.py | 1,206 | 4.40625 | 4 | # -*- coding: utf-8 -*-
"""
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
给定一个二叉树,判断是否是一个镜像二叉树,即以它的中心进行轴对称。
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1
... |
b1a9c5d2dc4a1ee658d25eb8ef83f75238109437 | HappyRocky/pythonAI | /LeetCode/66_Plus_One.py | 1,387 | 3.9375 | 4 | # -*- coding: utf-8 -*-
'''
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading... |
5d362ccefbceab83d19469ab5f0b48fa7591e4d4 | STNox/Python | /minesweeper.py | 936 | 3.53125 | 4 | import random
table = []
for i in range(11):
row = []
for k in range(11):
if i == 0 or i == 10 or k == 0 or k == 10:
row.append('-')
else:
mine = ['-', '*']
row.append(random.choice(mine))
table.append(row)
print(table)
for i in range(11):
for k in r... |
1b3fb7d964bf3afb43606796246fb1925793a324 | NaraVictor/python-fun-projects | /swiss_flag_drawer.py | 620 | 4 | 4 | # drawing the swiss national flag
from turtle import *
def smart_drawer(size, angle, _color, toggle_size):
color(_color)
fillcolor(_color)
begin_fill()
for index, line in enumerate(range(5)):
right(angle)
if index == 2:
if toggle_size == True:
forward(size*... |
87a3f93f72ee6b129ce94200dcfece1bf9e06dfa | jonathandantaschagas/DinoAI | /Genetic Algorithm/network.py | 844 | 3.59375 | 4 | import numpy as np
class Network:
def __init__(self):
self.input_size = 3 # Distância, Altura e Velocidade
self.hidden_size = 4 # Hidden Layers
self.output_size = 1 # Ação
self.W1 = np.random.randn(self.input_size, self.hidden_size) # Iniciando pesos aleatóriamente com di... |
cd000e3bc01a4ef44026bd9d0e69dd05a9a3cca7 | ChaconFrancoLuis/Ejemplos_en_clase | /bandit-env/test_Vuln1.py | 422 | 3.5625 | 4 | # Fill in this file with the code from parsing YAML exercise
import json
import yaml
with open('myfile.yaml','r') as yaml_file:
ouryaml = yaml.safe_load(yaml_file)
print(type(ouryaml))
print("The access token is {}".format(ouryaml['access_token']))
print("The token expires in {} seconds.".format(ouryaml['expires_... |
2f65ef0f529d998d0c895f372951d8d90dc6bf24 | riyajc/HackerRankProbs | /Warm-ups/Diagonaldifference.py | 769 | 3.609375 | 4 | n = int(input())
dig1 = 0
dig2 = 0
diff = 0
#initialize matrix
matrix = [] #matrix = [[]]? #matrix = [][]
print("Enter values:")
#input values in matrix
#A for loop for row
for j in range(n): # A for loop for col
a = []
for x in input().split():
a.append(int(x))
print(a)
matrix.append(a)
print... |
80127d22736b2a16f88f2b1517ce36467b50dc64 | riyajc/HackerRankProbs | /Warm-ups/A-very-Big-Sum.py | 780 | 3.828125 | 4 |
sum = 0
y = 0
n = int(input("Array length: ")) #input() stops the execution of the program and reads the line on the console as a string. Type casting int() will convert the input into an integer.
print(type(n))
x = input("Enter values: ").split() #split() function will split the input from the user console after spa... |
943952baf36d8ad45ce24555aa10e4b80abcf4ef | riyajc/HackerRankProbs | /Warm-ups/Time-Conversion-Part2.py | 2,088 | 4.53125 | 5 | #map(): function used to execute a specific function for each item of an iterable. Syntax - map(myfunc, iterables)."myfunc":- required, the function that executes for each item. "iterables":- A sequence/collecction or an iterator object. It returns a map object which is an iterator object. We can iterator through the m... |
5ae68b26e452a875929f6aebcc09cbebdae4bbb7 | BhavathariniAG/project-5 | /main.py | 621 | 4.03125 | 4 | def binary(number):
if number>=1:
binary(number//2)
print(number%2, end=" ")
def octal(number):
print("\n" ,oct(number))
def hexadecimal(number):
# hexadecimal(number / 16)
# x = (number % 16)
# if (x < 10):
# print(x)
# if (x == 10):
# print("A")
... |
511d11fdcdbe1b387258922b7c2b393f7c1c4477 | avinashingit/ctci | /IC/PermutationPalindrome/check_any_palindrome.py | 1,469 | 4.125 | 4 | '''
Write an efficient function that checks whether any permutation ↴ of an input
string is a palindrome.
You can assume the input string only contains lowercase letters.
Examples:
"civic" should return True
"ivicc" should return True
"civil" should return False
"livci" should return False
'''
import unittest
def... |
cbf3a27179f7a8e5166e48c2f914ddf7615c7581 | FuckBrains/automated-yt-channel | /main.py | 2,681 | 3.640625 | 4 | '''
1. Download clips
2. Compile video out of clips
3. Upload video to YouTube
4. Send tweet when video is published
'''
import sys
import os
import shutil
import datetime
import random
import string
import procedures.DownloadVideos as download_tiktok
import procedures.MakeCompilation as make_compilation
import procedu... |
8608633b74eb917d7c25f1e19b7d8692aa8fcaed | mrunaliniskulkarni100/Machine-and-Deep-Learning | /Code/Machine Learning/K-Nearest Neighbors/FromScratch/neighbors.py | 1,438 | 3.546875 | 4 | from Point import Point
from operator import itemgetter
import numpy as np # To use the random function, which will help in getting the Training and Testing List
import math # For Square and Square Root Functions
# Initialising Training Point List
training_points_list = []
temp = np.random.rand(100, 2)
for i in temp:... |
372e265edefd845e5e350c51bdfd39924bbdfb08 | vcskaushik1/ECEN662-Spring2018 | /Students/mason-rumuly/1Challenge/Selective_Bayes.py | 3,590 | 3.515625 | 4 | # Mason Rumuly
# Challenge 1
#
# Naive bayes detector incorporating automatic feature selection (naively remove misleading features)
import Naive_Bayes as nb
import numpy as np
class SelectiveBayes(nb.NaiveBayes):
# --------------------------------------------------------------------------------
... |
7acbe2f8197f51429dff2b88dae9ee3f9d63203c | sheky6398/FLAMES-GAME | /flames.py | 535 | 3.515625 | 4 | name1=list(input("Enter Your Name: ").lower())
name2=list(input("Enter Your Partner's Name: ").lower())
count=0
for i in name1[:]:
if i in name2:
name1.remove(i)
name2.remove(i)
count=len(name1)+len(name2)
flames=['Friends','Love','Affection','Marriage','Enemy','Siblings'... |
1edc27e3ef9054e9c3f007c077b4c65b323731c8 | TobiahRex/pythonLibrary | /pyScripts/arrays.py | 284 | 4.09375 | 4 | # slicing arrays
list1 = ['one', 'two', 'three', 'four', 'five', 'six'];
print('list = {}\n'.format(list1))
print('list[:5]: {}\n'.format(list1[:5]))
print('list[1::2]: {}\n'.format(list1[1::2]))
print('list1[:-5]: {}\n'.format(list1[:-5]))
print('list1[-1]: {}\n'.format(list1[-1]))
|
ca60115d6a106004a39e8db749cb2f6241e7066d | TobiahRex/pythonLibrary | /pyScripts/printSandbox.py | 508 | 4.03125 | 4 | name = 'TobiahRex'
score = 23
print("Total score for %s is %d" % (name, score))
# -------------------------- "tuple" ----------------------------------------
string1 = 'STRING 1'
string2 = 'STRING 2'
print("This is a sring: %s and another string: %s" % (string1, string2))
# -------------------- "new-style" string forma... |
0a874adbf5c5a3a6b056f1f78e72830f1e8ebfda | snguyenbui/minesweeper | /minesweeper.py | 4,098 | 3.5 | 4 | import tkinter as tk
from tkinter import *
import random
class Game(tk.Tk):
def __init__(self):
super().__init__()
menu = tk.Canvas(self, height=30)
game_area = tk.Canvas(self)
menu.pack(side=TOP)
game_area.pack()
self.rows = 10
self.columns = 10
self.list = []
s... |
4bbf21dbd751c595285a81f3b39879d811a75421 | zabulskyy/HashCodeTraining | /template/writer.py | 857 | 3.75 | 4 | from solution import Solution
class Writer:
def write(self, solution):
"""
:param solution: Solution to be written
@type solution: Solution
:return:
"""
raise Exception("Need to implement 'write' method")
class ConsoleWriter(Writer):
def write(self, solution)... |
2881b57971913e6ee259258d71ad7b484a31d4b1 | yevheniia-bd/Hillel_new_ | /Lesson_5/Task_5.py | 164 | 3.71875 | 4 | one_side = int(input('Enter side: '))
def square():
result = (4 * one_side, one_side * one_side,((one_side ** 2) / 2) ** 0.5)
return result
print(square())
|
b4c9d1024b57188c71a9b027c67a8b0cd4a8e5e1 | yevheniia-bd/Hillel_new_ | /Lesson_2/Task_2.py | 202 | 3.875 | 4 | q = int(input())
w = q + 1
e = q - 1
print('Please enter an integer number', ':', q)
print('The next number for the number', q, 'is', w, '.')
print('The previous number for the number', q, 'is', e, '.') |
ecd042ef3607a8c427577c961773afe900127aac | SEIAROTg/wheels | /minesweeper/strategies.py | 3,753 | 3.578125 | 4 | from collections import namedtuple
from itertools import chain, combinations
from functools import reduce
import operator
NeighborStats = namedtuple('NeighborStats', ['all', 'revealed', 'unrevealed', 'revealed_mine', 'remaining_mine_num'])
# https://docs.python.org/3/library/itertools.html
def powerset(iterable):
... |
3eb0fe3ea5b79d026e4bf0ea18f453448527bdf3 | kavyaparmar/Learning-Time | /alphabet.py | 162 | 3.703125 | 4 | s=['A','B','C','D','E','F','G','H']
n=int(input("Enter Alphabet Number= "))
for i in range(n):
for j in range(i):
print(s[i-1],end=' ')
print()
|
333b5fd7fda2aeb1c25337e0153b73e4631c1400 | utshav2008/python_training | /tree/all_path.py | 2,502 | 4 | 4 | from collections import deque
# Data structure to store a Binary Tree node
class Node:
def __init__(self, data, left=None, right=None):
self.data = data
self.left = left
self.right = right
# Function to check if given node is a leaf node or not
def isLeaf(node):
return node.left is No... |
32d1c782a1d055da9bc28fb1b0139496d0280d87 | utshav2008/python_training | /random/regex.py | 430 | 3.6875 | 4 | import re
nameage = """
Janica is 22 and Theon is 33
Gabrial is 44 and Joey is 21
"""
# ages = re.findall(r'\d{1,3}',nameage)
# name = re.findall(r'[A-Z][a-z]*',nameage)
#
# ageDict = {}
# x=0
#
# print(name)
# print(ages)
# # for eachname in name:
# # ageDict[eachname] = ages[x]
# # x+=1
# #
# # print(ageDic... |
8f61798486debc8de390c291deb9c1a71df75dd2 | menrot/DanaGraph | /Project_Graph_I_1.py | 2,648 | 3.609375 | 4 | #####################################
##
## Submission of Mini project
##
## Part I
##
#####################################
from Project_Graph_Classes import Node
########################################
# Question #1
# Build the list of nodes
########################################
def BuildNodes():
Nodes = [] #... |
73a4a6ac90eb5e5b5346bf3b6ae98c1548053ca5 | DanGrizzly/Computer-Simulation | /Polynomials/PolynomialsTest.py | 963 | 4.25 | 4 | from Polynomials import *
def main():
polynomialA = Polynomial([2,0,4,-1,6])
print("Pa(x) is equal to:")
polynomialA.printPolynomial()
polynomialB = Polynomial([-1,-3,0,4.5])
print("Pb(x) is equal to:")
polynomialB.printPolynomial()
orderOfPa = polynomialA.orderOf()
print("Order of Pa... |
eb0a8d3ef4ea1cca5fb4482a4a33c684b0a218af | raymanan11/TicTacToe | /ticTacToe.py | 4,833 | 3.796875 | 4 | # TicTacToe
def print_board(board):
for r in board:
for c in r:
if c == 0:
print(".", ' ', "|", ' ', end="")
elif c == 1:
print("X", ' ', "|", ' ', end="")
else:
print("O", ' ', "|", ' ', end="")
... |
aa058b472fa82e7551683bb7bb91810b76ea9088 | aliabbasrizvi/HackerRank | /warmup_challenges/counting_valleys.py | 516 | 3.578125 | 4 | #!/bin/python
import os
def countingValleys(n, s):
valley_count = 0
current_height = 0
for step in s:
if step == 'D':
current_height -= 1
if step == 'U':
current_height += 1
if current_height == 0:
valley_count += 1
return valley_count
if __name__ == '... |
fb6e4049561f928a10d4c4374f3976a5eba532cb | Maiorovaek/python | /Planeta_Torontus/Scenes.py | 2,387 | 3.78125 | 4 | from random import randint
class Scene(object):
def enter(self):
print("hi")
exit(1)
class CentralCoridor(Scene):
def enter(self):
print("action: piu, run, kidding")
action = raw_input("> ")
if action == "piu":
print ("you killed")
return "dea... |
559b7a443cf1253748db24371be46e662b6588ea | praveen7899/safeshop.ecommerce | /numbersprint.py | 80 | 3.53125 | 4 | #! /bin/usr
a=int(input("Enter any Number: "))
for i in range(a):
print(i)
|
531940dbf567faaf991ce1b0563c10bf1279c660 | aaroncymor/codefights | /solved/array_mode.py | 314 | 3.53125 | 4 | def arrayMode(sequence):
c,l,x,can = 0,0,list(set(sequence)),0
for i in range(len(x)):
for j in range(len(sequence)):
if x[i] == sequence[j]:
c += 1
if l < c:
l,c,can = c,0,x[i]
return can
print arrayMode([1,3,3,3,1,2,2,2,5,5,5,5,5,5]) |
da8136da96617c2e69a4ac79541de9f23801df91 | aaroncymor/codefights | /solved/can_update.py | 635 | 3.671875 | 4 | import re
def canUpdate(newUsername, curUsername, isChanged, users):
newUsername = newUsername.lower()
not_allowed = [c for c in re.split('[a-z0-9_]+',newUsername,flags=re.IGNORECASE) if c != '']
if not_allowed == []:
curUsername = curUsername.lower()
users = [user.lower() for user in users]
if newUsern... |
14b423bf91ff49ac70df0a604e06d883f30e2295 | aaroncymor/codefights | /solved/palindrome_or_not.py | 493 | 4.375 | 4 | """
Find out if the given string is a palindrome or not.
If s is a palindrome return "Yes", otherwise return "No".
Example:
PalindromeOrNot("aba") = "Yes"
PalindromeOrNot("abb") = "No"
[input] string s
A string of lowercase English letters, 0 ≤ s.length ≤ 300.
[output] string
... |
327ead1ccb98ba5cee456cc43c5516d0d1e74532 | aaroncymor/codefights | /solved/lightbulb.py | 700 | 3.609375 | 4 | def lightBulbs(lights, n):
temp_lights = [e for e in lights]
for i in range(n):
j = 0
while j < len(lights):
if lights[j] == 1:
#print j, (j + 1 < len(lights))
if j + 1 < len(lights):
if temp_lights[j + 1] == 1:
temp_lights[j + 1] = 0
else:
temp_lights[j + 1] = 1
e... |
e9fd2f16dcb5a80a2e571da9a97e3393d86a3c0b | aaroncymor/codefights | /solved/last_fib_digit.py | 1,313 | 4.25 | 4 | """
Fibonacci sequence is defined as follows:
F1 = 0, F2 = 1. For each i > 2: Fi = Fi - 1 + Fi - 2.
So the sequence starts with 0,1,1,2,3,5,8,13, ....
Your goal is to find the last digit of the nth number in this sequence, i.e. find F(n) mod 10.
Example
LastFibDigit(1) = F(1) mod 10 = 0 mod 10 = 0
... |
3c940a829a49c21340777654c642aa152a793903 | young10270/basic_Ruby_Python | /logical_operator/1.py | 179 | 3.8125 | 4 | in_str=input("ID를 입력해주세요 : ")
real_jsoul="JSoul"
real_julie="Julie"
if real_jsoul==in_str or real_julie==in_str:
print("Hello!")
else:
print("Who are you?")
|
f6cb65c50c2e9d6035ca69ad19e849e0956d8847 | young10270/basic_Ruby_Python | /logical_operator/3.py | 420 | 3.546875 | 4 | in_id=input("ID를 입력해주세요 : ")
in_pw=input("Password를 입력해주세요 : ")
real_id="JSoul"
real_pw="1111"
if real_id==in_id and real_pw==in_pw:
print("Hello!")
elif real_id==in_id and real_pw!=in_pw:
print("잘못된 Password입니다.")
elif real_id!=in_id and real_pw==in_pw:
print("잘못된 ID입니다.")
else:
print("ID와 Password를 확인... |
03e39b4101cdbb6d7bb893c99c950e8294ae482b | frank/keras_notes | /sequential_model.py | 3,939 | 4.34375 | 4 | '''
The sequential model is a linear stack of layers.
It's enough to initialize a sequential model and gradually add
the layers and activation functions to apply.
'''
from keras.models import Sequential
model = Sequential()
'''
- To specify the input shape, have that as an argument in the first
layer. In this ... |
800b5a898e1a25b27bfa00a5d776c7f2005eb039 | zonghui0228/rosalind-solutions | /code/rosalind_fibd.py | 1,093 | 3.78125 | 4 | # ^_^ coding:utf-8 ^_^
"""
Mortal Fibonacci Rabbits
url: http://rosalind.info/problems/fibd/
Given: Positive integers n≤100 and m≤20.
Return: The total number of pairs of rabbits that will remain after the n-th month if all rabbits live for m months.
"""
def num_rabbits(n, m):
# n is the n-th month.
# m is t... |
29bbb2f30863d7e8b78d4c8dd7c56cb8239e3225 | zonghui0228/rosalind-solutions | /code/rosalind_ts.py | 1,360 | 3.875 | 4 | # ^_^ coding:utf-8 ^_^
"""
Topological Sorting
url: http://rosalind.info/problems/ts/
Given: A simple directed acyclic graph with n≤103 vertices in the edge list format.
Return: A topological sorting (i.e., a permutation of vertices) of the graph.
"""
from collections import defaultdict
# the input
# ==============... |
1e7c8389b42c00be1e7d81a764fd67346584ca93 | zonghui0228/rosalind-solutions | /code/rosalind_bfs.py | 1,524 | 3.75 | 4 | # ^_^ coding:utf-8 ^_^
"""
Breadth-First Search
url: http://rosalind.info/problems/bfs
Given: A simple directed graph with n≤103 vertices in the edge list format.
Return: An array D[1..n] where D[i] is the length of a shortest path from the vertex 1 to the vertex i (D[1]=0). If i is not reachable from 1 set D[i] to −... |
7c5fb3e131e406d6c6da8e69c317b1c264e6dfb5 | zonghui0228/rosalind-solutions | /code/rosalind_fib.py | 626 | 3.734375 | 4 | # ^_^ coding:utf-8 ^_^
"""
Rabbits and Recurrence Relations
url:http://rosalind.info/problems/fib/
Given: Positive integers and .
Return: The total number of rabbit pairs that will be present after months, if we begin with 1 pair and in each generation, every pair of reproduction-age rabbits produces a litter of r... |
d79fc78e1344702927a03db92aaba83ac8820a49 | zonghui0228/rosalind-solutions | /code/rosalind_ini3.py | 654 | 3.6875 | 4 | # ^_^ coding:utf-8 ^_^
"""
Strings and Lists
url: http://rosalind.info/problems/ini3/
Given: A string s of length at most 200 letters and four integers a, b, c and d.
Return: The slice of this string from indices a through b and c through d (with space in between), inclusively. In other words, we should include eleme... |
4413742bebecd1c296d22cfd728809c964e4f616 | zonghui0228/rosalind-solutions | /code/rosalind_inv.py | 1,041 | 3.6875 | 4 | # ^_^ coding:utf-8 ^_^
"""
Counting Inversions
url: http://rosalind.info/problems/inv/
Given: A positive integer n≤105 and an array A[1..n] of integers from −105 to 105.
Return: The number of inversions in A.
"""
def MergeSortCountInversions(arr):
if len(arr) == 1:
return arr, 0
else:
a = arr... |
8e2de043f884645e7d7309b9d4731bc346b86671 | zonghui0228/rosalind-solutions | /code/rosalind_dna.py | 692 | 3.8125 | 4 | # ^_^ coding:utf-8 ^_^
"""
Counting DNA Nucleotides
url: http://rosalind.info/problems/dna/
Given: A DNA string of length at most 1000 nt
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in
"""
def count_DNA(string):
countA = strin... |
469ef7fcc3af29a5cf710d4a4444a82be09cdff7 | Panwan101/yrtt_entry_katas_python | /tasks/exercise002.py | 300 | 3.921875 | 4 | # The clock shows 'h' hours, 'm' minutes and 's' seconds after midnight.
# Your task is to make the 'past' function return the time converted to milliseconds.
# More examples in the test cases below.
def past(h, m, s):
total_millisecs=((h*3600000)+(m*60000)+(s*1000))
return(total_millisecs) |
8bc624829077da499c0e77c1a0ad2453c885843d | afizs/cashman | /app.py | 1,070 | 3.640625 | 4 | # cashman
# 1. date
# 2. Amount
# 3. Name
# 4. Type
from datetime import datetime
transactions = []
while(True):
print("1. Enter your transaction details")
print("2. Show All expenses")
print("3. Show All income")
print("4. Show the Balance")
print("5. Show all transactions")
print("6... |
be67812ea8201c0dfdab5435437e63f66d456956 | chaudharyachint08/SRGAN | /tests/vgg_demo.py | 5,493 | 3.734375 | 4 | '''
VGG original but kaffe link
http://www.robots.ox.ac.uk/~vgg/research/very_deep/
keras VGG usage link
https://machinelearningmastery.com/use-pre-trained-vgg-model-classify-objects-photographs/
The VGG() class takes a few arguments that may only interest you if you are looking
to use the model in your own... |
ced4099925f1c23d46b7cc62941839fa1400acfc | xiaohutuxiaohutu/excel | /read/python_gui.py | 1,900 | 3.5 | 4 | # import tkinter
# from Tkinter import *
import tkinter as tk
from tkinter.filedialog import *
from tkinter import filedialog
import os
application_window = tk.Tk()
file_types = [('excel文件', '.xls')]
file_types1 = [('excel文件', '.xls'), ('excel文件', '.xlsx')]
# f = askopenfilename(title='askopenfilename', initialdir="D:... |
1b46b1ea52cb5df4aa1055ccc5cdfbd4d9623d7a | esperanc/pyprocessing | /examples/handbook/3D_03.py | 1,644 | 3.734375 | 4 | from pyprocessing import *
# Draw a cylinder centered on the y-axis, going down from y=0 to y=height.
# The radius at the top can be different from the radius at the bottom,
# and the number of sides drawn is variable.
def setup() :
size(400, 400);
def draw():
background(0);
lights();
translate(width / 2, he... |
cc88876bd62606dd666d2db34d26e93943f3fb7e | pablomolteni/PY4E | /strings.py | 378 | 3.734375 | 4 | fruit = 'banana'
index=0
while index < len(fruit):
print (index,fruit[index])
index= index+1
print()
fruit2 = 'apple'
for i in fruit2:
print (i)
print ()
count = 0
for i in fruit2:
if i == 'p':
count = count + 1
print ('Cantidad de p en apple: ', count)
print()
print(frui... |
b77958b10eb8fa0065e4fc2926f8a4234321d82d | GEEGABYTE1/Connection | /graph.py | 1,258 | 3.59375 | 4 | from vertex import Vertex
class Graph:
def __init__(self, directed=False):
self.directed = directed
self.graph_dict = {}
def add_vertex(self, vertex):
print('Adding vertex {}'.format(vertex.value[0]))
self.graph_dict[vertex.value[0]] = vertex
def add_edge(self, from_vert... |
b037f39ea83d2fafca2087177c23727f607c492f | bushschool/IntroCS_IA | /RecursiveFunctions.py | 2,701 | 4.46875 | 4 | #https://trinket.io/python/85ef3ed403
def fib(n):
"""Function that returns the nth term of the Fibonnaci sequence. The Fibonnaci sequence
is found by adding the previous two terms.
"""
if n == 0:
return 0
if n == 1:
return 1
else:
return fib(n-1) + fib (n-2)
print ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.