blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
c299421c8fc95229e894873974ce0c6abb91ba2b | ibelievem/Python_Reptile | /6.5、lxml与xpath/2、xpath表达式过滤条件.py | 1,835 | 3.796875 | 4 | from lxml import etree
xmlStr = """
<bookstore>
<book>
<name type="python">学习爬虫</name>
<price>9.9ss</price>
</book>
<book id="book2">
<name type="pythonLib">Urllib</name>
<price>19.9</price>
</book>
<book id="book3">
<name type="pythonLib">学习Requests</nam... |
36dbd6d780e3264c87f39dbd4056d3cca674783d | fainorr/laf_adventure | /adventure/items.py | 26,456 | 3.828125 | 4 |
# ----------------------------------------------
# defines the items encountered in the adventure
# ----------------------------------------------
from random import *
# the base classes for all items
class item(object):
def __init__(self, name, description, value, size):
self.name = name
self.description = d... |
919c867a2cada5630ec4dcc484b6ada284cf0238 | minzhou1003/intro-to-programming-using-python | /practice5/11_7.py | 1,047 | 3.90625 | 4 | # minzhou@bu.edu
# Compute the distance between two points (x1, y1, z1), (x2, y2, z2)
def distance(x1, y1, z1, x2, y2, z2):
return ((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) ** 0.5
def nearestPoints(points):
# p1 and p2 are the indexes in the points list
p1, p2, p3 = 0, 1, 2# Initial two points
s... |
4e37fc8e8c7cf2c30148c2fd4b078b1d3ea002bf | minzhou1003/intro-to-programming-using-python | /practice3/4_1.py | 559 | 3.8125 | 4 | # copyright minzhou@bu.edu
import math
def quadratic(a, b, c):
discriminant = pow(b,2) - 4 * a * c
if discriminant < 0:
print('The equation has no real roots')
elif discriminant == 0:
r1 = (-b + math.sqrt(discriminant)) / (2 * a)
print('The root is ' + str(r1))
else:
r1 ... |
9e16ababa78b1ef8927e49d32c4d72d43448c196 | minzhou1003/intro-to-programming-using-python | /practice9/7_2.py | 1,288 | 3.609375 | 4 | # minzhou@bu.edu
class Stock:
def __init__(self, symbol, name):
self.__symbol = symbol
self.__name = name
self.__previousClosingPrice = 0
self.__currentPrice = 0
# getter
def getName(self):
return self.__name
def getSymbol(self):
return self.__symbol
... |
25dccf15cbfded31f217d032188007b5b5a42312 | minzhou1003/intro-to-programming-using-python | /practice3/5_1.py | 746 | 3.984375 | 4 | # copyright minzhou@bu.edu
def ave():
count_pos = 0
count_neg = 0
total = 0
a = int(input('Enter an integer, the input ends if it is 0: '))
if a != 0:
while(True):
if a == 0:
break
if a < 0:
count_neg += 1
if a > 0:
... |
7966e6f9ab6db6baef27ec98464135d8df9fe3b3 | minzhou1003/intro-to-programming-using-python | /practice9/7_5.py | 1,160 | 3.65625 | 4 | # minzhou@bu.edu
import math
class RegularPolygon:
def __init__(self, n = 3, side = 1, x = 0, y = 0):
self.__n = n
self.__side = side
self.__x = x
self.__y = y
# getter
def getN(self):
return self.__n
def getSide(self):
return self.__side
def get... |
510fbba7c75e902f66dcd15bd09c97c34ecad4a0 | fabianoft/FATEC-MECATRONICA-1600792021016-FABIANO | /LTP1-2020-2/pratica04/programa04.py | 398 | 4.1875 | 4 | # operadores da divisão (/) e resto da divisão (%)
#divisao = 15 / 2
#resto = 15 % 2
#print('divisao', divisao)
#print('resto', resto)
# Ler um numero para ver se ele é par ou impar
numero = int(input('Informe um numero:'))
# calcula o resto da divisão do numero par por 2
resto = numero % 2
# olha para o valor do res... |
beeb8a86d3af4251a30b8236438964f0d932ffe7 | alu0100821390/diffie-hellman | /Modification/diffie-hellman_mod.py | 2,621 | 3.65625 | 4 | ############################################################################
## Universidad de La Laguna ##
## Escuela Superior de Ingeniería y Tecnología ##
## Grado en Ingeniería Informática ##
## Seguridad en Sistemas Informáticos ##
## Fecha: 25/04/2017 ##
## Autor: Kevin Estévez ... |
3559f135331743e89947aab7ff91c9af977d5400 | Diego-Zulu/leetcode_answers | /python3/817.linked-list-components.200231738.ac.py | 2,058 | 3.8125 | 4 | #
# @lc app=leetcode id=817 lang=python3
#
# [817] Linked List Components
#
# https://leetcode.com/problems/linked-list-components/description/
#
# algorithms
# Medium (56.79%)
# Likes: 324
# Dislikes: 872
# Total Accepted: 39.9K
# Total Submissions: 70.3K
# Testcase Example: '[0,1,2,3]\n[0,1,3]'
#
# We are give... |
eddee021498d63a203f771b8d91385dcc9cea7cd | Diego-Zulu/leetcode_answers | /python3/1108.defanging-an-ip-address.276912248.ac.py | 825 | 3.8125 | 4 | #
# @lc app=leetcode id=1108 lang=python3
#
# [1108] Defanging an IP Address
#
# https://leetcode.com/problems/defanging-an-ip-address/description/
#
# algorithms
# Easy (86.65%)
# Likes: 318
# Dislikes: 732
# Total Accepted: 171.5K
# Total Submissions: 197.9K
# Testcase Example: '"1.1.1.1"'
#
# Given a valid (I... |
045fe3694970f5692d6706d4bf4fe7c6e85d2c21 | Diego-Zulu/leetcode_answers | /python/685.redundant-connection-ii.206246424.ac.py | 2,701 | 3.609375 | 4 | #
# @lc app=leetcode id=685 lang=python
#
# [685] Redundant Connection II
#
# https://leetcode.com/problems/redundant-connection-ii/description/
#
# algorithms
# Hard (32.20%)
# Likes: 685
# Dislikes: 198
# Total Accepted: 32.8K
# Total Submissions: 101.7K
# Testcase Example: '[[1,2],[1,3],[2,3]]'
#
#
# In this... |
a2e25cd68e8e7625135088ccf04551a9f2afc4e3 | Diego-Zulu/leetcode_answers | /python3/425.word-squares.208105172.ac.py | 3,343 | 3.78125 | 4 | #
# @lc app=leetcode id=425 lang=python3
#
# [425] Word Squares
#
# https://leetcode.com/problems/word-squares/description/
#
# algorithms
# Hard (47.30%)
# Likes: 497
# Dislikes: 38
# Total Accepted: 34.3K
# Total Submissions: 72.4K
# Testcase Example: '["area","lead","wall","lady","ball"]'
#
# Given a set of w... |
6e1e8038bec1a8ce347131ddde7f96a1d9be371f | Diego-Zulu/leetcode_answers | /python/270.closest-binary-search-tree-value.206413943.ac.py | 1,106 | 3.703125 | 4 | #
# @lc app=leetcode id=270 lang=python
#
# [270] Closest Binary Search Tree Value
#
# https://leetcode.com/problems/closest-binary-search-tree-value/description/
#
# algorithms
# Easy (46.99%)
# Likes: 659
# Dislikes: 52
# Total Accepted: 125.5K
# Total Submissions: 266.7K
# Testcase Example: '[4,2,5,1,3]\n3.71... |
254b55eda76751ef8171836d8d45fff3fca0cea7 | Diego-Zulu/leetcode_answers | /python3/42.trapping-rain-water.201502705.ac.py | 1,491 | 3.90625 | 4 | #
# @lc app=leetcode id=42 lang=python3
#
# [42] Trapping Rain Water
#
# https://leetcode.com/problems/trapping-rain-water/description/
#
# algorithms
# Hard (47.69%)
# Likes: 6376
# Dislikes: 111
# Total Accepted: 476.5K
# Total Submissions: 998.8K
# Testcase Example: '[0,1,0,2,1,0,1,3,2,1,2,1]'
#
# Given n non... |
432121324df67982a3510e6c45ea6939a8e7b815 | Diego-Zulu/leetcode_answers | /python3/328.odd-even-linked-list.340208255.ac.py | 1,590 | 4.1875 | 4 | #
# @lc app=leetcode id=328 lang=python3
#
# [328] Odd Even Linked List
#
# https://leetcode.com/problems/odd-even-linked-list/description/
#
# algorithms
# Medium (53.12%)
# Likes: 1458
# Dislikes: 277
# Total Accepted: 221.3K
# Total Submissions: 416.2K
# Testcase Example: '[1,2,3,4,5]'
#
# Given a singly link... |
a276dfa80e684e89376361cd8c66b87ce08e0ee9 | Diego-Zulu/leetcode_answers | /python3/64.minimum-path-sum.326646685.ac.py | 1,176 | 3.625 | 4 | #
# @lc app=leetcode id=64 lang=python3
#
# [64] Minimum Path Sum
#
# https://leetcode.com/problems/minimum-path-sum/description/
#
# algorithms
# Medium (53.28%)
# Likes: 2694
# Dislikes: 55
# Total Accepted: 395.7K
# Total Submissions: 742.3K
# Testcase Example: '[[1,3,1],[1,5,1],[4,2,1]]'
#
# Given a m x n gr... |
109b26aa729a327fc0320709cd1040527fe9eb9e | Diego-Zulu/leetcode_answers | /python3/200.number-of-islands.240595006.ac.py | 1,576 | 3.6875 | 4 | #
# @lc app=leetcode id=200 lang=python3
#
# [200] Number of Islands
#
# https://leetcode.com/problems/number-of-islands/description/
#
# algorithms
# Medium (45.88%)
# Likes: 4996
# Dislikes: 189
# Total Accepted: 676.1K
# Total Submissions: 1.5M
# Testcase Example: '[["1","1","1","1","0"],["1","1","0","1","0"]... |
b5ff1dc5b656b961aa52cc19ab8b54fbb23edd14 | Diego-Zulu/leetcode_answers | /python3/1055.shortest-way-to-form-string.337453739.ac.py | 2,261 | 3.71875 | 4 | #
# @lc app=leetcode id=1055 lang=python3
#
# [1055] Shortest Way to Form String
#
# https://leetcode.com/problems/shortest-way-to-form-string/description/
#
# algorithms
# Medium (56.99%)
# Likes: 424
# Dislikes: 28
# Total Accepted: 28.4K
# Total Submissions: 49.8K
# Testcase Example: '"abc"\n"abcbc"'
#
# From... |
118f4c9aeb3e7d03d5121bc9b0ef0bd41d074870 | Diego-Zulu/leetcode_answers | /python3/23.merge-k-sorted-lists.205645292.ac.py | 1,527 | 3.9375 | 4 | #
# @lc app=leetcode id=23 lang=python3
#
# [23] Merge k Sorted Lists
#
# https://leetcode.com/problems/merge-k-sorted-lists/description/
#
# algorithms
# Hard (39.15%)
# Likes: 4275
# Dislikes: 271
# Total Accepted: 605.7K
# Total Submissions: 1.5M
# Testcase Example: '[[1,4,5],[1,3,4],[2,6]]'
#
# Merge k sorte... |
0da9aa49179e54b9dc2d307ea962f8ec6ffca5c6 | Diego-Zulu/leetcode_answers | /python3/202.happy-number.321448511.ac.py | 1,268 | 3.75 | 4 | #
# @lc app=leetcode id=202 lang=python3
#
# [202] Happy Number
#
# https://leetcode.com/problems/happy-number/description/
#
# algorithms
# Easy (49.89%)
# Likes: 1926
# Dislikes: 406
# Total Accepted: 485.2K
# Total Submissions: 972.4K
# Testcase Example: '19'
#
# Write an algorithm to determine if a number n ... |
bd8d9d35a2e05aea196e120176d2bac1df1f3047 | Diego-Zulu/leetcode_answers | /python3/367.valid-perfect-square.336704590.ac.py | 1,057 | 3.625 | 4 | #
# @lc app=leetcode id=367 lang=python3
#
# [367] Valid Perfect Square
#
# https://leetcode.com/problems/valid-perfect-square/description/
#
# algorithms
# Easy (41.49%)
# Likes: 794
# Dislikes: 166
# Total Accepted: 209.5K
# Total Submissions: 505.2K
# Testcase Example: '16'
#
# Given a positive integer num, w... |
30c46436958c538b79f7a999dc1a4a3d25e211da | Diego-Zulu/leetcode_answers | /python3/314.binary-tree-vertical-order-traversal.239803380.ac.py | 2,365 | 3.890625 | 4 | #
# @lc app=leetcode id=314 lang=python3
#
# [314] Binary Tree Vertical Order Traversal
#
# https://leetcode.com/problems/binary-tree-vertical-order-traversal/description/
#
# algorithms
# Medium (44.04%)
# Likes: 906
# Dislikes: 162
# Total Accepted: 108.2K
# Total Submissions: 245.6K
# Testcase Example: '[3,9,... |
eccbeb361942131dd2afc9d696369f6926f6c9a5 | lfchesebrough/pythonds | /chapter1.py | 10,472 | 3.796875 | 4 | # exercise to practice python fundamentals
import string
import random
# random string generator with alphabet letters and spaces
def generate(N):
return ''.join(random.choice(string.ascii_lowercase + ' ') for i in range(N))
# create a score comparing two strings, 1 point for every matched character in the same ... |
bed1c1fc4dcd7ca1d1b5e2d2165f3c70b5a6c475 | liranbd1/Amazons-Project | /Game_Enginge/StringInput.py | 1,750 | 3.84375 | 4 | letters_dictionary = {}
def set_letters_dictionary(dictionary):
global letters_dictionary
letters_dictionary = dictionary
def translating_move(move_input):
queen = move_input.split("-")
arrow = move_input.split("/")
current_queen_position = translate_position(queen[0])
new_queen_position = q... |
8fc17a864c0d067b834427d80ba63d94c970875b | practiceDS/practice_Data_structures | /python/Practice/Conditional_Statements/2.py | 511 | 4.125 | 4 | #WAP to check whether a program is pass or fail, if it requires total of 40% and at least 33% in each subject to pass. Assume 3 subjects and take marks as an input from the user.
subject1 = int(input("Enter the marks of Subject 1 :"))
subject2 = int(input("Enter the marks of Subject 2 :"))
subject3 = int(input("Enter ... |
4efb2102465acb989c38e4d2dcf866c217e93b9c | practiceDS/practice_Data_structures | /python/Practice/List_tuples/2.py | 346 | 4.125 | 4 | #WAP to program to accept marks of 6 students and display them in a sorted manner
s1 = input("Marks of student 1: ")
s2 = input("Marks of student 2: ")
s3 = input("Marks of student 3: ")
s4 = input("Marks of student 4: ")
s5 = input("Marks of student 5: ")
s6 = input("Marks of student 6: ")
marks = [s1,s2,s3,s4,s5,s6]
... |
4cd8a6decad676c9e6b4f11399786c7e5433a7fa | practiceDS/practice_Data_structures | /python/Practice/loops/5.py | 186 | 4.25 | 4 | #WAP to find the factorial of a given number
fact = 1
num = int(input("Enter the number : "))
while (num != 0):
fact = fact * num
num = num -1
print("Factorial of number is ",fact)
|
ab18dc810adfd2b69e87f1460839b79b02ce29a3 | practiceDS/practice_Data_structures | /python/16.py | 582 | 4.40625 | 4 | #Inheritance, if you create an object of subclass it will first try to find the object of subclass, if its not present, then it call the init of super class.
#Note :- there is a super() method used to call both the constructor of both sub class and super class
class A(object):
def __init__(self):
print("... |
7811b741a603a1f9e86ce8c14bdd9361f2ea15aa | practiceDS/practice_Data_structures | /python/Practice/Functions_Recursion/3.py | 188 | 3.96875 | 4 | # WAP a recursive program to calculate sum of 1st n natural numbers
def sum(n):
if(n == 1):
return 1
return n + sum(n-1)
num = int(input("Enter the number : "))
print(sum(num))
|
360701fd24a16a4f1af0281fcfeaa4e1e4b2553c | practiceDS/practice_Data_structures | /python/pattern/3.py | 236 | 3.578125 | 4 | #WAP to display a particular pattern mentioned below :-
# # # #
# # #
# #
#
from __future__ import print_function
i = 4
while(i >= 0):
for j in range(i):
print("# ",end=" ")
print("\n")
i = i - 1
|
8de46223b5f952402039c938b49440e3b0b40780 | practiceDS/practice_Data_structures | /python/Practice/List_tuples/4.py | 161 | 3.5 | 4 | #WAP to sum a list of 4 number
num = [2,3,1,7]
i=0
total = 0
length = len(num)
print(length)
while(i<length):
total = total + num[i]
i = i + 1
print(total)
|
75a86e79ff7af84a485fc9a1183b1da460892fba | aplaceoutofthesun/fondumentals | /insertsort.py | 820 | 4.21875 | 4 | #!/usr/bin/env python3
#
"""Implementation of insertion sort algorithm"""
def insertion_sort(seq):
"""Maintains a sorted sublist in the lower positions in the list.
Each new item is then inserted back into the prev sublist s.t.
the sorted sublist is one item larger.
Complexity: O(n**2)
... |
84ba5bb5d6cde5d66ca8ede5ec0cdd9dac1bb7e6 | WLPGit/Discrete-Math | /filter.py | 961 | 3.5625 | 4 | class Pair():
def __init__(self, a, b):
self.first = a
self.second = b
def reversed(self):
return Pair(self.second, self.first)
def __eq__(self, other):
if (self.first == other.first and self.second == other.second) or (self.reversed().first == other.first and self.rev... |
d0560cca9b6ee232a04017e9db96b4a445ebcdc3 | edwardshen3033/pylesson | /Day6/rewriteIntDemo.py | 121 | 3.65625 | 4 | class int(int):
def __add__(self, other):
return int.__sub__(self,other)
i = int("2")
j = int("5")
print(i+j) |
703d15ac5bc8afba3a87ebf9ebdb7a737f5074c7 | edwardshen3033/pylesson | /Day7/ClockDemo.py | 697 | 3.625 | 4 | import time
class Clock:
def __init__(self):
self.begin = 0
self.end = 0
self.lasted = []
self.prompt = "未开始计时"
def start(self):
self.start_time = time.localtime()
self.prompt = "请调用stop方法"
print("开始计时")
def stop(self):
self.stop_time = time.lo... |
db23145c488f39b1dcd4a8212dc2ab90baa8d038 | edwardshen3033/pylesson | /Day4/practiceDemo.py | 315 | 3.8125 | 4 | print("我说:\"你是不是傻?\"")
str1 = r"你好我是\\"
print(str1)
i = 10
while i:
print("我爱鱼C")
i-=1
s = 3.5415926
print(int(s+0.5))
getmessage = input("请输入1到100间的数字")
num = int(getmessage)
if 1<=num<=100:
print("你妹妹好漂亮")
else:
print("你大爷好丑") |
bcb3a16856126a9e426a264accdebea6c34f3910 | edwardshen3033/pylesson | /Day2/FormatDemo.py | 651 | 3.921875 | 4 | print("My name is %(name)s,I am %(age)d years old" % {'name':'sss', 'age':21})
print("%+7x" % 10)
print(("%-5d" % 5))
print('{:0>8}'.format('70'))
print('{:.2f}'.format(3.1415926))
print('{:,}'.format(1234567890))
print('%+d' % 7)
print('%#x' % 17)
a = list()
print(a) #生成空列表
b = "I love you"
b = list(b)
print(b)
c... |
63b9488a0e560b53caaa08ed19266f11393dabbb | eDimasya/FirstPython | /Lection_6.py | 6,171 | 4.25 | 4 | def check_array(array):
"""
Функция проверки массива на правильность
:param array: Исходный массив
:return: True, если с массивом всё в порядке. False, если массив ошибочный
"""
if array is None:
return False
if not array:
return False
if type(array) != list:
retu... |
81b61b5c5e0f7a753fdfa76c602f766b59b3798c | CeYuIT/DBE14_Chat_Application | /simpleclient.py | 975 | 3.578125 | 4 | import socket
# Create a UDP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Server application IP address and port
server_address = 'hasanoglu.ddnss.de'
server_port = 10001
# Buffer size
buffer_size = 1024
# Message sent to server
message = 'Hi server!'
value = input("Please... |
bc827bdfc279552989e4969e08251b767c5140cb | haberkornsam/CS-3080 | /Homework 5/hw5_samuel_haberkorn_ex_2.py | 1,041 | 4.28125 | 4 | from math import sqrt, pow
"""
Assignment: Homework 5, Exercise 2
Name: Samuel Haberkorn
Date: November 2, 2020
Description: This program prints the first n pythagorean triples. We were not told how to rank them
(i.e. what number to sort by x, y, or z) I made the assumption that it was the first value (x).
"""
# inte... |
4cdf86aa7b1b1d28734cd5f1f748e17f588b4895 | haberkornsam/CS-3080 | /Homework 2/hw2_samuel_haberkorn_ex_4_3.py | 1,675 | 4.1875 | 4 | import random
"""
Assignment: Homework 2, Exercise 4.3
Name: Samuel Haberkorn
Date: Sept 13, 2020
Description: Expands part 2 by making the computer play the game in a very unintelligent way
"""
def main():
# generate random target number
lower_bound = random.randint(1, 100)
# give a little space between ... |
7eedb1b4bc0f1e0dd45a37e50b10b65b2253bbec | haberkornsam/CS-3080 | /Homework 6/hw6_haberkorn_samuel_ex_2.py | 1,744 | 4.375 | 4 | import functools
"""
Assignment: Homework 6, Exercise 2
Name: Samuel Haberkorn
Date: November 11, 2020
Description: The program implements a cache to speed up the process of calculation the fibonacci sequence.
Conclusion: When you are calculating fewer than the first 20 numbers, you do not see much of a difference wit... |
efb2a7fee801f84e5329dd4214d41f45e9647070 | dvstter/OnlinePriceComparison | /climod/premod/short.py | 768 | 3.65625 | 4 | from tkinter import *
# 预览图的简要信息展示区域,目前仅支持最低价格展示
class ShortInfo(Frame):
def __init__(self, master=None):
super().__init__(master)
self.grid()
self.__price_tag = None
self.__hot_index = None
self.__create_widgets()
self.__place_widgets()
def set_lowest_price(s... |
d3874014179c277cb5cb137611af90e11eb2a95d | spsanderson/python_for_informatics | /ch4/ch4.py | 2,619 | 4.65625 | 5 | # This is an example of a function in python
# this function is user defined.
# A function is a bit of reusable code that
# takes arguments(s) as input and does something
# that we define and the result gets returned
# def is used to tell python that we are making
# a function and it is something we defined.
def hello... |
c1390e7f8e37c4d208ca6d287771368a21aa0112 | spsanderson/python_for_informatics | /ch7/ch7.py | 2,639 | 3.9375 | 4 | '''Chapter 7 python for informatics code and exercises in this
chapter we will start to open up files and work with them
in their current working directory. You can download a test
file at the following address:
http://www.py4inf.com/code/mbox.txt
'''
# We will open a file called mbox.txt which is in the director
# Dr... |
1457dabb80f71da9fa292bea0e5485eeb642a5f2 | adenzhang/algotests | /src/SlidingWindowMaximum.py | 1,689 | 4.09375 | 4 | """
http://www.lintcode.com/en/problem/sliding-window-maximum/
Given an array of n integer with duplicate number, and a moving window(size k), move the window at each iteration from the start of the array, find the maximum number inside the window at each moving.
Example
For array [1, 2, 7, 7, 8], moving window size ... |
254062638811e5833db687e9ab7b5d0446ddf475 | spiroxide/COMP-17100 | /Functions/Functions.py | 415 | 3.734375 | 4 | def fahrenheit_to_celsius(fahrenheit):
"""
converts fahrenheit to celsius
:param fahrenheit: temperature in fahrenheit
:return: temperature in celsius
"""
return (fahrenheit - 32) * 5 / 9
def celsius_to_fahrenheit(celsius):
"""
converts celsius to fahrenheit
:param celsius: tempera... |
53b67514b69a635edec9515780f0924e55405bf8 | spiroxide/COMP-17100 | /XmasTree/XmasTree.py | 329 | 3.828125 | 4 | # name: Erich Ostendarp
# date: 10/4/17
num = int(input("Enter an integer: "))
i = 1
while i <= num:
# prints spaces before stars
j = num - i
while j >= 1:
print(' ', end='')
j -= 1
# prints starts
k = 1
while k <= (i * 2) - 1:
print('*', end='')
k += 1
p... |
e55b414c7059ff8e309663f7f19935ba68c2c874 | spiroxide/COMP-17100 | /Lab5/Lab5.py | 1,092 | 4.03125 | 4 | # Erich Ostendarp
# 10/24/17
# Prints the user's age in days, hours, minutes and seconds
def yearsToDays(years):
"""
Converts years to days
:param years: number of years
:return: number of days in those years
"""
return years * 365
def daysToHours(days):
"""
Converts days to hours
... |
04ceaa6adb13ebb8c8494c970b47b68bc0ab01da | spiroxide/COMP-17100 | /Lab2Functions/Lab2Functions.py | 1,094 | 4.15625 | 4 | from math import *
# name: Erich Ostendarp
# date: 10/16/17
# purpose: To find the number of 1 gallon paint cans needed to paint the sides of a house with gables.
def cans_of_paint(length, width, height, gable_height):
"""
finds the number of 1 gallon cans of paint needed to paint a house
:param length: t... |
750adfc1ca538f2f1918b3604920ed65a30c54d6 | jtorres96/python-for-everybody | /Chapter 2/Exercise 2.2.py | 760 | 4.5 | 4 | # Exercise 2.2: Write a program that uses input to prompt a user for their name and then welcomes them.
# For this we will use the input() function and string concatenation:
name = input("Enter your name: ") # We set the function to ask for the user's name. Keep in mind that the variable will be a string, so if w... |
9d13cfad2ffa21e45ef3bee8ee43dd6892ceb08c | avasich/a3200-2015-algs | /lab9/Vasich/k_max_p1.py | 1,698 | 3.765625 | 4 | class Queue:
def pop(self):
pass
def push(self, n):
pass
def size(self):
pass
class MinHeap(Queue):
def __init__(self, k):
self._size = 0
self._k = k
self._seq = []
def pop(self):
if self._size > 0:
self._seq[0], self._seq[self... |
bfcc887203bf2a1b075792216841eb1268813309 | avasich/a3200-2015-algs | /lab7/Vasich/generators.py | 992 | 3.609375 | 4 | from random import randint
def random_array(low, high, size):
seq = [0] * size
i = 0
while i < size:
seq[i] = randint(low, high)
i += 1
return seq
def semi_sorted_array(low, high, size):
seq = [0] * size
value = randint(low, high)
seq[0] = value
sign = 1
i = 1
... |
bd6d72910037ab49cecd922eb5972eb6a744a9a6 | Michael-dot-byte/OpenCV_Course_Other | /Section Mike #1 - Basics/draw.py | 774 | 3.96875 | 4 | import cv2 as cv
import numpy as np
# blank image (black)
blank = np.zeros((500,500,3), dtype='uint8') # creates an array with 500 with the dimensions of 500,500,3
# cv.imshow('blank',blank)
#
# # 1.Paint the image a certain color
# blank[200:300, 300:400] = 0,255,0
#
# # 2.Draw a rectangle
# cv.rectangle(blank, (0... |
512450e52423705f9af4925c71a52e6edb2f951e | Godliver143/Scrum-Game | /numlessthanfive.py | 156 | 3.578125 | 4 | b = [9,675,4,2,1,8,9,10,3,0,3,2,2,4,20,21,90,100,300,5,5,6,2,1,]
list = []
for number in b:
if number < 5:
list.append(number)
print (list)
|
86b4b28a65cd86fdd3e7349ade58afc893a1f893 | Moloq/ML-assignments | /a3/grasp/cleaner.py | 1,831 | 3.640625 | 4 | """Functions to deal with basic data pre-processing and cleaning on a pandas Dataframe.
Todo:
Convince the python community to move towards overloading and polymorphism
"""
import pandas
def fill_in_column_using_mean(dataframe, column_list, inplace=True, **kwargs):
""" Fills in a column in a Pandas dataframe... |
c500f6190f66ca4e4b6ad34ea15918a7e9658743 | Aparna20071996/Python-Problem-Solving | /Solution Reverse Integer.py | 270 | 3.546875 | 4 | class Solution:
def reverse(self, x: int) -> int:
if x>=0:
num=int(str(x)[::-1])
else:
num= int('-'+str(-1*x)[::-1])
if (num>=2**31) | (num<=-2**31):
return 0
else:
return num
|
ce4e3a0e3c2a19f6a029a138f83f6de2f0a3e697 | YijiangNemo/Python | /Quiz/quiz_6.py | 3,982 | 3.953125 | 4 | # Creates 3 classes, Point, Line and Parallelogram.
# A point is determined by 2 coordinates (int or float).
# A line is determined by 2 distinct points.
# A parallelogram is determined by 4 distint lines,
# two of which having the same slope, the other two having the same slope too.
# The Parallelogram has a method, d... |
11314c9f028f363b47dcd4bcf2120fd64cc3f061 | YijiangNemo/Python | /Quiz/quiz_3.py | 2,347 | 3.625 | 4 | # Randomly fills an array of size 10x10 with 0s and 1s, and outputs the number of blocks
# in the largest block construction, determined by rows of 1s that can be stacked
# on top of each other.
#
# Written by *** and Eric Martin for COMP9021
from random import seed, randrange
import sys
dim = 10
def display_gri... |
e9b2d62a17f67c250178722c8048de1fa8815848 | hsuan81/2020spring_NTNU_IR | /HW2/test.py | 1,168 | 3.6875 | 4 | import os
def split_searchfile(_file) -> list:
"""split the file and store different terms in a list and return the list. """
answer = []
dump = []
for i in _file:
print(i)
term = i.split("\n")
#print("trimfile: {name}".format(name=term))
if len(dump) == 3:
t... |
88da7dca7c0f486e5c8d3cc2cdbdb63de0136d00 | anushamokashi/prgm | /comb_dict.py | 159 | 3.546875 | 4 | l1 = [1,2,3,4,5]
l2 = ['a','b','c','d','e']
d1 = {}
for l1_ in l1:
for l2_ in l2:
d1[l1_] = l2_
l2.remove(l2_)
break
print (d1)
|
0e4b99b309606309fbee03d3271d5863c471974d | anushamokashi/prgm | /pgm2.py | 378 | 3.5625 | 4 | import os
import re
def rename_files():
os.chdir('/home/anusha/Downloads/anusha1/')
print os.getcwd()
file_list=os.listdir("/home/anusha/Downloads/anusha1/")
print(file_list)
for filename in file_list:
print filename
renamed = re.search('([a-zA-Z])+.*',filename)
renamed = renamed.group()
print "rnamed... |
d69a3f3afd4e97ccebc18d74fac79b9029badcf9 | s570504071/learngit | /date/date0820/class12.py | 433 | 3.84375 | 4 | class adder:
def __init__(self,value=0):
self.data=value
def __add__(self,other):
self.data+=other
x=adder()
print x
print '*'*8
class addrepr(adder):
#__repr__ for any typr
def __repr__(self):
return 'addrepr(%s)'% self.data
x=addrepr(2)
x+1
x
str(x),repr(x)
class addst... |
f5e0c58163b678b6c109d2e796f6bb69ba8b165f | s570504071/learngit | /date/date0825/test2.py | 887 | 3.6875 | 4 | class Cj:
def __init__(self,score):
self.score=score
if score in range(90,101):
print 'classA'
elif score in range(80,91):
print 'classB'
elif score in range(70,81):
print 'classC'
elif score in range(60,71):
... |
fa207fefd3a7150ebf035c0176372920f5460f47 | shivakalva/pythonBackend | /pythonBackend/Functions/parchild.py | 1,162 | 4.1875 | 4 | class Person:
# initializing the variables
name = ""
age = 0
# defining constructor
def __init__(self, personName, personAge):
self.name = personName
self.age = personAge
# defining class methods
def showName(self):
print(self.name)
def showAge(self):
... |
adbc29e33c0b276b287f6dd0dc18ae100db7b267 | shivakalva/pythonBackend | /pythonBackend/Basics/input.py | 719 | 3.71875 | 4 | # greeting = input("what is your age? \n")
# name = int(greeting)
# print(name)
###################################################################
# squares = []
# for x in range(1, 11):
# squares.append(x**2)
# print(squares)
###################################################################
squares = [x**2 for x... |
b3d1a59b664a914e769dc5b4c8853578b6223cd9 | Shyvmence/KALAYAYA | /KALAYAYA/minigame_fight.py | 29,785 | 3.53125 | 4 | import random
class personaje():
global characters
def __init__(self, vidaMax):
self.vidaMax = vidaMax
self.fe = 100
self.vida = vidaMax
self.alive = True
self.win = False
## self.hearts = getHearts(self.vida, self.vidaMax)
def takeDamage(self, d... |
d4475ca73baa7731fc1fd59d25a1bc910ab825e2 | MuhammadRaheelNaseem/How_TO_Find_Armstrong_Number | /armstrong.py | 226 | 4.125 | 4 | num=int(input("Enter a number: "))
Sum=0
temp = num
while temp>0:
digit=temp%10
Sum+=digit**3
temp//=10
if num == Sum:
print(num," is an armstrong number")
else:
print(num," is not an armstrong number")
|
435e2659d435c9efe0780dd34928843581684589 | vifino/benchmark_loop | /tests/benchmark_loop.py | 134 | 3.65625 | 4 | import time
iter = 0
start = time.time()
while iter%128 != 0 or (time.time()-start)<1:
iter+=1
print("{} iterations".format(iter))
|
3f99e6ead3b937c6d9f836d3b2dc612297d2e018 | williamclarktennis/connect4 | /Player.py | 7,143 | 4.125 | 4 | import Board
import random
"""
Implementation of a Connect-4 Player class
Author: William Clark and Henry Howell
"""
class Player:
"""A type for representing the behavior of a Connect-4 player who decides
what move to play next by looking a few moves ahead.
Attributes:
side - a single character ... |
0478fd131a9c889508758cd652b294b912ce16ee | Seven-star-club/universal-acceptance-check | /main.py | 2,340 | 3.609375 | 4 | import re
import validators
import socket
def checkDomain(d):
try:
return validators.domain.domain(d)
except Exception as e:
return False
def good_netloc(netloc):
try:
socket.gethostbyname(netloc)
return True
except Exception as e:
return False
print("UNI... |
991f7ca2c4e0e0da4408812017e80e937b1c5d63 | firdausraginda/python-beginner-to-advance | /intermediate-level/intermediate-#1-conditionals-loops.py | 3,200 | 4.15625 | 4 | # RULE
# python uses indentation to define code blocks (if, for, while), function & clases
# uses indentation means that white spaces (4 spaces or a tab key) are used as delimiters for code blocks
# after every if, for, while statement, or function or class definition, must use a colon
# ------------------------------... |
789653e393b86d5541f2baa87422b8688a76f8b4 | firdausraginda/python-beginner-to-advance | /zero-level/zero-level-#1-variables-data-types.py | 1,050 | 4.3125 | 4 | # USER INPUT
# user_says = input("Please enter the string you want to print: ")
# print(user_says)
# ----------------------------------------------------------
# VARIABLES
# 1. should start w/ a letter (can't start with a number)
# 2. can't include spaces
# 3. can't use symbols other than underscore (_)
# 4. Hyphens... |
2597983473cef9bdd5d3d24043e80c7103464fb0 | firdausraginda/python-beginner-to-advance | /intermediate-level/intermediate-#3-functions-modules.py | 3,721 | 4.4375 | 4 | # RULE
# defined using def keywoard, followed by the name of the function, pair of parentheses, & a colon
# example of a function
# def my_first_function():
# "This is my first function" # space to give description of the function
# print("Hello Python")
# can check the description of a function with help() f... |
d6d0e7059550477aaffe8a64c47ead3f7718571c | ValentinCalomme/hashcode2020 | /src/library.py | 1,515 | 3.984375 | 4 | from __future__ import annotations
import copy
class Library:
"""Library object
A library is represented by:
- the set of books in the library
- the time in days it takes to sign the library up for scanning
- the number of books that can be scanned each day from the librar... |
fec1e8b85ecaa22f6acff8653bfd2279c1583c0a | WilliamFireDev/SelectRightNumber | /main.py | 781 | 3.609375 | 4 | from randomint import *
print("Игра: ВЫБЕРИ ПРАВИЛЬНУЮ ЧИСЛО ЧТОБЫ ВЫЖИТЬ!")
#1 lvl
playerSelect = input("Введите число(От 1 до 5): ")
con = int(playerSelect)
if con == k:
print("Правильно!")
else:
print("Неправильно! Число было:" + str(k))
#2 lvl
playerSelect2lvl = input("Введите число(От 1 до 6): ")
con2 = ... |
e142a6906e22f37b4bbcfdabfd8c9597c53e2eec | rolifshitz/Intro-to-Computer-Science | /Assignment 2 - Vehicle Inventory Interactive Database/HelperFunctions.py | 4,388 | 4.28125 | 4 | """
This module contains helper functions that are used in multiple other modules. Specifically, the helper
functions prompt the user to enter information in the console. The functions verify that this information matches a
condition.
"""
# Created By: Romi Lifshitz
def getInt():
"""
This function gets an int... |
fd936d496a09421b5334a17a61b2cd04ba15a4ac | rolifshitz/Intro-to-Computer-Science | /Assignment 2 - Vehicle Inventory Interactive Database/ReportInventory.py | 17,654 | 4 | 4 | """
This module allows the user to choose what information they would like to report from the vehicle inventory (lis of lis)
and how they would like for the information to be reported (in the console, or in a .txt file).
"""
# Created By: Romi Lifshitz
"""
Importing the necessary modules.
"""
import operator
import U... |
a75074fdd6e950ae367b7fdad81e4e1d70ebf28a | rolifshitz/Intro-to-Computer-Science | /Assignment 4 - Recursion/swapElements.py | 3,311 | 4.125 | 4 | """
Question 4
"""
# Created By: Romi Lifshitz
def swapElements(lis, copyLis = None):
"""
This function recursively swaps the neighbouring elements in a list.
Args:
lis (list): list of integers
copyLis (None/list): list of integers (None by default)
Returns:
copyLis (list): lis... |
77fd51283e68c8d81164936fb8fb597371c2a69e | AFRINIC-Labs/africa-ixp-obs | /src/data/pfix2as/v4/download.py | 3,690 | 3.515625 | 4 | """
This script ???
To be filled
"""
import config
import os
import glob
import numpy as np
from datetime import date, datetime, timedelta
import requests
from bs4 import BeautifulSoup
def get_resource_to_download(url):
"""
Thi is an example script.
It seems that it has to have THIS docstring with a sum... |
a28e664c262f93e22841ad718b79af77e52b2a40 | HamzaHammoutou/CodeSignalProblems | /AllLongestStrings.py | 250 | 3.5625 | 4 | import sys
def allLongestStrings(inputArray):
length = [ len(s) for s in inputArray]
longestString = max(length)
return [s for s in inputArray if len(s) == longestString]
print(allLongestStrings(["aba", "aa", "ad", "vcd","aba"]))
|
552b1699578cb7755242d18c0b40db935259a8d3 | jaseemkp/thinkcs-python | /vectors.py | 1,011 | 3.671875 | 4 | def add_vectors(u, v):
"""
>>> add_vectors([1, 0], [1, 1])
[2, 1]
>>> add_vectors([1, 2], [1, 4])
[2, 6]
"""
matrix = []
for index1, row1 in enumerate(u):
for index2, row2 in enumerate(v):
if index1 == index2:
matrix += [row1 + row2]
retur... |
418154ceef7c388521c08e3d49805558d552b5ef | Silversmithe/Connect4 | /python/GameFlow/core/GameState.py | 1,276 | 4.125 | 4 | """
Define the base class for a game state
"""
import abc
class GameState(metaclass=abc.ABCMeta):
"""
State of the game
"""
def __init__(self, label, identity):
self.LABEL = label
self.ID = identity
def get_label(self):
"""
:return: string : the english identifier
... |
b17f0aec6bafa8cf1936f5724a5e04efd2bd4571 | Silversmithe/Connect4 | /python/GameMechanics/Inspector.py | 7,859 | 4.09375 | 4 | """
A class specifically for examining the board
"""
class Inspector(object):
"""
Examines the board it has been given and returns
information on the groupings of pieces.
- So the inspector passes this information onto the
controller to change the state of the board
OR
- the inspector pass... |
aa043b9618b46179f4259f1e9b2b8c9628b0026e | sankalp7654/HackerRank | /Python/Find a string/Solution.py | 234 | 3.5 | 4 | #author SANKALP SAXENA
def count_substring(string, sub_string):
l = len(sub_string)
u = len(string)
count = 0
for i in range(0, u-l+1):
if string[i : i + l] == sub_string:
count += 1
return (count)
|
1ebd2c05cd988b4703634ec1fb30cfafd8e028f0 | Gagan213/Advent_of_code | /Day_1/question_2.py | 464 | 3.671875 | 4 | import math
input_file = open("/home/gagandeep/Desktop/Advent_of_code/Day_1/input.txt")
mass_list = input_file.readlines()
input_file.close()
def get_fuel(mass, fuel_sum):
fuel = math.floor(mass / 3) - 2
if fuel > 0:
fuel_sum = fuel_sum + fuel
return get_fuel(fuel, fuel_sum)
else:
... |
5f36ff0bafce39cbe44665b36b2b8f7fb0365383 | alemor10/SketchPass | /sketchtools/display.py | 1,939 | 3.8125 | 4 | import pygame
def display_grid(grid):
# Initialize pygame
pygame.init()
SIZE = len(grid) #As all grids will be squares
# Define some colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0,0,255)
PURPLE = (142,68,173)
ORANGE = (230,12... |
0e0830649ed76195f6f009419e1cd73319951fa0 | nlandy/AdventofCode2020 | /day2/day2_problem2.py | 586 | 3.53125 | 4 | array = []
with open('input_day2.txt') as f:
for line in f:
pos1 = int(line.split('-')[0])
pos2 = int(line.split(' ')[0].split('-')[1])
letter = line.split(':')[0].split(' ')[1]
pw = line.split(' ')[2].split('\n')[0]
array += [(pos1, pos2, letter, pw)]
num_valid = 0
for pw... |
c355d7eb30746c90d65930209755e02d4631058d | aldhair8/Examen-Parcial | /Examen_parcial/Ejercicio_5.py | 427 | 3.75 | 4 | def algoritmo5Dpl():
# Datos de entrada
print ("Cauanto es tu salario: ")
salarioAh = int (input (" > "))
# Proceso
print ("Año " + " : " + " Salario")
salarioIncrementoAh = salarioAh * 0.10
for incrementoAh in range(1,7):
salarioAh = salarioIncrementoAh + salarioAh
print (in... |
8bf3b960319c2bfd19ce8db02c0e07586fd68b2e | sunfax/aganitha_prj | /front_last.py | 301 | 3.90625 | 4 | def check_front_last(word):
front=""
last=""
if(len(word)>1):
if word[-1]==',' or word[-1]=='.':
last=word[-1]
word=word[:-1]
if word[0]==',' or word[0]=='.':
front=word[0]
word=word[1:]
return front,word,last
|
f654b0f18e0d9a0b28caad2ee615a1c13ca24eec | anastasiia-shevchenko/Python-3-course | /lab 03/main.py | 2,833 | 3.8125 | 4 | import random
from random import randint
def main():
task_1()
task_2()
task_3()
def task_1():
print("Введите количество элементов в списке")
Size = int(input())
my_list = list()
i = 0
while i < Size:
my_list.append(random.randint(-60, 60))
i += 1
print(my_list)
... |
d213959e0f85a9fb7557086443a3815360f14ac6 | ellBasso/CP1404_Practicals | /prac_06/guitar.py | 677 | 3.828125 | 4 | CURRENT_YEAR = 2021
VINTAGE_AGE = 49
class Guitar:
def __init__(self, name="", year=0, cost=0):
"""Guitar characteristic variables"""
self.name = name
self.year = year
self.cost = cost
def __str__(self):
"""Returns guitar information in formatted string"""
retu... |
423294d8062bac01919a1d6cd45fa525bc349a2e | ellBasso/CP1404_Practicals | /prac_05/hex_colours.py | 975 | 4.4375 | 4 | """
Use a constant dictionary of about 10 colour names and write a program that allows a user to enter
a name and get the code, e.g. entering AliceBlue (or aliceblue - don't worry about matching the case)
should show #f0f8ff.
Entering an invalid colour name should not crash the program.
Allow the user to enter names u... |
e6ad2f44d4749f556816d612433486ef2c5f9496 | ellBasso/CP1404_Practicals | /prac_01/shop_calculator.py | 659 | 4.34375 | 4 | """
The program allows the user to enter the number of items and the price of each different item.
Then the program computes and displays the total price of those items.
If the total price is over $100, then a 10% discount is applied to that total before the amount is displayed on the screen.
"""
number_of_items = in... |
743f0f73cada38027a1ad821a07da1a6d7b6bc2b | ellBasso/CP1404_Practicals | /prac_06/guitars.py | 979 | 3.984375 | 4 | """The program should use a list to store all the user's guitars
(keep inputting until they enter a blank name), then print their details."""
from prac_06.guitar import Guitar
def main():
guitars = get_guitars()
show_guitars(guitars)
def get_guitars():
guitars = []
print("My guitars!")
name = i... |
02aa02ad3fd1461b902dc31c5f6af75729dec1ef | abdoulayegk/Daily_Coding_Challenge | /addUpDigits.py | 437 | 4.21875 | 4 | """Give a non-negative integer numb, repeteadly add all its digits until the
result has only one digit.for example :39=3+9=12 output:3"""
def addDigits(num):
sum = 0
while num > 0:
r = num % 10
sum = sum + r
num = int(num / 10)
result = sum
if sum > 9:
result = addDigit... |
275cb1da5fa60df8a915f0262c6dbadcf279fe1c | Peteliuk/IAD_Labs | /Lab3/grayAndBinConvertor.py | 808 | 3.59375 | 4 | def dec_to_bin(num):
arr = list(''.join(bin(num).split("0b")))
if num < 0:
arr.pop(0)
if len(arr) < 8:
arr.reverse()
while True:
arr.append("0")
if len(arr) == 8:
break
arr.reverse()
if num < 0:
arr[0] = "-"
return arr
bin_to_dec = lambda arr: int(''.join(arr),2)
# Helper function to xor... |
bb519bea192d70ee683fd707ae4be2a9ad5f89df | cvsogor/Algorithms | /Merged_Intervals.py | 1,503 | 4.09375 | 4 | from __future__ import print_function
def first(elem):
return elem.start
class Interval:
def __init__(self, start, end):
self.start = start
self.end = end
def print_interval(self):
print("[" + str(self.start) + ", " + str(self.end) + "]", end='')
def merge(intervals):
merged... |
a7ddd6633e29bf494ec2613d1705c99f1a5926f3 | RobertoCruzF/Intensivo-Nivelacion | /20082019/000837.py | 486 | 4.0625 | 4 | # define la funcion la cual en primer lugar imprime en consola el valor de la variable
# del input, luego imprime "still in this function", termina retornando el valor de la
# variable del input multiplicada por 3. Todo esto claramente cuando se evalua la funcion4
def function4(x):
print x
print "still in this fun... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.