blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
e6a688b5a85a54fedd45925b8d263ed5f79a5b41 | shardul1999/Competitive-Programming | /Sieve_of_Eratosthenes/Sieve_of_Eratosthenes.py | 1,018 | 4.25 | 4 | # implementing the function of Sieve of Eratosthenes
def Sieve_of_Eratosthenes(n):
# Creating a boolean array and
# keeping all the entries as true.
# entry will become false later on in case
# the number turns out to be prime.
prime_list = [True for i in range(n+1)]
for number in range(2,n):
# I... | true |
94a4e95a13557630c6e6a551f297a934b01e72f1 | gadamsetty-lohith-kumar/skillrack | /N Equal Strings 09-10-2018.py | 836 | 4.15625 | 4 | '''
N Equal Strings
The program must accept a string S and an integer N as the input. The program must print N equal parts of the string S if the string S can be divided into N equal parts. Else the program must print -1 as the output.
Boundary Condition(s):
2 <= Length of S <= 1000
2 <= N <= Length of S
Ex... | true |
cb332c445ab691639f8b6fb76e25bf95ba5f7af4 | gadamsetty-lohith-kumar/skillrack | /Remove Alphabet 14-10-2018.py | 930 | 4.28125 | 4 | '''
Remove Alphabet
The program must accept two alphabets CH1 and CH2 as the input. The program must print the output based on the following conditions.
- If CH1 is either 'U' or 'u' then print all the uppercase alphabets except CH2.
- If CH1 is either 'L' or 'l' then print all the lowercase alphabets except CH2.... | true |
51edd7c35ccfe2b7d07bcbfe97395f0c88c251fa | TAMU-BMEN207/Apple_stock_analysis | /OHLC_plots_using_matplotlib.py | 2,535 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 13 21:20:18 2021
@author: annicenajafi
Description: In this example we take a look at Apple's stock prices and write a
program to plot an OHLC chart. To learn more about OHLC plots visit
https://www.investopedia.com/terms/o/ohlcchart.asp
#Dataset... | true |
68bb040d0e9828fc34660de7b3d0d4ffa6e36d2d | s-nilesh/Leetcode-May2020-Challenge | /14-ImplementTrie(PrefixTree).py | 1,854 | 4.40625 | 4 | #PROBLEM
# Implement a trie with insert, search, and startsWith methods.
# Example:
# Trie trie = new Trie();
# trie.insert("apple");
# trie.search("apple"); // returns true
# trie.search("app"); // returns false
# trie.startsWith("app"); // returns true
# trie.insert("app");
# trie.search("app"); // re... | true |
e8b6ef6df71a327b6575593166873c6576f78f7b | SirazSium84/100-days-of-code | /Day1-100/Day1-10/Bill Calculator.py | 911 | 4.1875 | 4 | print("Welcome to the tip calculator")
total_bill = float(input("What was the total bill? \n$"))
percentage = int(input(
"What percentage tip would you like to give ? 10, 12 or 15?\n"))
people = int(input("How many people to split the bill? \n"))
bill_per_person = (total_bill + total_bill * (percentage)/100)/(peopl... | true |
24a69e38cdc2156452898144165634fd6579ef6c | keyurgolani/exercism | /python/isogram/isogram.py | 564 | 4.375 | 4 | def is_isogram(string):
"""
A function that, given a string, returns if the string is an isogram or not
Isogram is a string that has all characters only once except hyphans and
spaces can appear multiple times.
"""
lookup = [0] * 26
# Assuming that the string is case insensitive
string =... | true |
8af76392fb8ade32aa16f998867a9312303cd2fa | porigonop/code_v2 | /linear_solving/Complex.py | 2,070 | 4.375 | 4 | #!/usr/bin/env python3
class Complex:
""" this class represent the complex number
"""
def __init__(self, Re, Im):
"""the numer is initiate with a string as "3+5i"
"""
try:
self.Re = float(Re)
self.Im = float(Im)
except:
raise TypeError("please enter a correct number")
def __str__(self):
""" a... | true |
af2c02c975c53c1bd12955b8bbe72bac35ab54fd | BryanBain/Statistics | /Python_Code/ExperimProbLawOfLargeNums.py | 550 | 4.1875 | 4 | """
Purpose: Illustrate how several experiments leads the experimental probability
of an event to approach the theoretical probability.
Author: Bryan Bain
Date: June 5, 2020
File: ExperimProbLawOfLargeNums.py
"""
import random as rd
possibilities = ['H', 'T']
num_tails = 0
num_flips = 1_000_000 # change this value ... | true |
d2e63bfba6fdfa348260d81a84628cacc6243a18 | Yasthir01/Bootcamp-Tasks-and-Projects-Part1 | /Level 1/Task 7/investment_calculator.py | 986 | 4.125 | 4 | """A program on an Investment Calculator"""
import math
# user inputs
# the amount they are depositing
P = int(input("How much are you depositing? : "))
# the interest rate
i = int(input("What is the interest rate? : "))
# the number of years of the investment
t = int(input("Enter the number of years of the investm... | true |
720fefd121f1bc900454dcbfd668b12f0ad9f551 | Yasthir01/Bootcamp-Tasks-and-Projects-Part1 | /Level 1/Task 2/conversion.py | 445 | 4.25 | 4 | """Declaring and printing out variables of different data types"""
# declare variables
num1 = 99.23
num2 = 23
num3 = 150
string1 = "100"
# convert the variables
num1 = int(num1) # convert into an integer
num2 = float(num2) # convert into a float
num3 = str(num3) # convert into a string
string1 = int(string1) # c... | true |
1143957f959a603f694c7ed6012acf2f7d465a4c | Yasthir01/Bootcamp-Tasks-and-Projects-Part1 | /Level 1/Task 7/control.py | 258 | 4.125 | 4 | """Program that evaluates a person's age"""
# take in user's age
age = int(input("Please enter in your age: "))
# evaluate the input
if age >= 18:
print("You are old enough!")
elif age >= 16:
print("Almost there")
else:
print("You're just too young!") | true |
aa41b93ab44deded12fa4705ea497d2c6bbc74e8 | Yasthir01/Bootcamp-Tasks-and-Projects-Part1 | /Level 1/Task 10/logic.py | 648 | 4.1875 | 4 | """A program about fast food service"""
menu_items = ['Fries', 'Beef Burger', 'Chicken Burger', 'Nachos', 'Tortilla', 'Milkshake']
print("***MENU***")
print("Pick an item")
print("1.Fries\n2.Beef Burger\n3.Chicken Burger\n4.Nachos\n5.Tortilla\n6.Milkshake")
choice = int(input("\nType in number: "))
for i in menu_i... | true |
7eafe6d1231ff66b56fdeab6c409922e82ec5691 | purvajakumar/python_prog | /pos.py | 268 | 4.125 | 4 | #check whether the nmuber is postive or not
n=int(input("Enter the value of n"))
if(n<0):
print("negative number")
elif(n>0):
print("positive number")
else:
print("The number is zero")
#output
"""Enter the value of n
6
positive number"""
| true |
0fc620866a5180d3a6d0d51547d74896a6d3c193 | ky822/assignment7 | /yl3068/questions/question3.py | 734 | 4.3125 | 4 | import numpy as np
def result():
print '\nQuestion Three:\n'
#Generate 10*3 array of random numbers in the range [0,1].
initial = np.random.rand(10,3)
print 'The initial random array is:\n{}\n'.format(initial)
#Question a: pick the number closest to 0.5 for each row
initial_a = abs(initial-0... | true |
39e36aeb85538a4be57dd457d005fd12bc642e25 | ky822/assignment7 | /ql516/question3.py | 1,927 | 4.1875 | 4 | # -*- coding: utf-8 -*-
import numpy as np
def array_generate():
"""
generate a 10x3 array of random numbers in range[0,1]
"""
array = np.random.rand(10,3)
return array
def GetClosestNumber(array):
"""
for each row, pick the number closest to .5
"""
min_index = np.argmin(np.ab... | true |
7d82924a9a4123d5a340cbbd352ddea2bd4b3e18 | ky822/assignment7 | /wl1207/question1.py | 694 | 4.125 | 4 | import numpy as np
def function():
print "This is the answer to question1 is:\n"
array = np.array(range(1,16)).reshape(3,5).transpose()
print "The 2-D array is:\n",array,"\n"
array_a = array[[1,3]]
print "The new array contains the 2nd column and 4th rows is:\n", array_a, "\n"
array_b = array[:, 1]
prin... | true |
ae63f36897ced379ec1f7b20bc399182c36682c5 | Kamilet/learning-coding | /python/ds_str_methods.py | 305 | 4.1875 | 4 | #这是一个字符串对象
name = 'Kamilet'
if name.startswith('Kam'):
print('Yes, the string starts with "Kam"')
if 'a' in name:
print('Yes, contains "a"')
if name.find('mil') != -1:
print('Yes, contains "mil"')
delimiter='_*_'
mylist = ['aaa', 'bbb', 'ccc', 'ddd']
print(delimiter.join(mylist)) | true |
5b01a489805c58909979dae65c04763df722bfaa | Sauvikk/practice_questions | /Level6/Trees/Balanced Binary Tree.py | 1,233 | 4.34375 | 4 | # Given a binary tree, determine if it is height-balanced.
#
# Height-balanced binary tree : is defined as a binary tree in which
# the depth of the two subtrees of every node never differ by more than 1.
# Return 0 / 1 ( 0 for false, 1 for true ) for this problem
#
# Example :
#
# Input :
# 1
# / \
... | true |
9cea8f90b8556dcacec43dd9ae4a7b4500db2114 | Sauvikk/practice_questions | /Level6/Trees/Sorted Array To Balanced BST.py | 951 | 4.125 | 4 | # Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
#
# Balanced tree : a height-balanced binary tree is defined as a
# binary tree in which the depth of the two subtrees of every node never differ by more than 1.
# Example :
#
#
# Given A : [1, 2, 3]
# A height balance... | true |
7708927408c989e6d7d6a297eb62d27ca489ee49 | Sauvikk/practice_questions | /Level6/Trees/BinaryTree.py | 2,379 | 4.15625 | 4 |
# Implementation of BST
class Node:
def __init__(self, val): # constructor of class
self.val = val # information for node
self.left = None # left leef
self.right = None # right leef
self.level = None # level none defined
self.next = None
# def __str__(self):
... | true |
4a0eca90de3ce7fb0ab6decb0ec6aadb32c1a9fa | Sauvikk/practice_questions | /Level6/Trees/Identical Binary Trees.py | 998 | 4.15625 | 4 | # Given two binary trees, write a function to check if they are equal or not.
#
# Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
#
# Return 0 / 1 ( 0 for false, 1 for true ) for this problem
#
# Example :
#
# Input :
#
# 1 1
# / \ / \
# 2 3 ... | true |
8bf85ec04b5f5619a235f1506b7226597a75bef0 | Kaushikdhar007/pythontutorials | /kaushiklaptop/NUMBER GUESS.py | 766 | 4.15625 | 4 | n=18
print("You have only 5 guesses!! So please be aware to do the operation\n")
time_of_guessing=1
while(time_of_guessing<=5):
no_to_guess = int(input("ENTER your number\n"))
if no_to_guess>n:
print("You guessed the number above the actual one\n")
print("You have only", 5 - time_of_gue... | true |
be99bff4b371868985a64a79a23e34be58a0831f | KrishnaPatel1/python-workshop | /theory/methods.py | 1,722 | 4.28125 | 4 | def say_hello():
print("Hello")
print()
say_hello()
# Here is a method that calculates the double of a number
def double(number):
result = number * 2
return result
result = double(2)
print(result)
print()
# Here is a method that calculates the average of a list of numbers
def average(list_of_numbers):
... | true |
06bea009748a261e7d0c893a18d60e4b625d6243 | hoanghuyen98/fundamental-c4e19 | /Session05/homeword/Ex_1.py | 1,302 | 4.25 | 4 |
inventory = {
'gold' : 500,
'pouch': ['flint', 'twine', 'gemstone'],
'backpack' : ['xylophone', 'dagger', 'bedroll', 'bread loaf']
}
# Add a Key to inventory called 'pocket' and Set the value of 'pocket' to be a list
print("1: Add a Key to inventory called 'pocket' and Set the value of 'pocket' to be a... | true |
e1139905c3f17bd9e16a51a69853a0923160c84f | bbaja42/projectEuler | /src/problem14.py | 1,496 | 4.15625 | 4 | '''
The following iterative sequence is defined for the set of positive integers:
n n/2 (n is even)
n 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13 40 20 10 5 16 8 4 2 1
It can be seen that this sequence (starting at 13 and finishing at 1)
contains 10... | true |
fc846895589cb0b3d0227622ca53c4c6a62b61bc | Mahedi522/Python_basic | /strip_function.py | 384 | 4.34375 | 4 | # Python3 program to demonstrate the use of
# strip() method
string = """ geeks for geeks """
# prints the string without stripping
print(string)
# prints the string by removing leading and trailing whitespaces
print(string.strip())
# prints the string by removing geeks
print(string.strip(' geeks'))
a = list... | true |
0b9e842cbeb52e819ecc2a10e135008f4380f8ed | monadplus/python-tutorial | /07-input-output.py | 1,748 | 4.34375 | 4 | #!/user/bin/env python3.7
# -*- coding: utf8 -*-
##### Fancier Output Formatting ####
year = 2016
f'The current year is {year}'
yes_votes = 1/3
'Percentage of votes: {:2.2%}'.format(yes_votes)
# You can convert any variable to string using:
# * repr(): read by the interpreter
# * str(): human-readable
s = "Hello,... | true |
c6145249ef56fe9890f142f597766fdb55200466 | Ahmad-Saadeh/calculator | /calculator.py | 810 | 4.125 | 4 | def main():
firstNumber = input("Enter the first number: ")
secondNumber = input("Enter the second number: ")
operation = input("Choose one of the operations (*, /, +, -) ")
if firstNumber.isdigit() and secondNumber.isdigit():
firstNumber = int(firstNumber)
secondNumber = int(secondNumber)
if opera... | true |
4f603beccd737bea2d9ebd9d92bf3013dc91b9d1 | surajkumar0232/recursion | /binary.py | 233 | 4.125 | 4 | def binary(number):
if number==0:
return 0
else:
return number%2+10 * binary(number//2)
if __name__=="__main__":
number=int(input("Enter the numner which binary you want: "))
print(binary(number)) | true |
4647a038acd767895c4fd6cdbfcc130ef60a87ce | shreeyash-hello/Python-codes | /leap year.py | 396 | 4.1875 | 4 |
while True :
year = int(input("Enter year to be checked:"))
string = str(year)
length = len(string)
if length == 4:
if(year%4==0 and year%100!=0 or year%400==0):
print("The year is a leap year!")
break
else:
print("The year isn't a leap year... | true |
b74ba7ee11dafa4f0482c903eeee240142181873 | bengovernali/python_exercises | /tip_calculator_2.py | 870 | 4.1875 | 4 |
bill = float(input("Total bill amount? "))
people = int(input("Split how many ways? "))
service_status = False
while service_status == False:
service = input("Level of service? ")
if service == "good":
service_status = True
elif service == "fair":
service_status = True
elif service_... | true |
e54410cf9db5300e6ef5c84fd3432b1723c017c6 | MeganTj/CS1-Python | /lab5/lab5_c_2.py | 2,836 | 4.3125 | 4 | from tkinter import *
import random
import math
# Graphics commands.
def draw_line(canvas, start, end, color):
'''Takes in four arguments: the canvas to draw the line on, the
starting location, the ending location, and the color of the line. Draws a
line given these parameters. Returns the handle of the l... | true |
f84fdef224b8a97d88809dcf45fb0f574dc61ed4 | SnarkyLemon/VSA-Projects | /proj06/proj06.py | 2,181 | 4.15625 | 4 | # Name:
# Date:
# proj06: Hangman
# -----------------------------------
# Helper code
# (you don't need to understand this helper code)
import random
import string
WORDLIST_FILENAME = "words.txt"
def load_words():
"""
Returns a list of valid words. Words are strings of lowercase letters.
Depending on t... | true |
d7736ee0897218affa62d98dbb4117ff96d59818 | djmgit/Algorithms-5th-Semester | /FastPower.py | 389 | 4.28125 | 4 | # function for fast power calculation
def fastPower(base, power):
# base case
if power==0:
return 1
# checking if power is even
if power&1==0:
return fastPower(base*base,power/2)
# if power is odd
else:
return base*fastPower(base*base,(power-1)/2)
base=int(raw_input("Enter base : "))
power=int(raw_i... | true |
c1b83c2ac9d096558fa7188d269cc55f2a25ecf1 | tolu1111/Python-Challenge | /PyBank.py | 2,088 | 4.1875 | 4 | #Import Dependencies perform certain functions in python
import os
import csv
# define where the data is located
bankcsv = os.path.join("Resources", "budget_data.csv")
# define empty lists for Date, profit/loss and profit and loss changes
Profit_loss = []
Date = []
PL_Change = []
# Read csv file
with op... | true |
317e92540d3a6e00bec3dcddb29669fe4806c7fa | Frank1963-mpoyi/REAL-PYTHON | /FOR LOOP/range_function.py | 2,163 | 4.8125 | 5 | #The range() Function
'''
a numeric range loop, in which starting and ending numeric values are specified. Although this form of for loop isn’t directly built into Python, it is easily arrived at.
For example, if you wanted to iterate through the values from 0 to 4, you could simply do this:
'''
for n in (0, 1, 2, 3... | true |
1eec2e1904286641b7140f572c19f7b860c3427e | Frank1963-mpoyi/REAL-PYTHON | /WHILE LOOP/whileloop_course.py | 2,036 | 4.25 | 4 | ''' Iteration means executing the same block of code over and over, potentially many times. A programming structure that implements iteration is called a loop'''
'''
In programming, there are two types of iteration, indefinite and definite:
With indefinite iteration, the number of times the loop is executed isn’t
sp... | true |
cf38d3bf5f83a42c436e46a934f2557763ab0ff4 | utkarsht724/Pythonprograms | /Replacestring.py | 387 | 4.65625 | 5 | #program to replace USERNAME with any name in a string
import re
str= print("Hello USERNAME How are you?")
name=input("Enter the name you want to replace with USERNAME :") #taking input name from the user
str ="Hello USERNAME How are you?"
regex =re.compile("USERNAME")
str = regex.sub(name,str) #repla... | true |
f81f22047a6538e19c1ef847ef365609646ed2df | utkarsht724/Pythonprograms | /Harmonicno.py | 296 | 4.46875 | 4 | #program to display nth harmonic value
def Harmonic(Nth):
harmonic_no=1.00
for number in range (2,Nth+1): #iterate Nth+1 times from 2
harmonic_no += 1/number
print(harmonic_no)
#driver_code
Nth=int(input("enter the Nth term")) #to take Nth term from the user
print(Harmonic(Nth)) | true |
5b74b55cbc8f0145d125993fc7ac34702d8954f7 | rawatrs/rawatrs.github.io | /python/prob1.py | 819 | 4.15625 | 4 | sum = 0
for i in range(1,1000):
if (i % 15 == 0):
sum += i
elif (i % 3 == 0):
sum += i
elif (i % 5 == 0):
sum += i
print "Sum of all multiples of 3 or 5 below 1000 = {0}".format(sum)
'''
**** Consider using xrange rather than range:
range vs xrange
The range function creates a list containing numbers defin... | true |
6936a4fbce24ffa6be02883497224eb0fc6ad7e5 | nirmalshajup/Star | /Star.py | 518 | 4.5625 | 5 | # draw color filled star in turtle
import turtle
# creating turtle pen
t = turtle.Turtle()
# taking input for the side of the star
s = int(input("Enter the length of the side of the star: "))
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
# set the ... | true |
cd03b7b76bfb8c217c0a82b3d48321f8326cc017 | jnassula/calculator | /calculator.py | 1,555 | 4.3125 | 4 | def welcome():
print('Welcome to Python Calculator')
def calculate():
operation = input('''
Please type in the math operation you would like to complete:
+ for addition
- for substraction
* for multiplication
/ for division
** for power
% for modulo
''')
number_1 = int... | true |
6741dfd84673f751765d5b93a377a462b82da315 | BatuhanAktan/SchoolWork | /CS121/Assignment 4/sort_sim.py | 2,852 | 4.21875 | 4 | '''
Demonstration of time complexities using sorting algorithms.
Author: Dr. Burton Ma
Edited by: Batuhan Aktan
Student Number: 20229360
Date: April 2021
'''
import random
import time
import a4
def time_to_sort(sorter, t):
'''
Returns the times needed to sort lists of sizes sz = [1024, 2048, 4096, 8192]
... | true |
a38ccc08bc8734389f11b1a6a9ac15eca5b7d53a | sammhit/Learning-Coding | /HackerRankSolutions/quickSortPartion.py | 521 | 4.1875 | 4 | #!/bin/python3
import sys
#https://www.hackerrank.com/challenges/quicksort1/problem
def quickSort(arr):
pivot = arr[0]
left = []
right = []
for i in arr:
if i>pivot:
right.append(i)
if i<pivot:
left.append(i)
left.append(pivot)
return left+right
# Co... | true |
78a204b4a7ddcc8d39cab0d2c92430d292ad204a | bswood9321/PHYS-3210 | /Week 03/Exercise_06_Q4_BSW.py | 1,653 | 4.34375 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Sep 7 19:50:39 2019
@author: Brandon
"""
import numpy as np
import numpy.random as rand
import matplotlib.pyplot as plt
def walk(N):
rand.seed()
x = [0.0]
y = [0.0]
for n in range(N):
x.append(x[-1] + (rand.random() - 0.5)*2.0)... | true |
70fe8fdf2f0d12b61f21f5d9bd825d2f0a0ec93f | LiuJLin/learn_python_basic | /ex32.py | 639 | 4.53125 | 5 | the_count = [1, 2, 3, 4, 5]
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
#this first kind of for-loop goes through a list
for number in the_count:
print("This is count %d"% number)
#also we can go through mixed lists too
#notice we have use %r since we don't know what's in it
for i in change:
print("I g... | true |
8b8945a9936304593b65b5648bcb882365ba5ad3 | Phongkaka/python | /TrinhTienPhong_92580_CH05/Exercise/page_145_exercise_06.py | 469 | 4.1875 | 4 | """
Author: Trịnh Tiến Phong
Date: 31/10/2021
Program: page_145_exercise_06.py
Problem:
6. Write a loop that replaces each number in a list named data with its absolute value
* * * * * ============================================================================================= * * * * *
Solution:
Display resu... | true |
fc399182e128c75611add67a65ddfe18d180dc55 | gamershen/everything | /hangman.py | 1,151 | 4.25 | 4 |
import random
with open(r'C:\Users\User\Desktop\תכנות\python\wordlist.txt', 'r') as wordfile:
wordlist = [line[:-1] for line in wordfile] # creates a list of all the words in the file
word = random.choice(wordlist) # choose random word from the list
letterlist = [letter for letter in word] # the word convert... | true |
e0d6812a81d0a65fb8998b63ac1af09247fc803e | Nihilnia/June1-June9 | /thirdHour.py | 1,283 | 4.21875 | 4 | """ 7- Functions """
def sayHello():
print("Hello")
def sayHi(name = "Nihil"):
print("Hi", name)
sayHello()
sayHi()
def primeQ(number):
if number == 0 or number == 1:
print(number, "is not a Primer number.")
else:
divs = 0
for f in range(2, number):
... | true |
af4c141fc364f89f4d1ad14541b368c164f40b81 | stephenfreund/PLDI-2021-Mini-Conf | /scripts/json_to_csv.py | 1,116 | 4.15625 | 4 | # Python program to convert
# JSON file to CSV
import argparse
import csv
import json
def parse_arguments():
parser = argparse.ArgumentParser(description="MiniConf Portal Command Line")
parser.add_argument("input", default="data.json", help="paper file")
parser.add_argument("out", default="data.csv", he... | true |
c64c542b57107c06de2ce0751075a81fcb195b61 | DmitriiIlin/Merge_Sort | /Merge_Sort.py | 1,028 | 4.25 | 4 | def Merge (left,right,merged):
#Ф-ция объединения и сравнения элементов массивов
left_cursor,right_cursor=0,0
while left_cursor<len(left) and right_cursor<len(right):
if left[left_cursor]<=right[right_cursor]:
merged[left_cursor+right_cursor]=left[left_cursor]
left_cursor+=1... | true |
1605bc14384fc7d8f74a0af5f3eb1b03f23b1cd5 | Oussema3/Python-Programming | /encryp1.py | 343 | 4.28125 | 4 | line=input("enter the string to be encrypted : ")
num=int(input("how many letters you want to shift : "))
while num > 26:
num = num -26
empty=""
for char in line:
if char.isalpha() is True:
empty=chr(ord(char)+num)
print(empty, end = "")
else:
empty=char
print(... | true |
162acf35104d849e124d88a07e13fbdbc58e261b | stevewyl/chunk_segmentor | /chunk_segmentor/trie.py | 2,508 | 4.15625 | 4 | """Trie树结构"""
class TrieNode(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.data = {}
self.is_word = False
class Trie(object):
def __init__(self):
self.root = TrieNode()
def insert(self, word):
"""
Inserts a... | true |
eb1ba8ee65ab19dad296f9793e0a0f6ba6230100 | LeilaBagaco/DataCamp_Courses | /Supervised Machine Learning with scikit-learn/Chapter_1/1-k-nearest-neighbors-fit.py | 2,163 | 4.28125 | 4 | # ********** k-Nearest Neighbors: Fit **********
# Having explored the Congressional voting records dataset, it is time now to build your first classifier.
# In this exercise, you will fit a k-Nearest Neighbors classifier to the voting dataset, which has once again been pre-loaded for you into a DataFrame df.
# I... | true |
39d5510129b23fc19a86740a018f61f19638570c | duchamvi/lfsrPredictor | /utils.py | 599 | 4.28125 | 4 | def bitToInt(bits):
"""Converts a list of bits into an integer"""
n = 0
for i in range (len(bits)):
n+= bits[i]*(2**i)
return n
def intToBits(n, length):
"""Converts an integer into a list of bits"""
bits = []
for i in range(length):
bits.append(n%2)
n = n//2
re... | true |
8e0148c31c798685c627b54d2d3fe90df4553443 | Lukasz-MI/Knowledge | /Basics/01 Data types/06 type - tuple.py | 907 | 4.28125 | 4 | data = tuple(("engine", "breaks", "clutch", "radiator" ))
print (data)
# data [1] = "steering wheel" # cannot be executed as tuple does not support item assignment
story = ("a man in love", "truth revealed", "choice")
scene = ("new apartment", "medium-sized city", "autumn")
book = story + scene + ("length",) # Tuple ... | true |
164fcb27549ae14c058c7eaf3b6c47b58d198e6d | Dan-krm/interesting-problems | /gamblersRuin.py | 2,478 | 4.34375 | 4 | # The Gambler's Ruin
# A gambler, starting with a given stake (some amount of money), and a goal
# (a greater amount of money), repeatedly bets on a game that has a win probability
# The game pays 1 unit for a win, and costs 1 unit for a loss.
# The gambler will either reach the goal, or run out of money.
# W... | true |
2e2821bc842d2b6c16a6e9a5f5252b64c4f2d097 | ngenter/lnorth | /guessreverse.py | 631 | 4.125 | 4 | # Nate Genter
# 1-9-16
# Guess my number reversed
# In this program the computer will try and guess your number
import random
print("\nWelcome to Liberty North.")
print("Lets play a game.")
print("\nPlease select a number, from 1-100 and I will guess it.")
number = int(input("Please enter your number: "))
if num... | true |
fe297a22342a92f9b3617b827367e60cb7b68f20 | jpallavi23/Smart-Interviews | /03_Code_Forces/08_cAPS lOCK.py | 1,119 | 4.125 | 4 | '''
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accident... | true |
4344f818cad8fd3759bab9e914dafb31171782f8 | jpallavi23/Smart-Interviews | /06_SI_Basic-Hackerrank/40_Hollow rectangle pattern.py | 628 | 4.21875 | 4 | '''
Print hollow rectangle pattern using '*'. See example for more details.
Input Format
Input contains two integers W and L. W - width of the rectangle, L - length of the rectangle.
Constraints
2 <= W <= 50 2 <= L <= 50
Output Format
For the given integers W and L, print the hollow rectangle pattern.
Sample Input ... | true |
5510d31f40b640c9a702d7580d1d434715469ba9 | smzapp/pyexers | /01-hello.py | 882 | 4.46875 | 4 |
one = 1
two = 2
three = one + two
# print(three)
# print(type(three))
# comp = 3.43j
# print(type(comp)) #Complex
mylist = ['Rhino', 'Grasshopper', 'Flamingo', 'Bongo']
B = len(mylist) # This will return the length of the list which is 3. The index is 0, 1, 2, 3.
print(mylist[1]) # This will return the value at... | true |
5da5f3b2063362046288b6370ff541a13552f9c8 | adamyajain/PRO-C97 | /countingWords.py | 279 | 4.28125 | 4 | introString = input("Enter String")
charCount = 0
wordCount = 1
for i in introString:
charCount = charCount+1
if(i==' '):
wordCount = wordCount+1
print("Number Of Words in a String: ")
print(wordCount)
print("Number Of Characters in a String: ")
print(charCount) | true |
80240cb2d0d6c060e516fd44946fd7c57f1a3b06 | hungnv132/algorithm | /recursion/draw_english_ruler.py | 1,689 | 4.5 | 4 | """
+ Describe:
- Place a tick with a numeric label
- The length of the tick designating a whole inch as th 'major tick length'
- Between the marks of whole inches, the ruler contains a series of 'minor sticks', placed at intervals of 1/2 inch,
1/4 inch, and so on
- As the size of the interval dec... | true |
7240fb816fb1beba9bf76eaf89579a7d87d46d67 | hungnv132/algorithm | /books/python_cookbook_3rd/ch01_data_structures_and_algorithms/07_most_frequently_occurring_items.py | 1,516 | 4.28125 | 4 | from collections import Counter
def most_frequently_occurring_items():
"""
- Problem: You have a sequence of items and you'd like determine the most
frequently occurring items in the sequence.
- Solution: Use the collections.Counter
"""
words = [
'look', 'into', 'my', 'eyes', 'look', ... | true |
d5004f19368c1db3f570771b70d9bd82f94f1a3b | hungnv132/algorithm | /design_patterns/decorator.py | 1,029 | 4.3125 | 4 | def decorator(func):
def inner(n):
return func(n) + 1
return inner
def first(n):
return n + 1
first = decorator(first)
@decorator
def second(n):
return n + 1
print(first(1)) # print 3
print(second(1)) # print 3
# ===============================================
def wrap_with_prints(fun... | true |
10bdaba3ac48babdc769cb838e1f7f4cdef66ae9 | nikitaagarwala16/-100DaysofCodingInPython | /MonotonicArray.py | 705 | 4.34375 | 4 | '''
Write a function that takes in an array of integers and returns a boolean representing whether the array is monotonic.
An array is said to be monotonic if its elements, from left to right, are entirely non-increasing or entirely non -decreasing.
'''
def monoArray(array):
arraylen=len(array)
increasing=True
... | true |
433ad06ffcf65021a07f380078ddf7be5a14bc0d | senorpatricio/python-exercizes | /warmup4-15.py | 1,020 | 4.46875 | 4 | """
Creating two classes, an employee and a job, where the employee class has-a job class.
When printing an instance of the employee object the output should look something like this:
My name is Morgan Williams, I am 24 years old and I am a Software Developer.
"""
class Job(object):
def __init__(self, title, sal... | true |
41fdc8a89fb3e7ecdcfaec78e5c668fc0e6e4e80 | JoshuaShin/A01056181_1510_assignments | /A1/random_game.py | 2,173 | 4.28125 | 4 | """
random_game.py.
Play a game of rock paper scissors with the computer.
"""
# Joshua Shin
# A01056181
# Jan 25 2019
import doctest
import random
def computer_choice_translator(choice_computer):
"""
Translate computer choice (int between 0 - 2 inclusive) to "rock", "paper", or "scissors".
PARAM choic... | true |
0ca8c1dc04f5e98a3d08b588e2a4c5903e7f61da | amit-kr-debug/CP | /Geeks for geeks/Heap/Sorting Elements of an Array by Frequency.py | 2,697 | 4.125 | 4 | """
Given an array A[] of integers, sort the array according to frequency of elements. That is elements that have higher
frequency come first. If frequencies of two elements are same, then smaller number comes first.
Input:
The first line of input contains an integer T denoting the number of test cases. The descriptio... | true |
e2fb43f0392cd69430a3604c6ddcf3b06425b671 | amit-kr-debug/CP | /Geeks for geeks/array/sorting 0 1 2.py | 1,329 | 4.1875 | 4 | """
Given an array of size N containing only 0s, 1s, and 2s; sort the array in ascending order.
Example 1:
Input:
N = 5
arr[]= {0 2 1 2 0}
Output:
0 0 1 2 2
Explanation:
0s 1s and 2s are segregated
into ascending order.
Example 2:
Input:
N = 3
arr[] = {0 1 0}
Output:
0 0 1
Explanation:
0s 1s and 2s are segregated
i... | true |
6069283e9388e6d1704f649d14b84e4a288f8d86 | amit-kr-debug/CP | /Cryptography and network security/lab - 2/Vigenere Cipher encrypt.py | 669 | 4.21875 | 4 | def encrypt(plain_text, key):
cipher_text = ""
# Encrypting plain text
for i in range(len(plain_text)):
cipher_text += chr(((ord(plain_text[i]) + ord(key[i]) - 130) % 26) + 65)
return cipher_text
if __name__ == "__main__":
# Taking key as input
key = input("Enter the key:")
# Taki... | true |
4602c2628ae813e68f997f36b18d270316e42a43 | amit-kr-debug/CP | /hackerrank/Merge the Tools!.py | 1,835 | 4.25 | 4 | """
https://www.hackerrank.com/challenges/merge-the-tools/problem
Consider the following:
A string, , of length where .
An integer, , where is a factor of .
We can split into subsegments where each subsegment, , consists of a contiguous block of characters in . Then, use each to create string such that:
The c... | true |
efa3c5294a1274ba4c2133c34b6aaa32fb3ad590 | ayatullah-ayat/py4e_assigns_quizzes | /chapter-10_assignment-10.2.py | 921 | 4.125 | 4 | # 10.2 Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages. You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon.
# From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008... | true |
2836445a3619bd8f3a5554d962f079cc0de9cd9a | sooty1/Javascript | /main.py | 1,240 | 4.1875 | 4 |
names = ['Jenny', 'Alexus', 'Sam', 'Grace']
dogs_names = ['Elphonse', 'Dr. Doggy DDS', 'Carter', 'Ralph']
names_and_dogs_names = zip(names, dogs_names)
print(list(names_and_dogs_names))
# class PlayerCharacter:
# #class object attribute not dynamic
# membership = True
# def __init__(self, name="anonymou... | true |
5b2267600ac663d2493599080b5bf482511015d3 | nehaDeshp/Python | /Tests/setImitation.py | 623 | 4.25 | 4 | '''
In this exercise, you will create a program that reads words from the user until the
user enters a blank line. After the user enters a blank line your program should display
each word entered by the user exactly once. The words should be displayed in
the same order that they were entered. For example, if the user e... | true |
a15d13da749137921a636eb4acf2d56a4681131a | nehaDeshp/Python | /Tests/Assignment1.py | 559 | 4.28125 | 4 | '''
Write a program that reads integers from the user and stores them in a list. Your
program should continue reading values until the user enters 0. Then it should display
all of the values entered by the user (except for the 0) in order from smallest to largest,
with one value appearing on each line. Use either the s... | true |
8a61b80b3b96c4559149609d9630323a05f3a134 | tanviredu/DATACAMPOOP | /first.py | 292 | 4.34375 | 4 | # Create function that returns the average of an integer list
def average_numbers(num_list):
avg = sum(num_list)/float(len(num_list)) # divide by length of list
return avg
# Take the average of a list: my_avg
my_avg = average_numbers([1,2,3,4,5,6])
# Print out my_avg
print(my_avg) | true |
caaf2c8cf85b91b74b917523796029eda659131f | samithaj/COPDGene | /utils/compute_missingness.py | 976 | 4.21875 | 4 | def compute_missingness(data):
"""This function compute the number of missing values for every feature
in the given dataset
Parameters
----------
data: array, shape(n_instances,n_features)
array containing the dataset, which might contain missing values
Returns
-------
n_missin... | true |
31116f0e83ba9681303f5540d51b28e8d7d0c1c3 | kellyseeme/pythonexample | /220/str.py | 228 | 4.3125 | 4 | #!/usr/bin/env python
import string
a = raw_input("enter a string:").strip()
b = raw_input("enter another string:").strip()
a = a.upper()
if a.find(b) == -1:
print "this is not in the string"
else:
print "sucecess"
| true |
d66a2b7006d3bbcede5387ed1a56df930862bccb | kellyseeme/pythonexample | /221/stringsText.py | 945 | 4.21875 | 4 | #!/usr/bin/env python
"""this is to test the strings and the text
%r is used to debugging
%s,%d is used to display
+ is used to contact two strings
when used strings,there can used single-quotes,double-quotes
if there have a TypeError,there must be some format parameter is not suit
"""
#this is use %d to set the valu... | true |
5a2b8b97398fce8041886ad4920b5f7acd092ef7 | kellyseeme/pythonexample | /323/stringL.py | 693 | 4.15625 | 4 | #!/usr/bin/env python
#-*coding:utf-8 -*-
#this is use the string method to format the strins
#1.use the ljust is add more space after the string
#2.use the rjust is add more space below the string
#3.use the center is add more space below of after the string
print "|","kel".ljust(20),"|","kel".rjust(20),"|","kel".cen... | true |
0db7502613ff0c05461e17509d9b8b6abb1be3d2 | kellyseeme/pythonexample | /33/using_list.py | 1,053 | 4.34375 | 4 | #!/usr/bin/env python
"""
this is for test the list function
"""
#this is define the shoplist of a list
shoplist = ["apple","mango","carrot","banana"]
#get the shoplist length,using len(shoplist)
print "Ihave",len(shoplist),"items to pruchase."
#this is iteration of the list,the list is iterable
print "These items ar... | true |
a2861764344d6b0302e21b4d670addd638b13e38 | CorinaaaC08/lps_compsci | /class_samples/3-2_logicaloperators/college_acceptance.py | 271 | 4.125 | 4 | print('How many miles do you live from Richmond?')
miles = int(raw_input())
print('What is your GPA?')
GPA = float(raw_input())
if GPA > 3.0 and miles > 30:
print('Congrats, welcome to Columbia!')
if GPA <= 3.0 or miles <= 30:
print('Sorry, good luck at Harvard.')
| true |
06366e956623f3305dbb737d6f91ddcea542daf4 | dataneer/dataquestioprojects | /dqiousbirths.py | 2,146 | 4.125 | 4 | # Guided Project in dataquest.io
# Explore U.S. Births
# Read in the file and split by line
f = open("US_births_1994-2003_CDC_NCHS.csv", "r")
read = f.read()
split_data = read.split("\n")
# Refine reading the file by creating a function instead
def read_csv(file_input):
file = open(file_input, "r")
read = fil... | true |
fb9b299eff93179ac097d797c7e5ce59bc20f63a | yugin96/cpy5python | /practical04/q5_count_letter.py | 796 | 4.1875 | 4 | #name: q5_count_letter.py
#author: YuGin, 5C23
#created: 26/02/13
#modified: 26/02/13
#objective: Write a recursive function count_letter(str, ch) that finds the
# number of occurences of a specified leter, ch, in a string, str.
#main
#function
def count_letter(str, ch):
#terminating case when string is... | true |
599df5c53d26902da3f2f16cb892a0ae6501be78 | yugin96/cpy5python | /practical04/q6_sum_digits.py | 482 | 4.28125 | 4 | #name: q6_sum_digits.py
#author: YuGin, 5C23
#created: 26/02/13
#modified: 26/02/13
#objective: Write a recursive function sum_digits(n) that computes the sum of
# the digits in an integer n.
#main
#function
def sum_digits(n):
#terminating case when integer is 0
if len(str(n)) == 0:
return 0... | true |
fbd7624f47d4e14b47722923fd568c31e082d91d | Monsieurvishal/Peers-learning-python-3 | /programs/for loop.py | 236 | 4.59375 | 5 | >>for Loops
#The for loop is commonly used to repeat some code a certain number of times. This is done by combining for loops with range objects.
for i in range(5):
print("hello!")
Output:
hello!
hello!
hello!
hello!
hello!
| true |
c56cc5a285093da9ca9cc2265e344bfdbf03f929 | Monsieurvishal/Peers-learning-python-3 | /programs/for loop_p3.py | 282 | 4.3125 | 4 | >>Write a python script to take input from the user and print till that number.
#Ex: if input is 10 print from 1 till 10.
n=int(input("enter the number:"))
i=0
for i in range(n):
print(i)
i=i+1
print("finished")
#output:
enter the number:
0
1
2
3
4
5
6
7
8
9
finished
| true |
24b146a3e423fd413124b988150d4e1ee01b4204 | dell-ai-engineering/BigDL4CDSW | /1_sparkbasics/1_rdd.py | 1,467 | 4.25 | 4 | # In this tutorial, we are going to introduce the resilient distributed datasets (RDDs)
# which is Spark's core abstraction when working with data. An RDD is a distributed collection
# of elements which can be operated on in parallel. Users can create RDD in two ways:
# parallelizing an existing collection in you... | true |
c767555ee9c73ae671ed7d37c5951dbe943c3635 | hoangqwe159/DoVietHoang-C4T5 | /Homework 2/session 2.py | 258 | 4.21875 | 4 | from turtle import *
shape("turtle")
speed(0)
# draw circles
circle(50)
for i in range(4):
for i in range (360):
forward(2)
left(1)
left(90)
#draw triangle # = ctrl + /
for i in range (3):
forward(100)
left(120)
mainloop() | true |
fe892de04ecbf1e806c4669f14b582fd1a801564 | qodzero/icsv | /icsv/csv | 578 | 4.15625 | 4 | #!/usr/bin/env python3
import csv
class reader(obj):
'''
A simple class used to perform read operations
on a csv file.
'''
def read(self, csv_file):
'''
simply read a csv file and return its contents
'''
with open(csv_file, 'r') as f:
cs = csv.reader(f)
... | true |
8b9059649cbaad48bb6b53fa8a4624eb9b5819a9 | aha1464/lpthw | /ex21.py | 2,137 | 4.15625 | 4 | # LPTHW EX21
# defining the function of add with 2 arguments. I add a and b then return them
def add(a, b):
print(f"ADDING {a} + {b}")
return a + b
# defining the function of subtract
def subtract(a, b):
print(f"SUBTRACKTING {a} - {b}")
return a - b
# defining the function of multiply
def multiply(a,... | true |
6345bac40a37f7811ffd2cf6b011e339bdd072f7 | aha1464/lpthw | /ex16.py | 1,371 | 4.25 | 4 | # import = the feature argv = argument variables sys = package
from sys import argv
#
script, filename = argv
# printed text that is shown to the user when running the program
print(f"We're going to erase (filename).")
print("If you don't want that, hit CTRL-C (^c).")
print("If you do want that, hit RETURN.")
# input =... | true |
3af1f947862099145d100d986ad158586368d47b | thetrashprogrammer/StartingOutWPython-Chapter3 | /fat_and_carbs.py | 1,491 | 4.375 | 4 | # Programming Exercise 3.7 Calories from Fat and Carbohydrates
# May 3rd, 2010
# CS110
# Amanda L. Moen
# 7. Calories from Fat and Carbohydrates
# A nutritionist who works for a fitness club helps members by
# evaluating their diets. As part of her evaluation, she asks
# members for the number of fat grams and carbohy... | true |
7dcc48ffebb1ae534fa973cab9d70c77e7b7a610 | wade-sam/variables | /Second program.py | 245 | 4.15625 | 4 | #Sam Wade
#09/09/2014
#this is a vaiable that is storing th value entered by the user
first_name = input("please enter your first name: ")
print(first_name)
#this ouputs the name in the format"Hi Sam!"
print("Hi {0}!".format(first_name))
| true |
d490e1f73448f32eb150b3994f359cffb155acc4 | pankhurisri21/100-days-of-Python | /variables_and_datatypes.py | 548 | 4.125 | 4 | #variables and datatypes
#python variables are case sensitive
print("\n\nPython variables are case sensitive")
a=20
A=45
print("a =",a)
print("A =",A)
a=20#integer
b=3.33 #float
c="hello" #string
d=True #bool
#type of value
print("Type of different values")
print("Type of :",str(a)+" =",type(a))
print("Type of :",s... | true |
b2eb51f1c07dc6b03bd49499e392191e4578a2ed | rbk2145/DataScience | /9_Manipulating DataFrames with pandas/2_Advanced indexing/1_Index objects and labeled data.py | 814 | 4.4375 | 4 | ####Index values and names
sales.index = range(len(sales))
####Changing index of a DataFrame
# Create the list of new indexes: new_idx
new_idx = [month.upper() for month in sales.index]
# Assign new_idx to sales.index
sales.index = new_idx
# Print the sales DataFrame
print(sales)
######Changing index name labels
... | true |
a991555e799064d6a89f9c0c1cc460fcf41ce8ea | TazoFocus/UWF_2014_spring_COP3990C-2507 | /notebooks/scripts/cli.py | 664 | 4.21875 | 4 | # this scripts demonstrates the command line input
# this works under all os'es
# this allows us to interact with the system
import sys
# the argument list that is passed to the code is stored
# in a list called sys.argv
# this list is just like any list in python so you should treat it as such
cli_list = sys.argv
... | true |
f68f8aaf53e834b5b3297a2852518edba06ebbe0 | denrahydnas/SL9_TreePy | /tree_while.py | 1,470 | 4.34375 | 4 | # Problem 1: Warm the oven
# Write a while loop that checks to see if the oven
# is 350 degrees. If it is, print "The oven is ready!"
# If it's not, increase current_oven_temp by 25 and print
# out the current temperature.
current_oven_temp = 75
# Solution 1 here
while current_oven_temp < 350:
print("The oven is... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.