blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
b299c50e3fa26dbf0c1f7dab579813670ec6dea1 | moonlimb/tree_problems | /isBST.py | 383 | 4.1875 | 4 | from Node import Node
def is_BST(node):
"""returns True if a given node is a root node of a binary search tree"""
if node.is_leaf():
return True
else:
# Node class contains comparison methods
if (node.left and node.left >= node) or (node.right and node >= node.right):
re... | true |
8db19628f571ab9cb2e0babcb961974c8baaf99d | imsreyas7/DAA-lab | /Recursion/expo3.py | 263 | 4.21875 | 4 | def expo3(x,n):
if n=0:
return 1
else:
if n%2 ==0:
return expo3(x,n/2)*expo(x,n/2)
else:
return x*expo(x,n-1)
x=int(input("Enter a number whose power has to be found "))
n=int(input("Enter the power "))
print("The result is ",expo3(x,n)) | true |
ad02d70583ed30bea2710fbc61df4a00680dfdc0 | Aksharikc12/python-ws | /M_2/Q_2.py | 1,407 | 4.53125 | 5 | '''2. Write a program to accept a two-dimensional array containing integers as the parameter and determine the following from the elements of the array:
a. element with minimum value in the entire array
b. element with maximum value in the entire array
c. the elements with minimum and maximum values in each column
d. t... | true |
211f7d8c6027e43fa5933eb581ecee3a8daf0edb | Aksharikc12/python-ws | /M_1/Q_1.py | 413 | 4.25 | 4 | '''1. Write a program to accept a number and determine whether it is a prime number or not.'''
import math
num=int(input("enter the number"))
is_prime=True
if num<2:
is_prime=False
else:
for i in range(2,int(math.sqrt(num)) + 1):
if num % i == 0:
is_prime=False
break
if is_pr... | true |
50959738f8045b5b3d0beea7c9992cbbe820dc82 | murphy1/python_problems | /chapter6_string.py | 1,577 | 4.1875 | 4 | # file for Chapter 6 of slither into python
import re
# Question 1, user input will state how many decimal places 'e' should be formatted to.
"""
e = 2.7182818284590452353602874713527
format_num = input("Enter Format Number:")
form = "{:."+format_num+"f}"
print(form.format(e))
"""
# Question 2, User will input 2 ... | true |
da1190857891ba038938c4e7bba4cd26dbcc21ac | zabdulmanea/movie_trailer_website | /media.py | 555 | 4.125 | 4 | class Movie():
"""
This class provides the structure to store movie information
Attributes:
title (str): The movie title
trailer_youtube_url (str): A link to the movie trailer on youtube
poster_image_url (str): A link to the movie poster
"""
# constructor of Movie class, ca... | true |
b73b09b2466c362a584cada47b9ed0ba2c249d9e | Nitin-Diwakar/100-days-of-code | /day25/main.py | 1,431 | 4.53125 | 5 | # Write a Python GUI program
# using tkinter module
# to input Miles in Entry widget
# that is in text box and convert
# to Kilometers Km on button click.
import tkinter as tk
def main():
window= tk.Tk()
window.title("Miles to Kilometers Converter")
window.geometry("375x200")
# cr... | true |
3d6cab692c8588bf46a2f4f4b96c441141472660 | Endie990/pythonweek-assigments | /Assignment_Guessing_game.py | 534 | 4.125 | 4 | #ass 2- guessing game
import random
guessnum=random.randint(1,9)
num= int(input('Guess a number between 1 and 9: '))
while guessnum!='num':
if num<guessnum:
print('Guess is too low,Try again')
num= int(input('Guess a number between 1 and 9: '))
elif ... | true |
5de52fcb51cf062e250533875d749f7fcd0c5a1e | AdityaJsr/Bl_week2 | /week 2/dictP/createDict.py | 587 | 4.125 | 4 | """
Title - Write a Python program to create a dictionary from a string.
Note: Track the count of the letters from the string.
Sample string : 'w3resource'
Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}
Access individual element through indexes.
Author... | true |
423df06c344e381a8d09156226b10ef17f37bebd | thatguysilver/pswaads | /listing.py | 966 | 4.21875 | 4 | '''
Trying to learn about the different list concatenation methods in py
and examine their efficiency.
'''
import time
def iterate_concat():
start = time.time()
new_list = []
for i in range(1000):
new_list += [i]
end = time.time()
return f'Regular iteration took {end - start} seconds.'
d... | true |
304769d3a15878e844f87a8fa360e8a7ee5a5c97 | dan480/caesars-cipher | /main.py | 1,364 | 4.3125 | 4 | #!/usr/bin/python
# -*- coding: UTF-8 -*-
import argparse
from src.select_alphabet import select_alphabet
from src.decoding import decoding_func
from src.encoding import encoding_func
"""
The main file that runs the program logic.
The function of creating a command line parser is implemented here.
In the main () func... | true |
c9a18125f74caacb4b470d986bf7e09fe119b180 | Tchomasek/Codewars | /Codewars/6 kyu/Sort the odd.py | 663 | 4.3125 | 4 | def sort_array(source_array):
result = list(source_array)
even = {}
for index,num in enumerate(source_array):
if num % 2 == 0:
even[index] = num
result.remove(num)
result.sort()
for index,num in even.items():
result.insert(index, num)
return result
print(... | true |
0adb0d78954c719dadafd33dde275e43387b70bc | Machin-Learning/Exercises | /Section-1/Data Types/set.py | 1,475 | 4.40625 | 4 | # #Set
# 1. Set in python is immuttable/non changeable and does not show duplicate
# 2. Set are collection of element seprated by comma inside {,}
# 3. Set can't be indexed or... | true |
f6b584f4a4315fc01bba5463bca09b968f9f2d76 | Machin-Learning/Exercises | /Section-1/Data Types/variables.py | 1,191 | 4.125 | 4 | # Variables in python
# var = 5
# print(var)
# var = "Muzmmil pathan"
# print(var)
# Data Types
# 1. int()
# 2. str()
# 3. float()
# 4. list()
# 5. tuple()
# 6. set()
# 7. dict()
num = 4 #integers are a number "without point / non fractional / Decimal from 1-9 only"
print(type(num)... | true |
d9e48b09f2c3a902b3009279f89263b5eee7087e | yashbagla321/Mad | /computeDistancePointToSegment.py | 1,014 | 4.15625 | 4 | print 'Enter x and y coordinates of the point'
x0 = float(input())
y0 = float(input())
print 'Enter x and y coordinates of point1 then point2 of the line'
x1 = float(input())
y1 = float(input())
x2 = float(input())
y2 = float(input())
import math
def computeDistancePointToSegment(x1,y1, x2,y2, x3,y... | true |
e898d4e4b96bf10bdba01c473cfa8de608ff158d | mxu007/leetcode | /414_Third_Maximum_Number.py | 1,890 | 4.1875 | 4 | # Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
# Example 1:
# Input: [3, 2, 1]
# Output: 1
# Explanation: The third maximum is 1.
# Example 2:
# Input: [1, 2]
# Output: 2
# Explanation: The ... | true |
00a7856bbfb3690bf77899cfa4ce5e1c59b43191 | saifeemustafaq/Magic-Maths-in-Python | /test.py | 892 | 4.25 | 4 | print ""
print " Please press enter after each step!"
print ""
print ' Think of a number below 10...'
a=raw_input( )
print ' Double the number you have thought.'
b=raw_input()
c= int(input(" Add something from 1-10 with the getting result and type it here (type only within 1-10... | true |
85f11d93c2b76f8a0f8def3f861002cb73056ef9 | Hariharan-K/python | /remove_all_occurrences.py | 1,086 | 4.34375 | 4 | # Remove all occurrences of a number x from a list of N elements
# Example: Remove 3 from a list of size 5 containing elements 1 3 2 3 3
# Input: 3 5 1 3 2 3 3
# Output: 1 2
# Input: 4 7 1 4 4 2 4 7 9
########################
import sys
def remove_all_occurrences(mylist,n):
# loop to traverse each element in list... | true |
b68c2c507980032894a5f75f3a3c619b28b559d1 | Hariharan-K/python | /max_sum_of_non_empty_array.py | 1,411 | 4.28125 | 4 | """
Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maxim... | true |
88f55010db0303121f3c6ba25cba54efe923589f | Colfu/codewars | /6th_kyu/autocomplete_yay.py | 2,620 | 4.21875 | 4 | # It's time to create an autocomplete function! Yay!
# The autocomplete function will take in an input string and a dictionary array
# and return the values from the dictionary that start with the input string. **Cr.1
# If there are more than 5 matches, restrict your output to the first 5 results. **Cr.2
# If there a... | true |
8c1e72d62ca4f9dcdc61a861d0dc8ed095d922ba | sankari-chelliah/Python | /int_binary.py | 414 | 4.34375 | 4 | #Program to convert integer to Binary number
num= int(input("Enter Number: "))
result=''
#Check the sign of the number
if num<0:
isneg=True
num = abs(num)
elif num==0:
result='0'
else:
isneg= False
# Does actual binary conversion
while num>0:
result=str(num%2)+result
num=num//2
#Display resu... | true |
ec094d809089a6cff9ded0f6cd4a10e98a698e60 | rstrozyk/codewars_projects1 | /#8 alternate_capitalization.py | 673 | 4.28125 | 4 | # Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index 0 will be considered even.
# For example, capitalize("abcdef") = ['AbCdEf', 'aBcDeF']. See test cases for more examples.
# The input will be a lowercase string with no spaces.
# Good luck!
d... | true |
1a84de296000421f725a38ef905ab5f590d085ac | SanghamitraDutta/dsp | /python/markov.py | 2,440 | 4.5625 | 5 | #!/usr/bin/env python
# Write a Markov text generator, [markov.py](python/markov.py). Your program should be called from the command line with two arguments: the name of a file containing *text to read*, and the *number of words to generate*. For example, if `chains.txt` contains the short story by Frigyes Karinthy, w... | true |
14f4b6abd789bffaf54ab8587be22f13dd87e572 | j721/cs-module-project-recursive-sorting | /src/searching/searching.py | 1,128 | 4.4375 | 4 | # TO-DO: Implement a recursive implementation of binary search
def binary_search(arr, target, start, end):
# Your code here
middle = (start +end)//2
if len(arr) == 0:
return -1 #empty array
#if target is equal to the middle index in the array then return it
if arr[middle] == target:
... | true |
570b85577fcc8343c1d9fa11d8e0bd95eb3a4e3f | kulsuri/playground | /daily_coding_problem/solutions/problem_9.py | 611 | 4.1875 | 4 | # Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative.
# For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, and 5. [5, 1, 1, 5] should return 10, since we pick 5 and 5.
def largest_sum(l):
inclusive = 0
exclusive = 0
... | true |
4ecf79677118a95f24d80fe0ead4272e8f61eeec | kulsuri/playground | /udemy-11-essential-coding-interview-questions/1.1_arrays_most_freq_no.py | 911 | 4.21875 | 4 | # return the most frequent element in an array in O(n) runtime
def most_frequent(given_array):
# insert all elements and corresponding count in a hash table
Hash = dict()
for c,v in enumerate(given_array):
if given_array[c] in Hash.keys():
Hash[given_array[c]] += 1
else:
... | true |
07d0eb183fcc1f3fd342e785a743043658114649 | kylebush1986/CS3080_Python_Programming | /Homework/Homework_3/hw3_kyle_bush_ex_3.py | 1,708 | 4.4375 | 4 | '''
Homework 3, Exercise 3
Kyle Bush
9/21/2020
This program stores a store inventory in a dictionary.
The user can add items, delete items, and print the inventory.
'''
def printInventory(inventory):
print()
print('Item'.ljust(20), 'Quantity'.ljust(8))
for item, number in inventory.items():
print(i... | true |
1270188cab6e1d289056abee5013a4f729bfb40d | justinDeu/path-viz | /algo.py | 1,273 | 4.40625 | 4 | from board import Board
class Algo():
"""Defines an algorithm to find a path from a start to an end point.
The algorithm will be run against a 2D array where different values
signify some state in the path. The values are as follows:
0 - a free cell
1 - a blocked cell (cannot ... | true |
5d3f9ba65e4c68e743ea21a0db8dbbb54c92bd6f | prahate/python-learn | /python_classes.py | 926 | 4.21875 | 4 | # self is defined as an instance of a class(similar to this in c++),and variables e.g. first, last and pay are called instance variables.
# instance variables are the ones that are unique for each instance e.g. first, last and pay. They are unique to each instance.
# __init__ is called as constructor(in languages like ... | true |
e9d4a5afa1859ec6b3ad87a3000bee910afef669 | prahate/python-learn | /python_sqlite.py | 698 | 4.5 | 4 | import sqlite3
# Creating a connection sqlite database, it will create .db file in file system
# other way to create is using memory, so database will be in memory (RAM)
# conn = sqlite3.connect(':memory:')
conn = sqlite3.connect('employees.db')
# To get cursor to the database
c = conn.cursor()
# Create table using... | true |
ae1562f866cb8c54589f22867ba55c460fde26b3 | keshavsingh4522/Data-Structure-and-Algorithm | /prefix infix postfix/prefix_to_postfix.py | 689 | 4.21875 | 4 | '''
Algorith:
- Read the Prefix expression in reverse order (from right to left)
- If the symbol is an operand, then push it onto the Stack
- If the symbol is an operator, then pop two operands from the Stack
- Create a string by concatenating the two operands and the operator after them.
- string = operand1 + operand2... | true |
561ee4fb8b21c6eb2b2a3e0d9faab32145c58318 | jain7727/html | /2nd largest.py | 278 | 4.25 | 4 | num1=int(input("enter the first no"))
num2=int(input("enter the second no"))
num3=int(input("enter the third no"))
print(num1,num2,num3)
if(num1>num2>num3):
print("2nd largest no is ", num2)
elif(num2>num3>num1):
print("2nd largest no is ", num3)
else:
print(num1) | true |
18d1349155c4a17df235d6ef2a6adbaefd711cf8 | delroy2826/Programs_MasterBranch | /regular_expression_excercise.py | 2,675 | 4.59375 | 5 | #1 Write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-Z and 0-9).
import re
def check(str1):
match = pattern.search(str1)
return not bool(match)
pattern = re.compile(r'[^\w+]')
str1 = "delro3y1229"
print(check(str1))
str1 = "delro#3y1229"
print(check(st... | true |
d4352cfdd84a15f13d8c17ce5e69d6f20b0d3952 | delroy2826/Programs_MasterBranch | /pynativedatastruct5.py | 277 | 4.21875 | 4 | #Given a two list of equal size create a set such that it shows the element from both lists in the pair
firstList = [1, 2, 3, 4, 5]
secondList = [10, 20, 30, 40, 50]
new_list = []
for i in range(len(firstList)):
new_list.append((firstList[i],secondList[i]))
print(new_list) | true |
a47908baf91fad4982439dfd1c66059761aa92e4 | catliaw/hb_coding_challenges | /concatlists.py | 1,054 | 4.59375 | 5 | """Given two lists, concatenate the second list at the end of the first.
For example, given ``[1, 2]`` and ``[3, 4]``::
>>> concat_lists([1, 2], [3, 4])
[1, 2, 3, 4]
It should work if either list is empty::
>>> concat_lists([], [1, 2])
[1, 2]
>>> concat_lists([1, 2], [])
[1, 2]
>>> con... | true |
fb218791404f9ab8db796661c91e1ab0097af097 | yu-shin/yu-shin.github.io | /downloads/code/LeetCode/Array-Introduction/q977_MergeSort.py | 1,533 | 4.5 | 4 | # Python3 program to Sort square of the numbers of the array
# function to sort array after doing squares of elements
def sortSquares(arr, n):
# first dived array into part negative and positive
K = 0
for K in range(n):
if (arr[K] >= 0 ):
break
# Now do the same process ... | true |
fb9f96fd4b3a3becd84531f4d07748c13bf6706d | kawing-ho/pl2py-ass1 | /test01.py | 268 | 4.53125 | 5 | #!/usr/bin/python3
# Use of "#" character in code to mimic comments
for x in range(0,5):
print("This line does't have any hash characters :)") #for now
print("but this one does! #whatcouldgowrong ? ") #what happens here ?
print("I love '#'s") and exit(ord('#'))
| true |
71b552431f56fea84e1062924a6c1782449fe976 | PrechyDev/Zuri | /budget.py | 1,882 | 4.1875 | 4 | class Budget:
'''
The Budget class creates budget instances for various categories.
A user can add funds, withdraw funds and calculate the balance in each category
A user can also transfer funds between categories.
'''
##total balance for all categories
total_balance = 0
@classmethod
... | true |
d30896b9eb8a8bf8f73d05439906a5fd1a5c1973 | Weyinmik/pythonDjangoJourney | /dataTypeNumbers.py | 581 | 4.21875 | 4 | """
We have integers and floats
"""
a = 14
print(a)
b = 4
print(b)
print(a + b) # print addition of a and b, 18.
print(a - b) # print subtraction of a and b, 10.
print(a * b) # print multiplication of a and b, 56.
print(a / b) # print division of a and b in the complete decimal format, -... | true |
f7e5cd52ac7324617717081db83c6b849f5fab32 | katecpp/PythonExercises | /24_tic_tac_toe_1.py | 546 | 4.125 | 4 | #! python3
def readInteger():
value = ""
while value.isdigit() == False:
value = input("The size of the board: ")
if value.isdigit() == False:
print("This is not a number!")
return int(value)
def printHorizontal(size):
print(size * " ---")
def printVertical(size):
prin... | true |
c6ff43950f21b27f9c3dd61cf3d6840748ad2864 | katecpp/PythonExercises | /11_check_primality.py | 515 | 4.21875 | 4 | #! python3
import math
def readInteger():
value = ""
while value.isdigit() == False:
value = input("Check primality of number: ")
if value.isdigit() == False:
print("This is not a number!")
return int(value)
def isPrime(number):
upperBound = int(math.sqrt(number))
for ... | true |
d849a589929e610b588067d845bfcf182ca5b3b5 | Legoota/PythonAlgorithmTraining | /Sorts/mergesort.py | 572 | 4.125 | 4 | def mergesort(array):
if len(array) < 2:
return array
center = len(array)//2
left, right = array[:center], array[center:]
left = mergesort(left)
right = mergesort(right)
return mergelists(left, right)
def mergelists(left, right):
result = []
while len(left) > 0 and len(right) >... | true |
58451f498859eb61cd3e28d95915567432396483 | avigautam-329/Interview-Preparation | /OS/SemaphoreBasics.py | 842 | 4.15625 | 4 | from threading import Thread, Semaphore
import time
# creating semaphore instance to define the number of threads that can run at once.
obj = Semaphore(3)
def display(name):
# THis is where the thread acquire's the lock and the value of semaphore will decrease by 1.
obj.acquire()
for i in range(3):
... | true |
839181892842d62b803ab6040c89f29a2718514e | chuducthang77/Summer_code | /front-end/python/project301.py | 1,158 | 4.15625 | 4 | #Project 301: Banking App
#Class Based
# Withdraw and Deposit
# Write the transaction to a python file
class Bank:
def __init__(self, init=0):
self.balance = init
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
account = Bank()... | true |
798f3df4e5b30737ace8d3071d048a59745494e8 | bjchu5/pythonSort | /insertionsort.py | 1,848 | 4.5 | 4 | def insertionsort_method1(aList):
"""
This is a Insertion Sort algorithm
:param n: size of the list
:param temp: temporarily stores value in the list to swap later on
:param aList: An unsorted list
:return: A sorted ist
:precondition: An unsorted list
:Co... | true |
ed571b223307d9ccf5f43fcc1d1aa0469c213bbf | Dongmo12/full-stack-projects | /Week 5 - OOP/Day 3/exercises.py | 666 | 4.34375 | 4 | '''
Exercise 1 : Built-In Functions
Python has many built-in functions, and if you do not know how to use it, you can read document online.
But Python has a built-in document function for every built-in functions.
Write a program to print some Python built-in functions documents, such as abs(), int(), raw_input().
And... | true |
fcb2f3f5194583a7162a38322303ab2945c8de79 | Dongmo12/full-stack-projects | /Week 4 Python and web programming/Day 2/exercises.py | 1,705 | 4.5 | 4 | '''
Exercise 1 : Favorite Numbers
Create a set called my_fav_numbers with your favorites numbers.
Add two new numbers to it.
Remove the last one.
Create a set called friend_fav_numbers with your friend’s favorites numbers.
Concatenate my_fav_numbers and friend_fav_numbers to our_fav_numbers.
# Solution
my_fav_numbers... | true |
790e8b58ab3d9178d1468041d9f77b17c63fa8c1 | Dongmo12/full-stack-projects | /Week 4 Python and web programming/Day 1/exercises.py | 2,370 | 4.5 | 4 | '''
Exercise 4 : Your Computer Brand
Create a variable called computer_brand that contains the brand of your computer.
Insert and print the above variable in a sentence,like "I have a razer computer".
# Solution
computer_brand = "msi"
print('I have a {} computer'.format(computer_brand))
'''
'''
Exercise 5: Your Infor... | true |
edfcc0b98db78aa300f6cf4a804757129cf53321 | harasees-singh/Notes | /Searching/Binary_Search_Bisect.py | 947 | 4.125 | 4 | import bisect
# time complexities of bisect left and right are O(logn)
li = [8, 10, 45, 46, 47, 45, 42, 12]
index_where_x_should_be_inserted_is = bisect.bisect_right(li, 13) # 2 returned
index_where_x_should_be_inserted_is = bisect.bisect_left(li, 46) # 4 returned
print(index_where_x_should_be_inserted_is)
p... | true |
62b6bcd482dd774b75a816056a21247487f32b86 | maindolaamit/tutorials | /python/Beginer/higher_lower_guess_game.py | 1,519 | 4.3125 | 4 | """ A sample game to guess a number between 1 and 100 """
import random
rules = """
=========================================================================================================
= Hi, Below are the rules of the game !!!! =
= 1. At the Start of th... | true |
ecf870ac240d1faf8202039bcc235bdb14bb8440 | vsandadi/dna_sequence_design | /generating_dna_sequences.py | 2,007 | 4.28125 | 4 | '''
Function to generate DNA sequences for each bit string.
'''
#initial_sequence = 'ATTCCGAGA'
#mutation_list = [(2, 'T', 'C'), (4, 'C', 'A')]
#bitstring = ['101', '100']
def generating_sequences(initial_sequence, mutation_list, bitstring):
'''
Inputs: initial_sequence as a string of DNA bases
... | true |
18b3a779a6f144bf679eb47b8438b997e87f04ba | summitkumarsharma/pythontutorials | /tut28.py | 752 | 4.1875 | 4 | # file handling - write operation
# f = open("test-write.txt", "w")
# content = "To write to an existing file, you must add a parameter to the open()function" \
# "\n1.a - Append - will append to the end of the file \n2.w - Write - will overwrite any existing content"
# no_of_chars = f.write(content)
# print... | true |
f07bddfa311a3cf735afe4d7e7f139a0bbe94c6c | KiikiTinna/Python_programming_exercises | /41to45.py | 1,684 | 4.15625 | 4 | #Question 41: Create a function that takes a word from user and translates it using a dictionary of three words,
#returning a message when the word is not in the dict,
# considering user may enter different letter cases
d = dict(weather = "clima", earth = "terra", rain = "chuva")
#Question 42: Print out the ... | true |
c65bc508a10563fa6a391cdfdd1997db19569b7a | bsamaha/hackerrank_coding_challenges | /Sock Merchant.py | 761 | 4.125 | 4 | # %%
from collections import defaultdict
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
"""[Find how many pairs can be made from a list of integers]
Args:
n ([int]): [nymber of socks]
ar ([list of integers]): [inventory of socks]
Returns:
[type]: [description... | true |
e064d9a951cc77879be234b921f3712a4782652e | jz1611/python-codewars | /squareDigits.py | 377 | 4.1875 | 4 | # Welcome. In this kata, you are asked to square every digit of a number.
# For example, if we run 9119 through the function, 811181 will come out,
# because 92 is 81 and 12 is 1.
# Note: The function accepts an integer and returns an integer
def square_digits(num):
new = []
for num in list(str(num)):
new.ap... | true |
d75bbaf6a902034ade93a755ce5762091a2f2532 | driscolllu17/csf_prog_labs | /hw2.py | 2,408 | 4.375 | 4 | # Name: Joseph Barnes
# Evergreen Login: barjos05
# Computer Science Foundations
# Homework 2
# You may do your work by editing this file, or by typing code at the
# command line and copying it into the appropriate part of this file when
# you are done. When you are done, running this file should compute and
# print ... | true |
498852c54abdaf2be80bfe67dc88c0490f5a8ae1 | chrisalexman/google-it-automation-with-python | /Crash Course in Python/Week_2/main.py | 2,822 | 4.1875 | 4 | # Data Types
x = 2.5
print(type(x))
print("\n")
# Expressions
length = 10
width = 5
area = length * width
print(area)
print("\n")
# Expressions, Numbers, and Type Conversions
print(7 + 8.5) # implicit conversion
print("a" + "b" + "c")
print("\n")
base = 6
height = 3
area = (base * height) /... | true |
cf2ed5f62e36f00f2f5dead043ceec03a21a5ab3 | AlexFeeley/RummyAIBot | /tests/test_card.py | 2,223 | 4.21875 | 4 | import unittest
from src.card import *
# Tests the card class using standard unit tests
# from src.card import Card
class TestCard(unittest.TestCase):
# Tests constructor returns valid suit and number of card created
def test_constructor(self):
card = Card("Hearts", 3)
self.assertEqual(card... | true |
de7296225ab80c6c325bd91d83eae0610115b263 | kvraiden/Simple-Python-Projects | /T3.py | 266 | 4.21875 | 4 | print('This a program to find area of a triangle')
#The formulae is 1/2 h*b
h = float(input("Enter the height of the triangle: "))
b = float(input("Enter the base of the triangle: "))
area = 1/2*h*b
print("The area of given triangle is %0.2f" % (area)+" unit.") | true |
b50f2c051b7ae0506cbc6f8a414d943ab3a20c51 | tristandaly/CS50 | /PSET6/mario/more/mario.py | 727 | 4.1875 | 4 | from cs50 import get_int
def main():
# Begin loop - continues until a number from 1-8 is entered
while True:
Height = get_int("Height: ")
if Height >= 1 and Height <= 8:
break
# Based on height, spaces are added to the equivalent of height - 1, subtracting with each row from t... | true |
c8646e494885027bdf3819d0773b1ebb698db0a1 | fatih-iver/Daily-Coding-Interview-Solutions | /Question #7 - Facebook.py | 951 | 4.21875 | 4 | """
This problem was asked by Facebook.
Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.
For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.
You can assume that the messages are decodable. For example, '001' i... | true |
3e3f17c7877bf2001a9de9d48ca4b9652648bc1f | natepill/problem-solving | /PracticePython/Fibonacci.py | 490 | 4.25 | 4 | # Write a program that asks the user how many Fibonnaci numbers to generate and then generates them.
# Take this opportunity to think about how you can use functions.
# Make sure to ask the user to enter the number of numbers in the sequence to generate.
# (Hint: The Fibonnaci seqence is a sequence of numbers where the... | true |
5e37fb9cff13522653e0e9006951e0db5839e259 | aarontinn13/Winter-Quarter-History | /Homework2/problem6.py | 938 | 4.3125 | 4 | def palindrome_tester(phrase):
#takes raw phrase and removes all spaces
phrase_without_spaces = phrase.replace(' ', '')
#takes phrase and removes all special characters AND numbers
phrase_alpha_numeric = ''.join(i for i in phrase_without_spaces if i.isalpha())
#takes phrase and transforms all upper ... | true |
bf26a7742b55fa080d22c1fadffccbf21ae9ce34 | aarontinn13/Winter-Quarter-History | /Homework3/problem7.py | 1,088 | 4.28125 | 4 | def centered_average_with_iteration(nums):
#sort list first
nums = sorted(nums)
if len(nums) > 2:
#remove last element
nums.remove(nums[-1])
#remove first element
nums.remove(nums[0])
#create total
total = 0.0
#iterate through and add all remaining in ... | true |
4d80546ca7dfd20737f12f2dfddf3f9a0b5db00b | nip009/2048 | /twentyfortyeight.py | 2,776 | 4.125 | 4 | # Link to the problem: https://open.kattis.com/problems/2048
def printArr(grid):
for i in range(len(grid)):
row = ""
for j in range(len(grid[i])):
if(j != 3):
row += str(grid[i][j]) + " "
else:
row += str(grid[i][j])
print(row)
def ... | true |
e3ce4ff4dff53081b377cee46412ea42365651fa | digvijaybhakuni/python-playground | /pyListDictionaries/ch1-list.py | 2,221 | 4.1875 | 4 |
numbers = [5, 6, 7, 8]
print "Adding the numbers at indices 0 and 2..."
print numbers[0] + numbers[2]
print "Adding the numbers at indices 1 and 3..."
print numbers[1] + numbers[3]
"""
Replace in Place
"""
zoo_animals = ["pangolin", "cassowary", "sloth", "tiger"]
# Last night our zoo's sloth brutally... | true |
52c0773a6f69824b10bfe91e91d21acb1154012b | pmcollins757/check_sudoku | /check_sudoku.py | 2,091 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Author: Patrick Collins
"""
# Sudoku puzzle solution checker that takes as input
# a square list of lists representing an n x n
# sudoku puzzle solution and returns the boolean
# True if the input is a valid
# sudoku square solution and returns the boolean False
# otherwise.
# A valid sudo... | true |
60950955c5fcd3bc7a7410b78c3be383feb7e9ed | marcotello/PythonPractices | /Recursion/palindrome.py | 1,696 | 4.4375 | 4 | def reverse_string(input):
"""
Return reversed input string
Examples:
reverse_string("abc") returns "cba"
Args:
input(str): string to be reversed
Returns:
a string that is the reverse of input
"""
# TODO: Write your recursive string reverser solution here
... | true |
a26b16019c44c2ff2ea44916bcc3fa66a62a826e | marcotello/PythonPractices | /P0/Task1.py | 2,427 | 4.3125 | 4 | """
Read file into texts and calls.
It's ok if you don't understand how to read files.
"""
import csv
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
texts = list(reader)
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
calls = list(reader)
"""
TASK 1:
How many different telephone num... | true |
2252d7e3ea30fe49636bbeeb50f6c3b3c7fdf80d | marcotello/PythonPractices | /DataStrucutures/Linked_lists/flattening_linked_list.py | 1,622 | 4.125 | 4 | # Use this class as the nodes in your linked list
class Node:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return str(self.value)
class LinkedList:
def __init__(self, head):
self.head = head
def append(self, value):... | true |
1543e31bbe36f352dd18b284bd9fc688332e9486 | LucasBeeman/Whats-for-dinner | /dinner.py | 1,446 | 4.40625 | 4 | import random
ethnicity = [0, 1, 2, 3]
type_choice = -1
user_choice = input("Which ethnnic resturaunt would you like to eat at? Italian(1), Indian(2), Chinese(3), Middle Eastern(4), Don't know(5)")
#if the user pick I dont know, the code will pick one for them through randomness
if user_choice.strip() == "5":
... | true |
9f60c2a26e4ea5bf41c310598568ea0b532c167b | Rajeshinu/bitrm11 | /4.Stringcount.py | 231 | 4.25 | 4 | """Write a program that asks the user for a string
and returns an estimate of how many words are in the string"""
string=input("Please enter the string to count the number of words in the string\n")
c=string.count(" ")
print(c+1)
| true |
42bd0e1748a8964afe699112c9d63bc45cd421f3 | Rajeshinu/bitrm11 | /8.Numbersformat.py | 347 | 4.125 | 4 | """Write a program that asks the user for a large integer and inserts commas into it according
to the standard American convention for commas in large numbers. For instance,
if the user enters 1000000, the output should be 1,000,000"""
intnum=int(input(print("Please enter the large integer number : ")))
fnum=format(... | true |
50531ecdd319b058d9c2fe98b17a76a1392f85bf | Aqib04/tathastu_week_of_code | /Day4/p1.py | 306 | 4.21875 | 4 | size = int(input("Enter the size of tuple: "))
print("Enter the elements in tuple one by one")
arr = []
for i in range(size):
arr.append(input())
arr = tuple(arr)
element = input("Enter the element whose occurrences you want to know: ")
print("Tuple contains the element", arr.count(element), "times")
| true |
058d1ae6fa21662f7bac3d3e05ef0aedfdbe14b2 | gneelimavarma/practicepython | /C-1.19.py | 340 | 4.4375 | 4 | ##C-1.19 Demonstrate how to use Python’s list comprehension syntax to produce
##the list [ a , b , c , ..., z ], but without having to type all 26 such
##characters literally.
##ascii_value = ord('a')
##print(ascii_value)
i=0
start = 97 ##ascii of 'a'
result = []
while(i<26):
result.append(chr(start+i))
i+=1
p... | true |
0396e783aca5febe373e32fc544dead5a5817760 | marbor92/checkio_python | /index_power.py | 367 | 4.125 | 4 | # Function finds the N-th power of the element in the array with the index N.
# If N is outside of the array, then return -1.
def index_power(my_list, power) -> int:
pos = 0
index = []
for i in my_list:
index.append(pos)
pos += 1
if power not in index:
ans = -1
else:
... | true |
2c455ec9c2bbd31d79aa5a3b69c4b9b17c25b7a7 | whalenrp/IBM_Challenge | /SimpleLearner.py | 1,584 | 4.125 | 4 | import sys
import math
import csv
from AbstractLearner import AbstractLearner
class SimpleLearner(AbstractLearner):
"""
Derived class implementation of AbstractLearner. This class implements the learn()
and classify() functions using a simple approach to classify all as true or false
"""
def __init__(self, trai... | true |
d272fde739325284f99d1f148d1603d739d24721 | ganesh28gorli/Fibonacci-series | /fibonacci series.py | 678 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# # fibonacci series
# In[15]:
# n is the number of terms to be printed in fibonacci series
# In[16]:
n = int(input("enter number of terms: "))
# In[17]:
# assigning first two terms of the sequence
# In[18]:
a=0
b=1
# In[19]:
#checking if the number of terms of... | true |
aef6477c03006ff40a937946213ea05c1ec11106 | ta11ey/algoPractice | /algorithms/linkedList_insertionSort.py | 1,088 | 4.3125 | 4 | # Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.
# The steps of the insertion sort algorithm:
# Insertion sort iterates, consuming one input element each repetition and growing a sorted output list.
# At each iteration, insertion sort removes one element... | true |
084cb1de7fece4e3f74452233bd61c03af0812b8 | amitp-ai/Resources | /leet_code.py | 1,353 | 4.65625 | 5 | #test
"""
Syntax for decorators with parameters
def decorator(p):
def inner_func():
#do something
return inner_func
@decorator(params)
def func_name():
''' Function implementation'''
The above code is equivalent to
def func_name():
''' Function implementation'''
func_name = (decorator(para... | true |
fb55395ee175bdce797e17f48c6c04d7f2c574a2 | dukeofdisaster/HackerRank | /TimeConversion.py | 2,484 | 4.21875 | 4 | ###############################################################################
# TIME CONVERSION
# Given a time in 12-hour am/pm format, convert it to military (24-hr) time.
#
# INPUT FORMAT
# A single string containing a time in 12-hour clock format (hh:mm:ssAM or
# hh:mm:ssPM) wehre 01 <= hh <= 12 and 00 <= mm, ss <... | true |
f7c35cd71de55bd957da4338110c3343918c641d | Dr-A-Kale/Python-intro | /str_format.py | 669 | 4.125 | 4 | #https://python.swaroopch.com/basics.html
age = 20
name = 'Swaroop'
print('{0} was {1} years old when he wrote this book'.format(name, age))
print('Why is {0} playing with that python?'.format(name))
print(f'{name} was {age} years old when he wrote this book')
print(f'Why is {name} playing with that python?')
print("Wh... | true |
03b4609e13f7b1f3bafbdc8c9ffc83e04ca49b04 | KartikeyParashar/FunctionalPrograms | /LeapYear.py | 322 | 4.21875 | 4 | year = int(input("Enter the year you want to check that Leap Year or not: "))
if year%4==0:
if year%100==0:
if year%400==0:
print("Yes it is a Leap Year")
else:
print("Not a Leap Year")
else:
print("Yes it is a Leap Year")
else:
print("No its not a Leap Year... | true |
169d013c1c226c53da4c2e5d0fa6444d7f8bb087 | natalya-patrikeeva/interview_prep | /binary-search.py | 1,672 | 4.3125 | 4 | """You're going to write a binary search function.
You should use an iterative approach - meaning
using loops.
Your function should take two inputs:
a Python list to search through, and the value
you're searching for.
Assume the list only has distinct elements,
meaning there are no repeated values, and
elements are in ... | true |
eed9c8739eb2daa6ecbc47e10693e3d9b1970d82 | sarthakjain95/UPESx162 | /SEM I/CSE/PYTHON CLASS/CLASSx8.py | 1,757 | 4.71875 | 5 | # -*- coding: utf-8 -*-
#! /usr/bin/env python3
# Classes and Objects
# Suppose there is a class 'Vehicles'
# A few of the other objects can be represented as objects/children of this super class
# For instance, Car, Scooter, Truck are all vehicles and can be denoted as a derivative
# of the class 'Vehicle'
# Furthe... | true |
f0cf8343b7cb9293b5ecea2532953d0ca0b55d49 | devaljansari/consultadd | /1.py | 1,496 | 4.59375 | 5 | """Write a Python program to print the following string in a specific
format (see the output).
Sample String :
"Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what y... | true |
2b18385f2dc36a87477c3e7df27ff8bd2a988c33 | heet-gorakhiya/Scaler-solutions | /Trees/Trees-1-AS_inorder_traversal.py | 1,783 | 4.125 | 4 | # Inorder Traversal
# Problem Description
# Given a binary tree, return the inorder traversal of its nodes values.
# NOTE: Using recursion is not allowed.
# Problem Constraints
# 1 <= number of nodes <= 10^5
# Input Format
# First and only argument is root node of the binary tree, A.
# Output Format
# Return an in... | true |
459ee1c60423011457183df6e5a897df77b7b62d | ani07/Coding_Problems | /project_euler1.py | 491 | 4.28125 | 4 | """
This solution is based on Project Euler Problem Number 1.
If we list all 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.
"""
class MultiplesThreeFive():
def multiples(self):
sum =... | true |
5d401b278b9e481bc02bfd5c57cedcbf945b9104 | DeepakMe/Excellence-Technologies- | /QONE.py | 309 | 4.15625 | 4 | # Question1
# Q1.Write a function which returns sum of the list of numbers?
# Ans:
list1 = [1,2,3,4]
def Sumlist(list,size):
if (size==0):
return 0
else:
return list[size-1]+Sumlist(list,size-1)
total = Sumlist(list1,len(list1))
print("Sum of given elements in List: ",total) | true |
e31e1faec48a064176ad9dba34ed13ba8d263272 | SaratM34/CSEE5590-490-Python-and-DL-SP2018 | /Python Lab Assignment 1/Source/Q2.py | 771 | 4.4375 | 4 | # Taking input from the user
list1 = input("Enter Sentence: ").split(" ")
# Function for evaluating the sentence
def give_sentence(list1):
# Declaring empty list
list2 = []
#Print middle words in a sentence
print("Middle Words of the Sentence are: "+list1[len(list1)//2], list1[(len(list1)//2)+1])
... | true |
b66e53fcea2e0232c032ed701e780a9846377322 | ashiifi/basic-encryption | /encryption.py | 2,527 | 4.40625 | 4 | """
Basic Encryption Project:
encryption(S,n) takes in a string and a number. It then moves each letter in the string
n amount of times through the alphabet. In this way, 'encrypting' the string
then decryption(W) takes in the encrypted string with the n at the end of it. like "helloworld1"
"""
def encryption(S, n):
... | true |
b2a7a14ccf32ece134f0d20b577fc3fcb6b4a132 | brittCommit/lab_word_count | /wordcount.py | 831 | 4.21875 | 4 | # put your code here.
import sys
def get_word_count(file_name):
"""Will return word count of a given text file.
user will enter python3 wordcount.py 'anytextfilehere' on the command
line to run the code
"""
text_file = open(sys.argv[1])
word_count = {}
special_charac... | true |
22f8f3f61f63a9c1a0c174761c56bfd621a4c915 | AnabellJimenez/SQL_python_script | /data_display.py | 1,395 | 4.34375 | 4 | import sqlite3
'''Python file to enter sql code into command line and generate a csv file with the information from the: fertility SQL DB '''
from Database_model import Database
import requests
import csv
#open sqlite3 connection
def db_open(filename):
return sqlite3.connect(filename)
#close sqlite3 connection
def ... | true |
f95eb88f8b5ae743155b8d3b55389c6d8686cfe2 | ravisjoshi/python_snippets | /Array/SearchInsertPosition.py | 801 | 4.15625 | 4 | """
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Input: [1,3,5,6], 5 / Output: 2
Input: [1,3,5,6], 2 / Output: 1
Input: [1,3,5,6], 7 / Output: 4
Input: [1,3,5,6]... | true |
0334ea3d2d970823df4f5b66f1cfc5855d972206 | ravisjoshi/python_snippets | /Basics-3/ConstructTheRectangle.py | 2,118 | 4.15625 | 4 | """
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:
1. The area of the rectangular web page you designed must equal to ... | true |
272a9925a7e7c9fa671779a87354cac682c8e379 | ravisjoshi/python_snippets | /Strings/validateParenthesis.py | 1,217 | 4.40625 | 4 | """
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:
Any left parenthesis '(' must have a corresponding right parenthesis ')'.
Any right parenthesis ')' must have a correspondin... | true |
3a2ab445be28e3da8491cc57473ba43252435d4a | ravisjoshi/python_snippets | /Strings/LongestUncommonSubsequenceI.py | 1,496 | 4.21875 | 4 | """
Given two strings, you need to find the longest uncommon subsequence of this two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other string.
A subsequence is a sequence that can be derived from one se... | true |
dc52061454014fea26d67bd88c9c4a34f5bdd17c | ravisjoshi/python_snippets | /DataStructure/sorting/quickSort.py | 854 | 4.1875 | 4 | """
Quick Sort: https://en.wikipedia.org/wiki/Quicksort
Ref:
https://www.youtube.com/watch?v=1Mx5pEeTp3A
https://www.youtube.com/watch?v=RFyLsF9y83c
"""
from random import randint
def quick_sort(arr):
if len(arr) <= 1: return arr
left, equal, right = [], [], []
pivot = arr[randint(0, len(arr)-1)]
fo... | true |
03670d974ef18610084e94c1e19573c55e060cdc | ravisjoshi/python_snippets | /DataStructure/StackAndQueue/MaximumElement.py | 1,417 | 4.3125 | 4 | """
You have an empty sequence, and you will be given N queries. Each query is one of these three types:
1 -Push the element x into the stack.
2 -Delete the element present at the top of the stack.
3 -Print the maximum element in the stack.
Input Format: The first line of input contains an integer N. The next line... | true |
848696aadc4c2889406f5b2f1c61c47adb09f41d | ravisjoshi/python_snippets | /ProjectEuler/Basics-0/009-SpecialPythagoreanTriplet.py | 540 | 4.46875 | 4 | """
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
def pythagoreanTriplet(num):
for a in range(1, num//2):
for b in ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.