blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
b77d9ad34b7ca42a441be75c4ba747a1e68f905a
Techbanerg/TB-learn-Python
/02_DataTypes/List/list_comprehension.py
700
4.34375
4
# This short course breaks down Python list comprehensions for yuo step by step # see how python's comprehensions can be transformed from and to equivalent for loops # so you wil know exactly what's going on behind the scenes # one of the favorite features in Python are list comprehension. # they can seem a bit arcan...
true
83e6ff6c51fbe4792d8436a147a9891d9b7fcb4c
sub7ata/Pattern-Programs-in-Python
/pattern13.py
224
4.125
4
""" Example: Enter the number of rows: 5 A B B C C C D D D D E E E E E """ n = int(input("Enter the number of rows: ")) for i in range(1, n + 1): for j in range(1, i + 1): print(chr(64 + i), end=" ") print()
false
34e73359d26da46aa90d3ac78717f9e134eba568
sub7ata/Pattern-Programs-in-Python
/pattern73.py
248
4.21875
4
""" Example: Enter a number: 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 """ num = int(input("Enter a number: ")) for i in range(1, num+1): print(" "*(i-1),end=" ") for j in range(1,num+2-i): print(num+2-i-j,end=" ") print()
false
fdd01f4e6ed62cfca31426b445134f69cc65e62b
sub7ata/Pattern-Programs-in-Python
/pattern27.py
261
4.25
4
""" Example: Enter the number of rows: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 """ n = int(input("Enter the number of rows: ")) for i in range(1, n + 1): print(" "*(n - i), end=" ") for j in range(1, i + 1): print(j, end=" ") print()
false
97e50ce2795bf7e6ac149ab76ab97f147209d5a2
sub7ata/Pattern-Programs-in-Python
/pattern41.py
296
4.125
4
""" Example: Enter the number of rows: 5 A A B C A B C D E A B C D E F G A B C D E F G H I """ n = int(input("Enter the number of rows: ")) for i in range(1, n + 1): print(" "*(n - i), end=" ") for j in range(65, 65 + 2 * i - 1): print(chr(j), end=" ") print()
false
df46645a243da1227b13c372061a61fb59cc9576
sub7ata/Pattern-Programs-in-Python
/pattern62.py
314
4.1875
4
""" Example: Enter a number: 5 4 3 4 2 3 4 1 2 3 4 0 1 2 3 4 1 2 3 4 2 3 4 3 4 4 """ num = int(input("Enter a number: ")) for i in range(1,num+1): for j in range(1,i+1): print(num-i+j-1,end=" ") print() for a in range(1,num+1): for k in range(0, num-a): print(k+a,end=" ") print()
false
9160b2901c50fe7aa9e901598409315daf832b98
sub7ata/Pattern-Programs-in-Python
/pattern12.py
215
4.25
4
""" Example: Enter the number of rows: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 """ n = int(input("Enter the number of rows: ")) for i in range(1, n + 1): for j in range(1, i + 1): print(j, end=" ") print()
true
d07265f2a6bb6fe86770efa6d3d67d680d0c6c41
VishalGupta2597/techopy
/multi_userinput.py
1,753
4.15625
4
#try: Hin, Eng, Maths, Phy, Che=input("Enter the marks").split(",") print(Hin, Eng, Maths, Phy, Che) print(int(Hin) + int(Eng) + int(Maths) + int(Phy) + int(Che)) """print("Student Result : ") Hin = int(input("Enter the marks of Hindi : ")) if Hin < 0 or Hin > 100: raise ValueError("Marks cannot be mor...
false
e41d6ea1c9c686ebaa71f250f3f790360f03c48e
Dmach12/GeekBrainsTutorial-Python_lessons_basic
/less_1_home_1.py
1,002
4.1875
4
#1) Поработайте с переменными, создайте несколько, # выведите на экран, запросите у пользователя # несколько чисел и строк и сохраните в переменные, # выведите на экран. a = 1 print(a) b = - 2 print(b) print(a-b) c = input('Введите Ваше имя и фамилию') print(c) print(a, c) print(a + c) name = input('Введи...
false
03da85580e8cdc8e967f94677a5837c31e8bf245
HanChaun/driving
/driving.py
420
4.1875
4
country = input('Which country are you from:') age = input('pls input your age:') age = int(age) if country == 'Taiwan': if age >= 16 : print('you can test for Driving Licence ') else: print('you can not test for Driving Licence ') elif country == 'USA': if age >= 16 : print('you can test for Driving Licence '...
false
3cdfd9358e1fd875787b179dff332289f293304a
ashley-honn/homework2-
/solution1.py
444
4.15625
4
# solutions ##This is for Solution 1 #Titles for cells cell_1 = 'Number' cell_2 = 'Square' cell_3 = 'Cube' space = '20' align = ' ' #This will print titles for all cells print(f'{cell_1 :{align}>{space}}',f'{cell_2 :{align}>{space}}',f'{cell_3 :{align}>{space}}') num = 0 #This will print number, squared, and cube...
true
369ec93632634b50b84c774397449edfbf1b4332
SmiththeHacker/tehnikum_domashka
/domashka3/task3.py
593
4.15625
4
print('Здравствуйте, я программа, которая умеет писать ваш список наоборот') print() print('Давайте для начала добавим данные в список. Введите "stop", когда решите остановиться') base = [] while True: x = input() base.append(x) print(base) print('Добавим что-то еще?') if x == 'stop': break ...
false
b34a8ceb62caf8cf858f8cb987890ed60d48fa2f
itchyporcupine/Project-Euler-Solutions
/problems/problem1.py
538
4.28125
4
""" If we list all of the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. http://www.projecteuler.net/index.php?section=problems&id=1 """ def problem_1(): print "The sum of all natural numbers...
true
7a8ba86d03fd50adc54e8950c416c4dc466bb251
prepiscak/beatson_rosalind
/id_HAMM/RS/006_Rosalind_HAMM.py
2,367
4.125
4
#!/usr/bin/env python3 ''' Counting Point Mutations Problem Given two strings s and t of equal length, the Hamming distance between s and t, denoted dH(s,t), is the number of corresponding symbols that differ in s and t. Given: Two DNA strings s and t of equal length (not exceeding 1 kbp). Return: The Hamming dista...
true
1f769ec8e3df1f204b67776026c50589b3623163
bhupathirajuravivarma/positive-numbers-in-a-range
/positivenoinrange.py
523
4.3125
4
#positive numbers in lists list1 = [6,-7,5,3,-1] for num in list1: #using membership operator to check if value exists in 'list1'& iterating each element in list. if num>=0: #checking for positive number in list. print(num,end=" ") print("\n") list2=[2,14,-45,3] for num...
true
39169e30f904bb9755256220e758e17e2b2afe67
stoneand2/python-washu-2014
/day2/clock2.py
1,330
4.21875
4
class Clock(): def __init__(self, hours, minutes=00): self.hours = hours # this is an instance variable, able to be accessed anywhere you call self self.minutes = minutes @classmethod #instead of self, the first thing we access is the class itself def at(cls, hours, minutes=00): return cls(hours, minutes...
true
6624b10758eae9ab14ca93e6b309731311f167b3
Charles1104/Codewars
/cube.py
240
4.125
4
def cube_odd(arr): sum = 0 for i, k in enumerate(arr): if isinstance(k, (int, float, complex)): if k%2 != 0: sum += pow(k, 3) else: return None return sum if __name__ == "__main__": cube_odd([1,2,3,4])
false
14653072f7d31ba1164f26ecbb20c324046ddb66
ayanakshi/journaldev
/Python-3/basic_examples/leap_year.py
321
4.15625
4
try: print('Please enter year to check for leap year') year = int(input()) except ValueError: print('Please input a valid year') exit(1) if year % 400 == 0: print('Leap Year') elif year % 100 == 0: print('Not Leap Year') elif year % 4 == 0: print('Leap Year') else: print('Not Leap Year'...
false
6e948d96919febbb19d304897276e6ab366960d5
ayanakshi/journaldev
/Python-3/basic_examples/float_function.py
617
4.59375
5
# init a string with the value of a number str_to_float = '12.60' # check the type of the variable print('The type of str_to_float is:', type(str_to_float)) # use the float() function str_to_float = float(str_to_float) # now check the type of the variable print('The type of str_to_float is:', type(str_to_float)) print...
true
ecb48a4e1889f6e7a88dfaf1bcea829668c3e6e9
doanthanhnhan/learningPY
/01_fundamentals/04_functions/03_built_in_functions.py
1,051
4.40625
4
# Strings # Search # a_string.find(substring, start, end) random_string = "This is a string" print(random_string.find("is")) # First instance of 'is' occurs at index 2 print(random_string.find("is", 9, 13)) # No instance of 'is' in this range # Replace # a_string.replace(substring_to_be_replace, new_string) a_string...
true
d999f45998e7e623f150f3fcad477524da21ee0a
doanthanhnhan/learningPY
/02_oop/04_polymorphism/06_abstract_base_classes.py
561
4.3125
4
from abc import ABC, abstractmethod class Shape(ABC): # Shape is a child class of ABC @abstractmethod def area(self): pass @abstractmethod def perimeter(self): pass class Square(Shape): def __init__(self, length): self.length = length def area(self): return...
true
e9aba8cf06774f9232d5b242efef69fb799f3e76
doanthanhnhan/learningPY
/01_fundamentals/04_functions/02_function_scope.py
1,561
4.78125
5
# Data Lifecycle # In Python, data created inside the function cannot be used from the outside # unless it is being returned from the function. # Variables in a function are isolated from the rest of the program. When the function ends, # they are released from memory and cannot be recovered. name = "Ned" def func():...
true
6191157eb90cbf6b994c06b80b884695b36e9f01
doanthanhnhan/learningPY
/02_oop/01_classes_and_objects/12_exercise_01.py
490
4.375
4
""" Square Numbers and Return Their Sum Implement a constructor to initialize the values of three properties: x, y, and z. Implement a method, sqSum(), in the Point class which squares x, y, and z and returns their sum. Sample Properties 1, 3, 5 Sample Method Output 35 """ class Point: def __init__(self, x, y, z)...
true
be2d9d9f1ea11a20209c8d2e816452567dd3114b
carolinetm82/MITx-6.00.1x
/Python_week2/week2_pbset2_pb1.py
1,305
4.21875
4
""" Problem 1 - Paying Debt off in a Year Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the credit card company each month. The following variables contain values as described below: balance - the outstanding balance on the credit c...
true
69f67048cf25a900a9eb5fa3f444c2c42f0cfb40
sarozzx/Python_practice
/Functions/18.py
205
4.3125
4
# Write a Python program to check whether a given string is number or not # using Lambda. check_number = lambda x:True if x.isnumeric() else False a=str(input("Enter a string ")) print(check_number(a))
true
0743869ff6c47e458db2290981671f555b539794
sarozzx/Python_practice
/Functions/2.py
247
4.125
4
# Write a Python function to sum all the numbers in a list. def sum1(list): return sum(list) list =[] n=int(input("Enter number of items in list")) for i in range(0,n): x=int(input()) list.append(x) print("THe sum is ",sum1(list))
true
971c857b14a11f193b4e814f8844854e587d0b0f
sarozzx/Python_practice
/Data Structures/27.py
430
4.25
4
# Write a Python program to replace the last element in a list with another list. def con_list(list1,list2): list1[-1:]=list2 return list1 list1 =[] n=int(input("Enter number of items in list1")) for i in range(0,n): x=str(input()) list1.append(x) list2 =[] n=int(input("Enter number of items in li...
true
ab919b511392475452595c0610cb72f6ca0525a4
sarozzx/Python_practice
/Functions/9.py
376
4.1875
4
# Write a Python function that takes a number as a parameter and check the # number is prime or not. def prime1(n): if (n==1): return False elif (n==2): return True; else: for x in range(2,n): if(n % x==0): return False return True x=int(input("E...
true
19bcef6d7e895e153eebe00dcd434e88b340058b
sarozzx/Python_practice
/Data Structures/38.py
296
4.21875
4
# Write a Python program to remove a key from a dictionary. dict1 = {} n=int(input("Enter number of items in dictionary")) for i in range(n): x=str(input("key")) y=str(input("value")) dict1[x]=y print(dict1) q=str(input("which key do u wanna remove")) del dict1[q] print(dict1)
true
464c3eecf884c6008379552d1bfe2e151a140b4b
sarozzx/Python_practice
/Functions/5.py
320
4.28125
4
# Write a Python function to calculate the factorial of a number (a non-negative # integer). The function accepts the number as an argument. def facto(x): if(x==0): return 0 if(x==1): return 1 return x*facto(x-1) y=int(input("Enter a number : ")) print("The factorial of ",y,"is",facto(y))
true
1d0d4598b8477da1f94808a2bea06a28e3211a09
sarozzx/Python_practice
/Data Structures/23.py
312
4.28125
4
# Write a Python program to check a list is empty or not. def check_emp(list): if not list: print("it is an empty list") else: print("it is not an empty list") list =[] n=int(input("Enter number of items in list")) for i in range(0,n): x=input() list.append(x) check_emp(list)
true
56e9001a79d3810a3b29fb33e3d37e79d27b7732
starmap0312/refactoring
/dealing_with_generalization/pull_up_constructor_body.py
1,457
4.34375
4
# - if there are identical constructors in subclasses # you can pull up to superclass constructor and call superclass constructor from subclass constructor # - if see common behaviors in normal methods of subclasses, consider to pull them up to superclass # ex. if the common behaviors are in constructors, you need ...
true
fb1b1e73c7d5311e36eb7f1fd8d2cddd9ad9fb7b
starmap0312/refactoring
/simplifying_conditional_expressions/introduce_null_object.py
722
4.15625
4
# - if you have repeated checks for a null value, then replace the null value with a null object # - if one of your conditional cases is a null, use introduce null object # before: use conditionals class Customer(object): # abstract class def getPlan(self): raise NotImplementedError # client has a co...
true
79f5435bbcf2bd7b757b6e2f1a0da40e4bf82836
starmap0312/refactoring
/composing_method/introduce_explaining_variable.py
930
4.4375
4
# - if have a complicated expression that is hard to understand, put the result of the expression # or parts of the expression in a temp variable with a name explaining its purpose # - an alternative is to use extract method, but sometimes extract method is hard, # because there are too many local temp variables t...
true
18164044687548ed741c2d8833149e564f708fa1
shmishkat/PythonForEveryone
/Week05/forLoopDic.py
436
4.21875
4
#for loop in dictionaries. countsofNames = {'sarowar': 1, 'hossain': 2, 'mishkat': 2, 'mishu': 2} for key in countsofNames: print(key,countsofNames[key]) #converting dictionary to list nameList = list(countsofNames) print(nameList) print(countsofNames.keys()) print(countsofNames.values()) print(countsofNames.it...
true
4d29c7a19f10bd73b6c7a132e8024bf92e0de176
tanmay2298/Expenditure_Management
/database.py
1,715
4.3125
4
import sqlite3 from datetime import date # get todays date def create_table(): conn = sqlite3.connect("Expenditure.db") cur = conn.cursor() cur.execute("CREATE TABLE IF NOT EXISTS Expenditure(ID INTEGER PRIMARY KEY, expenditure_date text, Item text, Cost real)") conn.commit() conn.close() def insert_data(expendi...
true
c183d38420f2103fa6eb54b8698f2128e45238a1
zhaopeiyang/PythonLearning
/python_180905_迭代器.py
955
4.28125
4
# 可以被next()函数调用并不断返回下一个值的对象称为迭代器:Iterator。 # 生成器都是Iterator对象,但list、dict、str虽然是Iterable,却不是Iterator。 # 把list、dict、str等Iterable变成Iterator可以使用iter()函数 # 你可能会问,为什么list、dict、str等数据类型不是Iterator? # 这是因为Python的Iterator对象表示的是一个数据流, # Iterator对象可以被next()函数调用并不断返回下一个数据, # 直到没有数据时抛出StopIteration错误。 # 可以把这个数据流看做是一个有序序列,但我们却不能提前...
false
e587c00fe271c502b50586b227f077929c609af2
FaisalRehman234/Basic-Calculator
/Basic Python Calculator.py
1,015
4.21875
4
import argparse parser=argparse.ArgumentParser( description='''Select Operators by choosing options '1, 2, 3 & 4'. ''', epilog="""Author: Faisal Rehman.""") args=parser.parse_args() print("Type '-h' or '--help' to show help") def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x...
false
d6944aa05f2adbb15f1eeeca1bc0713cb8e0000a
geoniju/PythonLearning
/Basics/DictEx1.py
422
4.15625
4
"""" Write a program that reads words in words.txt and stores them as keys in a dictionary. It doesnt matter what the values are. Then you can use the in operator to check whether a string is in the dictionary. """ fhand = open('words.txt') word_dict = dict() for line in fhand: words = line.split() for word...
true
df562ec851108571c9c64114e44b38088a5ca605
lucas-deschamps/LearnPython-exercises
/ex6.py
948
4.40625
4
types_of_people = 10 x = f"There are {types_of_people} types of people." binary = "binary" do_not = "don't" y = f"Those who know {binary} and those who {do_not}." print(x) print(y) print(f"I said: {x}") print(f"I also said: '{y}'") hilarious = False joke_evaluation = "Isn't that joke so funny?! {} {}"...
true
6be6ef4eec51a80a29e1516c6c4e074ccb64f5f7
lucas-deschamps/LearnPython-exercises
/ex38.py
1,772
4.25
4
ten_things = "Apples Oranges Crows Telephone Light Sugar" print("\nWait, there are not 10 things in that list. Let's fix that.\n") # splits string into a list @ emptyspaces stuff = ten_things.split(' ') # 8 items in the list, but ten_things only needs 4 more more_stuff = ['Day', 'Night', 'Song', 'Frisbee', ...
true
68ab6e0241554dd0677be30bb3a47066104df38c
18101555672/LearnPython
/JM_Python/python_01.py
1,413
4.15625
4
print('hello world') # 基础 # 更详细的格式化方法 print('{:-^40}'.format('更详细的格式化方法')) # 对于浮点数‘0.333’保留小数点后三位 print('{:.3f}'.format(1.0/3)) # 使用指定符号填充文本,并保持文字处于中间位置 print('{:^11}'.format('hello')) print('{:_^11}'.format('hello')) print('{:0^11}'.format('hello')) # 基于关键词输出 print('{name} wrote {book}'.format(name='Swaroop',book='A B...
false
bdeddd92cfaed29ffe474b9ce8130046597fcc82
DhivyaKavidasan/python
/problemset_3/q7.py
421
4.40625
4
''' function named uses_only that takes a word and a string of letters, and that returns True if the word contains only letters in the list submitted by : dhivya.kavidasan date: 05/12/2017 ''' def uses_only(word, only_letters): i = 0 while i <len(word): if word[i] in only_letters: i+=1 else: ...
true
403d1aa48cd5b2505b7fde211ba0e0bbb9b0cd20
DhivyaKavidasan/python
/problemset_3/q10.py
659
4.15625
4
''' function called is_anagram that takes two strings and returns True if they are anagrams submitted by:dhivya.kavidasan date: 06/12/2017 ''' def is_anagram(list1,list2): list3=[] list4=[] list1.sort() list2.sort() for i in list1: list3.append(i) for j in list2: ...
false
8914f54cf44b5bfcab97d30db464ecbb58e4b15b
wesleyendliche/Python_exercises
/World_2/039militaryservice.py
592
4.15625
4
from datetime import date ano = int(input('Digite o ano de seu nascimento: ')) sexo = str(input('Você é HOMEM ou MULHER? Digite H ou M. ')).upper() idade = date.today().year - ano if idade == 18 and sexo == 'h': print('Você está com 18 anos. Deve se alistar IMEDIATAMENTE!') elif idade < 18 and sexo == 'h': prin...
false
cdefa6f65d75c76a213a108b0223122b72b30a2f
morrosquin/aleandelebake
/crypto/caesar.py
385
4.125
4
from helpers import alphabet_position, rotate_char def encrypt (text, rot): encrypted_text = "" for characters in text: encrypted_text += rotate_char(characters, rot) return encrypted_text def main(): text = input('Enter your message: ') rotation = int(input('Enter rotation: ')) prin...
true
89d25d50b13a4ee345ba2aeee3b4f4f2063e0947
tiveritz/coding-campus-lessons-in-python
/src/dcv/oct/day09part01.py
695
4.3125
4
def bubble_sort(arr): sorted = arr.copy() to_swap = True while to_swap: to_swap = False for i in range(1, len(arr)): if (sorted[i - 1] > sorted[i]): to_swap = True sorted[i - 1], sorted[i] = sorted[i], sorted[i - 1] return sorted def hello_wo...
true
e98f57cc800492598ded6a914a801cd2f78cf846
tiveritz/coding-campus-lessons-in-python
/src/dcv/sept/day06.py
2,030
4.1875
4
from math import ceil def hello_world_recursion(n): # Recherchiere Recursion if (n == 0): print("End of Recursion") else: print("Recursion number " + str(n)) n -= 1 hello_world_recursion(n) # Declare global variables for sorting algorithm compare_counter = 0 swap_counter ...
false
0c65b84132465c366b5eb84628cad04d5a80866f
StRobertCHSCS/fabroa-hugoli0903
/Working/Practice Questions/2.livehack_practice_solution2.py
896
4.46875
4
''' ------------------------------------------------------------------------------- Name: 2.livehack_practice_solution2.py Purpose: Determining if the triangle is a right angled Author: Li.H Created: 14/11/2019 ------------------------------------------------------------------------------ ''' # Receive the side leng...
true
f0a756e7cdc7e35be0efcc03def4afdd366376e7
cloudacademy/pythonlp1-lab2-cli
/src/code/YoungestPresident/solution-code/youngest_pres.py
1,449
4.15625
4
#! /usr/bin/python3 import sys sys.version_info[0] lab_exercise = "YoungestPresident" lab_type = "solution-code" python_version = ("%s.%s.%s" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])) print("Exercise: %s" % (lab_exercise)) print("Type: %s" % (lab_type)) print("Python: %s\n" % (pytho...
true
bd3f71a840393b9e85508b627bc234bd20f670bc
CSPon/Workshop_Materials
/Python_Workshop_Files/Works_010.py
2,236
4.34375
4
# Python 2.X workshop # File: Works_010.py # Files I/O and Exceptions # To simply print to the Python shell, use the print keyword print "Hello, Python!" print # Empty line # To read keyboard input within the shell... print "User input Demo" string = raw_input("Enter your name: ") print "Hello, " + string + "!" pri...
true
070f868f26cdeaa2f44ccb0885a9dc5889b1070d
CSPon/Workshop_Materials
/Python_Workshop_Files/Try_Files_Completed/Works_Try_001.py
644
4.125
4
# Python 2.7.X # Try_001.py # Modifying the quadratic equation # Continuing with quadratic equation, modify your code # So it can check with imaginary numbers # If 4 * a * c is negative, program must let user know # quadratic equation is unsolvable import math a = 5.0 b = 2.0 c = 10.0 # Write your code here if ((b*...
true
e8af090f30548f575478a7ef18ac554b77bf2dd4
jonbleibdrey/python-playhouse
/lessons/space/planet.py
971
4.25
4
class Planet: # class level attribute- has acesss to all instances shape = "round" #class methods #this is allso a decorator and it extends the methods below here. @classmethod def commons(cls): return f"All planets are {cls.shape} becuase of gravity" #static methods #this is ...
true
009f0354abb393920fd0570f056dab386960f30f
nateychau/leetcode
/medium/430.py
1,243
4.34375
4
# 430. Flatten a Multilevel Doubly Linked List # You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multi...
true
33457f0033848661c5312884471133f808943b54
nateychau/leetcode
/medium/735.py
2,073
4.15625
4
# 735. Asteroid Collision # We are given an array asteroids of integers representing asteroids in a row. # For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. # Find out the state of th...
true
35c0dd06be1544c645f19ff2b6ff101cc04e06c0
macyryan/lists
/main.py
1,855
4.53125
5
# a list is a sequence of items # 1D list like a single row or a single column in Excel # Declare a list using [] and a coma seperated of values list_ints = [0, 1, 10, 20] #there are unique indexes for each element in the list # 0-based, meaning the first element is at zero and the last element is n-1 # where n is th...
true
08ee5d07cc4cd9fa9ac995979b3ae921875651e9
eluttrell/string-exercises
/rev.py
274
4.3125
4
# This way works, but is too easy! # string = raw_input("Give me a string to reverse please\n:") # print string [::-1] string = "Hello" char_list = [] for i in range(len(string) - 1, - 1, - 1): char list.append(string[i]) # output = ' '.join(char_list) print output
true
aae92769398e2798c61f59b17eb3e509c1437bfa
Techie-Tessie/Big_O
/linear.py
766
4.28125
4
#Run this code and you should see that as the number of elements #in the array increases, the time taken to traverse it increases import time #measure time taken to traverse small array start_time = time.time() array1 = [3,1,4] for num in array1: print(num) print("\n%s seconds" % (time.time() ...
true
1bbdf14acb9ddbc2a8d4074b54330152dae6a582
rajeshkr2016/training
/chapter2_list_map_lambda_list_comprehension/51_loopin1.py
681
4.40625
4
#When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the enumerate() function. for i, v in enumerate(['tic', 'tac', 'toe']): print(i, v) # To loop over two or more sequences at the same time, the entries can be paired with the zip() function. question...
true
436590717e700ec74574b56332a1023362f73ee7
rajeshkr2016/training
/chapter4_class_method_inheritance_override_polymorphism/3_method_1.py
585
4.625
5
''' The Constructor Method The constructor method is used to initialize data. It is run as soon as an object of a class is instantiated. Also known as the __init__ method, it will be the first definition of a class and looks like this: ''' class Shark: def __init__(self): print("This is the constructor me...
true
f781dd47a06f79559ff931a13009f0453944b41c
rajeshkr2016/training
/fib.py
464
4.15625
4
#recurrsive # big O notation = O(n^2) def fiboRec(n): if n == 0: return 0 elif n == 1: return 1 else: return fiboRec(n-1)+fiboRec(n-2) #iter # big O notation = O(n) def fibIter(n): a=0 b=1 result=[0] for i in range(0,n): a, b = b, a+b result.append(a)...
false
22ea187f2fe994d8aca2eabeda4ea458af8162b9
rajeshkr2016/training
/chapter10-Generator_Fibanocci/8-Nested_list_comp.py
369
4.21875
4
#''' my_list = [] for x in [20, 40, 60]: for y in [2, 4, 6]: my_list.append(x * y) #print(my_list) my_list = [x * y for x in [20, 40, 60] for y in [2, 4, 6]] print(my_list) ''' List comprehensions allow us to transform one list or other sequence into a new list. They provide a concise syntax for compl...
true
798da748346e83c63566d0a2c24d36aa5467b49e
rajeshkr2016/training
/senthil/primeFactor.py
768
4.1875
4
''' Given int x, determine the set of prime factors f(5) = [1,5] f(6) = [2,3] f(8) = [2,2,2] f(10) = [2,5] 1) While n is divisible by 2, print 2 and divide n by 2. 2) After step 1, n must be odd. Now start a loop from i = 3 to square root of n. While i divides n, print i and divide n by i, increment i by 2 and continu...
true
0a72c3b845963090b651d57389478370565788c8
rajeshkr2016/training
/chapter2_list_map_lambda_list_comprehension/10_list_comp_if.py
669
4.3125
4
''' A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The result will be a new list resulting from evaluating the expression in the context of the for and if clauses which follow it. For example, this listcomp combines the elements of two ...
true
b62b52bbae9fc169f5a809824a2c188174c8101f
sujitdhamale/Python
/0805_slice.py
1,077
4.5
4
#!/usr/bin/python #0805_slice.py by Sujit Dhamale #to Understanding Operating on parts of a container with the slice operator def main(): print("") list = [1,2,3,4,5,6,7,8,9,10] print(list) print(list[0]) print(list[1]) #slice of first 5 item print("\nSlice of first 5 item ...
false
918a5296584c4fa3192d8debf40cedd8260b4dbd
sujitdhamale/Python
/0802_bitwise_operator.py
760
4.28125
4
#!/usr/bin/python #0802_bitwise_operator.py by Sujit Dhamale #to Understanding 0802_bitwise_operator def main(): print(5) print(0b0101) b(5) x,y=0x55,0xaa print("X==",end=" ") b(x) print("Y==",end=" ") b(y) #OR operator print("\n#OR operator") ...
false
09300b989cf42a78381dfd25fa4011cb33f346a0
sujitdhamale/Python
/0505_Aggregating_lists_and_tuples.py
892
4.5
4
#!/usr/bin/python #0505_Aggregating_lists_and_tuples.py by SUjit Dhamale def main(): print("Tuple ") #tuple is immutable object. we cannot insert, append, delete in tuple x=(1,2,3,4) print(type(x),x) print("List") # list is mutable object x=[1,2,3,4] print(type(x),x) #list ...
true
34863bd0e6251e5a1b22cd2fb68b65747b6bd240
liucheng2912/py
/leecode/easy/207/1603.py
660
4.125
4
''' 思路: 实现方式: 类定义和构造函数的定义 函数实现: ''' class ParkingSystem: def __init__(self,big,medium,small): self.big=big self.medium=medium self.small=small def addCar(self,carType): if carType==1: self.big-=1 return self.big>=0 elif carType==2: ...
false
e281a51a657d101f2127c4800eb8c2077f434822
BogartZZZ/Python-Word-Reverse
/WordReverse.py
330
4.15625
4
#my_string = input("Input a word to reverse: ") #for char in range(len(my_string) -1, -1, -1): # print(my_string[char], end="") def reverseWord(Word): words = Word.split(" ") newWords = [word[::-1] for word in words] newWord = " ".join(newWords) return newWord Word = "Can't stop me" print(reverseW...
true
b999f987b9b161c094cec43815873c38d18d9c66
PeturOA/2021-3-T-111-PROG
/assignments/while_loops/every_other_int.py
273
4.40625
4
num_int = int(input("Enter a number greater than or equal to 2: ")) # Do not change this line counter = 2 # Fill in the missing code below if num_int < 2: print("The number is too small.") else: while counter <= num_int: print(counter) counter += 2
true
3bde34c682bb98342601b3961eea5df04c152181
PeturOA/2021-3-T-111-PROG
/assignments/lists_and_tuples/fizzbuzz_sum.py
289
4.15625
4
def main(): max_num = int(input("What should max_num be?: ")) print(fizzbuzz_sum(max_num)) def fizzbuzz_sum(max_num): return sum([i for i in range(max_num) if i % 3 == 0 and i % 5 == 0]) # Main program starts here - DO NOT change it if __name__ == "__main__": main()
false
4f6f89f04e828f5d548e1d5784a97e67d78561d3
PeturOA/2021-3-T-111-PROG
/projects/p5/hex_decimal.py
2,379
4.375
4
PROMPT = "Enter option: " HEX_LETTERS = 'ABCDEF' DEC_TO_HEX_OPTION = 'd' HEX_TO_DEC_OPTION = 'h' EXIT_OPTION = 'x' MENU_STR = f"\n{DEC_TO_HEX_OPTION}. Decimal to hex\n{HEX_TO_DEC_OPTION}. Hex to decimal\n{EXIT_OPTION}. Exit\n" def main(): '''Displays menu, gets input from user and displays result''' displa...
false
0e5f551d767c513eeaa4c14a635b798555d5d45a
tiannaparmar/Python-Level-2
/Functions.py
1,885
4.34375
4
#Create new file #Save as Functions.py #Save in Python-Level-2 folder ---- repo(repository) #Add two numbers def AddNumbers(x,y,z): #Definition of the function return x + y + z def GetSquares(x): return x * x #Call our Function Total = AddNumbers(4,9,100) #Output the results print(f"The sum ...
true
115c846183893a1b02c883fe8418cd0190958d1d
kumarUjjawal/python_problems
/leap_year.py
349
4.28125
4
# Return true if the given input is a leap year else return false. def leap_year(year): leap = False if (year % 4 == 0): if (year % 100 == 0 and year % 400 == 0): leap = True else: leap = False else: leap = False return leap years = int(input())...
true
ab0a2984cc6b629a578c0e576bd6cd80bfc56ea3
mharre/pythonds
/RandomExercises/26-Queue.py
2,994
4.15625
4
class Node: def __init__(self, cargo=None, nextNode=None): self.cargo = cargo self.next = nextNode def __str__(self): return str(self.cargo) def print_backward(self): if self.next is not None: tail = self.next tail.print_backward() ...
false
dd0f35d4cb92dafa898193df17b2ce18f21f37de
anaselmi/simple_python
/simple/talkingclock.py
1,481
4.15625
4
def talking_clock(time): # Gives us hour and minute as ints hour = int(time[0:2]) minute = int(time[3:]) minute_tens = int(time[3]) minute_ones = int(time[4]) if hour >= 12: # Gives us our p.m hours in twelve hour time hour = hour - 12 day_or_night = "pm" # Used to tell...
false
b9cba0bc0de5e2ea45ab195ae4a756c419bfe1b4
arbiben/cracking_the_coding_interview
/recursion_and_dynamic_programming/multiply_recursively.py
1,445
4.46875
4
# write a recursive function to multiply two positive integers without using # the * operator. others are allowed, but you should minimize the number of operations def recursive_multiply(a, b): smaller = b if a > b else a larger = a if a > b else b print("recursing and decrementing: {}".format(multiply_de...
true
3fb55edd7992543a4459f4f2d399d21f8b3f45d0
zzzzzz5530041/python_learning
/hello_world/HelloWorld.py
1,452
4.21875
4
# -*- coding:UTF-8 -*- print('hello'); a = -1; b = -2; if a > b: print(a) # if a larger than b ,then print a else: print(b); # if statement if a > b: if a == 1: print(a) else: if a == 0: print(a) else: pass elif a == b: print(a, b); else: print(b)...
false
a3e35c2ef4501db0f733d10746df79993a226ffe
JeffreyYou55/cit
/TermProject/plotting.py
960
4.15625
4
from turtle import * import coordinates import square import linear import quadratic border = { "width" : 620, "height" : 620 } # draw square and coordinate print("< Jeffrey's Plotting Software >") print("drawing rectangular coordinates...") square.draw_square(border["width"], border["height"], -310, -300) penup() se...
true
c8257d92fba77a9b9c006c7b2277c393d546403f
cbain1/DataScience210
/python/ListsQ2.py
924
4.125
4
import sys import random def beret(request): total = 0 strings = 0 #Loops through all words in request for elem in request: count =0 #splits each word into its own string value word = list(elem) # this loops through each letter in each wo...
true
f23c5207a4cab807e897918fa84aea19db8023d9
andrewnnov/100days
/guess_number/main.py
1,530
4.15625
4
import random from art import logo print(logo) print("Welcome to the Number Guessing Game!") def play_game(): guess_number = random.randint(1, 100) print(guess_number) result_of_guess = True while result_of_guess: attempts = 0 print("I'm thinking of number between 1 and 100") ...
true
dd4d23a9d9fd69b70eab37f78093d7e0a6756c4b
andrewnnov/100days
/rps.py
1,055
4.15625
4
import random rock = ''' _______ ---' ____) (_____) (_____) (____) ---.__(___) ''' paper = ''' _______ ---' ____)____ ______) _______) _______) ---.__________) ''' scissors = ''' _______ ---' ____)____ ______) __________) (____) ...
false
16ec5926aa96c5a92794b797f3a597b3e60dbe39
mirielesilverio/cursoPython3
/logicOperators/using_logic_operators.py
337
4.21875
4
name = input('What is your name? ') age = int(input('How old are you? ') or 0) if not name: print('The name cannot be empty') elif ' ' in name: print('Very good! You entered your full name') elif ' ' not in name: print('You must enter your full name.') if not age or age < 0: print('Oh no! You entered ...
true
8b84715a6d780d92c3bd97fd0c92496f1c1e8c09
iam-amitkumar/BridgeLabz
/AlgorithmPrograms/Problem1_Anagram.py
605
4.21875
4
"""Anagram program checks whether the given user-input strings are anagram or not. @author Amit Kumar @version 1.0 @since 02/01/2019 """ # importing important modules import utility.Utility import util.Util global s1, s2 try: s1 = utility.Utility.get_string() s2 = utility.Utility.get_string() except Exceptio...
true
6416fd722282681c9da97207183871b94cf9e51f
iam-amitkumar/BridgeLabz
/ObjectOrientedPrograms/Problem1_Inventory.py
1,976
4.28125
4
"""In this program a JSON file is created having Inventory Details for Rice, Pulse and Wheat with properties name, weight, price per kg. With the help of 'json' module reading the JSON file. @author Amit Kumar @version 1.0 @since 10/01/2019 """ # Importing important modules import json # Inventory class class Invent...
true
b0574f764eb2af8d4e06fddc1c9781c13b7f73a2
iam-amitkumar/BridgeLabz
/DataStructureProgram/Problem4_BankingCashCounter.py
2,955
4.375
4
"""this program creates Banking Cash Counter where people come in to deposit Cash and withdraw Cash. It have an input panel to add people to Queue to either deposit or withdraw money and de-queue the people maintaining the Cash Balance. @author Amit Kumar @version 1.0 @since 08/01/2019 """ # importing important module...
true
e1a0391349896b3ab22365f4c9f295240dae6a9a
iam-amitkumar/BridgeLabz
/AlgorithmPrograms/Problem7_InsertionSort.py
963
4.21875
4
"""This program reads in strings from standard input and prints them in sorted order using insertion sort algorithm @author Amit Kumar @version 1.0 @since 04/01/2019 """ # importing important modules import utility.Utility import string global u_string try: u_string = input("Enter the number of string you want t...
true
8e1f1ee70acfa12c836eb7bc7274e1b424e5e747
iam-amitkumar/BridgeLabz
/DataStructureProgram/Problem3_BalancedParentheses.py
1,862
4.1875
4
"""Take an Arithmetic Expression where parentheses are used to order the performance of operations. Ensure parentheses must appear in a balanced fashion. @author Amit Kumar @version 1.0 @since 08/01/2019 """ # importing important modules from DataStructureProgram.Stack import * s1 = Stack() # creating object of Sta...
true
e993fb4db905e0d672d59137c376cbb9368d93a0
PhilipCastiglione/learning-machines
/uninformed_search/problems/travel.py
2,072
4.28125
4
from problems.dat.cities import cities """Travel is a puzzle where a list of cities in North America must be navigated in order to find a goal city. The navigation approach presents a problem to be solved using search algorithms of various strategies. The distance between cities is provided and a heuristic, straight ...
true
c8f4625094cc322c498da1b751ad70e838c98775
namelessnerd/flaming-octo-sansa
/graphs/breadth_first_search.py
1,609
4.25
4
def breadth_first_search(graph, starting_vertex): # store the number of steps in which we can reach a starting_vertex num_level= {starting_vertex:0,} #store the parent of each starting_vertex parent={starting_vertex:None,} #current level level= 1 #store unexplored vertices unexplored=[starting_vertex] print ...
true
8800b16c4518c85952934c96ba8ccf04cb2d3fe7
vaddanak/challenges
/mycode/fibonacci/fibonacci.py
2,392
4.15625
4
#!/usr/bin/env python ''' Author: Vaddanak Seng File: fibonacci.py Purpose: Print out the first N numbers in the Fibonacci sequence. Date: 2015/07/25 ''' from __future__ import print_function; import sys; import re; sequence = [0,1]; ''' Calculate and collect first N numbers in Fibonacci number sequence. Store res...
true
4296c919d465767998bee122b61e3cabc683d101
officialtech/xPython
/static_variable | xpython.py
2,954
4.125
4
**********************************************# STATIC VARIABLES ***************************************** # The variables which are declared inside the class and outside the 'method' are called static variable. # Static variables will holds common values for every object. # Static variables will get memory for one ...
true
6da56124e837982d56bed013942e60fc9068692b
amersulieman/Simple-Encryption-Decryption
/Decryption.py
1,552
4.15625
4
'''@Author: Amer Sulieman @Version: 10/07/2018 @Info: A decryption file''' import sys from pathlib import Path #check arguments given for the script to work if len(sys.argv)< 2: sys.exit("Error!!!!\nProvide <fileName> to decrypt!!"); def decryption(file): #File path to accomdate any running system filePath ...
true
323349df70f4586b2055c9ae5894a0195f1e79ba
vladn90/Algorithms
/Numbers/fibonacci.py
1,940
4.125
4
""" Comparison of different algorithms to calculate n-th Fibonacci number. In this implemention Fibonacci sequence is gonna start with 0, i.e. 0, 1, 1, 2, 3, 5... """ from timeit import timeit from functools import lru_cache def fib_1(n): """ Recursive algorithm. Very slow. Runs in exponential time. """ #...
true
6b974c6dfc21b4d8aeea7cf2a9536b8a33b02929
vladn90/Algorithms
/Sorting/insertion_sort.py
1,207
4.4375
4
""" Insertion sort algorithm description, where n is a length of the input array: 1) Let array[0] be the sorted array. 2) Choose element i, where i from 1 to n. 3) Insert element i in the sorted array, which goes from i - 1 to 0. Time complexity: O(n^2). Space complexity: O(1). """ import random def insertion_sort(a...
true
2f5ea417ad6f0ff70f0efcede02f9579c580533a
vladn90/Algorithms
/Sorting/bubble_sort.py
1,196
4.375
4
""" Bubble sort algorithm description, where n is a length of the input array: 1) Compare consecutive elements in the list. 2) Swap elements if next element < current element. 4) Stop when no more swaps are needed. Time complexity: O(n^2). Space complexity: O(1). """ import random def bubble_sort(array): """ Sor...
true
8c57f071fe179750c8be0d2b81ed023d94299ad7
vladn90/Algorithms
/Matrix_problems/spiral_matrix.py
2,011
4.25
4
""" Problem description can be found here: https://leetcode.com/problems/spiral-matrix/description/ Given a matrix of m x n elements, return all elements of the matrix in spiral order. For example, given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You should return [1, 2, 3, 6, 9, 8, 7, 4, 5]. ""...
true
cfadda58720b5b635c21235c4a73a91f6cffca40
ayr0/numerical_computing
/Python/GettingStarted/solutions_GettingStarted.py
2,065
4.375
4
# Problem 1 ''' 1. Integer Division returns the floor. 2. Imaginary numbers are written with a suffix of j or J. Complex numbers can be created with the complex(real, imag) function. To extract just the real part use .real To extract just the imaginary part use .imag 3. float(x) where x is the integer. 4. // ''' # ...
true
9d251fbd12296040c32f4eb9346005da200ebf25
pythagaurang/sort-analysis
/sorts/merge.py
810
4.15625
4
from main import main def merge(array1,array2): l_1=len(array1) l_2=len(array2) array3=[] i=j=0 while(i<l_1 and j<l_2): if array1[i]<array2[j]: array3.append(array1[i]) i+=1 elif array1[i]>array2[j]: array3.append(array2[j]) j+=1 ...
false
7eb6f26a36fd55f437aef7510db2d9df1e055d2e
flyburi/python-study
/io_input.py
223
4.375
4
def reverse(text): return text[::-1] def is_palindrome(text): return text == reverse(text) sth = raw_input("Enter text:") if is_palindrome(sth): print "yes it is a palindrome" else: print "no it is not a palindrome"
true