blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
b5d3beb20cc86479f91f35db74f4f4a87bd54dc4
KishoreMayank/CodingChallenges
/Interview Cake/Stacks and Queues/MaxStack.py
821
4.3125
4
''' Max Stack: Use your Stack class to implement a new class MaxStack with a method get_max() that returns the largest element in the stack. ''' class MaxStack(object): def __init__(self): self.stack = [] self.max = [] def push(self, item): """Add a new item to the top o...
true
c7a5d62ff9c478f7430982313345c1f0adb82459
kanatnadyrbekov/Ch1Part2-Task-31
/task31.py
470
4.28125
4
# Напишите функцию которая подсчитает количество строк, слов и букв в текстовом # файле. text = """Hello my name is Kanat, and I study in Maker's course mjdbvzjk zkjvasukz ksbvzu ubvu jbvab ajbvuzb """ string = text.count("\n") print(f"Text has: {string + 1} string") words = ' ' a = text.count(words)+1 print(f"Text has...
false
158b7350e9ad0138b32882cc0f3e1cee08ddde6f
wakabayashiryo/Library
/python/Practice/function.py
1,071
4.125
4
#動物の最高速度を辞書型で定義 animal_speed_dict = { "チーター":110,"トナカイ":80, "シマウマ":60,"ライオン":58, "キ リ ン":50,"ラ ク ダ":30, } #東京から各都市までの距離を辞書型で定義 distance_dict = { "静 岡":183.7, "名古屋":350.6, "大 阪":507.5, } #時間を計算する関数を定義 def calc_time(dist,speed): t = dist /speed t = round(t,1) return t #動物の各都市までの時間を...
false
95b549c39072f6cc6ad2cab9602f9522ff012079
tamanna-c/Python-Internship
/Day2.py
1,490
4.25
4
#Task-1 """print("Hello World")""" ''' This is an example of multiline comment''' """ This is also an example of multiline comment""" #Task-2 """ a=10 b=20.5 c="Tamanna" print(a) print("Value of b is:",b) print("My name is",c)""" #Task-3 """name="Tamanna" print("Name is:",name) #assigning a new va...
false
047638de234a37c895d55b1aa6f571f72d2c9f4c
stellakaniaru/practice_solutions
/learn-python-the-hard-way/ex16.py
877
4.3125
4
'''Reading and writing files''' from sys import argv script, filename = argv print "We're going to erase %r."%filename print "If you don't want that, hit CTRL-C(^C)." print "If you don't want that, hit RETURN." raw_input("?") print "Opening the file..." target = open(filename, 'w') #when you open the file in writ...
true
e670461879bb35a19b25ef3b8ca5364d2fd3c007
stellakaniaru/practice_solutions
/dict_learn.py
266
4.15625
4
''' A program that iterates through dict items and prints them out. ''' classmates = {'Mary :' : ' Sweet but talks too much', 'stella :' : ' cool,calm and collected', 'Mark :' : ' code ninja on the block'} for k, v in classmates.items(): print(k + v)
false
b1025eb52f8c374fecd1458fe6e151f38eb8ec1a
stellakaniaru/practice_solutions
/overlapping.py
500
4.1875
4
''' Define a function that takes in two lists and returns True if they have one member in common.False if otherwise. Use two nested for loops. ''' #function definition def overlapping(list1, list2): #loop through items in first list for i in list1: #loop through items in second list for j in list2: #check...
true
5b49cf35ea8a0c178691c729f4275a93519be37c
stellakaniaru/practice_solutions
/learn-python-the-hard-way/ex7.py
849
4.40625
4
'''more printing''' #prints out a statement print 'Mary had a little lamb.' #prints out a statement with a string print 'Its fleece was as white as %s.'%'snow' #prints out a statement print 'And everywhere that Mary went.' print '.' * 10 #prints a line of ten dots to form a break #assigns variables with a characte...
true
053d3a417ab0f05a201f9999917babd870869561
stellakaniaru/practice_solutions
/years.py
664
4.25
4
''' Create a program that asks the user to enter their name and age. Print out a message addressed to them that tells them the year they will turn 100 years old. ''' from datetime import date #ask for user input on name and age name = input('Enter your name: ') age = int(input('Enter your age: ')) num = int(input('...
true
1f42e53223e2ec4d0ce3f185cf5e4919985e0f0c
stellakaniaru/practice_solutions
/max_three.py
364
4.3125
4
''' Define a function that takes in three numbers as arguments and returns the largest of them. ''' #function definition def max_of_three(x,y,z): #check if x if the largest if x > y and x > z: return x #check if y is the largest elif y > x and y > z: return y #if the first two conditions arent met,z becom...
true
d3b3b842686d62d102ef89dfdffb0fefdc834343
prabhatpal77/Adv-python-oops
/refvar.py
475
4.1875
4
# Through the reference variable we can put the data into the object, we can get the data from the object # and we can call the methods on the object. # We can creste a number of objects for a class. Two different object of a same class or different classes # does not contain same address. class Test: """sample cla...
true
80d0dafe8c5f6604e94c34dca7d6aeefc9acbf9b
prabhatpal77/Adv-python-oops
/abstraction4.py
543
4.125
4
# We can access the hidden properties of a super class within the subclass through special syntax. class X: __a=1000 def __init__(self): self.__b=2000 def __m1(self): print("in m1 of x") class Y(X): __c=3000 def __init__(self): self.__d=4000 super().__init__() def...
false
69996ed2547992a8a7b8eb86e554740f0ac3647b
IrinaVladimirTkachenko/Python_IdeaProjects_Course_EDU
/Python3/TryExcept/else_finaly.py
855
4.34375
4
# If we have an error - except block fires and else block doesn't fire # If we haven't an error - else block fires and except block doesn't fire # Finally block fires anyway #while True: # try: # number = int(input('Enter some number')) # print(number / 2) #except: # print('You have to ent...
true
b7c8c1f93678be20578422e02e01adeba36041f9
Ballan9/CP1404-pracs
/Prac01/asciiTable.py
420
4.25
4
LOWER = 33 UPPER = 127 print("Enter a character:") character = input() print("The ASCII code for g is", ord(character)) number = int(input("Enter a number between {} and {}:".format(LOWER,UPPER))) if number < LOWER or number > UPPER: print("Invalid number entered") else: print("The Character for {} is ".format...
true
82b1b76a67d899523d77c2ee9d6fdea0812cbd67
catherinelee274/Girls-Who-Code-2016
/Python Projects/fahrenheittocelsius.py
356
4.28125
4
degree = input("Convert to Fahrenheit or celsius? For fahrenheit type 'f', for celsius type 'c'") value = input("Insert temperature value: ") value =int(value) if degree == "c": value = value-32 value = value/1.8 print(value) elif degree == "f": value = value*1.8 + 32 print(value) else:...
true
77a30e9dc9d474a27928153ebef45acfccfcbbfa
kononeddiesto/Skillbox-work
/Module20/07_sort_function/main.py
306
4.25
4
def sort(some_tuple): for i_int in some_tuple: if type(i_int) != int: return some_tuple elif type(i_int) == int and i_int == some_tuple[-1]: new_tuple = sorted(list(some_tuple)) return tuple(new_tuple) my_tuple = (4, 3, 2, 1) print(sort(my_tuple))
false
c42c463b4cc15dce457eb07ff2338d8e9c52c391
kononeddiesto/Skillbox-work
/Module18/13_anagram/main.py
384
4.125
4
first_word = list(input('Введите 1 слово:')) second_word = input('Введите 2 слово:') for i in second_word: if i in first_word: first_word.remove(i) if not first_word: print('Слова являются анаграммами друг друга') else: print('Слова не являются анаграммами друг друга')
false
3775cb6c2e02e1b142b14ef88f2cadd57fd47d3e
blakerbuchanan/algos_and_data_structures
/datastructures/datastructures/queues.py
697
4.1875
4
# Impelement a queue in Python # Makes use of the list data structure inherent to Python class Queue: def __init__(self): self.Q = [] def remove(self): try: self.Q.pop(0) except: print("Error: queue is empty.") def add(self, item): self.Q.append(ite...
true
54785e654145533309b1197a6f17aea09a8d7b28
go1227/PythonLinkedLists
/DoubleLinkedList.py
1,655
4.1875
4
__author__ = "Gil Ortiz" __version__ = "1.0" __date_last_modification__ = "4/7/2019" __python_version__ = "3" #Double Linked List class Node: def __init__(self, data, prev, next): self.data = data self.prev = prev self.next = next class DoubleList: head = None tail = None d...
true
56bfaaa56ffb54a986b9d7ea862cb670405b785e
carloslorenzovilla/21NumberGame
/main.py
2,291
4.34375
4
""" Created on Sun Jul 14 10:17:48 2019 @author: Carlos Villa """ import numpy as np # This game is a take on a 21 Card Trick. 21 numbers are randomly placed # in a 7x3 matrix. The player thinks of a number and enters the column that # the number is in. This step is repeated three times. Finally, the number # that t...
true
f7e6ef2007bcea37aa7aa2d7ba71a125b0bde471
yulyzulu/holbertonschool-web_back_end
/0x00-python_variable_annotations/7-to_kv.py
442
4.15625
4
#!/usr/bin/env python3 """Complex types""" from typing import Tuple, Union def to_kv(k: str, v: Union[int, float]) -> Tuple[str, float]: """ type-annotated function to_kv that takes a string k and an int OR float v as arguments and returns a tuple. The first element of the tuple is the string k. ...
true
5e1816ef1384ba6d66df4cd9639bbcd08a4e4805
jaeheon-lee/pre-education
/quiz/pre_python_02.py
1,010
4.15625
4
""""2.if문을 이용해 첫번째와 두번 수, 연산기호를 입력하게 하여 계산값이 나오는 계산기를 만드시오 예시 <입력> 첫 번째 수를 입력하세요 : 10 두 번째 수를 입력하세요 : 15 어떤 연산을 하실 건가요? : * <출력> 150 """ def calculator(a,b,c): if c == '*': print(a*b) elif c =='/': if b == 0: print('0으로 나눌 수 없습니다.') b= int(input('두 번째 수를 입력하세요.:')) ...
false
d4d47e92f11fbac4d36867562b0616dd8fad565e
je-castelan/Algorithms_Python
/Python_50_questions/10 LinkedList/merge_sorted_list.py
1,009
4.1875
4
""" Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists. """ from single_list import Node def mergeTwoLists(l1, l2): newList = Node(0,None) pos = newList while (l1 and l2): if l1.value < l2.value: ...
true
42ea8bfbfab0cda471b19eb65d3981a235888341
je-castelan/Algorithms_Python
/Python_50_questions/19 Tree Graphs/max_path_sum.py
1,457
4.125
4
""" A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node's values in the path. Given th...
true
6c8974807d165228b8465c8fbf0f469b7d6ac8c6
dmoncada/python-playground
/stack.py
1,359
4.1875
4
class Stack: '''A simple, generic stack data structure.''' class StackNode: def __init__(self, item, next_node): self.item = item self.next = next_node class EmptyStackException(Exception): pass def __init__(self): '''Initializes self.''' self....
true
c122d2a776f88be7797cfbd7768db9be8e54e8a3
murthyadivi/python-scripts
/Prime number check.py
864
4.1875
4
# returns the number input by user def input_number(prompt): return int(input(prompt)) # Checks if the given number is a primer or not def check_prime(number): #Default primes if number == 1: prime = False elif number == 2: prime = True #Test for all all ...
true
da4be3a59e10efd46c69195b9f9839561e9039de
TaoCurry/Basic_Python3
/高阶函数/埃拉托色尼筛选法.py
499
4.15625
4
#!/usr/bin/env python3 #-*- coding:utf-8 -*- def _is_odd(): n = 1 while True: n = n + 2 #筛选出奇数 yield n def _not_divisible(n): #筛选函数 return lambda x: x % n > 0 def primes(): yield 2 it = _is_odd() #初始序列,3开始的奇数 while True: n = next(it) #返回序列的第一个数 yiel...
false
e2fdeb9dfe2706ee3eee86e871f49b4df3c8ae92
yuanyuanzijin/Offer-in-Python
/排序算法/insertion_sort.py
1,142
4.28125
4
""" 插入排序(Insertion Sort) 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。 算法描述 一般来说,插入排序都采用in-place在数组上实现。具体算法描述如下: 从第一个元素开始,该元素可以认为已经被排序; 取出下一个元素,在已经排序的元素序列中从后向前扫描; 如果该元素(已排序)大于新元素,将该元素移到下一位置; 重复步骤3,直到找到已排序的元素小于或者等于新元素的位置; 将新元素插入到该位置后; 重复步骤2~5。 """ def insertion(array): for...
false
eba206f339e529b0c09661825ef6b4d24a36808a
AlexHoang2012/hoangtheduong-python-D4E12
/Session2/Homeworks/Homework2.py
356
4.15625
4
print("BMI calculation") h = int(input("Please input your height (cm): ")) w = int(input("Please input your weight (kg): ")) BMI= w/(h*h/10000) print("Your BMI is: ",BMI) if(BMI<16): print("Severely underweight") elif(BMI<18.5): print("underweight") elif(BMI<25): print("Normal") elif(BMI<30): print("Ov...
false
3e8715e64fe0540e8b00d7c28567773c3a8b178c
Krishan00007/Python_practicals
/AI_ML_visulizations/ML_linear_regression.py
1,873
4.15625
4
import warnings warnings.filterwarnings(action="ignore") # Practical implementation of Linear Regression # ----------------------------------------------- import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression def get_data(filename): dataframe = pd.read_csv(fil...
true
61c414f192b860ad7fd4f392ce611b22d58d0f98
Krishan00007/Python_practicals
/practical_6(2).py
2,141
4.28125
4
""" Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. These components should be arranged in a grid where the labels occupy the first row and the corresponding fields occu...
true
d8c97706c79eaeff2111524b111e3a25753176b7
Krishan00007/Python_practicals
/AI_ML_visulizations/value_fill.py
1,035
4.34375
4
# Filling a null values using interpolate() method #using interpolate() functon to fill missing values using Linear method import pandas as pd # Creating the dataframe df = pd.DataFrame( { "A": [12, 4, 5, None, 1], "B": [None, 2, 54, 3, None], ...
true
23c50555c6cf85b3157b30c463e390d4b374d50c
Krishan00007/Python_practicals
/practical_3(1).py
2,229
4.78125
5
""" A bit shift is a procedure whereby the bits in a bit string are moved to the left or to the right. For example, we can shift the bits in the string 1011 two places to the left to produce the string 1110. Note that the leftmost two bits are wrapped around to the right side of the string in this operation. Def...
true
14c47f156cf416431864448d62d3f27918d5226b
PNai07/Python_1st_homework
/02_datatypes.py
1,888
4.5625
5
# Data Types # Computers are stupid #They doi not understand context, and we need to be specific with data types. #Strings # List of Characters bundled together in a specific order #Using Index print('hello') print(type('hello')) #Concatenation of Strings - joining of two strings string_a = 'hello there' name_perso...
true
9908be12de460b5cb7a690eae3b9030e8422e8a2
PNai07/Python_1st_homework
/06_datatypes_booleans.py
1,426
4.5625
5
# Booleans # Booleans are a data type that is either TRUE or FALSE var_true = True var_false = False #Syntax is capital letter print(type(var_true)) print(type(var_false)) # When we equate/ evaluate something we get a boolean as a response. # Logical operator return boolean # == / ! / <> / >= / <= weather = 'Rain...
true
53e2fc8c6c8ba4b78ad525d40a369a082611cb30
Parth731/Python-Tutorial
/Quiz/4_Quiz.py
264
4.125
4
# break and continue satement use in one loop while (True): print("Enter Integer number") num = int(input()) if num < 100: print("Print try again\n") continue else: print("congrautlation you input is 100\n") break
true
9641bd85b9168ca13ea4e70c287dd703d3f7c19c
Parth731/Python-Tutorial
/Exercise/2_Faulty_Calculator.py
920
4.1875
4
#Exercise 2 - Faulty Calculator # 45*3 = 555, 56+9 = 77 , 56/6 = 4 # Design a caluclator which will correctly solve all the problems except # the following ones: # Your program should take operator and the two numbers as input from the user and then return the result print("+ Addition") print("- Subtraction") print("...
true
0a5b0d751a1fcbfa086452b6076527668aa4fcbc
shrobinson/python-problems-and-solutions
/series (2,11).py
365
4.28125
4
#Given two integers A and B. Print all numbers from A to B inclusively, in ascending order, if A < B, or in descending order, if A ≥ B. #Recommendation. Use for loops. #For example, on input #4 #2 #output must be #4 3 2 A = int(input()) B = int(input()) if A < B: for i in range(A, B+1): print(i) else: for i...
true
bb4b6083ef0eca3abca1627acfab5a77dd0bc485
shrobinson/python-problems-and-solutions
/length_of_sequence (2,4).py
394
4.1875
4
#Given a sequence of non-negative integers, where each number is written in a separate line. Determine the length of the sequence, where the sequence ends when the integer is equal to 0. Print the length of the sequence (not counting the integer 0). #For example, on input #3 #2 #7 #0 #output should be #3 n = int(inp...
true
608a587c0123d50950fb43f3321572f01a2450e2
shrobinson/python-problems-and-solutions
/countries_and_cities (3,18).py
855
4.28125
4
#First line of the input is a number, which indicates how many pairs of words will follow (each pair in a separate line). The pairs are of the form COUNTRY CITY specifying in which country a city is located. The last line is the name of a city. Print the number of cities that are located in the same country as this cit...
true
28150f1848962980561507ee3bf9a41804f3e564
shrobinson/python-problems-and-solutions
/leap_year (1,13).py
508
4.15625
4
#Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON. #The rules in Gregorian calendar are as follows: #a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100 #a year is always a leap year if its number is exactly...
true
40861b19351648b058fee1f74ff2ce0d236808ab
chiefmky/ArrayAndStringProblem
/StringCompression.py
798
4.1875
4
#Implement a method to perform basic string compression using count of repeated characters #input:aabcccccaaa #output:a2b1c5a3 def compression(astr): # aabcccccaa ch = astr[0] count = 1 ans = "" for i in range(1, len(astr)): if ch == astr[i]: count += 1 else: ...
false
a7a8ba21ad69cd68dc8ab7d57faf2cd40681524f
Get2dacode/python_projects
/quickSort.py
1,180
4.15625
4
def quicksort(arr,left,right): if left < right: #splitting our array partition_pos = partition(arr,left,right) quicksort(arr,left, partition_pos - 1) quicksort(arr,partition_pos+1,right) def partition(arr,left,right): i = left j = right -1 pivot = arr[right] while i < j: ...
true
e10519c39e2ee2eb03adf844eda3d6ea6c0ed891
soumyaracherla/python-programs
/tenth.py
662
4.28125
4
fruits=['mango', 'apple', 'banana'] print(fruits) print(fruits[2]) print(fruits[-2]) # list print(fruits.index("apple")) fruits.append('grapes') print(fruits) # append operation vegetables=['onion', 'carrot', 'beetroot', 'tomato'] fruits.extend(vegetables) print(fruits) # extend operation fruits.insert(2,'pinea...
false
7b145f2578ad8e7a8b78b3230f38631bdc1f76c7
aadilkadiwal/Guess_game
/user_guess.py
651
4.15625
4
# Number guess by User import random def user_guess(number): random_number = random.randint(1, number) guess = 0 guess_count = 0 while guess != random_number: guess = int(input(f'Guess the number between 1 and {number}: ')) guess_count += 1 if guess > random_number: ...
true
b4f271e3a902188ce99905547ebcf43d52261f50
niloy-biswas/OOP-Data-structure-Algorithm
/oop.py
2,673
4.15625
4
class Person: def __init__(self, name: str, age: int, birth_year: int, gender=None): self.name = name # Person has a name // has a relation with instance self.__age = age self.__birth_year = birth_year # Private variable / Data encapsulation self.gender = gender def get_name(s...
true
2c758cd5b6825ae199112690ac55dc7e229f782d
ritopa08/Data-Structure
/array_rev.py
867
4.375
4
'''-----Arrays - DS: An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, , of size , each memory location has some unique index, (where ), that can be referenced as (you may also see it written as ). Given an array, , of integers, print each ele...
true
a87621ac4cb9c506b514ee5c6f69796330c92237
pratibashan/Day4_Assignments
/factorial.py
261
4.25
4
#Finding a factorial of a given no. user_number =int(input("Enter a number to find the factorial value: ")) factorial = 1 for index in range(1,(user_number+1)): factorial *= index print (f"The factorial value of a given number is {factorial}")
true
6671ca404f704cf143d719c60f030eddf9a48b8d
vasudhanapa/Assignment-2
/assignment 2.py
750
4.40625
4
#!/usr/bin/env python # coding: utf-8 # 1. Write a program which accepts a sequence of comma-separated numbers from console and generate a list. # 1. Create the below pattern using nested for loop in Python. # * # * * # * * * # * * * * # * * * * * # * * * * # * * * # * * # * # # In[1]: num1 = 1 num2 = ...
true
9709680af1eeef88c1b8472142c5f85b9003114c
AmitAps/advance-python
/generators/generator7.py
860
4.5
4
""" Understanding the Python Yield Statement. """ def multi_yield(): yield_str = "This will print the first string" yield yield_str yield_str = "This will print the second string" yield yield_str multi_obj = iter(multi_yield()) while True: try: prt = next(multi_obj) print(prt) ...
true
9f311f33adbc0a2fb31ffc1adb014bb66de0fb2b
AmitAps/advance-python
/oop/class2.py
337
4.15625
4
class Dog: #class attribute species = 'Canis familiaris' def __init__(self, name, age): self.name = name self.age = age """ Use class attributes to define properties that should have the same value for every class instance. Use instance attributes for properties that vary from one instance...
true
42f8e41488f1de16d53ced9f76053374fe5ce4a3
AmitAps/advance-python
/instance_class_and_static_method/fourth_class.py
1,073
4.15625
4
import math class Pizza: def __init__(self, radius, ingredients): self.radius = radius self.ingredients = ingredients def __repr__(self): return (f'Pizza({self.radius!r}, ' f'{self.ingredients!r})') def area(self): return self.circle_area(self.radius) ...
true
a4a9466ca29261aff4264cd4d2c565df7c19a0fa
AmitAps/advance-python
/dog-park-example.py
703
4.5
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Nov 22 09:25:55 2020 @author: aps """ class Dog: species = "Canis familiaris" def __init__(self, name, age, breed): self.name = name self.age = age self.breed = breed # Another instance method def speak(se...
true
c977f10079c4c36333dfc1b33635945b2e469c29
Ayselin/python
/candy_store.py
1,014
4.125
4
candies = { 'gummy worms': 30, 'gum': 40, 'chocolate bars': 50, 'licorice': 60, 'lollipops': 20, } message = input("Enter the number of the option you want to check?: \n1. To check the stock. \n2. How many candies have you sold? \n3. Shipment of new stock.") if message == '1': for candy, ...
true
1788d7fb0349eebc05ab37f91754b18e6ce66b3f
SeshaSusmitha/Data-Structures-and-Algorithms-in-Python
/SelectionSort/selection-sort.py
423
4.3125
4
def insertionSort(array1,length): for i in range(0, length ): min_pos = i; for j in range(i+1, length): if array1[j] < array1[min_pos]: min_pos = j; temp = array1[i]; array1[i] = array1[min_pos]; array1[min_pos] = temp; array1 = [2, 7, 4, 1, 5, 3]; print "Array before Selection sort" print(array1);...
true
4b414735cbd1563ac59a6598279f7a4863723828
zaidITpro/PythonPrograms
/inseritonanddeletionlinklist.py
1,106
4.15625
4
class Node: def __init__(self,data): self.data=data self.next=None class LinkedList: def __init__(self): self.head=None def insert(self,data): if(self.head==None): self.head=Node(data) else: current=self.head while(current.next!=None): current=current.next current.next=Node(data) d...
true
c239eddac5bd840e8c73c44e1da8e3c5e6e794ea
dxn19950918/dxn
/demo2.py
542
4.125
4
#循环语句:有规律切重复操作的语句 #列表 # a = [1,2,3,4] # for i in a : # for 中的in不是判断 # print(i) # #元组 # b = ("123",1,3,4) # for i in b: # print(i) # #字符串变量 # c = "儿童节快乐" # for i in c: # print(i) #字典 d = {"username":"张三","password":"123456"} for i in d: print(i) #i 第一次循环是username #print(d[i]) #下标key值方式取值 prin...
false
b5ddce8fc3ec17161f57cd3b0c51bc964105e383
Raise-hui/Sorting-algorithm
/堆排序.py
2,534
4.375
4
''' 根据升序降序选取不同的堆,一般升序选取大根堆,降序选取小根堆。 1.先将无序的序列构建成一个堆,根据升序降序的需求选取大根还是小根堆。 2.将堆顶元素和末尾元素交换,这样最大的元素就会沉底 3.重新调整结构,使其满足堆的特性。继续交换堆顶和末尾元素,直到整个序列有序。 ''' # 每次在顶更新元素 def push_down(heap, size, u): ''' :param heap: 堆 :param size: 堆的长度 :param u: 当前元素 :return: ''' # t 存的是最大值的索引,即根节点和左右儿子之间的最大值。 # 这里默...
false
294e065c455c87506bc42384c7b95f5c55df9dc6
petr-tik/lpthw
/ex40.py
766
4.125
4
""" classes in python: class name_of_class(object): def __init__(self): self.tangerine = "And now a thousand years between" def apple(self): print "I am classy APPLES!" by instantiating you create objects from classes and you create a mini module, which you can assign to a variable, so you can work with i...
false
e2c32f8e48cb84d2c52db49f4559746ac7a56eae
petr-tik/lpthw
/ex30.py
779
4.15625
4
#-*- coding=utf-8 -*- people = 30 cars = 40 trucks = 15 if cars > people: print "We should take the cars." elif cars < people: print "We should not take the cars." else: print "we cannot decide" if trucks > cars: print "That's too many trucks" elif trucks < cars: print "maybe we could take the trucks" else: p...
true
92fee0692d9bfd860c4235c13ca639065c0bb7ee
petr-tik/lpthw
/ex4.py
1,281
4.25
4
# assign the variable 'cars' a value of 100 cars = 100 # assign the variable 'space_in_a_car' a floating point value of 4.0 space_in_a_car = 4 # assign the variable 'drivers' a value of 30 drivers = 30 # assign the variable 'passengers' a value of 90 passengers = 90 # assign the variable 'cars_not_driven' a value equal...
true
7e4d07ccaffd2671193f8d011a8c209e15a02552
plooney81/python-functions
/madlib_function.py
887
4.46875
4
# create a function that accepts two arguments: a name and a subject # the function should return a string with the name and subject inerpolated in # the function should have default arguments in case the user has ommitted inputs # define our function with default arguments of Pete and computer science for name and su...
true
b41ce62b8a50afdc1fb0fecb58bfe7de4c59d9cd
psukalka/morning_blues
/random_prob/spiral_matrix.py
2,073
4.4375
4
""" Date: 27/06/19 Program to fill (and optionally print) a matrix with numbers from 1 to n^2 in spiral form. Time taken: 24min Time complexity: O(n^2) *) Matrix formed with [[0]*n]*n will result in n copies of same list. Fill matrix elements individually instead. """ from utils.matrix import print_matrix def fill_s...
true
26a29fa5956b9ef81041c2d0496c26fd4eb0ad08
psukalka/morning_blues
/random_prob/matrix_transpose.py
1,037
4.4375
4
""" Given a matrix, rotate it right by 90 degrees in-place (ie with O(1) extra space) Date: 28/06/19 Time Complexity: O(n^2) Time taken: 30 min """ from utils.matrix import create_seq_matrix, print_matrix def transpose_matrix(mat): """ Rotate a matrix by 90 degrees to right. Ex: Original: 1 2...
true
34c5432be9c10152035e994aa7aed5bcc09c28ef
SawonBhattacharya/Python
/dictionary.py
400
4.3125
4
#consists of elements in key value pair form car={"Name": "Ravi", "USN": 102 ,"address": "xcf"} print(car) print(car["USN"]) print(car.get("USN")) #updating value car["USN"]=103 print(car) for x in car.values(): print(x) for x in car: print(x) for x in car.items(): print(x) for x,y in ...
false
54053e477ab116aa59c4a4e52bb3744d28fe56b8
storans/as91896-virtual-pet-ajvl2002
/exercise_pet.py
2,167
4.25
4
# checks if the number entered is between 1-5 or 1,3 or whatever has been stated # check int function def check_int(question, error, low, high): valid = False # while loop while valid == False: number = input("{}".format(question)) try: number = int(number) if low <=...
true
0dba230b503ad68b4fa1c6185a947637633ba7a6
SimonLundell/Udacity
/Intro to Self-Driving Cars/Bayes rule/numpy_examples.py
638
4.375
4
# but how would you print COLUMN 0? In numpy, this is easy import numpy as np np_grid = np.array([ [0, 1, 5], [1, 2, 6], [2, 3, 7], [3, 4, 8] ]) # The ':' usually means "*all values* print(np_grid[:,0]) # What if you wanted to change the shape of the array? # For example, we can turn the 2D grid fr...
true
2c55e90b57860b41171344fcc2d3d1a7e69968b1
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/NumberRelated/DivisbleBy3And5.py
522
4.3125
4
# Divisible by 3 and 5 # The problem # For a given number, find all the numbers smaller than the number. # Numbers should be divisible by 3 and also by 5. try: num = int(input("Enter a number : ")) counter = 0 for i in range(num): if i % 15 == 0: print(f"{i} is divisible by 3 and 5.") ...
true
66af1aa9f857197a90b5a52d0d7e83a5a56f1d35
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/Reverse/ReverseNumber.py
376
4.3125
4
# Reverse a number # The problem # Reverse a number. def reverse_number(num: int) -> int: reverse_num = 0 while num > 0: reverse_num = reverse_num * 10 + num % 10 num //= 10 return reverse_num try: n = int(input("Enter a number : ")) print(f"Reverse of {n} is {reverse_number(n)}")...
true
4a31afea4a442fef55f57d261d0f93298e056efd
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/PrimeNumber/AllPrimes.py
530
4.1875
4
# All Prime Numbers # the problem # Ask the user to enter a number. Then find all the primes up to that number. try: n, p = int(input("Enter a number : ")), 2 all_primes = [False, False] all_primes.extend([True] * (n - 1)) while p ** 2 <= n: if all_primes[p]: for i in range(p * 2, n...
true
e2f84b0a47c1b9c39d804cd95e53820c1e99c47e
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/EasyOnes/TemporaryVariables.py
745
4.5
4
# Swap two variables # The problem # Swap two variables. # # To swap two variables: the value of the first variable will become the value of the second variable. # On the other hand, the value of the second variable will become the value of the first variable. # # Hints # To swap two variables, you can use a temp varia...
true
bc0cdadda198a60507364154b43e3a9088605e08
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/LoopRelated/SecondSmallest.py
848
4.25
4
# Second smallest element # The problem # For a list, find the second smallest element in the list try: size = int(input("Enter the size of the array : ")) user_list = [] unique_ordered = [] if size <= 0: raise ValueError("Size of array must be a non-zero positive integer") if size > 1: ...
true
0bf8f3f1388fc54ef3956e91899841438aca7482
kanuos/solving-https-github.com-ProgrammingHero1-100-plus-python-coding-problems-with-solutions
/PrimeNumber/SmallestPrimeFactor.py
770
4.1875
4
# Smallest prime factor [premium] # The problem # Find the smallest prime factor for the given number. def is_prime(number): number = abs(number) if number == 0 or number == 1: return False for i in range(2, number): if number % i == 0: return False return True def all_fac...
true
6fef789f70be17b87b1d40a9116dd018b0da6274
code-v1/list_exercise
/exercise_one.py
309
4.40625
4
#Create list named 'students' #print out second and last student name students = { 'student1':'berry', 'student2':'pickle', 'student3':'wilder', 'student4':'benny', 'student5':'doddy' } print ('Second student:', students.get('student2')) print ('Last student', students.get('student5'))
false
7bcb73db98b3c593be479799b1c548e8d83bbfed
ParkerCS/ch18-19-exceptions-and-recursions-elizafischer
/recursion_problem_set.py
2,681
4.125
4
''' - Personal investment Create a single recursive function (or more if you wish), which can answer the first three questions below. For each question, make an appropriate call to the function. (5pts each) ''' #1. You have $10000 on a high interest credit card with an APR of 20.0% (calculated MONTHLY, so MPR is APR...
true
41b46b0cbd0b3b8e5a8be106469a82bcfa096b60
koakekuna/pyp-w1-gw-language-detector
/language_detector/main.py
933
4.34375
4
# -*- coding: utf-8 -*- """This is the entry point of the program.""" from languages import LANGUAGES def detect_language(text, languages=LANGUAGES): """Returns the detected language of given text.""" # create dictionary to store counters of words in a language # example --> counters = {"spanish": 29...
true
d9ed893d4df5e5a5fb5819868aab00fc5feaa18e
databoy/processing.py-book
/chapter-08-dictionaries_and_json/dictionaries/dictionaries.pyde
1,438
4.25
4
student = ['Sam', 24] student = {'name': 'Sam', 'age': 24} # accessing dictionaries print(student['age']) # displays: 24 print(student['name']) # displays: Sam print(student) # {'name': 'Sam', 'age': 24} if 'age' in student: print(student['age']) # modifying dictionaries student['age'] = 25 print(s...
false
f70add96e7e82cf95f9f6a8df4f00a25b2a8f17d
ankity09/learn
/Python_The_Hard_Way_Codes/ex32.py
596
4.15625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jul 8 18:40:47 2019 @author: ankityadav """ the_count = [1,2,3,4,5] fruits = ['apples', 'oranges', 'pears', 'apricots'] change = [1, 'pennies', 2, 'dimes', 3, 'quarters' ] for number in the_count: print("This is count {}".format(number)) for fru...
true
eba680e70f99c565a0b95c2d230061034bf24291
tdominic1186/Python_Crash_Course
/Ch_3_Lists/seeing_the_world_3-5.py
833
4.40625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Feb 8 20:56:36 2018 @author: Tony_MBP """ places = ['new zealand', 'canada', 'uk', 'australia', 'japan'] print(places) #use sorted to to print list alphabetically w/o modifying list print(sorted(places)) #show list is still in same original order prin...
true
7e9f1fe1a143bd90aea5e8478c703ec8bc980a59
tdominic1186/Python_Crash_Course
/Ch_9_Classes/number_served.py
2,193
4.5
4
''' Start with your program from Exercise 9-1 (page 166). Add an attribute called number_served with a default value of 0. x Create an instance called restaurant from this class. x Print the number of customers the restaurant has served, and then change this value and print it again. x Add a method called set_numb...
true
fe45487f19bd0c0e402cd04b572741b9087d54ab
tdominic1186/Python_Crash_Course
/Ch_9_Classes/login_attempts.py
2,013
4.125
4
""" 9-5. Login Attempts: Add an attribute called login_attempts to your User class from Exercise 9-3 (page 166). x Write a method called increment_login_attempts() that increments the value of login_attempts by 1. x Write another method called reset_login_attempts() that resets the value of login_attempts to 0.x M...
true
153b1a2153121b5d00b452484b9f88d344b73ed6
tdominic1186/Python_Crash_Course
/Ch_8_Functions/unchanged_magicians_8-11.py
1,514
4.53125
5
""" 5/21/18 8-11. Unchanged Magicians: Start with your work from Exercise 8-10. Call the function make_great() with a copy of the list of magicians’ names. Because the original list will be unchanged, return the new list and store it in a separate list. Call show_magicians() with each list to show that you have one lis...
true
d7d65a0c5695274842767e20e5a337db4640d113
tdominic1186/Python_Crash_Course
/Ch_5_if_Statements/stages_of_life_5-6.py
522
4.125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Mar 18 11:58:03 2018 5-6 Stages of life - Write an if-elif-else chain that determines a person's stage of life. @author: Tony_MBP """ age = 65 if age < 2: print("You're a baby.") elif age >= 2 and age < 4: print("You're a toddler.") elif age ...
true
cbc38a58be400e83c18324be9acba86971729545
vladn90/Data_Structures
/heaps/heap_sort_naive.py
797
4.15625
4
""" Naive implementation of heap sort algorithm using Min Heap data structure. """ import random from min_heap_class import MinHeap def heap_sort_naive(array): """ Sorts an array in non-descending order using heap. Doesn't return anything. Time complexity: O(n * lg(n)). Space complexity: O(n), n is len(array)...
true
7c1249777a1cdf09f1da6fb492cc70e85d092ac0
AnjanaPradeepcs/guessmyno-game
/guessmyno.py
541
4.28125
4
import random number=random.randrange(1,10) guess=int(input("guess a number between 1 and 10)) while guess!= number: if guess>number: print("guess a lesser number.Try again") guess=int(input("guess a number between 1 and 10)) else: ...
true
8aee1e37b8d65fb372d200a9fd173abc719d6443
gloriasalas/GWC-Summer-Immersion-Program
/TextAdventure.py
1,549
4.1875
4
start = '''You wake up one morning and find yourself in a big crisis. Trouble has arised and your worst fears have come true. Zoom is out to destroy the world for good. However, a castrophe has happened and now the love of your life is in danger. Which do you decide to save today?''' print(start) done = False ...
true
58578e34604e68fc5b8fd9315959316a62a94c21
lward27/Python_Programs
/echo.py
240
4.125
4
#prec: someString is a string #times is a integer #postc: #prints someString times times to the screen #if times <=0, nothing prints. def repeat(someString, times): if times <= 0: return print someString repeat(someString, times - 1)
true
f6c9d0c94a80bbaa9db1e9bedc041baf70c2f6fd
jjulch/cti110
/P4HW3_NestedLoops_JeremyJulch.py
356
4.3125
4
# Making Nested Loops # 10-17-2019 # CTI-110 PH4HW3-Nested Loops # Jeremy Julch # # Making the first loop for row in range(6): print('#', end='', sep='') # Making the nested loop to create the spaces between the # for spaces in range(row): print( ' ', end='', sep='') # Mak...
true
e37676e882c196756d7af562c25b8fcb53643f0b
cliffjsgit/chapter-10
/exercise108.py
795
4.15625
4
#!/usr/bin/env python3 __author__ = "Your Name" ############################################################################### # # Exercise 10.8 # # # Grading Guidelines: # - Variable "answer" should be the answer to question 1: If there are 23 # students in your class, what are the chances that two of you have the...
true
5dbe2a4b8ff9eb3db18c2031b4205362b7164b18
babuhacker/python_toturial
/Variables/Variables.py
769
4.15625
4
# Global Variables PI = 3.4 # print(PI) # one = 1 # two = 2 # three = 3 one, two, three = 1, 2, 3 # print(one) # print(two) # print(three) two = 4 # print(two) # print(one) Decimal = 1.1 # print(Decimal) StringVar = "Hello" + "1" # print(StringVar) def FunctionName(): newVar = "World" # print(newVar) ...
false
26c421b5e6c299b69a7ff93badb3b01463acbe33
Avenger-py/MiniProjects
/AreaOfPolygon.py
1,338
4.125
4
def polygon(): q=input("Are number of sides of polygon finite? (y/n): ") s=float() pi=3.141592 if q=="y": a=int(input("Enter number of sides of polygon: ")) if a==0 or a==1 or a==2 or a>4: print("Am i a joke to you?") else: if a==3: print("E...
false
b06a2e53ae982a0d013b38968b99d0406aaaffc0
MrSameerKhan/Machine_Learning
/practice/reverse_list.py
1,288
4.40625
4
def reverse_a_list(): my_list = [1,2,3,566,6,7,8] original_list = my_list.copy() list_length = 0 for i in my_list: list_length += 1 for i in range(int(list_length/2)): main_value = my_list[i] mirror_value = my_list[list_length-i-1] my_list[i] = mirror_value ...
true
2c6fb1c822384688dab0f4f14bce369c01a029fb
tretyakovr/Lesson-01
/Task-04.py
1,246
4.15625
4
# Третьяков Роман Викторович # Факультет Geek University Python-разработки # Основы языка Python # Урок 1 # Задание 4: # Пользователь вводит целое положительное число. Найдите самую большую цифру в числе. # Для решения используйте цикл while и арифметические операции. # В теоретической части преподаватель проговорился...
false
2a18cc8fd70105eee7c47def0f4c4b8d1202fd04
weiiiiweiiii/AP-statistic-graphs
/Sources-For-Reference/Programs/Poisson.py
1,155
4.4375
4
# -*- coding: utf-8 -*- from scipy.stats import poisson import numpy as np import matplotlib.pyplot as plt import mpld3 #print "Welcome!" #print "This is a program that can help you plot graphs for poisson distributions" #Using poisson.pmf to create a list #rate = raw_input("Please enter the rate(rate should be an ...
true
3118d09cf3963b943a81b04a96e9729cece878f6
ProfessorJas/Learn_Numpy
/ndarray_shape.py
302
4.46875
4
import numpy as np a = np.array([[1, 2, 3], [4, 5, 6]]) print(a.shape) print() # This resize the array a = np.array([[1, 2, 3], [4, 5, 6]]) a.shape = (3, 2) print(a) print() # Numpy also provides a reshape function to resize an array a = np.array([[1, 2, 3], [4, 5, 6]]) b = a.reshape(3, 2) print(b)
true
bbf33249764feef08abaade1f3a30dec14229b28
KELETOR/health-insurance-costs
/Health care comps.py
1,946
4.125
4
# create the initial variables below age = 28 sex = 0 bmi = 26.2 num_of_children = 3 smoker = 0 # Add insurance estimate formula below insurance_cost = (250 *age) - (128 * sex) + (370 *bmi) + (425 * num_of_children) + (24000 * smoker) - 12500 print(f"This Persons insurance cost is {insurance_cost} dolars\n") ...
false
4e3b1fbdfe12194e77d28b3dcebd47fae42e44c8
dongheelee1/oop
/polymorphism.py
592
4.4375
4
#Polymorphism: #Example of Method Overriding class Animal(object): def __init__(self, name): self.name = name def talk(self): pass class Dog(Animal): def talk(self): print("Woof") class Cat(Animal): def talk(self): print("Meow") cat = Cat('KIT') cat.talk() dog = ...
true
e1aa34deed827d162257d8f4c3bbe65c2bdc7d4e
xuyagang/pycon
/base/001_NameSpace.py
1,148
4.28125
4
# 1.若函数内部有和全局变量的同名变量被赋值,则函数内部的为局部变量,函数外的为全局变量 # 此时函数内和全局变量同名的局部变量一定要先赋值再调用,否则会报错,如例1所示 # (UnboundLocalError: local variable 'a' referenced before assignment) # 例1 # def fun(): # print(a) # a = 'xyz' # print(a) # a = 'abc' # fun() # 结果: # 直接报错 # ------------------------------------------- # 例2 #...
false
ca9e22821f53b36efb8ce3efd97eb82516fa379a
MatPorter/Programowanie-IR
/Zestaw 1/fib_it.py
304
4.25
4
n = int(input("n = ")) def fibonacci(n): f_i_2 = 1 f_i_1 = 1 i = 3 if n == 1 or n == 2: return 1 else: while i in range(3, n+1): f_i = f_i_1 + f_i_2 f_i_2 = f_i_1 f_i_1 = f_i i+=1 return f_i print(fibonacci(n))
false
ad56dc7b368603b7d2592573ed26503dcce41e4b
moncefelmouden/python-project-ui-2018
/dbDemo.py
1,594
4.21875
4
import sqlite3 import os.path def initDatabase(): db=sqlite3.connect('dbDemo.db') sql="create table travel(name text primary key,country text)" db.execute(sql) sql="insert into travel(name,country) values('Korea Ski-ing Winter Tour','Korea')" db.execute(sql) db.commit() db.close() ...
true