blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
e24920a841c579ae46d74a759d9148c858222ea4
johnson365/python
/Design Pattern/Observer.py
1,986
4.1875
4
"""Implementation of Observer pattern""" from abc import ABCMeta, abstractmethod class Subject: """The abstract class of Subject put all Observer object in a collection!""" def __init__(self): self.observers = [] def attachObserver(self, observer): """add a observer into obser...
true
d37eec249f9eae3f11d1eff5939199c62054ffaf
JSheldon3488/Daily_Coding_Problems
/Chapter6_Trees/6.3_Evaluate_Arithmetic_Tree.py
2,033
4.15625
4
""" Date: 7/7/20 6.3: Evaluate Arithmetic Tree """ class Node(): """ Node class used for making trees """ def __init__(self, val, left = None, right = None): self.val = val self.left = left self.right = right ''' Problem Statement: Suppose an arithmetic expression is given as a binary t...
true
4ec43707554a617f2211609ec94ab0fbc756e70f
JSheldon3488/Daily_Coding_Problems
/Chapter4_Stacks_and_Queues/Stack.py
1,565
4.21875
4
class Stack: """ A basic Stack class following "last in, first out" principle. Supports methods push, pop, peek, and size. The stack is initialized as empty. Attributes: Size: Keeps track of the size of the stack """ def __init__(self): """ Initializes the stac...
true
ef6fa04462315f367b3d91186bbf2f3ed48fb559
JSheldon3488/Daily_Coding_Problems
/Chapter8_Tries/8.2_PrefixMapSum.py
2,066
4.25
4
""" Date: 7/26/20 8.2: Create PrefixMapSum Class """ ''' Problem Statement: Implement a PrefixMapSum class with the following methods: def insert(key: str, value: int) Set a given key's value in the map. If the key already exists overwrite the value. def sum(prefix: str) Return the sum of all values of keys th...
true
608ed5c38e186df1ef955933bf6c77a3aa340ef1
ARON97/Desktop_CRUD
/backend.py
1,676
4.28125
4
import sqlite3 class Database: # constructor def __init__(self, db): self.conn = sqlite3.connect(db) self.cur = self.conn.cursor() self.cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title text, author text, year integer, isbn integer)") self.conn.commit() def insert(self, title, au...
true
5990428dbea6421d99b43c21c6c83c55f2617a59
matthewmuccio/Assessment1
/q1/run.py
1,969
4.28125
4
#!/usr/bin/env python3 import random # Helper function that gets the number of zeroes in the given list. def get_num_zeroes(x): num = 0 for i in x: if i == 0: num += 1 return num # Moves all the 0s in the list to the end while maintaining the order of the non-zero elements. def move_zeroes(x): length = le...
true
95ba120923b093a6af9636f643f12719e0dee77e
angelinka/programming4DA
/week5/lab5DatastrTuple.py
588
4.4375
4
#Program creates a tuple that stores the months of the year, from that tuple create #another tuple with just the summer months (May, June, July), print out the #summer months one at a time. #Author: Angelina B months = ("January", "February", "March", "April", "May", "...
true
2bcf78b22555bc9db039525d2afb2fecae2fcce6
caoxiang104/algorithm
/data_structure/Linked_List/Singly_Linked_List.py
2,847
4.1875
4
# coding=utf-8 # 实现带哨兵的单链表 class LinkedList(object): class Node(object): def __init__(self, value, next_node): super(LinkedList.Node, self).__init__() self.value = value self.next = next_node def __str__(self): super(LinkedList.Node, self).__str__()...
true
62540e1e6192619838f134c1499907cbf03cf019
XuQiao/codestudy
/python/pythonSimple/list_comprehension.py
309
4.1875
4
listone = [2,3,4] listtwo = [2*i for i in listone if i>3] print (listtwo) def powersum(power, *args): '''Return the sum of each arguments raised to specified power''' total = 0 for i in args: total = total + pow(i,power) return total print (powersum(1,23,34)) print (powersum(2,10))
true
80fd1179076556a77d87ebe6aae78c2edd03ddf5
jhobaugh/password_generator
/password_generator.py
822
4.1875
4
# import random, define a base string for password, name, and characters in password import random password = "" name = "" chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!#$%&" # while loop to ensure a password is outputted while password == "": # limit input limit = int...
true
49a2f2e2c4b0da26013b635c66045373ad9e2654
xchmiao/Leetcode
/Tree/145. Binary Tree Postorder Traversal.py
2,366
4.15625
4
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None ## Solution-1 ''' 1.1 Create an empty stack 2.1 Do following while root is not NULL a) Push root's right child and then root to stack. b) Set...
true
ec8e857911afcc4b2e7c74377913639f5a4b964c
zheguang/fun-problems
/longest_common_sequence.py
1,503
4.21875
4
#!/usr/bin/env python # Longest common sequence # Given two strings, the task is to find the longest common sequence of letters among them. # The letters do not have to be next to each other in the original string. # E.g. C D E F G A B # D E G B R T Z # output: D E G B # # It is interesting to compare this proble...
true
a2da9360fd828ab92db4f8f4b7d13c25327309e4
ruslanfun/Python_learning-
/if_elif3.py
360
4.25
4
# Ask the user to enter a number between 10 and 20 (inclusive). # If they enter a number within this range, display the message “Thank you”, # otherwise display the message “Incorrect answer” number = int(input("enter a number between 10 and 20: ")) if number >= 10 and number <= 20: print('thank you') else: p...
true
1223e8cd384e5be4bf36329a22e85c3b538522b7
Priya-Mentorship/Python4Everybody
/arrays/adding.py
427
4.1875
4
import array as arr numbers = arr.array('i', [1, 2, 3, 5, 7, 10]) # changing first element numbers[0] = 34 print(numbers) # Output: array('i', [0, 2, 3, 5, 7, 10]) # changing 3rd to 5th element numbers[2:5] = arr.array('i', [4, 6, 8]) print(numbers) # Output: array('i', [0, 2, 4, 6, 8, 10]) numbers.ap...
true
8f6d3c5ab8ca31a8aaba3fb47e7234f0fa0c95c6
onuratmaca/Data-Analysis-w-Python-2020
/compliment.py
583
4.6875
5
#!/usr/bin/env python3 """ Exercise 2 (compliment) Fill in the stub solution to make the program work as follows. The program should ask the user for an input, and the print an answer as the examples below show. What country are you from? Sweden I have heard that Sweden is a beautiful country. What country are you ...
true
bb24c91663b4d3b52360a20fe35942c92daf7904
erarpit/python_practise_code
/secondprogram.py
324
4.125
4
print('A program for print list function') list = [ 2,4,5,5,5,6,'hello','ratio' ] print(list) print(list[4]) list.remove('hello') print(list) list.append('my') print(list) print(list[3:8]) newlist = list.copy() print(newlist) print(newlist.count(6)) print(newlist) list.index('my') print("printlist:",list)...
true
9573ba807776f8906f1da9e66a0f5c9ec2d6979f
blackviking27/Projects
/text_based_adventure.py
2,162
4.25
4
# text based adventure game print("Welcome to text adventure") print("You can move in two directions left and right and explore the rooms") print("but you cannot go beyond the rooms since it is not safe for you as of now") print("r or right to go in right direction") print("l or left to go in left direction") room=[1,2...
true
e3e5eeb60adb1ad74935c816db64847c71e7bf98
khadley312/NW-Idrive
/Exercise Files/Ch2/variables_start.py
564
4.3125
4
# # Example file for variables # # Declare a variable and initialize it f=0 print(f) # # re-declaring the variable works f="abc" print(f) # # ERROR: variables of different types cannot be combined print("this is a string" + str(123)) # Global vs. local variables in functions def someFunction(): global f #this m...
true
2e003018aa4a1511f5cb3a1e18202e5c2e47b0b5
marsbarmania/ghub_py
/codingbat/Logic-1/near_ten.py
464
4.125
4
# -*- coding: utf-8 -*- # Given a non-negative number "num", # return True if num is within 2 of a multiple of 10. # Note: (a % b) is the remainder of dividing a by b, # so (7 % 5) is 2. def near_ten(num): remainder = num while remainder > 10: remainder %= 10 # print "remainder: ",remainder return True if...
true
155580584152bc4acf0d52f76e7ee6491b4739dc
ananyapoc/CPSC230
/CPSC230/APochiraju_2/newvolume.py
459
4.3125
4
#this is to calculate the volume of a cylinder import math #asking the user for inputs r=int(input("give me a length for the radius of the cylinder")) #stating conditions for radius if(r==0): print("please do not give zero") elif(r!=0): h=int(input("give me a length for the height of the cylinder")) #stating co...
true
39d4e818838bb596e46ed641193a64392a3f25e0
barbmarques/HackerRank-Python-Practice
/Basic_Python_Challenges.py
1,285
4.4375
4
# Print Hello, World! print("Hello, World!") # Given an integer,n, perform the following conditional actions: -- If n is odd, print Weird -- If n is even and in the inclusive range of 2 to 5, print Not Weird -- If n is even and in the inclusive range of 6 to 20, print Weird -- If n is even and greater than 20, print ...
true
08d1d54fb84923904a94599150c528974fe86b3c
adid1d4/timer
/timer.py
1,114
4.15625
4
''' what should it do? it should decrease the seconds on the same line after the seconds go to 0, it should decrease a minute and get 59 on the seconds after this the iteration should repeat itself for the seconds when the minutes get to 0, the hour should decrease by 1, the minutes to 59, seconds to 59 and the i...
true
6a3afca3067a704a06be3892fdc773b16054bc69
njounkengdaizem/eliteprogrammerclub
/capitalize.py
962
4.34375
4
# write a simple program that takes a sentence as input, # returns the capitalized for of the sentence. ############################################################# result = "" # an empty string to hold the resulting string sentence = input("Enter a word: ") # gets inputs from the ...
true
7d2ca4711e013e5493e0532ad89d5c10380d73c3
mikestrain/PythonGA
/firstPythonScript.py
349
4.28125
4
print("this should be printed out") #this is a comment # print("The number of students is "+str(number_of_students)) # print(3**3) number_of_students = 6 number_of_classes = 10 total = number_of_students + number_of_classes print('number of students + number of classes = ' + str(total)) print('number of students +...
true
725e62fb19f409922b89b8cbfc94669976130255
17c23039/The-Unbeatable-Game
/main.py
2,939
4.375
4
from time import sleep import random score = int(0) print("Rock Paper Scissors, Python edition! This project is to see how complicated and advanced I can make a RPS game.") sleep(3) print("When it is your turn, you will have three options. [R]ock, [P]aper and [S]cissors! For a loss you will lose a point, a tie it will...
true
7250d2b24e69dce512edb4f99cb2710e770c1d80
buggy213/ML-120_Materials
/Unit-035/traditional_five_starter.py
2,620
4.1875
4
import random import sys # We will be using the following encoding for rock, paper, scissors, lizard, and Spock: # Rock = 0 # Paper = 1 # Scissors = 2 # Lizard = 3 # Spock = 4 # # Fill in the below method with the rules of the game. # determineWinner is a structure called a method. The code in th...
true
ac65076020ab2a9aa50ee4ea7f31679a90cdf949
The-SS/parallel_python_test
/parallel_py_test.py
2,517
4.25
4
# Author: # Sleiman Safaoui # Github: # The-SS # Email: # snsafaoui@gmail.com # sleiman.safaoui@utdallas.edu # # Demonstrates how to use the multiprocessing.Process python function to run several instances of a function in parallel # The script runs the same number of instance of the function in series and parallel ...
true
cef145f7edee15add71fd819ba64d39c7cb2f052
paulyun/python
/Schoolwork/Python/In Class Projects/3.10.2016/InClassActivity_3.10.2016.py
390
4.1875
4
#In class Activity for 3/10/2016 totalTime = int(input ("Enter a time in seconds")) resultMinutes = int(totalTime / 60) #this function divides the users totaltime by 60 to get the minute value resultSeconds = totalTime % 60 #this function gets the remainder value of the totaltime divided by 60 to get the remaining se...
true
27e0fcf49ea15c5bccf24a5858c85809fe5f022e
paulyun/python
/Schoolwork/Python/In Class Projects/5.17.2016/Palindrome.py
268
4.21875
4
def isPalindrome(): word = input("Please enter a word to see if it is Palindrome") reverse = "" for letter in range(len(word)-1, -1, -1): #range(start, stop, sequence) reverse+=word[letter] return reverse == word print(isPalindrome())
true
1ac8cbf4abb9d670f1e38bb7cfb706f0f8326308
Saksham-Bhardwaj/Password-Validation
/ValidationModule.py
1,105
4.25
4
#regex module import re #function to validate each password input def checkPass(str): if(len(str)<6 or len(str)>12): print(str + " Failure password must be 6-12 characters.\n") return if not re.search("[a-z]", str): print(str + " Failure password must contain at least one letter...
true
2505d32f0cea8d1d6813edfcf2d87973e8524b77
IMDCGP105-1819/text-adventure-Barker678
/Player.py
1,132
4.25
4
class Player(object): #we create a Player class that affects the inventory of the player, the players name and given direction to the player. def __init__ (self): self.Player = Player self.Name = "" #empty - for the players name self.inventory = [] #we define the inventory/we need it for...
true
112ead1004333cd0b246109dd25103e7e579820b
SpadinaRoad/Python_by_Examples
/Example_114/Example_114.py
1,019
4.15625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_114 # $ python3 Example_114.py # $ python3 Example_114.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 114 Using the Books.csv fi...
true
67e75bf152ecf46e74dfd00fcdfc7fa44523f85c
SpadinaRoad/Python_by_Examples
/Example_035/Example_035.py
599
4.125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_035 # $ python3 Example_035.py # $ python3 Example_035.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 035 Ask the user to enter ...
true
af64d3f5ecf4e84e40a4d58eeaf5112f12bf5595
SpadinaRoad/Python_by_Examples
/Example_058/Example_058.py
1,125
4.5
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_058 # $ python3 Example_058.py # $ python3 Example_058.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 058 Make a maths quiz that...
true
17110747677a3be407ce36d3a27a5d415d7d9432
SpadinaRoad/Python_by_Examples
/Example_022/Example_022.py
870
4.5
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_022 # $ python3 Example_022.py # $ python3 Example_022.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 022 Ask the user to enter ...
true
7603e32d8a1590523d33d29d2e331968e6881de0
SpadinaRoad/Python_by_Examples
/Example_121/Example_121.py
2,486
4.84375
5
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_121 # $ python3 Example_121.py # $ python3 Example_121.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 121 Create a program that ...
true
949e7b0d24b836761e0b5f326349dadd404c91c5
SpadinaRoad/Python_by_Examples
/Example_120/Example_120.py
2,377
4.59375
5
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_120 # $ python3 Example_120.py # $ python3 Example_120.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 120 Display the following ...
true
89696d06bfc3e0760c8fa983b4bdffa34a54a6a7
SpadinaRoad/Python_by_Examples
/Example_087/Example_087.py
628
4.71875
5
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_087 # $ python3 Example_087.py # $ python3 Example_087.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 087 Ask the user to type i...
true
59d41de6a817138dd30562aab81ef9e878ced7f1
SpadinaRoad/Python_by_Examples
/Example_008/Example_008.py
768
4.34375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_008 # $ python3 Example_008.py # $ python3 Example_008.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 008 Ask for the total pric...
true
b674a22cbac308660674199958dda064260eeb78
SpadinaRoad/Python_by_Examples
/Example_118/Example_118.py
781
4.4375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_118 # $ python3 Example_118.py # $ python3 Example_118.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 118 Define a subprogram th...
true
4cdf1d1b109601376c4046cd58fc940ba8a67ac0
SpadinaRoad/Python_by_Examples
/Example_073/Example_073.py
1,079
4.4375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_073 # $ python3 Example_073.py # $ python3 Example_073.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 073 Ask the user to enter ...
true
122071acd8cdcdb643aeb24d40edeb5bf00e5f72
SpadinaRoad/Python_by_Examples
/Example_005/Example_005.py
792
4.40625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_005 # $ python3 Example_005.py # $ python3 Example_005.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 005 Ask the user to enter ...
true
7acfe740b3794bfb3667c2012f8cad14ee51e14a
SpadinaRoad/Python_by_Examples
/Example_054/Example_054.py
1,300
4.3125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_054 # $ python3 Example_054.py # $ python3 Example_054.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 054 Randomly choose either...
true
862410ffce316943c47de2b0ab155f6549182f71
SpadinaRoad/Python_by_Examples
/Example_033/Example_033.py
1,029
4.5
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_033 # $ python3 Example_033.py # $ python3 Example_033.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 033 Ask the user to enter ...
true
9f61ce54a78450b8cd1151a94c177b3330e6b1f1
SpadinaRoad/Python_by_Examples
/Example_117/Example_117.py
2,151
4.4375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # To run in terminal # $ cd /home/james/Documents/Edoc/3Nohtyp/Python_By_Example/Example_117 # $ python3 Example_117.py # $ python3 Example_117.py <Input.txt >Output.txt """ Python by Example: Learning to Program in 150 Challenges by Nichola Lacey 117 Create a simple maths ...
true
b5e95bb07b2cb89f23c172c8af483b6bf595fa36
ooladuwa/cs-problemSets
/Week 1/07-SchoolYearsAndGroups.py
2,132
4.34375
4
Imagine a school that children attend for years. In each year, there are a certain number of groups started, marked with the letters. So if years = 7 and groups = 4For the first year, the groups are 1a, 1b, 1c, 1d, and for the last year, the groups are 7a, 7b, 7c, 7d. Write a function that returns the groups in the sc...
true
56c7032089bdb28b37620aa15a03faf782e67f26
ooladuwa/cs-problemSets
/Week 3/033-insertValueIntoSortedLinkedList.py
2,081
4.3125
4
# Singly-linked lists are already defined with this interface: # class ListNode(object): # def __init__(self, x): # self.value = x # self.next = None # """ - create function to insert a node - create new link node with value provided - set up a current variable pointing to the head of the list and set a ref ...
true
b900777c43b0910d9329b4a3e492e0da64aaf625
ooladuwa/cs-problemSets
/Week 2/027-WordPattern.py
1,640
4.21875
4
""" Given a pattern and a string a, find if a follows the same pattern. Here, to "follow" means a full match, such that there is a one-to-one correspondence between a letter in pattern and a non-empty word in a. Example 1: Input: pattern = "abba" a = "lambda school school lambda" Output: true Example 2: Input: pat...
true
690ffbac5d76e55e2ce80ff075bc81f97defbbd8
Deepakat43/luminartechnolab
/variabl length argument method/varargmethd.py
460
4.15625
4
def add(num1,num2): return num1+num2 res=add(10,20) print(res) #here 2 argumnts present #what if there are 3,4,5 etc arguments present #so we use ****variable length argument method**** def add(*args): print(args) add(10) add(10,20) add(10,20,30,40,50) #using this frmat we get argmnts in a (tuple) frmat #f...
true
afb2f7f9f469e96b342930d31461d9b9fa259171
jpierrevilleres/python-math
/square_root.py
1,291
4.28125
4
import math #imports math module to be able to use math.sqrt and abs function #Part 1 defining my_sqrt function def my_sqrt(a): #Python code taken from Section 7.5 x = a / 2 #takes as an argument and uses it to initialize value of x while True: #uses while loop as mentioned in Section 7.5 y =...
true
633b1ea1c5d61c406e9745dfe351f15cdf2b8bfd
markymauro13/CSIT104_05FA19
/Exam-Review-11-6-19/exam2_review3.py
490
4.3125
4
x = "Computational Concepts 1" y = "MSU" # What are the results of the following expressions? # a. How many ‘o’ in string x? # b. How can you find the substring “Concepts” in x? # c. How can you check if y starts with “M”? # d. How can you replace “MSU” in y with “Montclair State University”? #a print(x.c...
true
2a499ffe9355bb49ff0ca6ff45b8648a1841af15
markymauro13/CSIT104_05FA19
/Assignment3/1_calculateLengthAndExchange.py
443
4.25
4
x = str(input("Enter a string: ")) # ask for input from user if(len(x)>0): print("The length of string is: " + str(len(x))) # print the length of the string print("The resulted string is: " + str(x[-1]) + str(x[1:len(x) - 1]) + str(x[0])) # print the result of the modified string else: print("Try ...
true
c9cece85db973eedfc69fb0d9e8592935d21232e
markymauro13/CSIT104_05FA19
/Exam-Review-11-6-19/exam2_review6.py
445
4.1875
4
#6 for i in range(1,7): # controls the numbers of rows for j in range(1,i+1): # controls the numbers on those lines print(j, end = '') print() print("------") i = 1 while i <= 6: for j in range(1, i+1): print(j, end = '') print() i+=1 print("------...
true
548c422e96d13360a458557f1e0e2a465bf3f782
AastikM/Hacktoberfest2020-9
/Python_Solutions/Q24_factorial(recursion).py
451
4.3125
4
#Function for calulating the factorial def factorial(x): if x == 1 or x== 0 : #base/terimination condition return 1 elif(x < 0) : print("Sorry, factorial does not exist for negative numbers") else: return (x * factorial(x-1)) #Recursive Call for function factorial # main num ...
true
2d1c82316be30bb1a893f9d6c58b4678137e6814
AastikM/Hacktoberfest2020-9
/Python_Solutions/Q2BinaryDecimal.py
521
4.53125
5
# Python program to convert binary to decimal #Function to convert binary to decimal def binaryToDecimal(n): num=n; decimal=0; #Initializing base value to 1, i.e 2^0 base = 1; temp = num; while temp: last_digit=temp%10; temp//= 10; decimal += last_digit * base; ...
true
bf8e19eae13001826a645bdb92e1897927875d54
davinpchandra/ITP_Assignments
/AssignmentPage46
1,747
4.125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Nov 19 10:11:08 2019 @author: davinpc """ # 3-4 GuestList guest_list = ["Steve Jobs","Robert Downey Jr","Will Smith"] for guest in guest_list: print("Dear " + guest + ", please come to my dinner.") print(" ") # 3-5 ChangingGuestList print(guest_l...
true
bfbc32395535b56de1c2749b04614343afb18789
Dencion/practicepython.org-Exercises
/Exercise11.py
688
4.28125
4
def checkPrime(userNum): ''' Checks if the users entered number is a prime number or not ''' oneToNum = []#Creates a list starting from 1 - userNum divisorList = []#Empty list to be filled with divisors form userNum i = 1 while i <= userNum: oneToNum.append(i) i += 1 ...
true
92411f12036363a6056c85f71df242dbb9a119de
KenjaminButton/runestone_thinkcspy
/6_functions/exercises/6.13.3.exercise.py
629
4.25
4
# 6.13.3 Exercise: # Write a non-fruitful function drawPoly(someturtle, somesides, somesize) # which makes a turtle draw a regular polygon. When called with # drawPoly(tess, 8, 50), it will draw a shape like this: import turtle # Initializing turtle window = turtle.Screen() window.bgcolor("lightgreen") # Changing c...
true
a9fae446d7e342cc7e4ffc014d00f42993877f62
KenjaminButton/runestone_thinkcspy
/14_web_applications/14.5.py
1,922
4.375
4
# Writing Web Applications with Flask ''' In this section, you will learn how to write web applications using a Python framework called Flask. Here is an example of a Flask web application: The application begins by importing the Flask framework on line 1. Lines 6-11 define a function hello() that serves up a simple ...
true
9ad02888fbdeb4a86afc10d8be138e173475e075
KenjaminButton/runestone_thinkcspy
/10_lists/10.12.cloning_lists.py
603
4.34375
4
# 10.12 Cloning Lists ''' If we want to modify a list and also keep a copy of the original, we need to be able to make a copy of the list itself, not just the reference. This process is sometimes called cloning, to avoid the ambiguity of the word copy. The easiest way to clone a list is to use the slice operator. Tak...
true
1ee694e9e288b104b3f6054b511fb9768e71a535
KenjaminButton/runestone_thinkcspy
/9_strings/9.9.strings_are_immutable.py
899
4.34375
4
# 9.9 Strings Are Immutable ''' One final thing that makes strings different from some other Python collection types is that you are not allowed to modify the individual characters in the collection. It is tempting to use the [] operator on the left side of an assignment, with the intention of changing a character in a...
true
9435b6fa5b480be9729ec52eaa5b87f7207401e5
KenjaminButton/runestone_thinkcspy
/10_lists/10.17.lists_and_loops.py
1,006
4.46875
4
# 10.17 Lists and Loops ''' ''' fruits = ["apple", "orange", "banana", "cherry"] for afruit in fruits: # by item print(afruit) ''' In this example, each time through the loop, the variable position is used as an index into the list, printing the position-eth element. Note that we used len as the upper bound ...
true
d7c00c2393c1b3df29c77d606ccd92e456f5a5d9
KenjaminButton/runestone_thinkcspy
/11_files/exercises/11.9.4.py
2,501
4.25
4
''' Interpret the data file labdata.txt such that each line contains a an x,y coordinate pair. Write a function called plotRegression that reads the data from this file and uses a turtle to plot those points and a best fit line according to the following formulas: 𝑦=𝑦¯+𝑚(𝑥−𝑥¯) 𝑚=∑𝑥𝑖𝑦𝑖−𝑛𝑥¯𝑦¯∑𝑥2𝑖−𝑛𝑥¯2 ...
true
af4d0611190081213e50361f1913ee68f694257e
KenjaminButton/runestone_thinkcspy
/2_simple_python_data/2.7.operators_and_operands.py
1,457
4.53125
5
# Operators and Operands print("\n----------------------------") print(2 + 3) # <<< 5 print(2 - 3) # <<< -1 print(2 * 3) # <<< 6 print(2 ** 3) # <<< 8 print(3 ** 2) # <<< 9 print("\n----------------------------") minutes = 645 hours = minutes / 60 print(hours) # <<< 10.75 print("\n----------------------------") prin...
true
aec94d7f54cc24921ab10dabc07957947fa8f212
KenjaminButton/runestone_thinkcspy
/4_python_turtle_graphics/4.1.hello_little_turtles.py
1,538
4.84375
5
# 4.1 Hello Little Turtles ''' There are many modules in Python that provide very powerful features that we can use in our own programs. Some of these can send email or fetch web pages. Others allow us to perform complex mathematical calculations. In this chapter we will introduce a module that allows us to create a da...
true
dbd691354cf51c9b8c5ec66617d41ad250ca51cd
KenjaminButton/runestone_thinkcspy
/12_dictionaries/exercises/12.7.1.exercise.py
1,064
4.25
4
''' Write a program that allows the user to enter a string. It then prints a table of the letters of the alphabet in alphabetical order which occur in the string together with the number of times each letter occurs. Case should be ignored. A sample run of the program might look this this: Please enter a sentence: ThiS...
true
90e719b77b8664dd93f4b8a09b9fd822f5d64a5d
KenjaminButton/runestone_thinkcspy
/2_simple_python_data/2.8.input.py
887
4.25
4
# Input n = input("Please enter your name: ") print("\nHello", n) print("\n--------------------------") string_seconds = input("Please input the number of seconds you wish to convert: ") total_seconds = int(string_seconds) hours = total_seconds // 3600 seconds_still_remaining = total_seconds % 3600 minutes = seconds_s...
true
36755b3f1801a8ed276545370b54deaa06eeda2d
KenjaminButton/runestone_thinkcspy
/17_classes_and_objects_basics/exercises/17.11.2.exercise.py
553
4.125
4
''' Add a method reflect_x to Point which returns a new Point, one which is the reflection of the point about the x-axis. For example, Point(3, 5).reflect_x() is (3, -5) ''' import math class Point: def __init__(self, initX, initY): self.x = initX self.y = initY def reflect_x(self): ...
true
a7e1aa3372a75ce887a35011f0669cf329db940d
KenjaminButton/runestone_thinkcspy
/4_python_turtle_graphics/4.11_13_exercise.py
709
4.3125
4
''' # 13 A sprite is a simple spider shaped thing with n legs coming out from a center point. The angle between each leg is 360 / n degrees. Write a program to draw a sprite where the number of legs is provided by the user. ''' number_of_legs = input("input a number of legs (choose between 0 and 360): ") number_of_l...
true
36a370c8100c4b59b269f1eec97f1f6f9966c02b
KenjaminButton/runestone_thinkcspy
/6_functions/exercises/6.13.11.exercise.py
602
4.5
4
# Extend the star function to draw an n pointed star. # (Hint: n must be an odd number greater or equal to 3). # n pointed star import turtle # Initializing turtle window = turtle.Screen() window.bgcolor("lightgreen") # Changing colors and pensize for turtle kendrick = turtle.Turtle() kendrick.color("hotpink") kend...
true
f70d6eb25a2ea7a650c3309478a51c881c8eeb37
KenjaminButton/runestone_thinkcspy
/6_functions/exercises/6.13.6.exercise.py
662
4.34375
4
# Write a non-fruitful function drawEquitriangle(someturtle, somesize) which # calls drawPoly from the previous question to have its turtle draw a # equilateral triangle. import turtle # Initializing turtle window = turtle.Screen() window.bgcolor("lightgreen") # Changing colors and pensize for turtle kendrick = turt...
true
327dac896917535638efe1b3cca6bf3fb5727d11
KenjaminButton/runestone_thinkcspy
/11_files/exercises/11.9.3.py
477
4.15625
4
''' Using the text file studentdata.txt (shown in exercise 1) write a program that calculates the minimum and maximum score for each student. Print out their name as well. ''' def min_and_max(): f = open('studentdata.txt', 'r') for i in f: items = i.split() # print(items[1:]) minimum =...
true
95f96088c1d431c2ef6a1d6d8b1864c4a27c0b20
eoinpayne/Python
/Lab2circle.py
277
4.15625
4
from math import pi r = 12 area = pi * r ** 2 circumference = 2*pi*r #circumference = 2*pi*r... ca calculate on the fly or define the sum up here. print ("The area of a circle with radius", r, "is", area) print ("The circumference of a circle with radius" , r, "is", 2*pi*r)
true
1c13bb45f9fe5ef9b7eedd2d4e02575119566751
eoinpayne/Python
/Lab2average.py
1,297
4.40625
4
__author__ = 'D15123620' #(1 point) Write a program average.py that calculates and prints the average of three #numbers. Test it with 3, 5 and 6. Does it make a difference if you treat the input strings as #float or int? what about if you print the output result as float or an int? '''def what_is_average (num_1, num_...
true
45b5235a525b2007c4124fd16fb894f7f10f9c0f
ivyostosh/algorithm
/data_structure/queue.py
1,921
4.5
4
# Queue Implementation (https://www.educative.io/blog/8-python-data-structures """ We can use append() and pop() to implement a queue, but this is inefficient as lists must shift elements one by one. Instead, the best practice is to use a deque from collections module. Deques (double-ended queue) allow you to access b...
true
b0debf7de24d42f2106213afda16edb349e0c4dd
bikegirl/NLP-Nitro
/Word.py
878
4.34375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Word class holds the properties of a word: token, part_of_speech, and frequency. Has a method for computing complexity """ import math class Word: def __init__(self, word, part_of_speech, frequency = 0): self.__word = word self.__part_...
true
c9af8dd04b7a7cbac9ac159c22379174525ebc9a
suriyaaws2020/Python
/Create/NewfolderPython/python_101.py
807
4.34375
4
#variable declaration X=2, Y=-3, Z=0.4 #above declares the variables under respective variable type# #example X=2 is an integar, Z=0.4 is an float type# #print function is used to print the value# print(type(x)) #the above prints the value of X as 2. Output will be 2 #below command shows how to assign values into a var...
true
5d41a7c7404af46e3d985142f487373e60a3f206
usn1485/TipCalculator
/TipCalculator.py
2,422
4.3125
4
#Import the required Modules import math import os #Take user input for bill amount. bill=float(input("Enter the bill Amount:")) # Write function to calculate tip. def tipCalculator(bill,percent): # convert the percent input to whole number if it is given as 0.15 if(percent<1): tipPercent=percent*100 ...
true
d684aacc8759a7a4eb3b3e039e4813934624d407
campjordan/Python-Projects
/Numbers/pi.py
1,243
4.28125
4
''' Find PI to the Nth Digit - Enter a number and have the program generate PI up to that many decimal places. Keep a limit to how far the program will go. ''' def arctan(x, one=1000000): """ Calculate arctan(1/x) arctan(1/x) = 1/x - 1/3*x**3 + 1/5*x**5 - ... (x >= 1) This calculates it in fixed poi...
true
c2d9a1ac9c8ce3a8f2c63b1fa8768ffc5400f68f
rulesrmnt/python
/calc.py
350
4.34375
4
print (2+3) #addition print (2*3) #multiplication print (2-3) # substraction print (2/3) #float division print (2//3) #integer division print (3%2) # Module, gives remainder print (2%2) print(round(2/3,2)) #round function print (2**5) # exponent i.e. 2 to the power 5 print (2**5**2) # associative rule i.e exponents are...
true
4355be5058d5d5a3858c4cee03ea4a219a35293b
jwarlop/UCSD
/Extension/Cert_DM_Adv_Analytics/2018Win_Py4Info/Homework/A06/URL_reader.py
1,267
4.125
4
# Assignment 6 # Network Programming # John M Warlop # Python 3.x # Due 3/4/2018 from urllib.request import urlopen url = input("type url(ex: www.ibm.com): ") url = "http://"+url try: res=urlopen(url) except: print("Could not open "+url) size=0 Chunk = 512 flag = False while True: chunk = res.read(Chunk) ...
true
72611838082c1243f1fb63fab711af4c832459ab
vijayramalingom/SYSC-1005-Introduction-to-Software-Development-
/math_quiz_v3.py
1,776
4.25
4
""" Version 3 of a math quiz program. Adapted from a programming problem by Jeff Elkner. dlb Dept. of Systems and Computer Engineering, Carleton U. Initial release: October 21, 2014 (SYSC 1005) Revised: November 4, 2015 (SYSC 1005) The user is prompted to enter a command ("T" or "Q"). If the user types "Q", ...
true
512746e85cd9cc1c4b18b29fd05a103e4a915db1
dtingg/Fall2018-PY210A
/students/C_Farris/session03/list_lab.py
1,272
4.25
4
#!/usr/bin/env Python3 """ Date: November 11, 2018 Created by: Carol Farris Title: list Lab Goal: learn list functions """ def displayPfruits(myFruit): for x in myFruit: if x.lower().startswith('p'): print(x) else: print(x + " doesn't start with p") def addUsingInsert(m...
true
8ce538d1282639c0040cc9101cf9ca1750192fcf
dtingg/Fall2018-PY210A
/students/ZidanLuo/session02/printGrid.py
602
4.125
4
import sys def print_grid(x,y): count = 1 #count all the possible number of lines lines = (y + 1) * x + 1 plus = "+" minus = "-" shu = "|" empty = " " #draw the horizontal and vertical lines Horizontal = (plus + y * minus) * x +plus Vertical = (shu + y * empty) * x + shu ...
true
3ea0e0bef450bd1adf0135bbc54775a7aade1fb4
dtingg/Fall2018-PY210A
/students/ericstreit/session03/list_lab.py
2,511
4.15625
4
#Lesson03 #String Exercises ## # #!/usr/bin/env python3 #define variables mylist = ["Apples", "Pears", "Oranges", "Peaches"] #define function def myfunc(n): """Update the DocString""" pass #series 1 print("The list currently contains: ", mylist) additem = input("Pleaes enter another item: ") mylist.append(addit...
true
ab2aed6b36ee8a39a05d108704db93cad76a1311
dtingg/Fall2018-PY210A
/students/ZackConnaughton/session03/list_lab.py
709
4.15625
4
#!/usr/bin/env python def series1(): """ Shows what can be done with a simple list of fruitsself. """ fruits = ['Apples', 'Pears', 'Oranges', 'Peaches'] print(fruits) response = input('Input another Fruit: ') fruits.append(response) print(fruits) fruit_number = input('Enter the numb...
true
e07217f51ac1b0401635329a3ae81a54495135a7
dtingg/Fall2018-PY210A
/students/DiannaTingg/Session05/comprehensions_lab.py
2,453
4.4375
4
# Lesson 05 Exercise: Comprehensions Lab # Count Even Numbers # Using a list comprehension, return the number of even integers in the given list. def count_evens(l): return len([i for i in l if i % 2 == 0]) assert count_evens([2, 1, 2, 3, 4]) == 3 assert count_evens([2, 2, 0]) == 3 assert count_evens([1, 3, 5]...
true
29c93f8ba7065b60a30ea4264f4678eb90e8301a
dtingg/Fall2018-PY210A
/students/ZachCooper/session01/break_me.py
1,139
4.125
4
#!/usr/bin/env python # I tried a couple of error exceptions that I commonly ran into during my Foundations class # Example of ZeroValueError def divide_things(num1, num2): try: print(num1 / num2) except ZeroDivisionError: print("Ummm...You totally can't divide by 0") raise ZeroDivision...
true
f3348cba2eaaa6e973b8a28497d0cd5d942389a4
dtingg/Fall2018-PY210A
/students/HABTAMU/session04/dict_lab.py
2,076
4.125
4
#!/usr/bin/env python3 """Dictionaries 1""" # Create a dictionary containing “name”, “city”, and “cake” for “Chris” from “Seattle” who likes “Chocolate” # (so the keys should be: “name”, etc, and values: “Chris”, etc.) my_dict = {"name": "Chris","city": "Seattle","cake": "Chocolate"} # Display the dictionary. print...
true
b74f0019166cd600f9a17433f5b1807b7f94548b
dtingg/Fall2018-PY210A
/students/DiannaTingg/Session04/get_languages.py
2,111
4.40625
4
# Lesson 04 Exercise: File Exercise # File reading and parsing # Write a program that takes a student list and returns a list of all the programming languages used # Keep track of how many students specified each language # It has a header line and the rest of the lines are: Last, First: Nicknames, languages def get...
true
63a2168eeeddcc102e648ea5130a40d888569a7d
dtingg/Fall2018-PY210A
/students/JonSerpas/session02/series.py
1,395
4.25
4
def fibonacci(n): #first create our list with starting integers fiblist = [0,1] #appends to the end list of integers the sum of the previous two integers #this will loop until the length of the list is n long #finally we return the n value of the list while len(fiblist) < n: fiblist.append(sum(fiblist[-2:])) ...
true
e571de78c6e4fd094bcf760e2f2f522ff53958aa
dtingg/Fall2018-PY210A
/students/Adolphe_N/session03/slicing.py
1,307
4.5
4
#! python3 a_string = 'this is a string' a_tuple = (2,54,13,12,5,32) name = 'Seattle' ''' prints the list with the last item first and first item last ''' def exchange_first_last(): #this will exchange the first and last character of the string print(a_string) print ('{}{}{}'.format(a_st...
true
8dc90534107673e7574626c9816423f8c72bf4f2
Miriam-Hein/pands-problem-sheet
/es.py
710
4.125
4
# es.py # This program reads in a text file and outputs the number of e's it contains. # Author: Miriam Heinlein # Import library (System-specific parameters and functions) import sys # Function to read letter e in the file from an arugment in the command line def readText(): with open(sys.argv[1], "r") as f: ...
true
12b5743215371715e3fb8437c64f2c76ebb68cef
michaelkmpoon/Pandhi_Ayush_-_Poon_Michael_Assignment1_CTA200H
/question_1/find_replace.py
962
4.15625
4
#!/usr/bin/env python3 import os def find_replace(find: str, replace: str): # type check, only strings allowed as input os.makedirs(replace) # make directory called replace in working directory for file_name in os.listdir("."): if file_name.endswith(".txt"): file = open(file_name, "r") ...
true
8a2eb6e733d29afad05b36566efd71406ca57fbc
pankajnimgade/Python_Test101
/Function_Installation_and_Conditionals/code_with_branches_1_.py
1,574
4.25
4
phone_balance = 9 bank_balance = 100000000 if phone_balance < 10: phone_balance += 10 bank_balance -= 10 print("Phone Balance: " + str(phone_balance)) print("Bank Balance: " + str(bank_balance)) weight_in_kg = 55 height_in_m = 1.2 if 18.5 <= weight_in_kg/(height_in_m**2) < 25: print("BMI is considered 'normal...
true
9b5ad1db488ceb425f57abc3cac88fefa8d581c5
Prathamdoshi/UC-Berkeley-Data-Analytics-Bootcamp-Module-Exercises
/Python/Netflix.py
1,405
4.125
4
instructions =""" # Netflix lookup Finding the info to some of netlfix's most popular videos ## Instructions * Prompt the user for what video they are looking for. * Search through the `netflix_ratings.csv` to find the user's video. * If the CSV contains the user's video then print out the title, what it is rated ...
true
8507cee32a92b1d19214e08ac731be5a10bc8bb4
daviddwlee84/LeetCode
/Python3/LinkedList/MergeTwoSortedLists/Better021.py
892
4.125
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None from ..ListNodeModule import ListNode class Solution: def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode ...
true
009fb7f3db4c51738566e83de7ae32ecd2e813f6
daviddwlee84/LeetCode
/Python3/LinkedList/InsertionSortList/Naive147.py
1,124
4.1875
4
from ..ListNodeModule import ListNode class Solution: def insertionSortList(self, head: ListNode) -> ListNode: if not head or not head.next: return head fakeRoot = ListNode(-1) current = fakeRoot.next = head while current and current.next: if current.val <...
true
df797407e5c699b19a92585715a093d50f867c99
Kiddiflame/For_Assignment_5
/Documents/Forritun/max_int.py
590
4.59375
5
#1. Initialize with git init #2. input a number #3. if number is larger than 0, it becomes max-int #4. if number is greater than 0, user can input another number #5. repeat step 3 and 4 until negative number is given #6. if negative number is given, print largest number num_int = int(input("Input a number: "))# Do n...
true
d5deb525066d1bd891b52c84f63f4033bdcedae8
andrew-yt-wong/ITP115
/ITP 115 .py/Labs/ITP115_L8_1_Wong_Andrew.py
1,568
4.28125
4
# Andrew Wong, awong827@usc.edu # ITP 115, Spring 2020 # Lab 8-1 # Wants to continue function that checks whether the user is going to continue def wantsToContinue(): # Loop until a valid response is given validResponse = False while not validResponse: # Retrieve the response and capitalize it ...
true