blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
1ee2cd36967144cbf2fc7bceac39970507ced833
yangwenbinGit/python_programe
/python_07/class_property.py
1,074
4.46875
4
# 实例属性和类属性 # 由于Python是动态语言,根据类创建的实例可以任意绑定属性。给实例绑定属性的方法是通过实例变量,或者通过self变量 class Student(object): def __init__(self,name): # 实例属性 self.name = name # 但是,如果Student类本身需要绑定一个属性呢?可以直接在class中定义属性,这种属性是类属性,归Student类所有 # 类属性 age = 30 name ='Yangwen bin' s = Student('Bob') print(s.name) print(s.age)...
false
e11ca1c34731399a6432b19bf89606110df4e3ab
yangwenbinGit/python_programe
/python_08/create_class_on_the_fly.py
1,025
4.3125
4
class Hello(object): def hello(self,name='world'): self.name = name print('Hello,%s!!'%self.name) h =Hello() h.hello() print(type(Hello)) # <class 'type'> Hello是一个class,它的类型就是type print(type(h)) # <class '__main__.Hello'> 而h是一个实例,它的类型就是class Hello # type()函数既可以返回一个对象的类型,又可以创建出新的类型,比如,我们可以通过t...
false
da94819416e7a4a1d0afb66a2fba50469e51a458
edawson42/pythonPortfolio
/listEvens.py
277
4.125
4
#make new list of even numbers only from given list # # Copyright 2018, Eric Dawson, All rights reserved. def listEvens(list): """ (list) -> list Returns list of even numbers from given list """ evenList = [num for num in list if num % 2 == 0] return evenList
true
6821026f59936fa4f20df8e9ed72f04be20105bf
KeisukeSugita/Design_Pattern
/State/nonState.py
955
4.28125
4
# Stateパターンを利用しない場合 # 状態によってif文で処理を分岐させる必要があるため、 # 状態の追加・削除を行いたいときはif文を書き換える必要がある # 見通しが悪くなり、メンテナンスもしづらくなってしまう UPPER = 'Upper' LOWER = 'Lower' SWAP = 'Swap' DEFAULT = 'Default' class TextWriter: def __init__(self, text): self.text = text self.state = DEFAULT def set_state(self, state): self.state = state ...
false
27f36689b14dc824d0bd455fbbacf925ace550d0
karkyra/Starting_out_with_python3
/edabit/Last_Digit_Ultimate.py
323
4.15625
4
# Your job is to create a function, that takes 3 numbers: a, b, c and returns # True if the last digit of a * b = the last digit of c. Check the examples below for an explanation. def last_dig(a, b, c): total = a * b return str(total)[-1] == str(c)[-1] print(last_dig(25, 21, 125)) print(last_dig(12, 215, 2142...
true
c9b0fd090d633c3dee917dd6847f79dfc91371ff
karkyra/Starting_out_with_python3
/edabit/Find_the_Highest_Integer.py
420
4.125
4
# Create a function that finds the highest integer in the list using recursion. # Please use the recursion to solve this (not the max() method). def find_highest(lst): # return sorted(lst)[-1] if len(lst) == 1: return lst[0] else: current = find_highest(lst[1:]) return current if c...
true
bc28cd89b6ee3a1faad2a948204c04010cafbc77
karkyra/Starting_out_with_python3
/edabit/Enharmonic_Equivalents.py
420
4.125
4
# Given a musical note, create a function that returns its enharmonic equivalent. # The examples below should make this clear. def get_equivalent(note): d = {"Db": "C#", "Eb":"D#", "Gb":"F#", "Ab":"G#", "Bb":"A#"} for k,v in d.items(): if note == k: return v elif note == v: ...
true
f6bb7f7fcf292f512e9984696dc8151773259a30
karkyra/Starting_out_with_python3
/edabit/Buggy_Uppercase_Counting.py
451
4.28125
4
# In the Code tab is a function which is meant to return how many uppercase letters # there are in a list of various words. Fix the list comprehension so that the code functions normally! def count_uppercase(lst): return sum([letter.isupper() for word in lst for letter in word]) print(count_uppercase(["SOLO", "he...
true
10052b78817f1280becd708cc2aa42a383ffc763
karkyra/Starting_out_with_python3
/edabit/Characters_and_ASCII_Code_Dictionary.py
427
4.1875
4
# Write a function that transforms a list of characters into a list of dictionaries, where: # # The keys are the characters themselves. # The values are the ASCII codes of those characters. # example to_dict(["a", "b", "c"]) ➞ [{"a": 97}, {"b": 98}, {"c": 99}] def to_dict(lst): return [{i: ord(i)} for i ...
true
fa34f7934c15719235a12fd701d0ccac2d1284bc
karkyra/Starting_out_with_python3
/edabit/Stupid_Addition.py
718
4.375
4
# Create a function that takes two parameters and, if both parameters are strings, # add them as if they were integers or if the two parameters are integers, concatenate them. # If the two parameters are different data types, return None. # All parameters will either be strings or integers. def stupid_addition...
true
846061fdcbea83a17bc21cf23cd36455acf13814
karkyra/Starting_out_with_python3
/edabit/International_Greetings.py
856
4.375
4
# Suppose you have a guest list of students and the country they are from, stored as key-value pairs in a dictionary. # # GUEST_LIST = { # "Randy": "Germany", # "Karla": "France", # "Wendy": "Japan", # "Norman": "England", # "Sam": "Argentina" # } # # Write a function that takes in a name and returns a name tag, that s...
true
93b9229c6f5016ba015902dc03b3ae266fc315f1
JackCaff/WeeklyTask2-BMI-
/BMICalculation.py
511
4.34375
4
# Program will allow user to enter height in (CM) and weight in (KG) and calculate their BMI. Weight = float(input("Enter your Weight in Kg: ")) #Allows user to enter Weight Height = float(input("Enter your Height in Cm: ")) #Allows user to enter Height Meters_squared = ((Height * Height) / 100) #Converts height en...
true
5604489e590bc0224b0bb9aa5db23293d9a89ea2
umairgillani93/data-structures-algorithms
/coding_problems/sort_arr.py
357
4.1875
4
def sort(arr: list) -> list: ''' Sorts the given arraay in ascending order ''' while True: corrected = False for i in range(len(arr) -1): if arr[i] > arr[i+1]: arr[i], arr[i+1] = arr[i+1], arr[i] corrected = True if not corrected: return arr if __name__ == '__main...
true
f2378203319ab0d84940ac254ab24b7d047e0eae
schopr9/python-lone
/second_larjest.py
519
4.28125
4
def second_largest(input_array): """ To find the largest second number in the array """ max_1 = input_array[0] max_2 = input_array[1] for i in range(1, len(input_array)): if input_array[i] > max_1: max_2 = max_1 max_1 = input_array[i] elif input_array[i...
true
7410932a8f0c1b232a6cc12e393191775b6bdddb
NITHISH-DELL/my-captain-projects
/fibonacci.py
341
4.34375
4
#### Fibonacci numbers #### def fibonacci(n): print("the fibonacci numbers for",n,"numbers") i=0 j=1 print(i) print(j) for x in range(n): g=i+j print(g) i=j j=g n=int(input("enter the number to get the fibonacci value upto the n numbe...
false
d35591f10010cf1517a1243d6c0bb73ddd30a029
AsFal/euler
/pb9.py
719
4.15625
4
def check_pythagorean_triplet(a,b,c): if a*a + b*b == c*c: return True return False def print_triplet(a,b,c): print "(" + str(a) + ", " + str(b) +", " + str(c) + ")" triplet_found = False # because of a<b<c, the max value a can take is 332 for a in range(1, 333): # after setting a constant value f...
false
d26828c5f9c1d9490d1d397aa672c74f87f1e821
malianxun/AID2011month2
/select_server.py
1,384
4.125
4
""" 基于select 方法的io 多路复用网络并发 重点代码!! """ from select import select from socket import * # 地址 HOST = "0.0.0.0" PORT = 8888 ADDR = (HOST, PORT) def main(): # tcp套接字 连接客户端 sock = socket() sock.bind(ADDR) sock.listen(5) print("Listen the port %d" % PORT) #防止IO处理过程中产生阻塞行为 sock.setblocking(False)...
false
411c840c3eed902311543ed9aa459e952b6a7802
oleksandr-nikitenko/python-course
/Lesson_26/task3.py
817
4.15625
4
""" # Extend the Stack to include a method called get_from_stack that searches and returns an element e # from a stack. Any other element must remain on the stack respecting their order. # Consider the case in which the element is not found - raise ValueError with proper info Message # Extend the Queue to include a me...
true
e0a2336680d8b24bc1de0cabcb4aab1dd7135a3b
oleksandr-nikitenko/python-course
/Lesson_11/task1.py
696
4.21875
4
"""Make a class called Person. Make the __init__() method take firstname, lastname, and age as parameters and add them as attributes. Make another method called talk() which makes prints a greeting from the person containing, for example like this: “Hello, my name is Carl Johnson and I’m 26 years old”.""" class Perso...
true
5b3a41f5937f89cad7b16f7de0fa65b23bce89c1
oleksandr-nikitenko/python-course
/Lesson_8/task3.py
996
4.5625
5
""" Create a function called make_operation, which takes in a simple arithmetic operator as a first parameter (to keep things simple let it only be ‘+’, ‘-’ or ‘*’) and an arbitrary number of arguments (only numbers) as the second parameter. Then return the sum or product of all the numbers in the arbitrary parameter. ...
true
4df63417fc4ed7d520b59f1fdcb72fe2100c2d17
oleksandr-nikitenko/python-course
/Lesson_15/task3.py
1,266
4.21875
4
""" Write a decorator `arg_rules` that validates arguments passed to the function. A decorator should take 3 arguments: max_length: 15 type_: str contains: [] - list of symbols that an argument should contain If some of the rules' checks returns False, the function should return False and print the reason it failed; ot...
true
7fd94e0622223864c7334ddcf48e60af82159700
kikijtl/coding
/Candice_coding/Practice/Fibonacci_Sequence.py
639
4.375
4
''' Output the nth number in the Fibonacci Sequence. ''' def nthFibonacci_recursive(n): if n == 1 or n == 2: return 1 return nthFibonacci_recursive(n-1) + nthFibonacci_recursive(n-2) def nthFibonacci_loop(n): if n == 1 or n == 2: return 1 previous = 1 current = 1 ...
false
46412f98fa00fcf47357026805fa9deb87cd6c0c
kikijtl/coding
/Candice_coding/Cracking_the_Coding_Interview/Queue_by_2Stacks.py
1,388
4.15625
4
'''Implement a queue using two stacks.''' class Queue: def __init__(self): self.max_size = 10 self.front = 0 self.end = 0 self.arr = [None]*self.max_size self.tmp = [] def __repr__(self): return '%s(%r)' %(self.__class__.__name__, self.arr) ...
false
5095d554baf1909bb9731bda65af7e04d25b3809
kikijtl/coding
/Candice_coding/Leetcode/Permutations.py
778
4.15625
4
'''Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].''' from copy import deepcopy def permute(num): n = len(num) #count = [1] * n cur_result = [] results = [] ...
true
6eba1e86149ce3c05dcd297215f5371e400d8d92
kikijtl/coding
/Candice_coding/Leetcode/Closest_Binary_Search_Tree_Value.py
1,333
4.15625
4
# Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. # # Note: # Given target value is a floating point. # You are guaranteed to have only one unique value in the BST that is closest to the target. # Definition for a binary tree node. class TreeN...
true
c516bc3e2cde7d979b5155822f837f482c6e9a14
kikijtl/coding
/Candice_coding/Leetcode/Implement_Stack_Using_Queues.py
1,541
4.125
4
import collections class Stack(object): def __init__(self): """ initialize your data structure here. """ self.q1 = collections.deque() self.q2 = collections.deque() def push(self, x): """ :type x: int :rtype: nothing ...
false
fe7e219419804dcdb343c62dd89d3601d9802266
Rafaellinos/learning_python
/structures_algorithms/recursion/recursion3.py
282
4.3125
4
""" reverse string by using """ def reverse_str(string): return string[::-1] def reverse(string): print(string) if len(string) == 0: return string else: return reverse(string[1:]) + string[0] # print(reverse_str('hello')) print(reverse('hello'))
true
ec6c262f7c755bc2b30890ffff5b7da629e9b44d
Rafaellinos/learning_python
/OOP/objects.py
1,177
4.125
4
#OOP class PlayerCharcter: """ self represents the instance of the class. With this keyword, its possible to access atributes and methods of the class. When objects are instantiated, the object itself is passed into the self parameter. """ membership = True # class object attribute...
true
13a9e0c4334f1bbe6d0b89c69fe71a90d2b074f9
Rafaellinos/learning_python
/basics/learning_lists.py
1,694
4.125
4
lista = [1,2,3,4] lista.append(5) lista2 = lista print(lista2) # If I try to copy the last on that way (lista2 = lista), # any changes that I made on lista2 goes to lista aswell, because # they are pointing to the same place in memory. # the right way to copy a list, is lista2 = lista[:], or lista2 = lista.copy() list...
true
6d8cb09b90c7c9a7386e1210905b3005c51109bc
Rafaellinos/learning_python
/OOP/polymorphism.py
688
4.1875
4
""" Polymorphism: Poly means many and morphism means forms, many form in other words. In python means that objects can share the same names but work in diferent ways. """ class User: def attack(self): return "do nothing" class Archer(User): def __init__(self, name, arrows): self.n...
true
adbe2258d207f05702157e8fa1e1182a32ad35d0
Rafaellinos/learning_python
/functional_programming/reduce.py
661
4.125
4
from functools import reduce my_list = [1,2,3] def multiply_by2(item): return item*2 def accumulator(acc, item): print(acc, item) return acc+item # func item, acc print(reduce(accumulator, my_list, 0)) # default = 0 # output # 0 1 # 1 2 # 3 3 # 6 sum_total = reduce((lambda x,y: x+y...
true
3d6a633b77b2305a9f2bd3111645311ec6649881
Rafaellinos/learning_python
/basics/learning_tuples.py
600
4.40625
4
""" Tuples are immutables, so you can't update, sort, add item etc Usually more faster than lists. Tuple only has two methods: count and index, but it works with len """ tuple2 = (1,2,3,4) print(3 in tuple2) new_tuple = tuple2[1:4] print(new_tuple) a, b, *other = tuple2 #unpacking tuple print(other) print...
true
10b9250387e95708aab6cda408133fa0b157c3b2
Rafaellinos/learning_python
/structures_algorithms/algorithms/leet_code_1528.py
986
4.125
4
""" Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled string. Example 1: Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output: "leetcode" Explanation: As sho...
true
55abcf3f6a0916eeb2da275f5464c602c6a3a9b0
Erick-INCS/FSDI_114_Algorithms_and_DataStructures
/linked_list/linked_list.py
1,570
4.1875
4
#!/usr/bin/env python3 """ linked list implementation """ class Node: """ One directional node """ def __init__(self, val): self.val = val self.next = None def __str__(self): return str(self.val) class LinkedList: """ Data structure """ def __init__(self, val): ...
true
c3491d075ad662a00b7c0683d4192835c9aae475
agarw184/Data-Science
/PA04_final/problem2.py
2,102
4.15625
4
#perform a stencil using the filter f with width w on list data #output the resulting list #note that if len(data) = k, len(output) = k - width + 1 #f will accept as input a list of size width and return a single number def stencil(data, f, width) : #Fill in #Initialising Variables k = len(data) w = wi...
true
be1d306f7c0840dcc7f5df2a4fc9285a81079b3f
LiaoTingChun/python_advanced
/ch3_abstract.py
968
4.34375
4
# abstract class # 抽象類別不能生成實例, 只能被繼承 # class中包含一個以上abstract method, 即為abstract class # 改寫type, 就是在寫metaclass from abc import ABCMeta, abstractmethod, ABC # abstract base class # 改用ABCMeta生成class class Product(metaclass=ABCMeta): @abstractmethod def hi(self): pass @abstractmethod def hi2(self...
false
567ec46c085595c66571a67b0f6c7311a3d693e2
SaraAnttila/day2-bestpractices-1
/1a_e/animals/birds.py
365
4.15625
4
""" Package with types of birds """ class Birds: def __init__(self): """ Construct this class by creating member animals """ self.members = ['Sparrow', 'Robin', 'Duck'] def printMembers(self): print('Printing members of the Birds class') for member in self.membe...
true
b59587c38765e23a5d821cc6d9560284ca88a71e
Jitha-menon/jithapythonfiles
/PycharmProject/fundamental_programming/Swapping/flow_of_controls/Looping_For Loop.py
372
4.21875
4
# For i in range (5): # print('hello') for a in range (2,8): print (a) # for in range with initial value final value and increment value for i in range (1,10,2): print (i) #problem to find numbers between min and max range min= int(input('enter the min num')) max=int(input('enter the max num')) for...
false
d277b87aec7f8288dcb76b17a85b5eaef466a437
Jitha-menon/jithapythonfiles
/PycharmProject/Regular Expressions/quantifier rule 2.py
201
4.15625
4
import re x='a*' # counts all no:of data whether a is there or not it iterates r='aaa abc dsd avf aaa avg' matcher=re.finditer(x,r) for match in matcher: print(match.start()) print(match.group())
false
fcc9afc659b9b41084eef7c08d3da756e6f4fc33
SRashmip/FST-M1
/Python/Activities/Activity3.py
787
4.15625
4
user1 = input("What is player 1 name:") user2 = input("What is player2 name:") user1_answer = input(user1+ "Do you want to choose rock,paper or scissor" ) user2_answer = input(user2+"Do you want to choose rock,paper or scissor") if user1_answer==user2_answer: print("its tie") elif user1_answer=='rock': ...
true
c9e547c4ec6f2e42dc7703b372625705640860d8
momado350/fun
/pythagoren_check.py
684
4.3125
4
# in this challenge we will check if a list is applicable to return a pythagoren triplets # our assumptions #[3,4,5] = True # [4] = False # [12,1,7,9]= False # the code: #create a function to check if list is pythagoren triplets lst = [3, 4, 6] def p_t(lst): for i in range(len(lst)): for j in range(i+...
false
d89c05ca8e67c947a11fca49a107b4f2dd34843b
RKKgithub/databyte_inductions
/CountryCodes_task.py
606
4.375
4
import csv #take country codes as input code1, code2 = input().split() flag = False #empty list to store country names data = [] #open csv file and store data in a dictionary with open(r"CSV_FILE_PATH_GOES_IN_HERE") as file: reader = csv.DictReader(file) #add country names in between the two country ...
true
720d1526b00a45fbbcc8e76855b2514400954e31
Hussein-Mansour/ICS3UR-Assignment-6B-python
/volume_of_rectangle.py
1,166
4.15625
4
#!/usr/bin/env python3 # Created by: Hussein Mansour # Created on: Fri/May28/2021 # This program calculates the volume of rectangular prism def volume_rectangular(length_int, width_int, height_int): # this function calculates the volume of rectangular prism using return # process volume = length_int * wi...
true
803b0a3be00d0659b0451d4c211a962f4491cd4c
x223/cs11-student-work-genesishiciano
/Word_Count.py
866
4.3125
4
text_input= raw_input("Write your text here") # The text that you are going to use user_choice= raw_input("what word do you want to find? ") # the word that the person is looking for text_input=text_input.lower()# change all of the inputs into lower case text_input=text_input.replace(".", " ")# changes all of the '.' i...
true
f719f7f80d4eb84bb5bda99663f9b34963a38c35
gan-gan777/Python_Crash_Course
/04/4-11_Pizzas_you&me.py
449
4.21875
4
my_pizzas = ['Chicken', 'Durian', 'Beef'] friend_pizzas = my_pizzas[:] my_pizzas.append('Double') friend_pizzas.append('Mango') print("My favorite pizza are:") print(my_pizzas) for my_pizza in my_pizzas: print("I like " + my_pizza.lower() + " pizza.") print("\nMy friend's favorite pizza are:") print(friend_pizzas)...
false
71c7612841b4e6c0fe29bee99d5d73cbbe027fe4
krewper/Python_Commits
/misc_ops.py
1,204
4.125
4
#swapping variables in-place x, y = 10, 20 print(x, y) x, y = y, x print(x, y) #Reversing a string a = "Kongsberg Digital India" print("Reverse is", a[::-1]) #Creating a single string from all the elements in a list a = ["Geeks", "For", "Geeks"] print(" ".join(a)) #chaining of comparision operators n = 10 result = ...
true
8af810deab946e1010252e63292d9653ba6b6b50
Dream-Team-Pro/python-udacity-lab2
/TASK-3.py
694
4.46875
4
# Task 3: # You are required to complete the function maximum(x). where "x" is a list of numbers. the function is expected to return the highest number in that list. # Example: # input : [5,20,12,6] # output: 20 # you can change the numbers in the list no_list but you are not allowed to change the variable names or edi...
true
e2d8abd1867efe72fc0222e00189922e542497db
freddywilliam/Pensamiento_Computacional
/Diccionarios/dict_com.py
1,029
4.125
4
def run(): print(''' --------------------------------------------------- AQUI CREO MI DICCIONARIO ''') dict = { 'david' : 18, 'pedro' : 20, 'sara' : 10, 'melissa' : 17, } print(dict) print(''' --------------------------------------------...
false
2ce2e3f08b62ff843373991517e1af4cc2f230a7
SaiNikhilD/Dogiparty_SaiNikhil_Spring2017
/Assignment3/Question2_Part1.py
1,030
4.21875
4
# coding: utf-8 # # Question2_Part1 # •Use 'employee_compensation' data set. # •Find out the highest paid departments in each organization group by calculating mean of total compensation for every department. # •Output should contain the organization group and the departments in each organization group with the tot...
true
e4a51691d1de70e5b932773a7f34f9e7531449d7
njberejan/Palindrome
/palindrome_advanced.py
818
4.28125
4
import re # def reversed_string(sentence): # #recursive function to reverse string # if len(sentence) == 0: # return '' # else: # return reversed_string(sentence[1:]) + sentence[0] def is_palindrome(sentence): #uses iterative to solve, above function not called so commented out. sentence =...
true
8e95b399682602881a79f1f0dc5cdc0688a74efe
sarahmbaka/Bootcamp_19
/Day_4/MissingNumber/missing_number.py
340
4.21875
4
def find_missing(list1, list2): """Function that returns the difference between two lists""" if not list1 and list2: # checks if list is empty return 0 diff = list(set(list1) ^ set(list2)) # diff is the difference between the lists if not diff: return 0 return diff[0] #retrieve fir...
true
64b93a9f735a25f268123acf4474e0d8d1fd3738
aruntom/python
/hit_the_target.py
1,223
4.15625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Sep 18 11:55:39 2017 @author: aruntom """ #Arun Tom import turtle SCREEN_WIDTH=600 SCREEN_HEIGHT= 600 TARGET_LLEFT_X=100 TARGET_LLEFT_Y=250 TARGET_WIDTH=25 FORCE_FACTOR=30 PROJECTILE_SPEED=1 NORTH=90 SOUTH=270 EAST=0 WEST=180 turtle.setup(SCREEN_WIDT...
false
b61106c9d0e72482f7320c6ae12374e98c989d66
Riya258/PythonProblemSolvingCodeSubmission
/ps1b.py
1,233
4.25
4
# Name: Riya # REG. NO.: BS19BTCS005 # Time spend: 2:30 hours #Problem 2 #2.Paying Debt Off In a Year """ Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months. We will not be dealing with a minimum monthly payment rate. """ outsta...
true
55ee6660ae1b673ef68b2e225012cc1de26e68c3
NimalGv/Python-Programs
/MYSLATE/A2-Programs/Day-1/4.number_a_sum_of_two_primes.py
770
4.15625
4
# -*- coding: utf-8 -*- """ 1.Any even number greater than or equal to 4 can always be written as sum of two primes even : even+even and odd+odd; 2.The odd number can be written as sum of two primes if the number-2 is a prime number, because odd : odd+even and even+odd; so, IsPrim...
true
a1eb915db6312fe768536d0af922d02e569f476b
muhammadalie/python-think
/factorial.py
251
4.21875
4
def fact(n): if type(n)==int: print 'n is not integer' return None elif 0<=n<=2:return n elif n<0: print 'not defined,number is negative' return None return n*fact(n-1) n=input('type your number: ') print 'the factorial is ',fact(n)
true
82801a8c565f7c058270124cb270dd09b0213136
felix1429/project_euler
/euler04.py
1,058
4.21875
4
# Largest palindrome from multiplying two three digit numbers # 998001 is 999 * 999 # start at 998001 and iterate down until first palindrome # then divide that palindrome by 999, 999 - 1, 999 - 2 etc until it # divides evenly or runs out of numbers, in which case the next palindrome # is moved to def is_palindrome(n...
true
bb974d1a1a6dd9b6653db0ebfb6f883d5bd6f4d6
rajesh1994/lphw_challenges
/python_excercise/ex05.01.py
779
4.125
4
one_centimeter_equal_to = 0.393701 # Inches # Getting the centimeter value from the user centimeter = float(raw_input("Enter the centimeter value:")) # Calculating the equalent inches by using centimeter value inches_calculation = one_centimeter_equal_to * centimeter # Printing the converted value in inches print "T...
true
83de7ca67fdb04a015d4f0ee0dad0424a1a66e0f
nileshpandit009/practice
/BE/Part-I/Python/BE_A_55/assignment1_1.py
245
4.125
4
my_list = input("Enter numbers separated by spaces").split(" "); total = 0; for num in my_list: try: total += int(num) except ValueError: print("List contains non-numeric values\n") exit(-1) print(total)
true
c98bf8c90d9ac104f2cabc8669c7888ea8fa5fbe
bunnymonster/personal-code-bits
/python/learningExercises/ListBasics.py
760
4.46875
4
#This file demonstrates the basics of lists. animals = ["rabbit","fox","wolf","snail"] #prints the list print(animals) #lists are indexed like strings. slicing works on lists. print(animals[0]) print(animals[1:2]) #all slices return a new list containing the requested items. #lists support concatenation animals + ...
true
9bd76cf27d41a1e017011e2409c6ae68ffd41058
bunnymonster/personal-code-bits
/python/learningExercises/ErrorsAndExceptions.py
2,115
4.25
4
import sys # #Errors and Exceptiosn # #Error handled with basic try except try: print(x) except: print('Error! x not defined.') #multiple Exceptions may be handled by a single except #by being listed in a tuple. try: print(x) except (RuntimeError, TypeError, NameError): print('Error!') #a class C in...
true
aeb5387a37f4d61e2d9dbd67fa541a669312856e
praveen2896/python
/Assignment_op.py
428
4.15625
4
f_num=input("enter the number1") print f_num s_num=input("enter the number2") print s_num answer=f_num+s_num answer += f_num print "addition ",answer answer -= f_num print "subtraction ",answer answer *= f_num print "multiplication ",answer answer /= f_num print "division ",answer answer %= f_num print "m...
false
e196c243910c0b42dcee2195675ef2c7e393c703
rupol/cs-module-project-algorithms
/sliding_window_max/sliding_window_max.py
883
4.28125
4
''' Input: a List of integers as well as an integer `k` representing the size of the sliding window Returns: a List of integers ''' # return an array with the max value of each window (i to i + k) def sliding_window_max(nums, k): # create an array to save the max values in result = [0] * (len(nums) - (k - 1))...
true
f14f5b7612a5ac16d08ac92b6766ea08659e8c92
inickt/advent-of-code-2019
/aoc/day01.py
1,329
4.375
4
"""Day 1: The Tyranny of the Rocket Equation""" from math import floor def fuel_required(mass: float) -> float: """Find fuel required to launch a given module by its mass. Take mass, divide by three, round down, and subtract 2. Examples: >>> fuel_required(12) 2 >>> fuel_required(14) 2 ...
true
b25db4d630a000b0481c50402638811cb0106772
thevarunnayak/pythonprograms
/basicprograms/Function Demo.py
716
4.28125
4
# Program to demonstrate functions ''' print("WTC Namde!") print("Ee Sala Cup Namde!") print("Michael Vaughan is shit!") ''' # To repeat this 10 times, ''' for _ in range(10): print("WTC Namde!") print("Ee Sala Cup Namde!") print("Michael Vaughan is shit!") ''' ''' print("WTC Namde!") pri...
false
8a007237f7cc4430ab0a1e10793e03f78fa19335
Stubbycat85/csf-1
/Hw-1/hw1_test.py
1,615
4.3125
4
# Name: ... # Evergreen Login: ... # Computer Science Foundations # Programming as a Way of Life # Homework 1 # You may do your work by editing this file, or by typing code at the # command line and copying it into the appropriate part of this file when # you are done. When you are done, running this file should comp...
true
b10d3f99b7fe131537dc62af61c93c92885a9776
jhonatanmaia/python
/study/curso-em-video/14 - Funções.py
2,195
4.21875
4
''' Funções = rotina def = definição de função def mostraLinha(): print('-'*30) mostraLinha() print('Sistema de Alunos') mostraLinha() Os parametros passado pelo usuario sao os parametros reais e os parametros da funcao sao os parametros formais def mensagem(msg): print("-"*30) print(msg) print("-"...
false
36444a7d22f2f3bae8a8bc1bec97a6772b45e713
GhostGuy9/Python-Programs
/madlibs/Catcher/questions.py
1,808
4.125
4
import os #Configure this Section questions = [ "Type a Adverb", "Type a Verb", "Type a Verb in Past Tense", "Type a Adjective", "Type a Plural Noun", "Fictional Character Name", "Type a undesirable Noun", "Type a Verb", "Type a Noun", "Type a Verb in Past Tense ending in \"S\"",...
true
c7466693f23dcb10b71277637b895e78f6c1a668
neelamy/Algorithm
/DP/Way_to_represent_n_as_sum_of_int.py
975
4.125
4
# Source : http://www.geeksforgeeks.org/number-different-ways-n-can-written-sum-two-positive-integers/ # Algo/DS : DP # Complexity : O(n ^2) # Program to find the number of ways, n can be # written as sum of two or more positive integers. # Returns number of ways to write n as sum of # two or more positive integers...
true
06da28be20b6763e571b7245bb559e042855353d
leilacey/LIS-511
/Chapter 3/Guest List.py
392
4.28125
4
# 3-4 Guest List dinner_guests = ['Kurt Cobain', 'Bill Gates', 'Eddie Veddar'] for guest in dinner_guests print ("Would you like to have dinner with me " + guest + "?") # 3-5 Changing Guest List not_coming = "Bill Gates" dinner_guests.insert(1, "Dave Grohl") dinner_guests.remove(not_coming) for guest in din...
false
ec8410a8e32b0f3ecd96490b352611b9e9a6dfe0
cspfander/Module_6
/more_functions/validate_input_in_functions.py
1,260
4.5625
5
""" Program: validate_input_in_functions.py Author: Colten Pfander Last date modified: 9/30/2019 The purpose of this program is to write a function score_input() that takes a test_name, test_score, and invalid_message that validates the test_score, asking the user for a valid test score until it is in the range, then ...
true
556d13ca018fe2391fa65925fa52905ea2710219
gandhalik/PythonCA2020-Assignments
/Task 3/7.py
254
4.40625
4
#7. Write a program to replace the last element in a list with another list. # Sample data: [[1,3,5,7,9,10],[2,4,6,8]] # Expected output: [1,3,5,7,9,2,4,6,8] list1 = [1,3,5,7,9,10] list2 = [2,4,6,8] list1[-1:]=list2 print(list1)
true
c309e2fdf79e7ff8f27aa7c01ac4fe94d15fda8c
gandhalik/PythonCA2020-Assignments
/Task 4/3.py
509
4.65625
5
# Write a program to Python find out the character in a string which is uppercase using list comprehension. # Using list comprehension + isupper() # initializing string test_str = input("The sentence is: ") # printing original string print("The original string is : " + str(test_str)) # Extract Upper Case ...
true
44ed2cbea71e26cf87bebedb491deb1ea1e00574
DRay22/COOP2018
/Chapter08/U08_Ex06_PrimeLessEqual.py
1,489
4.3125
4
# U08_Ex06_PrimeLessEqual.py # # Author: # Course: Coding for OOP # Section: A2 # Date: 21 Mar 2019 # IDE: PyCharm # # Assignment Info # Exercise: Name and Number # Source: Python Programming # Chapter: # # # Program Description # This program will find prime numbers less or equal to n, a user input...
true
61d62433a082758c56de60870e8b63ec97f2c397
DRay22/COOP2018
/Chapter04/U04_Ex07_CircleGraphics.py
2,381
4.46875
4
# U04_Ex07_CircleGraphics.py # # Author: Donovan Ray # Course: Coding for OOP # Section: A2 # Date: 29 Oct 2018 # IDE: PyCharm # # Assignment Info # Exercise: Circle Graphics Ex07 # Source: Python Programming # Chapter: #04 # # Program Description # This program will make a circle with a user specif...
true
dabc27a62b7c1b993cece699ae98f7cfe8b1d8a1
DRay22/COOP2018
/Chapter06/U06_Ex06_Area_of_Tri_Modular.py
1,361
4.4375
4
# U06_Ex06_Area_of_Tri_Modular.py # # Author: Donovan Ray # Course: Coding for OOP # Section: A2 # Date: 17 Jan 2019 # IDE: PyCharm # # Assignment Info # Exercise: Area of Triangle 06 # Source: Python Programming # Chapter: #06 # # Program Description # This program will find the area of a triangle th...
true
6429e95316a74a6e65933c62d121395da234e974
DRay22/COOP2018
/Chapter04/U04_Ex09_CustomRectangle.py
1,814
4.25
4
# U04_Ex09_CustomRectangle.py # # Author: Donovan Ray # Course: Coding for OOP # Section: A2 # Date: 29 Oct 2018 # IDE: PyCharm # # Assignment Info # Exercise: Custom Rectangle Ex09 # Source: Python Programming # Chapter: #04 # # Program Description # This program will draw a rectangle based off of ...
true
b2468f3a4cc6e93daeabb9b8fbda27b2049c86ff
avikram553/Basics-of-Python
/string.py
458
4.34375
4
str = 'Hello World!' print(str) # Prints complete string print(str[0]) # Prints first character of the string print(str[2:7]) # Prints characters starting from 3rd to 5th print(str[2:]) # Prints string starting from 3rd character print(str * 2) # Prints string two times print(str + "T...
true
ab9c2b816a1713a162ef9500f7c00927fd2edd9e
luohaha66/MyCode
/python/python_magic_method/repreesent_class.py
2,434
4.4375
4
""" In Python, there’s a few methods that you can implement in your class definition to customize how built in functions that return representations of your class behave __str__(self) Defines behavior for when str() is called on an instance of your class. __repr__(self) Defines behavior for when repr() is called on an...
true
f08ec6439bfbcc2bef9ae906a869c157c60217ca
kjnevin/python
/09.Dictionaries P2/__init__.py
1,231
4.1875
4
fruit = {"Orange": "a sweet, orange citrus fruit", "Apple": "Round fruit used to make cider", "Banana": "Yellow fruit, used to make sandwiches", "Pear": "Wired shaped fruit", "Lime": "a sour green fruit"} # while True: # dict_keys = input("Please enter a piece of fruit:...
true
83813a6fc6389bc8839f0eb52c5f318a9361c819
MunavarHussain/Learning-Python
/Basics/io.py
1,177
4.125
4
''' print() and input() are basic stdio write and read functions respectively. let's see some examples to understand both functions, its usage and capabilities. ''' print('hello world') var = 10 # var is not a keyword in python print('The value of variable var is',var) ''' Output: hello world The value of variable v...
true
b73ae3d97ace11943c5ec19124c0370d840304ac
MunavarHussain/Learning-Python
/OOP/classes_instances.py
1,544
4.1875
4
#Tutorial 1 - Understanding classes and instances '''Object oriented programming is a way of programming, that in its unique way allows us to group data based on objects.It is indeed inspired from real world. In tutorial 1 we'll learn about class and instances. Classes are blueprint associated with some data and func...
true
b4b63b5670446d080a5de26eb6a6944737480559
mjfeigles/technical_interview_practice
/arraysAndStrings/rotate_matrix.py
1,239
4.15625
4
#input: n x n matrix as 2D array #output: the same matrix rotated 90 degrees #Run instructions: #python3 rotate_matrix.py matrix1 # Example matrix1: (can include spaces or not; must be n x n) # [[1, 2], [3, 4]] # [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] import sys import math def matrixRotate(matrix): ...
true
b03687696d732833496fbee14822b706ea6f1aa9
gaurishanker/learn-python-the-hard-way
/ex3.py
675
4.3125
4
#first comment print("I will now count my chickens:") #counting hens print("Hens", 25 + 30 / 6) print("Roosters", 100 - 25 * 3 % 4) print("Now I will count the eggs:") #an expression it will be evaluated as first 1/4 = 0.25 then from left to write # poit to note 1 + 4 % 2 is 1. print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6...
true
95ca0c279386ff25f693abab8c1a57a83816b08b
zeroam/TIL
/algorithm/insertion_sort.py
497
4.1875
4
def insertion_sort(arr: list) -> None: """삽입 정렬 알고리즘 각 값이 어떤 위치에 가야할 지 찾음 :param arr: 정렬할 리스트 """ for i in range(1, len(arr)): element = arr[i] j = i - 1 while j >= 0 and element < arr[j]: arr[j+1] = arr[j] j -= 1 arr[j+1] = element if __name...
false
2ce129db9c61fc233a8fffa7508b612e0c079dcc
Souji9533/Mycode
/python/simpiy.py
229
4.15625
4
num = 'week' print(type(num)) empty_list=list() #empty_tuple=tuple[] #empty_set=set{} #this is not empty set this is empty dictiory student = {'name' : 'john', 'age' : 23, 'courses' :['cse','ece','eee']} print(student['age'])
false
f975cdbc75ee254825989d79556328ab5b7c9ae5
19sblanco/cs1-projects
/futureDay.py
2,310
4.4375
4
''' requirement specification: have user play a game of rock paper scissors against a 'random' computer ''' ''' system anaysis: user inputs ''' ''' system design: 1. have user input 0, 1, or 2 (represents scissor, rock and paper) respectively 2. store number 1 as value 3. have computer randomly choose number between...
true
aaf71b8b743424126b75802724ea47942bfa7df6
LibbyExley/python-challenges
/FizzBuzz.py
492
4.1875
4
""" Write a program that prints the numbers from 1 to 100. If it’s a multiple of 3, it should print “Fizz”. If it’s a multiple of 5, it should print “Buzz”. If it’s a multiple of 3 and 5, it should print “Fizz Buzz”. """ numbers = list(range(1,101)) for number in numbers: if number % 5 == 0 and number % 3 == 0: ...
true
2895873d8b4e03ecd2a78284ab1978ee1725673f
MudassirASD/darshita..bheda
/.py
261
4.21875
4
n=int(input("Enter a number:")) if n>0: print("The number is positive") elif n<0: print("The number is negative:") else: print("The number is zero") def n=int(input("Enter the 1st integer:")) m=int(input("Enter the 2nd integer:"))
true
5592f7ca20d84a53346ad430715aefa58daeda17
ovjohn/masterPython
/12-Modulos/main.py
1,093
4.125
4
""" Modulos: Son funcionalidades ya hechas para reutilizar En la documentacion de Python existen muchos modulos para ser consultadas y utilizadas. Podemos conseguir modulos que ya vienen en el lenguaje, modulos de internet o tambien podemos CREAR nuestros modulos """ #LLamando los Modulos #import mimodulo #Importando...
false
8397c08437aedea80cd0ee729f98c9ffcbd17648
bradandre/Python-Projects
/College/Homework Programs/November 25th/One.py
899
4.375
4
#Initial list creation colors = ["red", "black", "orange"] #Appending new items to the list for c in ("yellow", "green", "blue", "indigo", "violet"): colors.append(c) #Removing the color black from the list colors.remove("black") #Outputting the third element print("Third element: {0}".format(colors[2])) #Outputti...
true
54678d9ea9aa057adc9cb30b354902ee1905e203
sokhij3/210CT-Coursework
/Question 10.py
1,249
4.21875
4
#Q - Given a sequence of n integer numbers, extract the sub-sequence of maximum length # which is in ascending order. l = input("Please input a list of integers: ") lis = list(map(int, l)) #map() function makes each iterable in the list lis an int def ascendingOrder(lis): temp = [] maxSeq = [0] ...
true
53e4a8503866e93d0895a1d012f2bedc6855803e
munikarmanish/cse5311
/algorithms/min_spanning_tree/prim.py
768
4.1875
4
""" Implementation of the Prim's algorithm to find the minimum spanning tree (MST) of a graph. """ from data_structures.heap import Heap def prim(G, root=None): """ Find the minimim spanning tree of a graph using Prim's algorithm. If root is given, use it as the starting node. """ nodes = Heap([(...
true
e4c25b4bf3e65511806a091af990dd9d6608b66f
Steven98788/Ch.08_Lists_Strings
/8.3_Adventure.py
2,609
4.21875
4
''' ADVENTURE PROGRAM ----------------- 1.) Use the pseudo-code on the website to help you set up the basic move through the house program 2.) Print off a physical map for players to use with your program 3.) Expand your program to make it a real adventure game ''' room_list=[] current_room=0 inventory = [] done= Fals...
true
8139cd54762564ee4824367d4a1c96ff0a199c1c
thread13/shpy-1
/demo00.py
612
4.1875
4
#!/usr/bin/python2.7 -u import sys # prints range between first two args and points at third arg if in range a = sys.argv[1] b = sys.argv[2] c = sys.argv[3] if (int(a) < int(b)): while (int(a) <= int(b)): # range up if (int(a) == int(c)): print str(a) + ' <<' else: ...
true
745ba7865afa129f13720c0d8d2f98ad5ebcfb8e
carefing/PythonStudy
/basics/clock.py
844
4.125
4
""" Define Clock and show clock time """ import time class Clock(object): def __init__(self, **hms): if 'hour' in hms and 'minute' in hms and 'second' in hms: self._hour = hms['hour'] self._minute = hms['minute'] self._second = hms['second'] else: tm = time.localtime(time.time()) self._hour = tm....
false
edfa5113c29949ee7567d472fc85021e395f8a13
SKVollala/PYTHON_REPO
/experienceCalc.py
717
4.25
4
""" This program calculates the age/experience in years, months, and days format Input: Asks the user to enter a date in YYYY-MM-DD format Output: Calculates and prints the experience in years, months, and days """ from datetime import date from dateutil.relativedelta import relativedelta def ...
true
6b99166a38563d7948c26b2fd571879a84c86b0b
mindnhand/Learning-Python-5th
/Chapter17.Scopes/nested_default_lambda.py
756
4.15625
4
#!/usr/bin/env python3 #encoding=utf-8 #------------------------------------------ # Usage: python3 nested_default_lambda.py # Description: nested scope and default argument #------------------------------------------ # nested scope rules def func(): # it works because of the nested scop...
true
835a6fde6e06b9253e64d2cdc22108df356abd07
mindnhand/Learning-Python-5th
/Chapter34.ExceptionCodingDetails/2-try-finally.py
1,169
4.15625
4
#!/usr/bin/env python3 #encoding=utf-8 #--------------------------------------- # Usage: python3 2-try_finally.py # Description: try-finally to do some cleanup jobs #--------------------------------------- ''' When the function in this code raises its exception, the control flow jumps back and runs the finally bl...
true
e5b34e73ebee7acbfda4bfab71c5dbaf4e039943
mindnhand/Learning-Python-5th
/Chapter31.DesigningWithClasses/converters.py
2,457
4.21875
4
#!/usr/bin/env python3 #encoding=utf-8 #--------------------------------------------- # Usage: python3 converters.py # Description: compostion and inheritance #--------------------------------------------- from streams import Processor class Uppercase(Processor): def converter(self, data): return da...
true
35739c614d955ff51bc8013a63450ae242870584
godsonezeaka/Repository
/PythonApp/stringFunctions.py
854
4.375
4
# String functions myStr = 'HelloWorld' # Capitalize print(myStr.capitalize()) # Swap case print(myStr.swapcase()) # Get length print(len(myStr)) # Replace print(myStr.replace('World', 'Everyone')) #Count - allows you to count the number of occurrences of a substring in a given string sub = 'l' print(myStr.count(...
true