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 |
|---|---|---|---|---|---|---|
be344fd136945a81eb038d99bbda7372fdba3c0b | anihakobyan98/group-2 | /Exceptions/task4.py | 274 | 4.5 | 4 | ''' Number that type is integer and it can be divided to 3 '''
try:
a = int(input("Enter a number: "))
except ValueError:
print("Entered value must be an integer type")
else:
if a % 3 != 0:
raise TypeError("Number must be divisible to 3")
else:
print("Excellent")
|
41762862f7f114e576333d07f53dd9aadcf40181 | anihakobyan98/group-2 | /HomeworksPython/Homework1.py | 112 | 3.78125 | 4 | list = [(x,y,z) for x in range(1,30) for y in range(x,30) for z in range(y,30) if z*z == x*x + y*y]
print(list)
|
e199b19193ccc76c588a096c853ef57026ad496c | tsandeep86/pythonDevOpsassignments | /7thWeek/banking_app/delete_account_bnk.py | 623 | 3.53125 | 4 | import current_balance_bnk
import display_accounts_bnk
def delete_account(db):
cursor=db.cursor()
acctno=input("Eneter account number to be deleted:\n")
bal=current_balance_bnk.current_balance(db,acctno)
if (bal) > 0 :
print "account has balance and cannot be deleted. Please withdraw amount and ... |
75e4dd79b3f9cdb7d06a8c3cc71df1d53c73d350 | fourmigh/PythonDemos | /fileutils.py | 1,084 | 3.828125 | 4 | import os
import zipfile
def delete_file_or_folder(root_path):
if os.path.isdir(root_path):
dir_or_files = os.listdir(root_path)
for dir_file in dir_or_files:
#获取目录或者文件的路径
dir_file_path = os.path.join(root_path,dir_file)
delete_file_or_folder(dir_file_path)
... |
32920b373fcef611df5215708f846022157770e2 | rtmiura/Projeto_1_Lets_Code | /robo_burro.py | 3,810 | 3.796875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Sep 30 18:28:21 2021
@author: rodrigo
"""
class Jogador(object):
def __init__(self,nome):
self.name=nome
self.vitorias=0
self.derrotas=0
self.n_tentativas_para_vencer=0
def tenta_nova_letra(self):
return input(f'{self... |
be4cac7e0ae69eb564eb4bceb21fc6cf7459076a | IDLabResearch/lovstats | /src/utils/ListCreator.py | 1,606 | 3.546875 | 4 | import util_functions
class ListCreator():
"""
This class creates a list from rdf:first, rdf:rest linked lists.
"""
def __init__(self, predicate):
self.listPredicate = predicate
self.roots = {}
self.list_values = {}
self.list_nodes = {}
self.list_roots = []
... |
b1119e6cb30d4b4a20dcc6a0f7065150fc080b32 | ayushthesmarty/Simple-python-car-game | /main.py | 1,336 | 4.25 | 4 | help_ = """
The are the commands of the game
help - show the commands
start - start the car
stop - stop the car
exit - exit the game
"""
print(help_)
running = True
car_run = False
while running:
command = input("Your command: ").lower()
if command == "help":
print(help_)
eli... |
eeec10b8bca8f47d2d92c45f3cc34398887161bb | AydenMcCann/SHPC4001 | /wk2/1.3.py | 1,136 | 3.71875 | 4 | import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
def bisect_root(f, lower, upper, eps, max_iter=100):
"""Find zero of a function in an interval to a given precision using the bis
ection method.
Arguments:
f: function, assumed continuous over interval [lower, upper]
... |
c2f6b85004f7add3a1c3660af1eed14e779b6b1b | chanzer/leetcode | /594_findLHS.py | 1,007 | 3.984375 | 4 | """
Longest Harmonious Subsequence
题目描述:
We define a harmonious array is an array where the
difference between its maximum value and its minimum value
is exactly 1.
Now, given an integer array, you need to find the
length of its longest harmonious subsequence among all its
possible subsequences.
Example 1:
Input:... |
21f4398c1e1213508a156c50b271bfe685716c76 | chanzer/leetcode | /printListFromTailToHead.py | 301 | 3.6875 | 4 | """
倒序输出链表
题目描述:
输入一个链表,按链表值从尾到头的顺序返回一个ArrayList.
"""
class Solution:
def printListFromTailToHead(self,listNode):
if listNode == listNode:
return []
else:
return self.printListFromTailToHead(listNode.next)+[listNode.val]
|
21ea14d3662fa02d145eeaf4974ebcfa3bfe8869 | chanzer/leetcode | /598_maxCount.py | 1,181 | 4.09375 | 4 | """
Range Addition II
题目描述:
Given an m * n matrix M initialized with all 0's and
several update operations.
Operations are represented by a 2D array, and each
operation is represented by an array with two positive
integers a and b, which means M[i][j] should be added by one
for all 0 <= i < a and 0 <= j < b.
You nee... |
d5432452130d4c4f8ff32b72596da7fb1a2947e4 | chanzer/leetcode | /204_countPrimes.py | 642 | 4.0625 | 4 | """
Count Primes质数/素数
题目描述:
Count the number of prime numbers less than a
non-negative number, n.
Example :
Input: 10
Output: 4
Explanation:There are 4 prime numbers less than 10,
they are 2, 3, 5, 7.
"""
class Solution:
def countPrimes(self, n):
"""
:type n :int
:rtype :int
"""
... |
f73aa0afd7c19dd8ab7caebe533540893b1be310 | chanzer/leetcode | /IsContinuous.py | 1,966 | 3.765625 | 4 | """
扑克牌顺子
题目描述:
LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,
2个小王(一副牌原本是54张^_^)...
他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,
如果抽到的话,他决定去买体育彩票,嘿嘿!!
“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....
LL不高兴了,他想了想,决定大小王可以看成任何数字,
并且A看作1,J为11,Q为12,K为13。
上面的5张牌就可以变成“1,2,3,4,5”(大小王分别看作2和4),
“So Lucky!”。LL决定去买体育彩票啦。
现在,要求你使用这幅牌模拟上面的过程,... |
1ff020d024ad2dd9d2e238125f6ec7402acac880 | chanzer/leetcode | /575_distributeCandies.py | 1,205 | 4.625 | 5 | """
Distribute Candies
题目描述:
Given an integer array with even length, where
different numbers in this array represent different kinds of
candies. Each number means one candy of the corresponding
kind. You need to distribute these candies equally in number
to brother and sister. Return the maximum number of kinds of
c... |
eb18fcfd1c007e23ff70af17426d8a9cafca29d0 | chanzer/leetcode | /MoreThanHalfNum_Solution.py | 757 | 3.859375 | 4 | """
数组中出现次数超过一半的数字
题目描述:
数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入
一个长度为9的数组{1,2,3,2,2,2,5,4,2}。由于数字2在数组中出现了5次,因
此输出2.如果不存在则输出0.
思路:
统计序列中元素的出现频度:
https://blog.csdn.net/u013679490/article/details/54425694
"""
import collections
class Solution:
def MoreThanHalfNum_Solution(self,numbers):
#collections.Counter(list)... |
b9a5eeead0b54b1a3fd6236c279b021e1e896983 | chanzer/leetcode | /Sum_Solution.py | 238 | 3.59375 | 4 | """
求1+2+3+4+...+n
题目描述:
求1+2+3+4+...+n,要求不能使用乘除法for while if else switch
case等关键字及条件判断语句(A?B:C)
"""
class Solution:
def Sum_Solution(self,n):
return sum(list(range(1,n+1)))
|
628c1178a554eef20522ee89c523a4aa3a5c35b2 | chanzer/leetcode | /717_isoneBitCharacter.py | 1,868 | 4 | 4 | """
1-bit and 2-bit Characters
题目描述:
We have two special characters. The first character can
e represented by one bit 0. The second character can be
represented by two bits (10 or 11).
Now given a string represented by several bits. Return
whether the last character must be a one-bit character or not.
The given stri... |
714d5070e3e668091fa1f1cd451ea020055320c4 | chanzer/leetcode | /724_pivotIndex.py | 1,239 | 4.03125 | 4 | """
Find Pivot Index
题目描述:
Given an array of integers nums, write a method that
returns the "pivot" index of this array.
We define the pivot index as the index where the sum of
the numbers to the left of the index is equal to the sum of
the numbers to the right of the index.
If no such index exists, we should retur... |
25b3275a82d546d5f17f9232ec4c363e2e85c402 | chanzer/leetcode | /867_transpose.py | 862 | 4.21875 | 4 | """
Transpose Matrix
题目描述:
Given a matrix A, return the transpose of A.
The transpose of a matrix is the matrix flipped over
it's main diagonal, switching the row and column indices of
the matrix.
Example 1:
Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [[1,4,7],[2,5,8],[3,6,9]]
Example 2:
Input: [[1,2,3],[4,5,6]]... |
72d2a01a0b5795b6e4daa2ac4e075453b539d2c2 | chanzer/leetcode | /EntryNodeOfLoop.py | 402 | 3.765625 | 4 | """
链表中环的入口节点
题目描述:
给一个链表,若其中包含环,请找出该链表的环的入口节点
否则输出null
思路:
遍历链表,环的存在,遍历遇见的第一个重复的即为入口节点
"""
class Solution:
def EntryNodeOfLoop(self,pHead):
res = []
p = pHead
while p:
if p in res:
return p
else:
res.append(p)
p = p.next
|
b49746d6003eee709761d8c886f021b7c68cdbdf | chanzer/leetcode | /720_longestWord.py | 1,411 | 4.0625 | 4 | """
Longest Word in Dictionary
题目描述:
Given a list of strings words representing an English
Dictionary, find the longest word in words that can be built
one character at a time by other words in words. If there is
more than one possible answer, return the longest word with
the smallest lexicographical order.
If ther... |
6d801ce1b4951d9b4b7fa1c7e39aa2d1dd69a1b4 | chanzer/leetcode | /697_findShortestSubArray.py | 1,269 | 4.21875 | 4 | """
Degree of an Array
题目描述:
Given a non-empty array of non-negative integers
nums, the degree of this array is defined as the maximum
frequency of any one of its elements.
Your task is to find the smallest possible length of a
(contiguous) subarray of nums, that has the same degree
as nums.
Example 1:
Input: [1, ... |
7e751241809fce287ebbf3bb588f5a5d81e9ba7a | chanzer/leetcode | /StrToInt.py | 817 | 3.71875 | 4 | """
把字符串转换成整数
题目描述:
将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,
但是string不符合数字要求时返回0),要求不能使用字符串转换整数的
库函数。 数值为0或者字符串不是一个合法的数值则返回0。
输入描述:
输入一个字符串,包括数字字母符号,可以为空
输出描述:
如果是合法的数值表达则返回该数字,否则返回0
示例:
输入: +123456789
1a22
输出:123456789
0
"""
class Solution:
def StrToInt(self,s):
#先排除异常特殊情况
if s in ['','-','+',... |
2ef0911b850180f0c8819d14215f0a9a96fadccd | chanzer/leetcode | /290_wordPattern.py | 948 | 4.0625 | 4 | """
Word Pattern
题目描述:
Given a pattern and a string str, find if str follows
the same pattern.
Here follow means a full match, such that there is a
bijection between a letter in pattern and a non-empty word
in str.
Example 1:
Input: pattern = "abba", str = "dog cat cat dog"
Output: true
Example 2:
Input: pat... |
b39a6c8a32cc17f3eed3abd4f36cdcaf5ca1f3bc | chanzer/leetcode | /202_isHappy.py | 977 | 3.859375 | 4 | """
Happy Number
题目描述:
Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following
process: Starting with any positive integer, replace the number
by the sum of the squares of its digits, and repeat the process
until the number equals 1 (where it will stay), or it loo... |
4eef3b2411dd7eaa18cd6ceb5224098379d4672c | chanzer/leetcode | /628_maximumProduct.py | 669 | 4.5 | 4 | """
Maximum Product of Three Numbers
题目描述:
Given an integer array, find three numbers whose
product is maximum and output the maximum product.
Example 1:
Input: [1,2,3]
Output:6
Example 2:
Input: [1,2,3,4]
Output:24
Note:
1.The length of the given array will be in range
[3,104] and all elements are in the range... |
3d25b8ce4186125d87dc7d6ce54e506c5c05bb2d | chanzer/leetcode | /Permutation.py | 618 | 3.84375 | 4 | """
字符串的排列
题目描述:
输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串
abd,则打印出由字符a,b,c所能排列出来的所有字符串
abc,acb,bac,bca,cab和cba.
思路:
"""
import itertools
class Solution:
def Permutation(self,ss):
result = []
if not ss:
result []
else:
#itertools.permutation() 返回对象全排列的iterators(迭代器)
# 使用时用list()转换即可
res = it... |
0f8c88f4a60a4c9f26553c9903e7d6d111ca8ed1 | chanzer/leetcode | /453_minMoves.py | 842 | 4.15625 | 4 | """
Minimum Moves to Equal Array Elements
题目描述:
Given a non-empty integer array of size n, find the
minimum number of moves required to make all array elements
equal, where a move is incrementing n - 1 elements by 1.
Example:
Input:[1,2,3]
Output:3
Explanation:Only three moves are needed (remember each
move increm... |
f6d33216069d7064328b03192b4de24cd05d43ac | MonkeyMushroom/python_exercise | /alien_invasion/ship.py | 1,393 | 3.578125 | 4 | # coding=utf-8
import pygame
class Ship:
def __init__(self, screen):
"""初始化飞船并设置其初始位置"""
self.screen = screen
self.screen_rect = screen.get_rect()
# 加载飞船图像并获取其外接矩形
self.image = pygame.image.load('drawable/ship.png')
self.rect = self.image.get_rect()
# 将每艘新... |
6947cc6a019c3b232b432788a8ce9ed5729e8551 | MichelGeorgesNajarian/randomscripts | /Python/recursive_rename.py | 907 | 4.28125 | 4 | # Python3 code to rename multiple
# files in a directory or folder
#give root directory as argument when executing program and all the file in root directory and subsequent folders will be renamed
#renaming parameter are to remove any '[xyz123]', '(xyz123)' and to replace '_' by ' '
# importing os module
import os... |
a21e99eb59909a3f8d5d09597b82cd34654b8ed2 | AshleyAlpha/news | /app/article_test.py | 752 | 3.671875 | 4 | import unittest
from models import article
Article = article.Article
class ArticleTest(unittest.TestCase):
'''
Test Class to test the behaviour of the Article class
'''
def setUp(self):
'''
Set up method that will run before every Test
'''
self.new_article = Article('S... |
bec8f8c2361f8f6f90428f2cfabc53a2ce0a1650 | JeremyLykken/app | /Section_7/utils/database.py | 1,617 | 4.03125 | 4 | """
Concerned with Storing and Retrieving Books from a sqlite file.
"""
import sqlite3
# Methods
def create_book_table():
connection = sqlite3.connect('data.db')
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS books(name TEXT PRIMARY KEY, author TEXT, read BOOLEAN)')
connec... |
0481530f54e91fb1de4c0312ce3495b12692f946 | GORosin/wine_data_practice | /wine_analysis.py | 3,328 | 4.09375 | 4 | #first three crucial libraries
import pandas as pd #basically excel for python, allows you to build tables to work with
import numpy as np #python's fast linear algebra library, a lot of useful functions for vector and matrix math
import matplotlib.pyplot as plt #for plotting
from scipy.optimize import curve_fit #to... |
91c82be23a3d1efe3624ec86f6fedf46958136ba | KIRANKUMAR-ENUGANTI/python_basics | /py_basics/dff == and is.py | 711 | 3.734375 | 4 | x=[]
y=[]
z=x
if x==y:
print(x,"==",y)
print("equal checks ths values so,x==y")
if x is not y:
print('id(x): ',id(x),"!= id(y): ",id(y))
print("is doesnot check the vlues but the id's so, x is not y")
if x is z:
print(id(x),"==",id(z))
print("is checks the id's so, x is z")
if (x==z ... |
34c3c8a51dcde891fd6d3ae87638480e2f58ef7a | mr-preacher/interview | /check_trees_equal.py | 2,177 | 4.03125 | 4 | # Python implementation to check if
# given 2 binary tries are equal
# recursive and iterative solutions
# A binary tree node containing data
# field, left and right pointers
class Node:
# constructor to create new node
def __init__(self, val):
self.data = val
self.left = None
self.ri... |
38a8742704a03b026748b9ffedb0f9ad4b903197 | ashrafm97/python_projects | /factory_functions_testing.py | 2,024 | 4.0625 | 4 | # define the tests before we code the functions
from factory_functions_actual import *
# make_dough()
## test 1 - make_dough()
print("When make_dough is called with 'water' and 'flour', return 'dough'")
print(make_dough('water','flour')=='dough')
print('got:', make_dough('water','flour'))
## test 2 - make_dough()
pri... |
7039fe41b55990eb3b9e2da505e6b91e17a3623a | gautam-kumar-22/tail-command-implementation | /tail_command_implementation.py | 836 | 3.578125 | 4 | """
Tail command implementation Python
Usage:
tail.py filename linenumbers
"""
import sys
class TailImplementation(object):
"""docstring for TailImplementation"""
def __init__(self, *args, **kwargs):
super(TailImplementation, self).__init__()
self.filename = args[0]
self.linenumbers = -int(args[1])
print(a... |
45bc14da5444edec571f5ab40959bce0739e4996 | digitalvectorz/ccarps-python | /ccarps/dice.py | 1,575 | 3.59375 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
from random import randint
class Dice(object):
def __init__(self):
self.roll()
def roll(self, type=6, qty=1, sets=1, rerollone=0):
'''
Rolls qty of type of dice in sets.
Returns: List of dice set(s).
'''
counts = []
for s in range(sets):
... |
8aa44d4ce458ac55419d09b6091611020b8208d5 | Claudiocfls/ITA-projects | /CES-22/1obimestre/3.11.py | 265 | 3.6875 | 4 | import turtle
wn = turtle.Screen()
wn.title("Exercicio 3.11")
wn.bgcolor("white")
alex = turtle.Turtle()
alex.shape("turtle")
alex.color("black")
# desenha a estrela
alex.speed(1)
alex.left(36)
for i in range(5):
alex.forward(200)
alex.left(144)
wn.mainloop()
|
8f633dcdb5c7f6a3a26ca3ed33cf026c30603f1a | Claudiocfls/ITA-projects | /CES-22/1obimestre/3.6.py | 1,027 | 3.90625 | 4 | import turtle
wn = turtle.Screen()
wn.title("Exercicio 3.6")
wn.bgcolor("white")
alex = turtle.Turtle()
alex.shape("turtle")
alex.color("blue")
# move alex para o lado esquerdo da tela
alex.penup()
alex.backward(300)
alex.pendown()
# desenha o triangulo equilatero
alex.begin_fill()
alex.color("red")
for i... |
9db62dba818e2eefcd3622c9b2453cecf8973b53 | BennyFranco/Bioinformatics-Algorithms | /ReverseComplement.py | 466 | 3.578125 | 4 | __author__ = 'Benny'
import sys
def reverse_complement(pattern):
complement = []
for acid in pattern:
if acid == 'A':
acid = 'T'
elif acid == 'T':
acid = 'A'
elif acid == 'G':
acid = 'C'
else:
acid = 'G'
complement.append... |
51968531399850c45c4443da54ca593345794cd3 | jlarge11/cracking_coding_interview | /arraysAndStrings/permutation.py | 745 | 3.53125 | 4 | # O(1) if the string lengths are different, and O(N) if the string lengths are the same.
def permutations(s1, s2):
if len(s1) != len(s2):
return False
char_counts = {}
for c in s1:
if c in char_counts:
char_counts[c] = char_counts[c] + 1
else:
char_counts[c]... |
b6e63aff86ee5cd0c90700f81ba4b1fd612a9a93 | jlarge11/cracking_coding_interview | /linkedList/palindrome.py | 674 | 3.5625 | 4 | # Input: (7 -> 1 -> 6) + (5 -> 9 -> 2). That is, 617 + 295
# Output: 2 -> 1 -> 9. That is, 912
from core.collections import LinkedList
def is_palindrome(l):
array = []
current = l.head
while current:
array.append(current.val)
current = current.next
length = len(array)
for i,... |
d3a5ebf2b51dc8a8874c7c5c7fc8b4c4e6fedef8 | xhamyd/python-lessons | /lesson 5.py | 233 | 3.5 | 4 | class Animal:
def __init__(self, species):
self.species = species
def speak(self):
return "Firefooooooooox!"
fox = Animal("fox")
print("Enter multi-shine Melee bastard: " + fox.species)
print(fox.speak())
|
e82f6901e3439a87211a99c0534ae4a5fbf41adf | teolemay/PHY407_Labs | /lab 1/lab01_Q3.py | 2,786 | 3.75 | 4 | ''' This code contains 1) The custom histogram function created
2) A for loop to test each sample size across the two functions
(as well as another for loop to average out these values over multiple tests)
***NOTE: plt.show() is currently commented out for both histograms so they don't
appear every loop. They... |
b7400d07f759078362ab97da1b7907d486795352 | teolemay/PHY407_Labs | /lab 1/lab01_Q2.py | 2,506 | 4.03125 | 4 | """
PHY 407 lab 1: question 2 A)
Teophile Lemay and Charlie Hughes
This script calculates the orbit of the Jupiter around the sun, as well as the earth's orbit while taking
into account the gravitational effect of Jupiter on the earth.
Purely Newtonian orbit are assumed.
For parts B and C of question 2, co... |
e7a5be11574def59dfb49210f433ea65102cfa90 | Tiltedprogrammer/HwProj1 | /3.py | 71 | 3.609375 | 4 | a = int(input())
b = int(input())
a += b
b = a -b
a = a - b
print(a,b)
|
b2a63e60d8d90023d1db42a551839c4d511aabbe | Sikhu-Ntaka/SikhuNtaka-Portfolio | /simple_game/game project.py | 7,420 | 4.15625 | 4 | # This is a game with a single player and three enemy objects, the goal of the
# game is to avoid collision with enemy objects, in additon there is a prize
# object, if player collides with prize object, player wins, if player collides
# with enemy object, player loses game
import pygame as py # Import game libra... |
602a528245df3919795ab17a9622fdcef29bca69 | carlocostacc/numerical_methods | /forwarderror.py | 909 | 3.578125 | 4 | import numpy as np
def forward_error(a, ans,Xr, cols, rows):
# enter the number of cols and rows of the main matrix
# the array a is for the matrix of coefficient
# enter the awnsers
r = np.linalg.solve(a, ans)
print("\nthe r matrix is \n", r)
print("\nthe Xr matrix is \n\n", Xr)
fina... |
2bfa29f73a3bd92d34a316489fd0c8d9b16e8e89 | karthikgvsk/project-euler | /p34.py | 860 | 4.03125 | 4 | # Digit factorials
# upper bound is important
from math import log
def getDigits(num):
l = []
while num > 10:
l.append(num % 10)
num = num // 10
if num == 10:
l.append(1)
l.append(0)
else:
l.append(num)
return l
# producing the factorial list
factList = [1]
i = 1
prod = 1
while i <= 9:
prod = prod * i... |
2eb1f4e9e362b620d78a24fffd59030899e70a7b | karthikgvsk/project-euler | /p36.py | 1,345 | 3.859375 | 4 | # Problem 36
# Double Base Palindromes
# BRUTE FORCE!
# we can generate palindromes in a base and check in another
def getDigits(n):
l = []
while n > 10:
l.append(n % 10)
n = n // 10
if n == 10:
l.append(0)
l.append(1)
else:
l.append(n)
l.reverse()
return l
def getBinDigits(n):
l = []
while n >... |
3aa27de67e528cae3d18c9a2952aaab298902574 | coopcat/sci-steps | /problems.py | 13,497 | 3.65625 | 4 | import math
import sympy as sp
from sympy.parsing.sympy_parser import *
from vectors import Vectors
class Problem(object):
'''Problems consist of steps for solving equations.'''
def __init__(self, equations, known_vars, vars_order):
self.equations = equations
self.known_vars = known_vars
... |
23d3a81166787259a93899dc21ac2ddb5775bae3 | liqihao2000/PSNM | /PythonPrograms/Programs/PythonCode/ODEsplitting.py | 826 | 3.546875 | 4 | """
A program to solve u_t'=u(u-1) using a splitting
method
"""
import time
import numpy
import matplotlib.pyplot as plt
Nt = 1000 # Number of timesteps
tmax = 1.0 # Maximum time
dt=tmax/Nt # increment between times
u0 = 0.8 # Initial value
t0 = 0 # Starting time
u = [u0] # Variables holding the val... |
e6b185ccc6ba8c7a74eb728d66448f651059522a | hipstertherapy/python-everything | /chatbotPython/TheChatBot.py | 1,463 | 3.984375 | 4 | file = open("stop-words.txt")
stopwords = file.readlines()
def testStop(sentence):
for word in stopwords:
next = word.strip()
sentence = sentence.replace(" " + next + " ", " ")
return sentence
#loop in the whole chat
while True:
input = raw_input( " Whats your name ?")
input = " " + in... |
659cc4e0751a11f4beca5b3275f121c7282c957e | wkrea/machine-learning-microservice-template | /source/data/data_loader.py | 949 | 3.71875 | 4 | # Template Imports
# Custom Imports
### Example:
from sklearn.datasets import load_iris
import pandas as pd
### End Example
class DataLoader():
'''
This Class is meant to be the interface between data engineer and data scientist.
Ideally, this is the only 'Data' Class needed by the Data Scientist.
'''... |
555772a81cf09a00c1e63d05b56999c8b2039f76 | ThomasZumsteg/adventofcode2016 | /day15.py | 806 | 3.5625 | 4 | #!/usr/bin/env python3
from get_input import get_input, line_parser
from itertools import count
import re
def part1(disks):
for time in count(0):
for disk, holes, start in disks:
if (time + disk + start) % holes != 0:
break
else:
return time
def test_part1(... |
b025bc8133eb92296791764dff85ffd08f92cbe1 | thomasballinger/tic-tac-toe-AI | /terminal.py | 3,485 | 3.765625 | 4 | blank_board = [
['_','_','_'],
['_','_','_'],
[' ',' ',' ']
]
other_board = [
['O','X','O'],
['X','O','O'],
['X','O','X']
]
class Board:
def __init__(self, grid = None):
if grid is None:
self.grid = [... |
8169058674ad625f20b50afd3966da182f2a6148 | radhikad60/Project01 | /Fun.py | 165 | 4.0625 | 4 | def add_sum(num1,num2):
return num1+num2
first=int(input("enter first number"))
second=int(input("enter second number"))
total=add_sum(first,second)
print(total) |
d4ff584c0828793ce1501088128f7e6a23960b88 | radhikad60/Project01 | /ForLoops.py | 179 | 3.765625 | 4 | # #name=["radhika","sabhrant","aditi","goli"]
# for x in "bnanana":
# print(x)
n=int(input("please enter any number"))
total=0
for i in range(1,n+1):
total+=i
print(total) |
f485ab1add50459d134059051fb5174fecbe120e | radhikad60/Project01 | /Aug01_2.py | 144 | 3.8125 | 4 | name="radhika"
age=23
#print("hello{name} your age is{age}")
#print("%s is %d years old." % (name, age))
print(f"hello{name} your age is {age}") |
e0a3b521672b25856538ca1bcc43e91414f4b658 | wrgsRay/playground | /Comma Code.py | 198 | 3.609375 | 4 | spam = ['apples', 'bananas', 'tofu', 'cats', 'aaaaa', True]
for i in range(len(spam)):
if i < len(spam) - 1:
print(str(spam[i]), end=", ")
else:
print("and " + str(spam[i]))
|
0d1564abb38b41d58ce025ee1353e90e62d084be | wrgsRay/playground | /amz_label.py | 2,181 | 4.21875 | 4 | """
Python 3.6
@Author: wrgsRay
"""
import time
class Shipment:
def __init__(self, last_page, total_pallet, pallet_list=[], current_pallet):
self.last_page = last_page
self.total_pallet = total_pallet
self.pallet_list = pallet_list
self.current_pallet = current_pallet
def get_... |
395259e933a15acf66b720349d3abd89f8971e69 | wrgsRay/playground | /PP11-Check Primality Functions.py | 652 | 4.03125 | 4 | if __name__ == '__main__':
def getnumber():
num = input('Give me a number to check if it is a prime number')
while True:
try:
num = int(num)
break
except ValueError:
num = input('That was not a number')
return num
d... |
6a785580948dded809262b2e12ae73ceeeeeab4f | wrgsRay/playground | /PP16-Password Generator.py | 779 | 4.0625 | 4 | from random import choice
import string
if __name__ == '__main__':
def makepass(digit):
passwordpool = string.ascii_letters + '!#$%*+_-@1234567890'
passlist = list()
while len(passlist) < digit:
passlist.append(choice(passwordpool))
newpass = ''.join(passlist)
re... |
90e0f3eca7bb4fab9b578f2db194789f1780d835 | stillxborn/Python_Beetroot | /Exercise 10: Arithmetic.py | 315 | 3.984375 | 4 |
from math import log10
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
print(a, "+", b, "is", a + b)
print(a, "-", b, "is", a - b)
print(a, "*", b, "is", a * b)
print(a, "/", b, "is", a / b)
print(a, "%", b, "is", a % b)
print("The base 10 logarithm of", a, "is", log10(a))
|
1a2132a57f31786ae27f189e4091d04893ecb581 | hoguea08/TempRead | /matrix_multiplication.py | 6,344 | 4.5625 | 5 | #! /usr/bin/env python3
'''
This program contains a matrix multiplication algorithm,
and initializes three matrices: XT, X, and Y.
It multiples XT * X and XT * Y and prints the resulting
matrices.
'''
from typing import List
def create_matrix(num_rows, num_cols):
"""
Creates the X matrix
:param num_rows... |
51878fe5b6f34ca06bd15a562ee59784577d3b29 | Amibyte/Class-Assignment-1---Getting-Started-with-Python-Programming | /question no3.py | 136 | 4 | 4 | import math
num = float(input("enter a no"))
ans = math.sqrt(num)
print("Square root of {} is {}".format(num, ans))
|
5851157c89ebf3b04ccce247750572119b486b52 | jamesaucode/ign-frontend | /answers/question3.py | 3,723 | 3.515625 | 4 | import re
from tabula import read_pdf
""" My thought process of solving this problem.
First, we have to lay out the limitations.
1. We have 300 Crowns
2. We each type of armor, and also an extra piece.
The intuition is that we have to optain the lowest price
of each piece of armor, then spend the r... |
a8e11b39c935ee089f0c50b596633efaa55f0760 | nolanporetz/BeginnerProjects | /Armstrong.py | 5,067 | 4.28125 | 4 | opening = """
Welcome to the Armstrong Number Test!\n\n
An Armstrong Number is an integer that is equal to the sum\n
of its own digits raised to the power of the number of digits.\n\n
We can represent this with the 3 digit number 'xyz' \n
raised to the power of n (which equals 3 since xyz is 3 digits):\n
x^3 + y^3 + z^... |
441cb7dd89e50bf45376641ca60c4e083f685489 | vishnuvasan/Jenkins | /list_jobs.py | 865 | 3.578125 | 4 | ##########################################################################
# LIST_JOBS.py
#
# Function Desc : To List all the Jobs in Jenkins
#
# No of Arguments : 0
#
# Arguments : Nil
#
# Exception Handler :
#
# Usage : Open Command Window and type the commands as below
#
# list_jobs.py
#
# Author : S... |
38927abc81fc417c0a9c69e060e6bcfc0d154506 | SaraKenig/codewars-solutions | /python/7kyu/Numbers in strings.py | 403 | 4 | 4 | # In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros.
# For example, solve("gh12cdy695m1") = 695, because this is the largest of all number groupings.
# Good luck!
import re
d... |
d603602255347b138dfb7b6685222b2b03501986 | SaraKenig/codewars-solutions | /python/7kyu/Unique string characters.py | 598 | 4.34375 | 4 | # In this Kata, you will be given two strings a and b and your task will be to return the characters that are not common in the two strings.
# For example:
# solve("xyab","xzca") = "ybzc"
# --The first string has 'yb' which is not in the second string.
# --The second string has 'zc' which is not in the first string.
... |
b7c8bcb1a7f1425a382ef1851a8e0920e71f0236 | SaraKenig/codewars-solutions | /python/4kyu/Next bigger number with the same digits.py | 1,138 | 3.796875 | 4 | # Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example:
# 12 ==> 21
# 513 ==> 531
# 2017 ==> 2071
# If the digits can't be rearranged to form a bigger number, return -1 (or nil in Swift):
# 9 ==> -1
# 111 ==> -1
# 531 ==> -1
# d... |
acbf417955c0e14618b09ab10a0952fc6e63d79a | SaraKenig/codewars-solutions | /python/7kyu/sort array by last character.py | 539 | 4.34375 | 4 | # Sort array by last character
# Write a function sortMe or sort_me to sort a given array or list by last character of elements.
# Element can be an integer or a string.
# Example:
# sortMe(['acvd','bcc']) => ['bcc','acvd']
# The last characters of the strings are d and c. As c comes before d, sorting by last chara... |
a1f2ffcaa69a250215e8f59fc82a6e604dbb84a4 | SaraKenig/codewars-solutions | /python/6kyu/Filling an array (part 2).py | 1,217 | 3.90625 | 4 | # Following on from Part 1, part 2 looks at some more complicated array contents.
# So let's try filling an array with...
# ...square numbers
# The numbers from 1 to n*n
# const squares = n => ???
# squares(5) // [1, 4, 9, 16, 25]
# ...a range of numbers
# A range of numbers starting from start and increasing by s... |
6b1b89b02e52dcaa6555a1a1310535bb44f00184 | KimtVak8143/PyLearn | /mcqquiz.py | 623 | 3.78125 | 4 | # MCQ Quiz
from mcqqn import Question
question_prompts = [
"What color are woods ?\n(a)Red\n(b)Brown\n(c)White\n\n",
"What color are Guava ?\n(a)Red\n(b)Green\n(c)White\n\n",
"What color are Oranges ?\n(a)Red\n(b)Brown\n(c)Orange\n\n",
]
questions = [
Question(question_prompts[0], "b"),
Question(... |
30cbc4922edef51a664c5a312f15aa1813089d66 | KarimIO/ASIC-Hierarchical-Router | /Python Archives/grid.py | 6,671 | 3.6875 | 4 | import sys
from Queue import *
class Grid:
"""Grid Class"""
width_ = 0
length_ = 0
xstart_ = 0
ystart_ = 0
xend_ = 0
yend_ = 0
grid_ = []
visiting_ = Queue(1000)
def __init__(self, width = 8, length = 8):
self.width_ = width
self.length_ = length
self.... |
f087f12bd1fa4e7b0bf884a58676e49dd99f5a27 | nikhilNathwani/project_euler | /euler26.py | 772 | 3.828125 | 4 | import time
import math
primes=[2]
start= time.time()
def isPrime(num):
sqrt= math.sqrt(num)
for elem in primes:
if num%elem==0:
return False
if elem>sqrt:
return True
return True
def primesUnder(n):
global primes
curr= 3
while curr<n:
#print curr, len(primes)
if isPrime(curr):
primes += [cur... |
bda6a35c61edc5967cb92ab85bcb58e20c2ff493 | nikhilNathwani/project_euler | /euler31.py | 277 | 3.53125 | 4 | import time
start= time.time()
def makeXPound(x,coins):
if x==0 or x==min(coins): return 1
elif x < min(coins): return 0
else: return makeXPound(x-coins[0],coins)+makeXPound(x,coins[1:])
print makeXPound(0, [1,2,5,10,20,50,100,200])
print "Time taken:", time.time()-start |
e26aa20c55958ce96d4c3993d98b8ed37929faa5 | nikhilNathwani/project_euler | /euler27.py | 1,375 | 3.734375 | 4 | import time
import math
#facts utilized:
#1) b must be prime
#2a) a+b must be >0 (otherwise result is negative for n=1)
#2b) a>0 and b>0 (follows from 2a)
#3) a must be odd (otherwise n^2 + an + b is even, thus not prime)
start= time.time()
primes=[2]
def isPrime(num):
if num<=1: return False
if num in primes: ret... |
36992169119a3e090fc95811547206c4da584164 | iverasp/ntnu | /tdt4136/exercise3/node.py | 1,908 | 3.75 | 4 | from colors import *
class Node:
# Instantiate a node with default values
def __init__(self, x, y):
self.x = x
self.y = y
self.g = 0
self.h = 0
self.f = 0
self.parent = None
self.nb = set()
self.start = False
self.end = False
... |
d741b5a358e1545a598d4d98a314e07767536a97 | iverasp/ntnu | /it3105/module_2/module_2.py | 2,682 | 3.59375 | 4 | from graph import Graph
import gui
import os
import platform
import re
import sys
sys.path.append("..")
from module_1.a_star import AStar
# The main function runs the basic terminal communication
def main():
# Clear the screen, prepare the mainlopp, create graph_list, create graph_path
os.system("clear")... |
32b1fdce0553b30a13993a7f2d487af7187b4500 | FrancoisCzarny/HackerRank | /Python/Python_weirdFunction.py | 565 | 4.46875 | 4 | #!/usr/bin/env python
#-*- coding : utf-8 -*-
"""
Given an integer, n, perform the following conditional actions:
If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weir... |
14f95e4bae449fdc0fed4c9c2b48356e87ad190a | avinashkumar95/PythonProjects | /dbTest.py | 3,678 | 3.78125 | 4 | import sqlite3 as sql
import random
def Delete_Table(x):
try:
conn=sql.connect("TestDB")
query = """DROP TABLE """+x
cur = conn.cursor()
cur.execute(query)
conn.commit()
except:
print("ERROR OCCUR WHILE DROP TABLE")
finally:
conn.close()
def Insert_Ta... |
bf3276fb6e6cd475127368a7a6423caead2ae610 | joshmarciniak/programming-practice | /Ch13Ex13.py | 1,060 | 3.734375 | 4 | from tkinter import *
import urllib.request
def main():
file1 = input("Enter a filename: ").strip()
infile = open(file1, "r")
numberOfVertices = eval(infile.readline())
vertices = []
edges = []
for i in range(numberOfVertices):
line = infile.readline().strip().split()
... |
a368578d6ce365277f4d9b15147be94e71e58b17 | tishafeed/oop-lab1 | /2.py | 1,163 | 3.84375 | 4 | import operator
import argparse
import sys
# parsing the args in a manner [keyword] [number] [number]
parser = argparse.ArgumentParser(description='А python-script that performs the standard math functions on the data')
parser.add_argument('function', help='function name')
parser.add_argument('first', help='first... |
14b7027781f7844c265e21e34a77ed48943396f6 | swap-beep/Calculator | /calculator.py | 3,062 | 3.578125 | 4 |
from tkinter import *
def click(event):
global scvalue
text = event.widget.cget("text")
print(text)
if text == "=":
if scvalue.get().isdigit():
value = int(scvalue.get())
else:
value = eval(screen.get())
scvalue.set(value)
sc... |
bdc7adebaa42259f908fd47ace488131d4fcb98a | andgpl/pyAutomatic | /Base/Decorator.py | 6,757 | 3.828125 | 4 | #! /usr/bin/python3
import inspect
class DecoratorMeta(type):
def __instancecheck__(cls, other):
return isinstance(other, cls.__DecoBaseClass__)
def __subclasscheck__(cls, other):
return issubclass(other, cls.__DecoBaseClass__)
class Decorator(metaclass = DecoratorMeta):
"""
... |
9c92d70445261f04e28f92cc64cdb94da07b5a35 | computer-lover/task0002 | /29.py | 196 | 3.6875 | 4 | class BMI:
def __init__(self,weight,height):
self.weight=weight
self.height=height
def BMI(self):
return self.weight/self.height**2
tb=BMI(60,1.7)
print(tb.BMI())
|
02c50f510db35c0297dbf775f9b6e17d4bdc3d32 | computer-lover/task0002 | /24.py | 130 | 3.765625 | 4 | a=1
for i in range(1,10):
print()
for u in range(1,i+1):
print('{0}×{1}={2}'.format(i,u,i*u),end=' ')
|
f3d9e126d310657b86a870044ef6df21c9868bcb | joyceyu6/coding_courses | /2021_4_19_to372/322.coin-change.py | 2,052 | 3.78125 | 4 | '''
You are given coins of different denominations and a total amount of money
amount. Write a function to compute the fewest number of coins that you
need to make up that amount. If that amount of money cannot be made up by
any combination of the coins, return -1.
You may assume that you have an infinite number of... |
cafba806562ce751b8749f3e27788d639076a140 | joyceyu6/coding_courses | /2021_4_19_to372/DP_120.triangle.py | 1,066 | 3.65625 | 4 | '''
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
Note:
Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
'''
#
# @lc app=leetcode id=120 lang=python3
#
# [120] Triangle
... |
3fb3f1ded6ad7db1a61f8e1907aceaa425f04822 | joyceyu6/coding_courses | /2021_4_19_to372/Binary Tree_BBT_110.balanced-binary-tree.py | 1,203 | 4.09375 | 4 | '''
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
'''
#
# @lc app=leetcode id=110 lang=python3
#
# [110] Balanced Binary Tree
#
# @lc code=sta... |
f4b78beaa18f9656c781b6e0dfc235b9cd7a4607 | joyceyu6/coding_courses | /2021_4_19_to372/Design_355.design-twitter.py | 3,705 | 4.25 | 4 | '''
Design a simplified version of Twitter where users can post tweets,
follow/unfollow another user and is able to see the 10 most recent tweets
in the user's news feed. Your design should support the following methods:
postTweet(userId, tweetId): Compose a new tweet.
getNewsFeed(userId): Retrieve the 10 most recent... |
4202f593bf060e3c830a96f3205f44cf9a36db94 | joyceyu6/coding_courses | /2021_4_19_to372/2_Pointers_209.minimum-size-subarray-sum.py | 1,706 | 3.578125 | 4 | '''
Given an array of n positive integers and a positive integer s,
find the minimal length of a contiguous subarray of which the sum ≥ s.
If there isn't one, return 0 instead.
'''
#
# @lc app=leetcode id=209 lang=python3
#
# [209] Minimum Size Subarray Sum
#
# @lc code=start
class Solution:
def minSubArrayLe... |
7f9adad347722d9341dc47298e00b95ab7f3f2d7 | joyceyu6/coding_courses | /2021_4_19_to372/Quick_Sort_Linked_List_148.sort-list.py | 2,559 | 3.859375 | 4 | #
# @lc app=leetcode id=148 lang=python3
#
# [148] Sort List
#
# @lc code=start
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def sortList(self, head: ListNode) -> ListNode:
# similar to... |
556be9decf8f2c711240f5b9b34498c537a1534c | joyceyu6/coding_courses | /2021_4_19_to372/DP_64.minimum-path-sum.py | 908 | 3.5 | 4 | #
# @lc app=leetcode id=64 lang=python3
#
# [64] Minimum Path Sum
#
# @lc code=start
class Solution:
def minPathSum(self, grid: List[List[int]]) -> int:
m = len(grid)
n = len(grid[0])
# note which is column and which is row
matrix = [[0 for _ in range(n)] for _ in range(m)]
... |
06ebf53c60964441b0be7982478e7165e005b729 | joyceyu6/coding_courses | /2021_4_19_to372/Detail_54.spiral-matrix.py | 1,261 | 3.515625 | 4 | #
# @lc app=leetcode id=54 lang=python3
#
# [54] Spiral Matrix
#
# @lc code=start
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
if len(matrix) == 0:
return []
result = []
self.recursive(matrix, 0, len(matrix)-1, 0, len(matrix[0])-1, result)
... |
4b579a9c97797541dc8de815edc9c46a144fc469 | joyceyu6/coding_courses | /2021_4_19_to372/Stack_150.evaluate-reverse-polish-notation.py | 2,117 | 3.5 | 4 | '''
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Note:
Division between two integers should truncate toward zero.
The given RPN expression is always valid. That means the expression would always evalua... |
fa6af42bdc4d28ddf903e1a1f925bed5d3c45c92 | joyceyu6/coding_courses | /2021_4_19_to372/Dictionary(easy)_299.bulls-and-cows.py | 1,607 | 3.84375 | 4 | '''
You are playing the Bulls and Cows game with your friend.
You write down a secret number and ask your friend to guess what the
number is. When your friend makes a guess, you provide a hint with the
following info:
The number of "bulls", which are digits in the guess that are in the
correct position.
The number... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.