blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
b0edb28c2f7c9c69361b8d5121d0e7372c50f93e | savadev/Leetcode-practice | /122 Sum and average.py | 501 | 4.1875 | 4 | Sum and Average from a List
Given a list of integers, write a method that returns the sum and average of only the 1st, 3rd, 5th, 7th etc, element.
For example, [1, 2, 3] should return 4 and 2.
The average returned should always be an integer number, rounded to the floor. (3.6 becomes 3.)
def sumavg(arr):
sum = 0
... | true |
9d6d5ac4882ae9213f56d729cf98c531f3a0f180 | jc328/CodeWars-1 | /7kyu_MostCommonFirst.py | 1,192 | 4.25 | 4 | // 7kyu - Most Common First
// Given a string, s, return a new string that orders the characters in order of
// frequency.
// The returned string should have the same number of characters as the original
// string.
// Make your transformation stable, meaning characters that compare equal should
// stay in their o... | true |
30ad4e8bf69f6407bd388987245d39c368ee0bed | lavisha752/Python- | /LCM.py | 889 | 4.125 | 4 | # User input and storing data in variables
var1=int(input("Enter the first number:"))
var2=int(input("Enter the second number:"))
# Using an if statement to find the smallest number and storing in a variable called smallest
if(var1 > var2):
smallest=var1
else:
smallest=var2
# A while loop is used to te... | true |
373d68168b0589221d4e0548104c737bd52ecf4d | mrech/LearnPython_TheHardWay | /shark.py | 741 | 4.15625 | 4 | #define a class with is methods (functions)
class Shark:
def swim(self):
print("The shark is swimming.")
def be_awesome(self):
print("The shark is being awesome.")
# function object
# create a variable called main that point the function object
def main():
sammy = Shark() # ... | true |
f6bc7d44457f10f177f97fd6fba284923262ab3d | MTset/Python-Programming-Coursework | /Python 01: Beginning Python/Lesson 11: Defining and Calling Your Own Functions/three_param.py | 640 | 4.1875 | 4 | #!/usr/local/bin/python3
def my_func(a, b="b was not entered", c="c was not entered" ):
""" right triangle check """
result = "Values entered: a - {0}, b - {1}, c - {2}\n".format(a, b, c)
if type(c) is int:
d = sorted([a, b, c])
if abs(complex(d[0], d[1])) == d[2]:
result += "Y... | true |
427ab151f21bdd3fbd09e2fce7dddcdbdac5eb5d | purcellconsult/jsr-training | /day_2_files/secret_number_game.py | 1,014 | 4.25 | 4 | # Secret Number Game
# -------------------
# A text based game written in python.
# The user gets to take an arbitrary number of guesse.
# They will be provided feedback on if their guess
# is less than, greater than, or equal to the secret num.
# If equal, the secret number should be revealed, and
# then the lo... | true |
bd1c05cbe4e34d9a8b3f5d9f65d0ac89ec5145a6 | zxcv-zxcv-zxcv/python_mega_course | /textpro_mysolution.py | 875 | 4.21875 | 4 | # 1. Output "Say Something"
# 2. take an input, store it into a list
# 3. end if user inputs /end
# 4. Capitalise first letter. End in a question mark if it starts with who,
# what , when, where, why, how
# 5. Print out each input.
inputs = []
word = ''
fullstop = '.'
sentence = ''
while True:
if w... | true |
cf5f292acb3d3bfd6f306cb80d49a31b9a194533 | nankyoku/nankyokusPython | /ex6.py | 1,262 | 4.375 | 4 | # Exercise 6: Strings and Text
# The below 4 statements set up variables and their values
x = "There are %d types of people." % 10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s." % (binary, do_not)
# The below 2 statements print out the values of the variables x and y.
print x
print y
#... | true |
a925aacc4744ec91d54bdd345e471dc9af142bf2 | Eqliphex/python-crash-course | /chapter08 - Functions/exercise8.8_user_albums.py | 1,269 | 4.375 | 4 | def make_album(album_artist, album_title, album_song_num=None):
"""Creates an album.
Args:
album_artist (str): Name of the artist.
album_title (str): Title of the album.
album_song_num (:obj:`str`, optional): The second parameter.
Defaults to None.
Returns:
bool:... | true |
11a0b9c55f4e24347745c648bd8ca2ccc8f34e97 | omkar-21/Python_Programs | /Que_34.py | 645 | 4.1875 | 4 | """
Write a procedure char_freq_table() that, when run in a terminal, accepts a
file name from the user, builds a frequency listing of the characters
contained in the file, and prints a sorted and nicely formatted character
frequency table to the screen.
"""
from collections import Counter
import os
def main():
... | true |
04e02bb6cbe311c3ad31150ad5816489651edcf3 | omkar-21/Python_Programs | /Que_37.py | 836 | 4.34375 | 4 | """
Write a program that given a text file will create a new text file in which all
the lines from the original file are numbered from 1 to n (where n is the
number of lines in the file).
"""
import os
def number_lines(file_path, path_for_new_file):
try:
with open(file_path,'r') as input_file, open(pa... | true |
1cb69c0e9b56b34d446dd27338c94dbb8d424439 | omkar-21/Python_Programs | /Que_36.py | 888 | 4.1875 | 4 | """
A hapax legomenon (often abbreviated to hapax) is a word which occurs only
once in either the written record of a language, the works of an author,
or in a single text. Define a function that given the file name of a text
will return all its hapaxes. Make sure your program ignores capitalization.
"""
import os
im... | true |
7fd8a9449de8ae605918a93e43925901f0794604 | omkar-21/Python_Programs | /Que_3.py | 425 | 4.125 | 4 | '''
Define a function that computes the length of a given list or string.
(It is true that Python has the len() function built in,
but writing it yourself is nevertheless a good exercise.)
'''
def findLen(str1):
counter = 0
for i in str1:
counter += 1
print("Length of string is",counter)
... | true |
d6171f54ce5fade36bd8eddf7ca3e20f270016ff | omkar-21/Python_Programs | /Que_32.py | 658 | 4.28125 | 4 | """
Write a version of a palindrome recogniser that accepts a file name from the user, reads each line, and prints the line
to the screen if it is a palindrome.
"""
import re
import os
def main():
try:
with open(input("Enter the file path to read\n>>"),'r') as input_file:
lines=in... | true |
8f5b0188b57f4db2e84ebc8d798465340f299e5a | omkar-21/Python_Programs | /Que_27.py | 871 | 4.46875 | 4 | """
Write a program that maps a list of words into a list of integers representing the lengths of the corresponding words.
Write it in three different ways: 1) using a for-loop, 2) using the higher order function map(), and 3) using list
comprehensions.
"""
def lengths_using_loop(words):
lengths = []
for word... | true |
c1f275be9c454a9542991878f85be18a0b03e516 | apoorvakashi/launchpad-Assignments | /problem3.py | 230 | 4.125 | 4 | numbers = [1, 3, 4, 6, 4, 35, 5, 43, 3, 4, 18, 3, 1, 1]
numlist= []
element = int(input("Enter a number: "))
for index, value in enumerate(numbers):
if value==element:
numlist.append(index)
print(numlist)
| true |
4ae99f08a25243205420fc508e86b53a86d2d032 | roger-mayer/python-practice | /crash_course/input_and_while_loops/greeter.py | 580 | 4.28125 | 4 | # # single line
# name = input("please enter your name: ")
# print(f"Hello, {name}!")
#
# # multi line prompt
# prompt = "If you tell us you name, we can personalize messages."
# prompt += "\nWhat is your name? "
#
# name = input(prompt)
# print(f"\nHello, {name}!")
# using int to accept numerical input
age = input("H... | true |
5d7d95edc99927d94276b4c44b0904fed9f9b5af | iam-abbas/cs-algorithms | /Searching and Sorting/Selection Sort/PYTHON/SelectionSort.py | 945 | 4.28125 | 4 | #Call 'main()' in the terminal/console to run Selection Sort on desired unsorted sequence.
#This algorithm returns the sorted sequence of the unsorted one and works for positive values.
def SelectionSort(arr):
pos = 0
min_num = 0
for i in range(0, len(arr)):
min_num = arr[i]
pos = i
... | true |
b7d9ab7dd8f30d06e51e1f8c9e73c797e5d62aa3 | iam-abbas/cs-algorithms | /Searching and Sorting/Linear Search/Python/linear search.py | 460 | 4.125 | 4 | # Python3 code to linearly search x in arr[].
# If x is present then return its location,
# otherwise return -1
def search(arr, n, x):
for i in range (0, n):
if (arr[i] == x):
return i;
return -1;
# Driver Code
arr = [ 2, 3, 4, 10, 40 ];
x = 10;
n = len(arr);
result = s... | true |
10219c8538c18b8955068ffb124244e2990603f0 | iam-abbas/cs-algorithms | /Floyd Cycle Loop Detection/floyd_cycle_loop_detection.py | 1,272 | 4.125 | 4 | class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
# Push value to the end of the list
def push(self, data):
new_node = Node(data)
if self.head is None:
self.head... | true |
7359a38cffa8a37405a0f7be60eefdae3685436a | TimTheFiend/Automate-the-Boring-Stuff-with-Python | /_Finished/Ch15/time_module.py | 1,489 | 4.1875 | 4 | import time
def intro():
print(time.time()) # 1574066563.5332215
"""Explanation:
Here I'm calling time.time() on 18th of November, 09:43.
The value is how many seconds have passed between the Unix epoch and the moment time.time() was called.
Epoch timestamps can be used to profile code, that is, t... | true |
0e9c5822ad15fa0fe196d6a7c1f072720e8c9c0f | JKam123/homework1 | /PrimeNumbersCode.py | 394 | 4.1875 | 4 | # Check if the number is a prime number
Int = 5
IsPrime = True
if Int != 0:
for x in range(2, Int / 2):
if Int%x == 0:
IsPrime = False
break
if IsPrime:
print "Its a prime number"
else:
print "Its not a prime number"
else:
... | true |
9ddb24b957201560c1491cf5333e453280648689 | aaron-goshine/python-scratch-pad | /workout/note_11.5.py | 648 | 4.46875 | 4 | ##
# Determine whether or not a string is a palindrome.
#
# Read the input from the user
line = raw_input("Enter a string: ")
# Assume that the string is a palindrome until
# we can prove otherwise
is_palindrome = True
# Check the characters, starting from the end until
# the middle is reached
for i in range(0, len(... | true |
3e2f558efe5f67fcf73a15fa759c3d488e074062 | aaron-goshine/python-scratch-pad | /workout/note_11.1.py | 1,394 | 4.5 | 4 | ##
# Compute the perimeter of a polygon.
# The user will enter a blank line for the x-coordinates
# that all of the points have been entered.
#
from math import sqrt
# Store the perimeter of the polygon
perimeter = 0
# Read the coordinates of the first point
first_x = float(raw_input("Enter the x part of the coordin... | true |
4507f6384a59dd92167050449c52ba68e0c9f624 | aaron-goshine/python-scratch-pad | /workout/shuffle_deck.py | 1,341 | 4.1875 | 4 | ##
# Create deck for cards and shuffle it
#
from random import randrange
# Construct a standard deck of cards with 4
# suits and 13 value per suit
# @return a list of card, with each represented by two characters
def createDeck ():
# Create a list to store the card in
cards = []
# For each suit and each v... | true |
a88d040a8ffb05efeefc349a1dd1d8dc54187075 | aaron-goshine/python-scratch-pad | /workout/reduce_measure.py | 2,453 | 4.34375 | 4 | ##
# Reduce an imperial measurement so that it is expressed using
# the largest possible unit of measure. For example, 59 teaspoon
# to 1 cup...
#
TSP_PER_TBSP = 3
TSP_PER_CUP = 48
## Reduce an imperial measurement to that it is expressed using
# the largest unit of measure.
# @param num the number of units that need... | true |
abbfbf2e681ac34c9d6c666a1ae5d11c2a83b19f | AnilSonix/CSPySolutions | /sol2.py | 727 | 4.46875 | 4 | # bubble sort
numbers = []
def bubble_sort(numbers):
n = len(numbers)
# Traverse through all array elements
for i in range(n - 1):
# range(n) also work but outer loop will repeat one time more than needed.
# Last i elements are already in place
for j in range(0, n - i - 1):
... | true |
4a6caafad025f117dcde3d67da1e8da181b102d1 | sanjidahw/python-bootcamp | /Week 1/Day 1/loops.py | 312 | 4.125 | 4 | counter = 0
while counter <= 10:
print(counter)
counter += 1
# range(start, stop, increment)
# includes the start, does not include the stopping number
print("using the inputs to range()")
for number in range(0,5,1):
print(number)
print("using one input to range()")
for number in range(5):
print(number)
| true |
341e1ef288d4cc92e435399d224d2a7ada282f9c | Innocent2240/calculations | /calculation_Operation.py | 905 | 4.25 | 4 | print("Choose your calculation operator")
print("1: ADDITION")
print("2: SUBTRACTION")
print("3: MULTIPLICATION")
print("4: DIVISION")
calculation = input()
if calculation == "1":
value1=input("Enter first value: ")
value2 = input("Enter second value: ")
print("The sum is " + str(int(value1) + ... | true |
5136c6d0b4a0fb45df849944d475d673e406a0b3 | qetennyson/CThink2018-LessonPlans | /tuples_ex.py | 1,323 | 4.65625 | 5 | ''' Lists are great for storing items we may want to change throughout the life of a program. We can also modify lists, they are mutable! However, there are situations where we may want a data structure that cannot be modified.
An immutable data structure! Hello tuples.'''
# here's a basic tuple that we might use ... | true |
f008853f6a2f3491a93297874181c1bf59a21506 | rybread32/cmpt120straub | /calc_functions.py | 1,696 | 4.34375 | 4 | #calculator.py
#Acts as a Working Calculator for basic arithmetic and PEMDAS
#Created by Ryan Straub
#3/5/19
#def main()
#Where you insert a formula.
#equation = input("Insert Problem: ").split(" ")
#Is what you inserted just a number or not?
#if len(equation)<=2:
#print("This is not ... | true |
b4eae0dc93b5f8d007c550727cdd8e210eafaa36 | ilanasufrin/dsa | /dynamicProgramming/uniquePaths.py | 1,153 | 4.28125 | 4 | """
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time.
The robot is trying to reach the bottom-right corner of the grid.
How many possible unique paths are there?
"""
class Solution(object):
def uni... | true |
b95a94ded927b4cbc3cd1e0ab8da0e63ff5dac12 | Ayamin0x539/Python-Homework | /Exercise_1.7_rockpaperscissors.py | 1,212 | 4.375 | 4 | #Exercise 1.7 - Rock, Paper, Scissors
'''
In this exercise, you are going to practice using conditionals (if, elif, else). You will write a small program that will
determine the result of a rock, paper, scissors game, given Player 1 and Player 2s choices. Your program will print out the result.
'''
#constants to print... | true |
602382747b1729970edc2e18b17fcdcfacc3b4ac | pshimanshu/AdvPython | /day_5/classes/special_methods.py | 903 | 4.21875 | 4 |
# special methods or magic methods or dunder methods
# __init__ -> constructor -> to initialize all intance attributes
# __str__ -> string representation of the class
# class Employee:
# def __init__(self, first, last, address, phone, salary):
# self.first = first
# self.last = last
# se... | true |
cbe63efe5bbf50c149dba5bfbf2d8f52ece79179 | pshimanshu/AdvPython | /day_4/db_programming/file1.py | 941 | 4.15625 | 4 | # Python with SQL database
def takeInput():
arr = []
arr.append(input("Enter name: "))
arr.append(input("Enter phone number: "))
arr.append(input("Enter address: "))
return arr
import sqlite3
# create a datbase object, if doesnt exist, else access it
db = sqlite3.connect("DB1.sqlite")
# create a ... | true |
9d7914e8b2225e21359fdd62217e1fc93be08b58 | satishp962/40-example-python-scripts | /14.py | 306 | 4.3125 | 4 | file = open('file_write.txt', 'r')
print("File contents: ")
for i in file:
print(i)
file = open('file_write.txt', 'a')
str = input("Enter the text to append to the file: ")
file.writelines(str)
file = open('file_write.txt', 'r')
print('File contents after appending: ')
for i in file:
print(i); | true |
cd39cce6b84c9126bd0c3635ac9aee4819a2bd10 | Jaden5672/Python_Coding | /Miles_Km.py | 485 | 4.1875 | 4 | pick=input("Type in A to convert miles to kilometers,or type in B to convert kilometers to miles:")
pick=pick.upper()
if pick=="A":
miles=input("Enter any number of miles to convert to kilometers")
miles=float(miles)
km=miles*1.609
print(km)
elif pick=="B":
kilometers=input("Enter any number... | true |
90a3020ea45bd4d51164bdaff21813ae02bb6099 | mmore21/ds_algo | /python/lib/bubble_sort.py | 703 | 4.1875 | 4 | """
Topic: Bubble Sort
Category: Algorithm
Author: Mason Moreland
Runtime: O(n^2)
"""
def bubble_sort(arr):
"""
Passes over a list comparing two elements and repeats with a smaller,
sliced off end of the list each iteration until sorted.
"""
for i in range(len(arr)):
for j in r... | true |
1610d166715de41a88683656df02011d3ac7453e | thommms/python-projects | /check if a number is in a given range.py | 313 | 4.21875 | 4 | #to check if a number is in a given range
start=int(input("enter the beginning of the range: "))
end=int(input("enter the end of the range:"))
number=int(input("enter the number to check: "))
if number not in range (start,end):
print ("\n",number," not in range")
else:
print ("\nnumber is in the range") | true |
d770deaf2335fb6a54a6205e74fe37c1e350afc9 | shirazh7/caesarCipher | /cipher.py | 2,153 | 4.25 | 4 |
# This is my Ceaser Cipher encryption program
# Written in python
def encryption():
print("******** Encryption ********")
msg = input("Enter message: ")
key = int(input("Enter cipher key (0-25): "))
encrypted_text = ""
for i in range(len(msg)):
if ord(msg[i]) == 32: # ord() will give t... | true |
89a5b8dd71ea1b785b4581ec2530047c1e4167ef | brommista/Login_credentials_creator | /login_credentials_creator.py | 1,288 | 4.25 | 4 | import random
import string
#Ask for User's First name
first_name = input("Please enter user's first name: ")
#Ask for User's last name
last_name = input("Please enter user's last name: ")
#defining a function to create username using firstname and lastname
def username(fisrt_name, last_name):
#Username will con... | true |
c09ca07feef647ee737f255e3afd88af685957e6 | michaelrbull/weathermantask | /runweathercheck.py | 2,838 | 4.1875 | 4 | ###
# Import both the list of sunny cities and the corresponding flight numbers
# from both the flight and weather program.
from weather_services import sunny_cities
from flight_services import sunny_flight_num
# Prints both lists but tidied up with string concentation.
print("Sunny Cities: " + str(sunny_cities))
p... | true |
51b146b590d9ee041588aa69e8dd0305d69056f1 | kimjane93/udemy-python-100-days-coding-challenges | /day-5-password-generator/even-nums.py | 708 | 4.28125 | 4 | # using range function
# use for loops with the rnage funciton
# good for genrating a range of numbers to loop through
# for number in range(a, b):
# print(number)
# DOES NOT INCLUDE END OF THE RANGE
# for number in range(1, 10):
# print(number)
# out puts 1-9
# if wanted all, would have to make it 1... | true |
55928cf794e01fbb58df8535557703841224712e | kimjane93/udemy-python-100-days-coding-challenges | /day-2-tip-calc/main.py | 2,281 | 4.28125 | 4 | print("Welcome To The Tip Calculator!")
total_bill = input("What was the total of your meal? \n$")
number_of_payers = input("How many of you will be splitting the cost? \n")
tip_percentage = input("What percentage would you like to tip? \n15, 18, or 20: \n")
total_bill_int = int(total_bill)
number_of_payers_int = int(... | true |
590f45f9a3071788b36c25d130dfb82cb498ca89 | kimjane93/udemy-python-100-days-coding-challenges | /day-8-create-caesar-ciper-inputs/prime_number_checker.py | 383 | 4.125 | 4 | # check if number is prime
# can only divided by one and itself without decimals
def prime_checker(number):
for n in range(2, number):
if number % n == 0:
print(f"{number} is not a prime number")
break
else:
print(f"{number} is a prime number")
break... | true |
52682fbd4fe8d676fc6ddcd274470a006db87193 | DushyantVermaCS/Python-Tuts | /practice quiz1.py | 525 | 4.21875 | 4 | #Practice Quiz:
'''In this scenario, two friends are eating dinner at a restaurant.
The bill comes in the amount of 47.28 dollars.
The friends decide to split the bill evenly between them,
after adding 15% tip for the service. Calculate the tip, the total amount to pay,
and each friend's share,then output a messag... | true |
bfd80edb5aa331477c537b233e77d6f832e47fe5 | DushyantVermaCS/Python-Tuts | /7.1.py | 403 | 4.5 | 4 | '''7.1 Write a program that prompts for a file name, then opens that file and
reads through the file, and print the contents of the file in upper case.
Use the file words.txt to produce the output below.
You can download the sample data at'''
#http://www.py4e.com/code3/words.txt
#Ans:
fname = input("Enter file ... | true |
fb1c90346864aabef133791cf080b3a30c3fcbdd | blackwer/sciware-testing-python | /sciware_testing_python/main.py | 1,192 | 4.40625 | 4 | # -*- coding: utf-8 -*-
"""Main module template with example functions."""
def sum_numbers(number_list):
"""Example function. Sums a list of numbers using a for loop.
Parameters
----------
number_list : list
List of ints or floats
Returns
-------
int or float
Sum of list
... | true |
e4b5ef9fe4a88ccc92e043d808dfbab567c315ea | KunalKokate/Python-Workshop | /ExceptionHandling.py | 1,250 | 4.40625 | 4 | # #Exception Handling
# try: #put that code in it which you think is a error
# except <Exception>: #put the posssible exception here
# print("Some error")
# else
# print("All went well")
#ex1-IOError
try:
fh = open("example_23.txt","w")
fh.write("This is my test file for exception ha... | true |
e3910278e81f810231b33c4557d0ebf4af9abfef | asaini/algo-py | /algos/max_diff_two.py | 519 | 4.28125 | 4 | def maximum_diff(array):
"""
Given an array array of integers,
find out the difference between any two elements such that
larger element appears after the smaller number in array
"""
max_diff = array[1] - array[0]
min_element = array[0]
n = len(array)
for i in range(1, n):
if array[i] - min_element > max_... | true |
a0c69c20ff2e64a4facb5ae0ffe72bd970d090e8 | asaini/algo-py | /algos/triangles.py | 459 | 4.1875 | 4 | def number_of_triangles(array):
"""
Given an array find the number of triangular
pairs in it
"""
array = sorted(array)
n = len(array)
count = 0
for i in range(n-2):
k = i+2
for j in range(i+1, n):
print count
while k < n and array[i] + array[j] < array[k]:
k += 1
count += k - j - 1
return co... | true |
966da861bcf16b3aef9480350356641b0e1679d8 | asaini/algo-py | /algos/word_break.py | 2,523 | 4.15625 | 4 | """
Given an input string and a dictionary of words,
segment the input string into a space-separated
sequence of dictionary words if possible. For
example, if the input string is "applepie" and
dictionary contains a standard set of English words,
then we would return the string "apple pie" as output.
See : http://then... | true |
114c8f6f3c901362a6bfd60eab2b9687132b7631 | Hayasak-a/E02a-Control-Structures | /main10.py | 2,103 | 4.34375 | 4 | #!/usr/bin/env python3
import sys, random
assert sys.version_info >= (3,7), "This script requires at least Python 3.7"
print('Greetings!') # The program greets the user.
colors = ['red','orange','yellow','green','blue','violet','purple'] # The program initializes an array of colors.
play_again = '' # the variable pl... | true |
14b7d57641e5ce1c727a4f7f36968ab417d270b2 | avi527/Decorator | /MultipleDecoratorstoaSingleFunction.py | 591 | 4.28125 | 4 | '''the decorators will be applied in the order that we've called them. Below we'll
define another decorator that splits the sentence into a list.
We'll then apply the uppercase_decorator and split_string decorator to a single function.'''
def splitString(function):
def wrapper():
fun=function()
funSplit=... | true |
b80defe74fc40a470982bbbac629e1ea78b05195 | vaibhavmathur91/GeeksForGeeks | /Arrays/15_print-missing-elements-that-lie-in-range-0-99.py | 1,316 | 4.25 | 4 | """
Print missing elements that lie in range 0 – 99
Given an array of integers print the missing elements that lie in range 0-99.
If there are more than one missing, collate them, otherwise just print the number.
Note that the input array may not be sorted and may contain numbers outside the range [0-99],
but only this... | true |
d59fdcf6ea0c733d27962abefcb1cd87074b55f5 | Daransoto/holbertonschool-machine_learning | /math/0x05-advanced_linear_algebra/2-cofactor.py | 2,811 | 4.15625 | 4 | #!/usr/bin/env python3
""" This module contains the functions determinant, minor and cofactor. """
def determinant(matrix):
"""
Calculates the determinant of a matrix.
matrix is a list of lists whose determinant will be calculated.
If matrix is not a list of lists, raises a TypeError with the message
... | true |
d4017458ff2330ae832679fd0779d14daecf3bb1 | Daransoto/holbertonschool-machine_learning | /math/0x03-probability/poisson.py | 2,052 | 4.28125 | 4 | #!/usr/bin/env python3
""" This module contains the Poisson class. """
class Poisson:
""" Class that represents a poisson distribution. """
e = 2.7182818285
def __init__(self, data=None, lambtha=1.):
"""
Constructor of the class. Sets the instance attribute lambtha as float.
data... | true |
0e644a3a1fefbc155515718c3c673db1492e0ac6 | Daransoto/holbertonschool-machine_learning | /supervised_learning/0x07-cnn/0-conv_forward.py | 2,266 | 4.15625 | 4 | #!/usr/bin/env python3
""" This module contains the function conv_forward. """
import numpy as np
def conv_forward(A_prev, W, b, activation, padding="same", stride=(1, 1)):
"""
Performs forward propagation over a convolutional layer of a neural
network.
A_prev is a numpy.ndarray of shape (m, h_prev, ... | true |
e0215726de40d2dd12c713a53114c0520ff19c5e | prince002021/College-Assignments | /Big Data/Python/Ex/ex1/mapper.py | 616 | 4.125 | 4 | import sys
#input comes from STDIN (standard input), i.e type file.txt brings the content of the file to the terminal, and we read it
for line in sys.stdin:
#remove leading and trailing whitespaces.(\n)
line = line.strip()
#split the line into words.
words = line.split()
#increase counter.
f... | true |
cfb0b17e9dc8cbcb5dab580c07632b14666129b3 | lvrbanec/100DaysOfCode_Python | /Project09, Beginner, Calculator/main.py | 1,395 | 4.375 | 4 | # 03.02.21, Frollo
# Level: beginner
# Project: Easy calculator
from art import logo
print(logo)
# Operations
# Add
def add(n1, n2):
return n1 + n2
# Substract
def substract(n1, n2):
return n1 - n2
# Multipy
def multipy(n1, n2):
return n1 * n2
# Divide
def divide(n1, n2):
return n1 / n2
operations = {
"+... | true |
d97018c87c0ef051616f1b15fa102759167061ab | lvrbanec/100DaysOfCode_Python | /Project16, Intermediate, TurtleRace using turtle module/main.py | 1,238 | 4.34375 | 4 | # 08.02.2021, Frollo
# Level: Intermediate
# Project: Make a turtle race betting game
from turtle import Turtle, Screen
import random
is_race_on = False
screen = Screen()
screen.setup(width=500, height=400)
user_bet = screen.textinput(title="Make your bet", prompt="Which turtle will win the race? Enter a color: ")
co... | true |
8912bd0934d08ba0573043e92ca11925324928c3 | anhnguyendepocen/Python-for-Research | /Part1/exercise 2c.py | 490 | 4.125 | 4 | #EXERCISE 2C
"""
The distance between two points x and y is the square root of the sum of s
quared differences along each dimension of x and y.
Create a function distance(x, y) that takes two vectors and outputs
the distance between them. Use your function to find the distance
between x=(0,0) and y=(1,1).
Print your ... | true |
87219f5f93f82ed8a9eaecccb2e894f73b6b6c98 | ankolaver/ALevel_Computing_Material | /Algorithms/sorting/bubblesort_iter.py | 815 | 4.1875 | 4 | '''Bubble sort has a worst-case and average complexity
of О(n2), where n is the number of items being sorted.
Most practical sorting algorithms have substantially
better worst-case or average complexity, often O(n log n).
The function below always runs O(n^2) time even if the array is sorted.
It can be optimized by sto... | true |
263e4a8e66f719ad1c39d97b68f8f5a75a51112f | Widdershin/CodeEval | /challenges/007-lowercase.py | 818 | 4.3125 | 4 | """
https://www.codeeval.com/browse/20/
Lowercase
Challenge Description:
Given a string write a program to convert it into lowercase.
Input Sample:
The first argument will be a text file containing sentences, one per line.
You can assume all characters are from the english language. E.g.
HELLO CO... | true |
36517dd0165ff7a251258d7a26795d6cf1d5a1b0 | Widdershin/CodeEval | /challenges/011-sumofintegersfromfile.py | 801 | 4.125 | 4 | """
https://www.codeeval.com/browse/24/
Sum of Integers from File
Challenge Description:
Print out the sum of integers read from a file.
Input Sample:
The first argument to the program will be a text file containing
a positive integer, one per line. E.g.
5
12
Output Sample:
Print out t... | true |
6e166497b93e4630729d919dd692231c67497830 | xeroxzen/Coding-Challenges | /Minimum Waiting Time.py | 2,672 | 4.15625 | 4 | # O(nlogn) - time | O(1) - space : where n is the number of queries
def minimumWaitingTime(queries):
## Understand:
'''
- executing the shortest query first is what will lead to the minimum waiting time
- because all queries after it will also have to wait a short/minimum time
- if we execute the query with the... | true |
bc1c7608fe9408b6831c288476894cb7d3ab4213 | MattPaul25/PythonPatterns | /DesignPatterns/Creational/AbstractFactory.py | 1,476 | 4.375 | 4 |
class Dog:
def speak(self):
return "Woof!"
def __str__(self):
return "Dog"
class Cat:
def speak(self):
return "Meow!"
def __str__(self):
return "Cat"
class DogFactory:
def get_pet(self):
#returns dog object
return Dog()
def get_food(self):
... | true |
41c984b50c251479bbb32e5fa4e672e52994ce4d | MattPaul25/PythonPatterns | /DesignPatterns/Behavorial/Visitor.py | 1,823 | 4.1875 | 4 | #visitor allows adding new features to existing class heirarchy without changing it
#scenario: house class, HVAC specialist is a vistor,
#Electrician is visitor 2 -- new actions to be performed on an existing class heirarchy.
class House(object): #the class being visited
"""this is the object that gets visite... | true |
8ffa476ccd0cdfcdb2078b610448cd45c7e54f28 | anitrajpurohit28/PythonPractice | /python_practice/String_programs/10_remove_duplicates.py | 1,485 | 4.15625 | 4 | # 10 Remove all duplicates from a given string in Python
input1 = 'aabbcccddekll12@aaeebbbb'
print(input1)
# by using set; unordered
print("----unordered set------")
def remove_duplicates_set(string):
unique_chars = set(string)
print(''.join(unique_chars))
remove_duplicates_set(input1)
print("----OrderedDict... | true |
8c4e3d0b18fac03abaf0ca86b1841ae0d5432d1f | anitrajpurohit28/PythonPractice | /python_practice/String_programs/14_remove_ith_char_from_string.py | 248 | 4.28125 | 4 | # 14 Python program for removing i-th character from a string
import string
### already covered in "3_remove_i_th_character.py"
string1 = "input string, input variable"
string2 = string1.replace("input", "abcdefg")
print(string1)
print(string2)
| true |
085617c6a15fb5100aeda22ffcca64eb89e8bb62 | zuping-qin/SDET-QA | /docker/app/cambia.py | 1,339 | 4.21875 | 4 | # This function tokenlizes the CSV content line by line
# into an array of list of words after stripping off the
# whitespace, including new line characters. It then
# sorts the line word list in an ascending order. Finally,
# it writes out the word lists into csv lines in the output
# file.
import sys
def ... | true |
a30beff7fc2b6b70debd39071ee3d92ea233a959 | cdhop/headfirstprogramming | /greeter.py | 628 | 4.15625 | 4 | #!/usr/bin/python3
def get_formatted_name(first_name, last_name):
"""Return a full name, neatly formatted."""
full_name = first_name + " " + last_name
return full_name.title()
done = False
while done != True:
print("\nPlease tell me your name:")
print("enter 'q' at any time to quit")
first_... | true |
f49bba91c297b11bbbd857045055ad3baa13840f | gwcahill/CodeEval | /capitalize_words/capitalize_words.py | 1,129 | 4.125 | 4 | '''
Created on Feb 24, 2015
https://www.codeeval.com/open_challenges/93/
Write a program which capitalizes the first letter of each word in
a sentence.
Input sample:
Your program should accept as its first argument a path to a filename.
Input example is the following:
Hello world
javaScript languag... | true |
50f472879fddad1453a99649717e688b23c02bc2 | gwcahill/CodeEval | /calculate_distance/calculate_distance.py | 2,334 | 4.15625 | 4 | '''
Created on Mar 27, 2015
https://www.codeeval.com/open_challenges/99/
You have coordinates of 2 points and need to find the distance
between them.
INPUT SAMPLE:
Your program should accept as its first argument a path to a filename.
Input example is the following
(25, 4) (1, -6)
(47, 43) (-25, -11)
All number... | true |
311cca70160671252efd6d2116f633249ef315ea | gwcahill/CodeEval | /n_mod_m/n_mod_m.py | 943 | 4.125 | 4 | '''
Created on Mar 11, 2015
https://www.codeeval.com/open_challenges/62/
Given two integers N and M, calculate N Mod M (without using any inbuilt
modulus operator).
Input sample:
Your program should accept as its first argument a path to a filename.
Each line in this file contains two comma separated p... | true |
3f3f9758332bbbbd05e2c3b42f3b1baadcf83fc4 | linhnvfpt/homework | /python/practice_python/exer6.py | 511 | 4.5 | 4 | # Ask the user for a string and print out whether this string is a palindrome or not.
# (A palindrome is a string that reads the same forwards and backwards.)
import math
string = input("Input a string: ")
lenstr = len(string)
stop = math.floor(lenstr / 2)
strLeft = string[0:stop:1]
if lenstr % 2 == 1:
st... | true |
c57e06c0a030903d5cd949ee03e4575760f9058a | linhnvfpt/homework | /python/practice_python/exer9.py | 797 | 4.25 | 4 | #Generate a random number between 1 and 9 (including 1 and 9).
#Ask the user to guess the number, then tell them whether they guessed too low,
#too high, or exactly right.
#(Hint: remember to use the user input lessons from the very first exercise)
#Extras:
#Keep the game going until the user types “exit”
... | true |
382a04567820ccba224bfa9301aa2b03b8c55d8f | linhnvfpt/homework | /python/w3resource/python-execises/part-I/18.py | 254 | 4.125 | 4 | # Write a Python program to calculate the sum of three given numbers, if the values are equal then return three times of their sum
def sum(a,b,c):
if a == b == c:
return 3 * a
return a + b + c
print(sum(1,2,3))
print(sum(1,1,1)) | true |
0ef8cb7de0f18c6c2841e091ac887947d0202e32 | SparshRajGupta/MyPythonStudy | /function2.py | 214 | 4.15625 | 4 | def max(a,b):
if a > b:
print 'a is greater than b'
if b > a:
print 'b is greater than a'
if b == a:
print "a is equal to b"
max(15,6)
x = 15
y = 15
max(x, y)
| true |
ff4234f503c0fa2950290a15fa7812a929339666 | shelkesagar29/CTCI | /Chapter2/p8_loop_detection.py | 2,880 | 4.1875 | 4 | import unittest
from DS.linkedlist import LinkedList
def solution1(ll):
"""
Time Complexity: O(n) where n is the length of the linked list
Space Complexity: O(1)
Args:
ll (LinkedList): linked list object
Returns:
data: Node value where loop starts if LL has loop.
-1: If LL h... | true |
23bc0cc710743858138edb3f0072f5665f5e79dc | Lokesh824/DataStrucutres | /SinglyLinkedList/LinkedList_RotateList.py | 2,201 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Wed Nov 13 15:56:37 2019
@author: inkuml05
"""
class Node:
def __init__(self, data):
self.next = None
self.data = data
class LinkedList:
def __init__(self):
self.Head = None
def append(self,data):
new_nod... | true |
334e546c84d7885009414d79597c9094b1fa4aaf | DesireeRainey/sorts | /merge.py | 1,381 | 4.3125 | 4 |
#Python Merge Sort
import time
import random
def merge(arr1, arr2):
results = []
while len(arr1) > 0 and len(arr2) > 0:
if arr1[0] > arr2[0]:
results.append(arr2.pop(0))
else:
results.append(arr1.pop(0))
return results + arr1 + arr2
def merge_sort(arr):
#base case: array length is ... | true |
dc7f52c08038a2921da8e5727eab7d08bc93e231 | lily-liu-17/ICS3U-Unit3-04-Python-Month_Number | /month_number.py | 1,049 | 4.46875 | 4 | #!/usr/bin/env python3
# Created by: Lily Liu
# Created on: Sept 2021
# This program converts the number to its corresponding month
def main():
# This program converts the number to its corresponding month
# input
user_input = int(input("Enter the number of the month (ex: 5 for May) : "))
# process... | true |
9e228a898159f911345e282a57e739435c13b58a | mrthomasjackson/DPW | /learning_python/main.py | 1,763 | 4.1875 | 4 | #I am trying python for the first time
__author__ = 'tjackson'
welcome_message = "Welcome!"
space = " "
#this is a one line comment
'''
Doc string (multiple line comments)
'''
first_name = "Thomas"
last_name = "Jackson"
#print(first_name + " " + last_name)
#response = raw_input("Enter Your Name")
#print welcome_me... | true |
7255ae920308382d90f7429a6fdd1b4ad5fbacf2 | CesaireTchoudjuen/programming | /week04-Flow/Weeklytask04-collatz.py | 597 | 4.40625 | 4 | # Program that asks the user to input any positive integer and outputs the successive values of the following calculation
# At each step calculate the next value by taking the current value and, if it is even, divide it by two, but if it is odd, multiply it by three and add one
# Program ends if the current value is on... | true |
ca6c1e7b3c4ada5a12875b77b2ed1fd98b14b5d0 | CesaireTchoudjuen/programming | /Week05-Datastructures/Lab5.1.py | 392 | 4.25 | 4 | # Author: Cesaire Tchoudjuen
# Create 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
months =("January",
"February",
"March",
"April",
"May",
"June",
"july",
"August",
"September",
"October",
"... | true |
0ddf38f7db811222edabfc4e52e8a105e1a64bd8 | CesaireTchoudjuen/programming | /Week05-Datastructures/Lab5.4.py | 477 | 4.3125 | 4 | # Author: Cesaire Tchoudjuen
# Program that stores a student name and a list of her courses and grades in a dict
student = {
"name":"Mary",
"modules": [
{
"courseName":"Programming",
"grades": 45
},
{
"courseName":"History",
"grades": 99
... | true |
cc1d552b37290d710e1527ba18251d93566212ce | ni/NI-ELVIS-III-Python-Examples | /examples/digital/DIO_multipleChannels.py | 2,510 | 4.28125 | 4 | """
NI ELVIS III Digital Input and Output Example - Single Point, Multiple Channels
This example illustrates how to write values to and read values from multiple
digital input and output (DIO) channels. The program first defines the
configuration for the DIO channels, and then writes to and reads from the DIO
channels.... | true |
80b1f540dbef03dccfa59a0018bd159b09e0667f | TripleM98/CSI-127-Assignments | /04/TheCollatzSequence.py | 377 | 4.25 | 4 | def collatz(number):
if (number % 2 == 0):
return number//2
elif(number % 2!=0):
return number*3+1
try:
n = int(input('Enter number:'))
while n>1:
print (collatz(n))
n=(collatz(n))
if(n<1):
print('You must enter a number greater than or equal to 1.')
except... | true |
03205d727383b65eebcc20252fe6831a82a65f4f | disfear86/Data-Analysis | /Udacity_Data_Analysis/convert_cols.py | 709 | 4.125 | 4 | import pandas as pd
grades_df = pd.DataFrame(
data={'exam1': [43, 81, 78, 75, 89, 70, 91, 65, 98, 87],
'exam2': [24, 63, 56, 56, 67, 51, 79, 46, 72, 60]},
index=['Andre', 'Barry', 'Chris', 'Dan', 'Emilio',
'Fred', 'Greta', 'Humbert', 'Ivan', 'James']
)
def convert_one(grade):
if grad... | true |
181a446bb977ca8cec16c9eb1e9d57b0f90579d4 | Dan-Blanchette/cs270-system-software | /pa5-Deadhuckabee-DanB-master/quick_sort/main.py | 2,180 | 4.25 | 4 | #!/usr/bin/env python3
# Dan Blanchette
# CS-270
# quick sort and binary search part 2B
# Acknowledgements: For removing encoding='uft-8-sig'
# https://stackoverflow.com/questions/53187097/how-to-read-file-in-python-withou-ufef
from quicksrt import quickSort
from binSearch import binarySearch
from PyDictionary impor... | true |
d95ca70a76412181d75b5a0f74ef43de76a3f910 | zezhouliu/am106 | /p2/mmi.py | 537 | 4.125 | 4 | import sys
import extended_euclid
def mult_mod_inverse(n, p):
'''
Applies the extended euclids in order to calculate the
multiplicative modular inverse.
returns x such that n * x = 1 mod p
'''
r1, r2 = extended_euclid.extended_euclids(n, p)
if r1 < 0:
r1 = r1 + p
return r1
if _... | true |
d82d9f4cf66e670676417cf7109d7cdfd4cda43c | AcerAspireE15/python-exception-handling | /12.py | 744 | 4.125 | 4 | def function1(a, b):
print(a+b)
print(a*b)
print(a-b)
print(a/b)
print(a%b)
function1(20, 3)
print('hello')
try:
a = 20
b = 0
print(a/b)
except ZeroDivisionError:
print('there is a divide by zero error')
try:
a = 20
b = 10
print(a/b)
except ZeroDivis... | true |
4f6a55c21dd48d5730f61e46124d8dcfc90527ed | shrikantnarvekar/Python-GUI | /checkdates.py | 513 | 4.125 | 4 | from date import Date
def main():
bornBefore = Date(6, 1, 1988)
date = promptAndExtractDate()
while date is not None :
if date <= bornBefore :
print( "Is at least 21 years of age: ", date )
date = promptAndExtractDate()
print( "Enter a birth date." )
... | true |
7fdee8036dbffc95abe749d3e6dd8fd7456442df | brittanyp/CP1404-Workshops | /WS2/shipCalc.py | 382 | 4.1875 | 4 | quantity = int(input("Enter amount of item: "))
while quantity < 0 :
print("Invalid input")
quantity = int(input("Enter amount of item: "))
costPerItem = float(input("Enter shipping cost per item: "))
totalCharge = costPerItem * float(quantity)
if totalCharge > 100 :
totalCharge = totalCharge - (0.1 * to... | true |
a528f8676030d3c51cd07a913f030a769b781522 | chipoltie0/Roguelike_v1.1 | /GamePiece.py | 1,412 | 4.28125 | 4 |
class Piece:
"""
This is the base object that interacts with the map object, contains information such as
the location of the object, what map it is on, and possible a connected character sheet
"""
def __init__(self,map, start_point, collision=False,color=(0,0,0),char='*'):
self.map = map ... | true |
89158eb6b1effb875571a0fcdebf4b6396901f9e | SoniaRode21/Python | /SearchingAndSorting/FOAproject1/quickSort.py | 1,159 | 4.25 | 4 | _author = 'Soniya Rode'
'''
The program includes functions to partition the array
and quick sort the data.
'''
def partition(arr, l, r):
'''
Function to partition the array based on pivot value
:param array: list containing elements to be sorted
:param l : left most index of the list
:par... | true |
c8763f1099ce7b22739d80cce03a639ef1eb18ec | jaehyunan11/Python_Learning | /Day_27/challenge_1.py | 921 | 4.28125 | 4 | from tkinter import *
"""
1. Pack
-> default located in the upper center
ex: input.pack(side="left")
2. Place
-> Specific coordinate
ex: my_label.place(x=100, y=200)
3. Grid
-> Row and column
"""
# Window setup
window = Tk()
window.title("My First GUI Program")
window.minsize(width=500, height=300)
window.config(pa... | true |
fc47f571e5d321bf5de59b7a82f2e85b8f763719 | jaehyunan11/Python_Learning | /Day_27/main.py | 2,311 | 4.15625 | 4 | from tkinter import *
window = Tk()
window.title("My First GUI Program")
window.minsize(width=500, height=300)
#Label
my_label = Label(text="I am a Label", font=("Arial", 24, "bold"))
my_label.pack()
# my_label["text"] = "New Text"
my_label.config(text= "New Text")
# Button
def button_clicked():
print("I got... | true |
769f56fe12f0c5f4557142390f77794e85ba6696 | joyc/python-book-test | /AutomatePython/scr/isPhoneNumber.py | 857 | 4.15625 | 4 | def isPhoneNumber(text):
if len(text) != 13:
return False # not phone number-sized
for i in range(0, 3):
if not text[i].isdecimal():
return False # not an area code
if text[3] != '-':
return False # does not have first hyphen
for i in range(4, 8):
if not te... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.