blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
b545f00ca11459c59fa36c7ffb5a947175d8471a | PengChen11/math-series | /math_series/series.py | 1,337 | 4.21875 | 4 | # function to calculate the nth fibonacci number. I hate using recursion for this task cause the big O is 2*n and when n goes above 30, it eats up all my computer's resources.
# The following solution's big O is only n-2. much faster.
# n starts with 0.
def fibonacci(n):
prev, nex = 0, 1
for i in range(n - 1):
... | true |
beba030545cf43bc8b8921a9f65796af35ebacd7 | mahmud-sajib/30-Days-of-Python | /L #23 - Class & Object.py | 1,997 | 4.65625 | 5 | ## Day 23: Class & Object
## Concept: Creating a Class - To define a class, use the class keyword, and define the data points inside.
# Simple class with a property
class Person:
name = "John Wick"
## Concept: Creating an Object - o create a new object, simply reference the class you want to build the object ou... | true |
f4aa81270ce4056c79fa5e5f165844b6984f4efe | mahmud-sajib/30-Days-of-Python | /L #20 - Generators.py | 934 | 4.46875 | 4 | ## Day 20: Python Generators
## What are generators in Python?
"""
Python generators are a simple way of creating iterators.
A generator is a function that returns an object (iterator) which we can iterate over (one value at a time).
"""
## How to create a generator in Python?
"""
It is the same as defining a normal... | true |
0b94b60f57bc7df66c46ab53e8876cc79c41f505 | mahmud-sajib/30-Days-of-Python | /L #14 - First Class Functions.py | 2,892 | 4.125 | 4 | ## Day 14: First Class Functions
## Concept: What are first class functions?
""" In Python, functions are first class object (first class citizen too!). Programming language theorists defined some criteria for first class object of a programming language. A “first class object” is a program entity which can be :
1... | true |
d75a3e2695842452e0b9e7b79b45603d17c438ac | srmchem/python-samples | /Python-code-snippets-201-300/294-All permutations of a string.py | 615 | 4.3125 | 4 | """Code snippets vol-59
294-Print permutations of a given string
Download all snippets so far:
https://wp.me/Pa5TU8-1yg
Blog: stevepython.wordpress.com
Requirements:
None
origin:
https://gist.github.com/accakks/fbf2383ce782bbf089c68a807695b3e1
"""
from itertools import permutations
def ... | true |
1f503566bf6c2b75cec56f463c8d255737b75f84 | srmchem/python-samples | /Python-code-snippets-201-300/284-Check string for pangram.py | 860 | 4.15625 | 4 | """Code snippets vol-57
284-Check string for a pangram
Download all snippets so far:
https://wp.me/Pa5TU8-1yg
Blog: stevepython.wordpress.com
Requirements:
None
original code here:
https://gist.github.com/Allwin12/4f8d9d8066adc838558a22949ba400c0
"""
import string
alphabets = string.ascii... | true |
9e75fdf33b319779671252f257d4f6c018c6ea4c | KarlosTan/python-bootcamp | /session1/conditions/speed_func.py | 1,710 | 4.25 | 4 |
def speed_function_simple(speed): # example of function with no return value
if speed < 80:
print(" speed is ok")
else:
print(" you. have to pay a fine")
def speed_function_advanced(speed, provisonal): # example of function with return value
total_fine = 0
print(provisonal, ' is pro... | true |
8eaeaa038a8a7fe4cb91b24eb0d881645fccfd53 | BeefCakes/CS112-Spring2012 | /hw10/multidim.py | 2,653 | 4.3125 | 4 | #!/usr/bin/env python
"""
multidim.py
Multidimensional Arrays
=========================================================
This section checks to make sure you can create, use,
search, and manipulate a multidimensional array.
"""
# 1. find_coins
# find every coin (the number 1) in a givven room
# room:... | true |
4be6912a06cdeb6e179e8168208d4869c8fab455 | ruchika0201/Basic-Data-Stuctures | /strings/Python/camel.py | 962 | 4.1875 | 4 | #Alice wrote a sequence of words in CamelCase as a string of letters, , having the following properties:
#It is a concatenation of one or more words consisting of English letters.
#All letters in the first word are lowercase.
#For each of the subsequent words, the first letter is uppercase and rest of the letters are l... | true |
d4bc2da87af4976f6a1e39162acfd8faea3504c5 | gugun/pythoncourse-coder-dojo | /day02/module_package/main.py | 374 | 4.3125 | 4 | """
This program will calculate triangle area using the formula
area = height * bottom /2
"""
import geometry.triangle as triangle
import geometry.square as square
import geometry.circle as circle
print 'Main Program'
print 'Triangle area', triangle.calc_triangle_area(10, 5)
print 'Square area', square.calc_square_are... | true |
c04ee354b90c1f259d29db36178d280d2c81db09 | longlee218/Python-Algorithm | /020_week5/020_rectangles.py | 663 | 4.21875 | 4 | """
A rectangle is represented as a list [x1, y1, x2, y2] where (x1, y1) are the coordinates of its bottom-left
corner, and (x2, y2) are the coordinates of its top-right corner.
Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only
touch at the corn... | true |
e4a6e5850fd8df693131d90db42251b15a8e5972 | longlee218/Python-Algorithm | /017_week2/17+4_dubstep.py | 1,384 | 4.25 | 4 | """
Let's assume that a song consists of some number of words. To make the dubstep remix of this song
,Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero)
,after the last word (the number may be zero), and between words (at least one between any pair of n... | true |
9165aca764ec0baab0df685e9148912420b82e20 | longlee218/Python-Algorithm | /014_largest_mul.py | 2,715 | 4.15625 | 4 | """
Hi, here's your prblem today. This problem was recently ask by Microsoft
You are given an array of integers. Return the largest product that can be made by
multiplying any 3 integers in the array
Example
[-4, -4, 2, 8] should return 128 as the largest product can made by multiplying
-4 * -... | true |
b16767793fdab1333e0ae15b6a6f11ddb2d70012 | PatrickArthur/FunWithPython | /demo.py | 385 | 4.1875 | 4 | name = raw_input("What is your name? ")
while name != "Patrick":
print("{} Nice to meet you, how do you like python".format(name, name))
print "Your name length: {0}".format(len(name))
raw_input("Press <ENTER> to exit\n")
name = raw_input("What is your name? ")
else:
print("{} Is my name, and I like python".... | true |
d530661de1b951cd8660beebd5e82f8343a87d4e | kamranajabbar/python3_practice | /10-classes.py | 1,458 | 4.46875 | 4 | #Chapter # 53-61 Classes
class Car():
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.battery = "200 AMP" #Default attribute
def descriptionCar(self):
print(f"The make of car is {self.make}")
print(f"The mo... | true |
10335d9043dd5add872d6dc67802c171959cfbb0 | kamranajabbar/python3_practice | /13-csv.py | 930 | 4.375 | 4 | #Chapter # 67-73 CSV files
#67: CSV files
#68: CSV files: Reading them
#69: CSV files: Picking information out of them
#70: CSV files: Loading information into them. Part 1
#71: CSV files: Loading information into them. Part 2
#72: CSV files: Loading information into them. Part 3
#73: CSV files: Appending rows to them... | true |
b54dfc1418d04d43179927efe953fcabcd067706 | khanhbao128/HB-Code-Challenge-Problems | /Whiteboarding problems/Easier/remove_duplicates.py | 818 | 4.21875 | 4 |
# given a list of items, return the new list of items in the same order but with all duplicates removed
# Q: what does an empty list return? empty list
def deduped(items):
"""Remove all duplicates in a list and return the new list of items in the same order"""
# new_list = []
# for item in items:
# ... | true |
080d4f2b339e75cb49611cd1920733dd26dece94 | tamatamsaigopi/python | /rotatearray.py | 829 | 4.6875 | 5 | # Python program to left rotate array
# Function to rotate arrays in Python
def rotateArrayLeft(arr, R, n):
for i in range(R):
firstVal = arr[0]
for i in range(n-1):
arr[i] = arr[i+1]
arr[n-1] = firstVal
# Taking array input from user
arr = [1, 2, 3, 4, 5, 6, 7]
n = int(input("Ent... | true |
117166ff8c5d0a3b4f2f08159c4056e071554d34 | xanderquigley/a1_prog1700 | /hipster_local_records.py | 1,751 | 4.34375 | 4 | """
Student Name: Alex Quigley - W0458866
Program Title: IT Data Analytics
Description: Assignment 1 - Problem 1 - Hipster's Local Vinyl Records
This program will take in customer information and calculate the total for the customer to pay for the records
purchased along with the price of delivery.
"""
def main():... | true |
556ce7be3a1a5d91f7138537ac575e94a72ff7b2 | alexpickering/Python | /printWithoutVowels.py | 600 | 4.34375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: taka0
"""
def print_without_vowels(s):
'''
s: the string to convert
Finds a version of s without vowels and whose characters appear in the
same order they appear in s. Prints this version of s.
Does not return anything
'''
vowels ... | true |
56977469a39132bf485b07cc6401d77c9a169f8b | nekocheik/python__back | /exercises /sort_array_by_element_frequency.py | 1,282 | 4.25 | 4 | """Sort the given iterable so that its elements end up in the decreasing frequency order,
that is, the number of times they appear in elements. If two elements have the same frequency,
they should end up in the same order as the first appearance in the iterable."""
from collections import Counter
def frequency_sor... | true |
0f0a720060fe01d52d250c29f505dc3d9010a27a | agastyajain/Number-Guessing-Game | /NumberGuessingGame.py | 594 | 4.21875 | 4 | import random
print('Welcome To The Number Guessing Game !!!')
number = random.randint(1,9)
chances = 0
print('Guess a number between 1 and 9 ...')
while chances < 5:
guess = int(input('Enter your guess: '))
if guess == number:
print('Congrats! You Won')
break
elif guess < numb... | true |
c7b0cb79a06393adb912e0b4ac6fdd38a002f2af | sofiakn/pycoding | /ch03-repetitions/01-while.py | 343 | 4.125 | 4 | number = int( input("Enter a number for times table (0 to stop): "))
while number != 0 :
print(f"{number} x 1 = {number*1}")
print(f"{number} x 2 = {number*2}")
print(f"{number} x 3 = {number*3}")
print()
number = int( input("Enter a number for times table (0 to stop): "))
print("Thank you fo... | true |
595207952cdedd6cb8f38c34800546c70a2b244d | sofiakn/pycoding | /ch02-conditions/02tax.py | 261 | 4.1875 | 4 | # Ask for the price and if price is dollar or more, there will be tax otherwise no tax is charged
price = float(input("What is the \"price\"? "))
if price >= 1.0 :
print("You will be charged tax")
else :
print("You will not be charged tax")
| true |
d8c571e90d7dd059c6822e3070af55c222013d40 | Monisha1892/Practice_Problems | /pounds to kg.py | 270 | 4.1875 | 4 | weight = float(input("enter your weight: "))
unit = input("enter L for pounds or K for Kg: ")
if unit.upper() == 'L':
print("weight in kg is: ", (weight*0.45))
elif unit.upper() == 'K':
print("weight in lbs is: ", (weight*2.205))
else:
print("invalid unit") | true |
f7b5f0ff26048662dc0f1f78774fa3de56c1a8c7 | agnesazeqirii/examples | /sorting_a_list.py | 642 | 4.34375 | 4 | # In this program I'm going to sort the list in increasing order,
# so that the numbers will be ordered from the smallest to the largest.
myList = []
swapped = True
num = int(input("How many elements do you want to sort: "))
for i in range(num):
val = int(input("Enter a list element: "))
myList.append(val)
w... | true |
d768b394c739caf10b87e8bbc743f9abdaeb400e | shoaib90/Python_Problems | /Sets_Mutation.py | 2,574 | 4.59375 | 5 | # We have seen the applications of union, intersection, difference and symmetric difference operations, but these operations do
# not make any changes or mutations to the set.
# We can use the following operations to create mutations to a set:
# .update() or |=
# .intersection_update() or &=
# .difference_update() or... | true |
cd0c4829ca166148b49ed27059b791e4aebbd147 | Fifthcinn/Pirple.com_py-projects | /New Clean Assignment 4.py | 1,442 | 4.21875 | 4 | """
# 1. guestName = enter name to check if permissable
# 2. name gets entered into input
# 3. function checks name
# 4. if function returns true, name gets added to myUniqueList
# 5. if function returns false, name gets added to myLeftovers
# 6. print both lists
# 7. user gets asked if they would like to enter anoth... | true |
93e97c5ea1e0b4316abe797dc587bffd35f85432 | GiliScharf/my_first_programs | /print_dict_in_a_chart.py | 468 | 4.15625 | 4 | #this function gets a dictionary of {student's_name:average_of_grades} and prints a chart of it
def formatted_print(my_dictionary):
list_of_students=list(my_dictionary.keys())
new_list=[]
for student in list_of_students:
new_list.append([my_dictionary[student],student])
new_list.sort(reverse=Tru... | true |
af74ef0de38c1ac94a530d6b5cfabccc9fa3bca6 | hitenjain88/algorithms | /sorting/heapsort.py | 949 | 4.3125 | 4 | def heap_sort(array):
'''
Implementation of Heap Sort in Python.
:param array: A array or a list which is supposed to be sorted.
:return: The same array or list sorted in Ascending order.e
'''
length = len(array)
for item in range(length, -1, -1):
heapify(array, item, length)
f... | true |
61d1db983af95bd86e051adf5eca11506c72fffb | jonesmabea/Algorithms | /fibonnaci/memo_bottom_up_fibonacci.py | 823 | 4.1875 | 4 | #Author: Jones Agwata
import timeit
def fibonacci(n):
'''
This is a memoized solution using a bottom up approach to the fibonacci problem.
f(n) = f(n-1)+f(n-2)...+f(n-n)
where f(0) = 0, f(1) = 1
params:
--------
n : int
n values to calculate fibonacci numbers
returns:
... | true |
771a449b8bc71ab78ff207c4169c894391b78c59 | Antonynirmal11/Translator-using-python | /translator.py | 450 | 4.21875 | 4 | from translate import Translator
#translate module gives us the translation of the required language
fromlanguage=input("Enter your input language:")
tolanguage=input("Enter the required language:")
#getting input from the user and storing in a variable
translator= Translator(from_lang=fromlanguage,to_lang=tolangu... | true |
dd848606c2d3690a58b55afcf70015906d1327eb | Ibramicheal/Onemonth | /Onemonth/tip.py | 607 | 4.21875 | 4 | # this calculator is going to determines the perecentage of a tip.
# gets bills from custome
bill = float(input("What is your bill? ").replace("£"," "))
print("bill")
# calculates the options for tips.
tip_one = 0.15 * bill
tip_two = 0.18 * bill
tip_three = 0.20 * bill
# prints out the options avaible.
print(f"You bil... | true |
b09be0cfe6021aaca3563e65264ff47a7dd3137b | HMGulzar-Alam/Python_Assignment | /ass3.py | 1,354 | 4.28125 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
# Q:1 Program make a simple calculator
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function ... | true |
80bbca4bf830c9f11d1a8e3805e48bfb6b7b3e29 | dantsub/holbertonschool-higher_level_programming | /0x0B-python-input_output/4-append_write.py | 460 | 4.375 | 4 | #!/usr/bin/python3
"""
append write module
"""
def append_write(filename="", text=""):
""" Function that appends a string at the end of
a text file (UTF8) and returns the number of
characters added
Args:
filename (str): filename.
text (str): text to append the file.
Return... | true |
5fff47e5d1428707dd39fe97ce34b077cc11b902 | dantsub/holbertonschool-higher_level_programming | /0x0B-python-input_output/7-save_to_json_file.py | 408 | 4.15625 | 4 | #!/usr/bin/python3
"""
save to json file module
"""
import json
def save_to_json_file(my_obj, filename):
""" Function that writes an Object to a text file,
using a JSON representation
Args:
my_obj (object): an object.
filename (str): filename.
Return:
Nothing
"""
w... | true |
40438fd29ec71fba2828e959c9352a25880b5d04 | Lyric912/conditionals | /secondary.py | 2,419 | 4.59375 | 5 | # author: Lyric Marner
# date: july 22, 2021
# --------------- # Section 2 # --------------- #
# ---------- # Part 1 # ---------- #
print('----- Section 2 -----'.center(25))
print('--- Part 1 ---'.center(25))
# 2 - Palindrome
print('\n' + 'Task 1' + '\n')
#
# Background: A palindrome is a word that is the same if re... | true |
e6c7ac66a67510483e211f99140504732579fed1 | Lamhdbk/liamhoang | /day_of_week.py | 663 | 4.3125 | 4 | # Python to find day of the week that given date
import re # regular expression
import calendar # module of python to provide useful function related to calendar
import datetime # module of python to get the date and time
def process_date(user_input):
user_input = re.sub(r"/", " ", user_input) #substitube/... | true |
9a1aecb6c84c9d2d743e72cd5770ea2305c34377 | mevorahde/FCC_Python | /caculator.py | 540 | 4.125 | 4 | # Seventh Excises: Building a Basic Calculator
# YouTube Vid: Learn Python - Full Course for Beginners
# URL: https://youtu.be/rfscVS0vtbw
# Ask the user for a number and store the value into the variable num1
num1 = input("Enter a number: ")
# Ask the user for a second number and store the value into the variable num... | true |
157f152e4ae2c05ec74055e537c65ae17c44926f | mevorahde/FCC_Python | /shape.py | 294 | 4.21875 | 4 | # Second Excises: Draw out a little triangle
# YouTube Vid: Learn Python - Full Course for Beginners
# URL: https://youtu.be/rfscVS0vtbw
# Example on how print statements can show output by buidling a triangle from print statements.
print(" /|")
print(" / |")
print(" / |")
print("/___|")
| true |
be055d9f72ac8c00c3c4561b34b32a58e054b583 | mevorahde/FCC_Python | /mad_lib_game.py | 639 | 4.46875 | 4 | # Eighth Excises: Building a Mad Libs Game
# YouTube Vid: Learn Python - Full Course for Beginners
# URL: https://youtu.be/rfscVS0vtbw
# Ask the user to enter in a color and set the value to the variable color
color = input("Enter a Color: ")
# Ask the user to enter in a plural noun and set the value to the variable ... | true |
8d0ba54ed431fcce3052153bb0567fb3a288fa3f | Marshea-M/Tech-Talent-Course-2021 | /HLW1Task5.py | 815 | 4.125 | 4 | user_input_number_a=int(input("Please type a random number"))
user_input_number_b=int(input ("Please type in another number"))
input_a=int(user_input_number_a)
input_b=int(user_input_number_b)
user_input_operator=input("Enter a to add, t to take-away, d to divide, m to multiply, p to power of or square the numb... | true |
32e49868f39a879034c63316aed946cfb4a9ff28 | SathvikPN/learn-Tkinter | /entry_widget.py | 381 | 4.15625 | 4 | # Write a complete script that displays an Entry widget that’s 40 text units wide
# and has a white background and black text. Use .insert() to display text in the widget
# that reads "What is your name?".
import tkinter as tk
window = tk.Tk()
txt = tk.Entry(
width=40,
bg="white",
fg="black",
)
txt.in... | true |
5e13544932db20738d00d6d9687c1081398db02f | srk0515/Flask_1 | /Test1.py | 1,939 | 4.46875 | 4 |
fruits=['apples','oranges','banana','grapes']
vege=['potato' ,'carrot']
print(fruits)
print(len(fruits))
print(fruits[3])
#negative index to come from reverse
print(fruits[-4])
#select index
print(fruits[0:3])
print(fruits[2:])
#add to end of list
fruits.append('pineapple')
#add to a position
fruits.insert(1,'ma... | true |
5cdadf056bff7aeef9ca0c59272d9c976353b435 | Ashish-Goyal1234/Python-Tutorial-by-Ratan | /ProgrammesByRatan/3_Python_Concatenation.py | 494 | 4.125 | 4 | # In python it is possible to concatenate only similar type of data
print(10 + 20) # possible
print("ratan" + "ratan") # Possible
print(10.5 + 10.5) # Possible
print(True + True) # Possible
# print(10 + "ratan") # Not possible : We will face type error because both are di... | true |
7747df62d4d274760d8b4efcd47134c888a7e195 | krmiddlebrook/Artificial-Neural-Network-practice | /ANNs/ANNs.py | 927 | 4.15625 | 4 |
# takes the input vectors x and w where x is the vector containing inputs to a neuron and w is a vector containing weights
# to each input (signalling the strength of each connection). Finally, b is a constant term known as a bias.
def integration(x,w,b):
weighted_sum = sum(x[k] * w[k] for k in xrange(0,len(x))... | true |
ba03262015d0a05c4b1eeb2824987a29dcc2f8a7 | monybun/TestDome_Exercise | /Pipeline(H10).py | 944 | 4.53125 | 5 | '''
As part of a data processing pipeline, complete the implementation of the pipeline method:
The method should accept a variable number of functions, and it should return a new function that accepts one parameter arg.
The returned function should call the first function in the pipeline with the parameter arg,
and ca... | true |
e2b4fea85d7b916ae8fc86e0886c1190e2055e9c | monybun/TestDome_Exercise | /Shipping(E15).py | 2,278 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A large package can hold 5 items, while the small package can hold only 1 item.
The available number of both large and small packages is limited.
All items must be placed in packages and used packages have to be filled up completely.
Write a function that calculates ... | true |
238363a6a8c8c3491e2e0af331513088f330216a | monybun/TestDome_Exercise | /routeplanner(H30).py | 2,621 | 4.5 | 4 | '''As a part of the route planner, the route_exists method is used as a quick filter if the destination is reachable,
before using more computationally intensive procedures for finding the optimal route.
The roads on the map are rasterized and produce a matrix of boolean values
- True if the road is present or False i... | true |
c59b935019ab6a665dcbe1b6f6c3fe062b6bb9ce | monybun/TestDome_Exercise | /Paragragh(E30).py | 1,676 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
An insurance company has decided to change the format of its policy numbers from
XXX-YY-ZZZZ to XXX/ZZZZ/YY (where X, Y and Z each represent the digits 0-9).
Write a method that re-formats all policy numbers in a well-formatted paragraph ('-' may appear elsewhere in ... | true |
cbc8c2cec4729218bbccf1cdf6a78d9f74e26245 | PWynter/paper_scissors_stone | /paper_scissors_stone2.0.py | 1,164 | 4.25 | 4 | """Paper,scissors,stone game.player selects an option,computer option is random """
# import random and the randint function to generate random numbers
from random import randint
# assign player an user input
player = input("rock (r), paper (p) or scissor (s)? ")
# print the user input, end tells python to end with ... | true |
0f02b53e49e2bfc742e22830db6b2e9d42423538 | archanakul/ThinkPython | /Chapter8-Strings/RotateString.py | 1,526 | 4.34375 | 4 | #PROGRAM - 18
"""
1. ORD() -> Given a string of length one, return an integer representing the
value of the byte
ord('a') -> 97
2. CHR()-> Return a character whose ASCII code is the integer i. The
argument must be in the range [0..255]
chr(97) -> 'a'
"""
def r... | true |
93a1ed0d22f242ddbdb099c2ac273bc741400b10 | archanakul/ThinkPython | /Chapter2-Variables/Arithmetics.py | 2,210 | 4.40625 | 4 | #PROGRAM - 2
# Operators are special symbols that represent computations
# There are basically two types of numeric data types - integer & floating point
# Comma separated sequence of data is printed out with spaces between each data
print 3,-5,56.98,-45.56
# Pre-defined function(type) prints out data type for the i... | true |
aadd007d43366ef0d66700a55aa411dbb37c2f1c | archanakul/ThinkPython | /Chapter10-Lists/NonRepeatedWords.py | 708 | 4.40625 | 4 | #PROGRAM - 27
"""
Open the file & read it line by line. For each line, split the line into a list of words using the split() function. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list.
When program completes, sort & p... | true |
d259e7fc46a18ed2e34e87bf02599bdfdf71662d | archanakul/ThinkPython | /Chapter7-Iteration/NewtonsSquareRoot.py | 1,329 | 4.34375 | 4 | #PROGRAM - 16
"""
1. Suppose we need to compute square root of A with an estimate of x then a
new better estimate for root of A would be determined by Newtons formula:
y = (x + A/x)/2
2. Floating point values rae only approximately right; hence rational 1/3 &
irrational number r... | true |
7c42789a83805552f67295596a668aa60ffdfc03 | archanakul/ThinkPython | /Chapter10-Lists/Anagram.py | 876 | 4.28125 | 4 | #PROGRAM - 30
"""
Two words are anagrams if you can rearrange the letters from one to
spell the other.
1. list.REMOVE(x): Removes the first appearance of x in the list.
ValueError if x is not found in the list.
2. list.POP([,index]): Removes an item at a specified location or at the end
... | true |
14c6140f6a35591767c4d712c782d8235396995a | jhn--/mit-ocw-6.0001-fall2016 | /ps4/ps4a.py | 2,827 | 4.375 | 4 | # Problem Set 4A
# Name: <your name here>
# Collaborators:
# Time Spent: x:xx
def get_permutations(sequence):
'''
Enumerate all permutations of a given string
sequence (string): an arbitrary string to permute. Assume that it is a
non-empty string.
You MUST use recursion for this part. Non-recur... | true |
7d808f0e1adf7d613b2e2aa4112e70f4d6b8a4c9 | carol3/python_practice | /area.py | 468 | 4.46875 | 4 | #this program calculates the perimeter and area of a rectangle
print("calculate information about a rectangle")
length=float( input("length :"))#python 3.x,input returs a string so height and length are string you need to convert them to either integers or floa
width= float(input("width :"))
area=length * width
print("... | true |
daa12bc0019384815c57854b2eb2cdf43d89f39a | tutorial0/wymapreduce | /maprq.py | 1,165 | 4.125 | 4 | # email: ringzero@0x557.org
"""this is frequency example from mapreduce"""
def mapper(doc):
# input reader and map function are combined
import os
words = []
with open(os.path.join('./', doc)) as fd:
for line in fd:
for word in line.split():
if len(word) > 3 and word... | true |
793005bc597f60a2f2cc454371031ebfac601ee9 | amaranmk/comp110-21f-workspace | /lessons/iterating-through-a-collection.py | 326 | 4.125 | 4 | """Example of looping through all cahracters in a string."""
__author__ = "730484862"
user_string: str = input("Give me a string! ")
# The variable i is a common counter variable name
# in programming. i is short for iteration
i: int = 0
while i < len(user_string):
print(user_string[i])
i = i + 1
print("Do... | true |
e2bbdc6f21dadd89fddbfc0bbc4c8149b8477143 | vintell/itea-py_cource | /exam/pyca.py | 1,943 | 4.40625 | 4 | from math import cos as mycos, sin as mysin
def plus(val_1, val_2):
"""
This is calculate a sum for two params
:param val_1: int or float
:param val_2: int or float
:return: int or float
"""
return val_1 + val_2
def minus(val_1, val_2):
"""
This is calculate a differ... | true |
76d900d7761432964196dd76b30c739739ac9d4b | JunYou42/PY4E | /EX2_3.py | 276 | 4.15625 | 4 | # programm to promt the user for hours and rate per hour using
# input to compute gross pay
#get string type
hrs = input("Enter hours:")
rate = input("Enter rate per hour:")
#convert to floating points
hrs = float(hrs)
rate = float(rate)
print('Pay:',hrs*rate)
| true |
c07d520fd5a69db8729a6749d948ca475ee61c51 | deorelaLara/PythonPruebas | /PracticasLibro/moreGuests.py | 1,481 | 4.71875 | 5 | """ 3-6. More Guests: You just found a bigger dinner table, so now more space is available.
Think of three more guests to invite to dinner.
• Start with your program from Exercise 3-4 or Exercise 3-5. Add a print statement to
the end of your program informing people that you found a b... | true |
d2ad1c2858888cb06bf244becbf5b63bf67dadf8 | jeremymiller00/Intro-Python | /Strings/strings.py | 1,492 | 4.5625 | 5 | #!/usr/bin/env python
"""
Strings Examples
This week continues where we left off working with strings. This week we will
cover string slicing, and a little bit of string formatting.
"""
firstName = "Rose"
lastName = "Tyler"
areaCode = 212
exchange = 664
numSuffix = 7665
print "We can cancatinate strings with the... | true |
6b5c293acad498cf0b7f26e4d1977a211b3bd076 | chagan1985/PythonByExample | /ex077.py | 855 | 4.1875 | 4 | #####
# Python By Example
# Exercise 077
# Christopher Hagan
#####
attendees = []
for i in range(0, 3):
attendees.append(input('Enter the name of someone to invite to a party: '))
addAnother = 'y'
while addAnother.lower().startswith('y'):
addAnother = input('Would you like to add another guest: ')
if addA... | true |
a603015ffb99493e82f42df18488b22ec4ec84b8 | chagan1985/PythonByExample | /ex041.py | 327 | 4.1875 | 4 | #####
# Python By Example
# Exercise 041
# Christopher Hagan
#####
name = input('Please enter your name: ')
repetitions = int(input('How many times should I repeat your name: '))
if repetitions < 10:
textToRepeat = name
else:
textToRepeat = 'Too high'
repetitions = 3
for i in range(0, repetitions):
pr... | true |
57797f4406bea4c20b5c1927b0f1430e85bc2a07 | chagan1985/PythonByExample | /ex038.py | 283 | 4.15625 | 4 | #####
# Python By Example
# Exercise 038
# Christopher Hagan
#####
name = input('Please enter your name: ')
repetitions = int(input('How many times should I loop through the characters in'
' your name? '))
for i in range(0, repetitions):
print(name[i % len(name)])
| true |
5bb0caaa44ae8d6285d30914d98971a9c3a73ca7 | chagan1985/PythonByExample | /ex093.py | 431 | 4.125 | 4 | #####
# Python By Example
# Exercise 093
# Christopher Hagan
#####
from array import *
nums = array('i', [])
removedNums = array('i', [])
while len(nums) < 5:
newNum = int(input('Enter a number to append to the array: '))
nums.append(newNum)
nums = sorted(nums)
print(nums)
userChoice = int(input('Enter a nu... | true |
3d7db392ce92cab8018a429e87054ff9f3f54e9a | chagan1985/PythonByExample | /ex142.py | 510 | 4.34375 | 4 | #####
# Python By Example
# Exercise 142
# Christopher Hagan
#####
import sqlite3
with sqlite3.connect("BookInfo.db") as db:
cursor = db.cursor()
cursor.execute("""SELECT * FROM Authors;""")
for author in cursor.fetchall():
print(author)
authorBirthPlace = input('Enter the place of birth of the author(s) yo... | true |
febdfec7639719ae6598e5c91a1e102382b091b4 | chagan1985/PythonByExample | /ex036.py | 214 | 4.21875 | 4 | #####
# Python By Example
# Exercise 036
# Christopher Hagan
#####
name = input('Please enter your name: ')
repetitions = int(input('How many times should I say your name: '))
for i in range(0, repetitions):
print(name)
| true |
b9c2acb11f8d955f59d111c5fad10ff639c5a852 | Jerrybear16/MyFirstPython | /main.py | 2,411 | 4.1875 | 4 |
#print your name
print("Jeroen")
#print the lyrics to a song
stairway = "There's a lady who's sure, all that glitters is gold, and she's buying a stairway to heaven"
print("stairway")
#display several numbers
x=1
print(x)
x=2
print(x)
x=3
print(x)
#solve the equation
print(64+32)
#same but with variables
x ... | true |
e7901d6febac3de5dc79ea4048e791d3cd815f59 | HarshCasper/Rotten-Scripts | /Python/Encrypt_Text/encrypt_text.py | 1,237 | 4.34375 | 4 | # A Python Script which can hash a string using a multitude of Hashing Algorithms like SHA256, SHA512 and more
import hashlib
import argparse
import sys
def main(text, hashType):
encoder = text.encode("utf_8")
myHash = ""
if hashType.lower() == "md5":
myHash = hashlib.md5(encoder).hexdigest()
... | true |
25fd335354c8560bbd7e8442462292d8d34174fe | HarshCasper/Rotten-Scripts | /Python/Caesar_Cipher/decipher.py | 1,457 | 4.4375 | 4 | """
A Python Script to implement Caesar Cipher. The technique is really basic.
# It shifts every character by a certain number (Shift Key)
# This number is secret and only the sender, receiver knows it.
# Using Such a Key, the message can be easily decoded as well.
# This Script Focuses on the Decoding Part only.
"""
... | true |
862212ea35de8f2a361e51bdd69a5cbbdea87f8c | HarshCasper/Rotten-Scripts | /Python/Countdown_Clock_and_Timer/countdown_clock_and_timer.py | 1,456 | 4.40625 | 4 | # import modules like 'os' and 'time'
import os
import time
os.system("clear")
# using ctime() to show present time
times = time.ctime()
print("\nCurrent Time: ", times)
print("\n Welcome to CountdownTimer!\n\n Let's set up the countdown timer...\n")
# User input for the timer
hours = int(input(" How ma... | true |
4a7b213cc577665d05961141dd2b30413182313d | anurag5398/DSA-Problems | /Misc/FormingMagicSquare.py | 1,987 | 4.3125 | 4 | """
We define a magic square to be an matrix of distinct positive integers from to where the sum of any row, column, or diagonal of length is always equal to the same number: the magic constant.
You will be given a matrix of integers in the inclusive range . We can convert any digit to any other digit in the ra... | true |
56e2e07ea84d6200924c1fb9d35cbead8f960e82 | Gyanesh-Mahto/Edureka-Python | /Class_Codes_Module_3&4/P9_07_Constructor_and_Destructor.py | 1,804 | 4.71875 | 5 | #Constructor and Destructor
'''
Construtor: __init__(self) is initiation method for any class. This is also called as contructor
Destructor: It is executed when we destroy any object or instance of the class. __del__(self) is destructor method for destrying the object.
'''
class TestClass:
def __init__(self):... | true |
04230c130fceeca7db61dc11b2422b752981dedf | Gyanesh-Mahto/Edureka-Python | /Class_Codes_Module_3&4/P8_Variable_length_arguments.py | 1,246 | 4.75 | 5 | '''
Variable-length Arguments: When we need to process a function for more arguments than you have specified while defining the function,
So, variable-length arguments can be used.
'''
def myFunction(arg1, arg2, arg3, *args, **kwargs):
print("First Normal Argument: "+str(arg1))
print("Second Normal Argum... | true |
27dad1a58b341711371a79cc7815e97b19e1d6d2 | theChad/ThinkPython | /chap2/chap2.py | 1,008 | 4.125 | 4 | # 2.2.1
# Volume of a sphere with radius 5
r = 5 #radius of the sphere
volume = 4/3*3.14159*r**3
print("2.2.1 Volume of sphere:", volume)
# 2.2.2
# Textbook price
cover_price = 24.95
discount = 0.4
shipping_book_one = 3
shipping_extra_book = 0.75
num_books = 60
total_shipping = shipping_book_one + shipping_extra_book*... | true |
4519920c83d465d689e03c2adbba42f4b822ffd5 | theChad/ThinkPython | /chap12/most_frequent.py | 920 | 4.125 | 4 | # Exercise 12.1
# From Exercise 11.2, just to avoid importing
def invert_dict(d):
"""Return a dictionary whose keys are the values of d, and whose
values are lists of the corresponding keys of d
"""
inverse = dict()
for key in d:
val = d[key]
inverse.setdefault(val,[]).append(key)
... | true |
531e4e63621e4b978f722c87b4c6a8759ebeb151 | theChad/ThinkPython | /chap9/ages.py | 1,358 | 4.28125 | 4 | # Exercise 9.9
# I think the child is 57, and they're 17-18 years apart
# I really shouldn't rewrite functions, but it's a short one and it's more convenient now.
def is_reverse(word1, word2):
return word1==word2[::-1]
# After looking at the solutions, this should really cover reversed numbers with two different
... | true |
628fdde22ad8c5816048781d068959c68fc118f5 | umitkoc/python_lesson | /map.py | 423 | 4.25 | 4 | # map function
#iterable as list or array
#function as def or lambda
#map(function,iterable) or
numbers=[1,2,3,4,5,6]
#example
def Sqrt(number):
return number**2
a=list(map(Sqrt,numbers))
print(a)
#example
b=list(map(lambda number:number**3,numbers))
print(b)
#map(str,int,double variable as ... | true |
12ef8b9534255a1fd3844b5a4aa6598e55e49080 | bernardobruno/Methods_Python_Basics | /Methods_Python_Basics.py | 2,123 | 4.53125 | 5 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
# Method - append() --- Adds an element at the end of the list
names = ["Jim", "John", "Joey"]
names.append("Jason")
print(names)
# In[2]:
# Method - clear() --- Removes all the elements from the list
names = ["Jim", "John", "Joey"]
names.clear()
print(names)
# ... | true |
817009a19f56b2f896ab51df41542bae0c64b533 | dhautsch/etc | /jython/MyTreeFactory.py | 1,144 | 4.4375 | 4 | class MyTreeFactory:
"""
From http://www.exampleprogramming.com/factory.html
A factory is a software design pattern as seen in the
influential book "Design Patterns: Elements of Reusable
Object-Oriented Software". It's generally good programming
practice to abstract your code as much as possibl... | true |
03ddc774d8ea887c8acd472096d8f211eb3ee367 | danny31415/project_euler | /src/problem1.py | 429 | 4.125 | 4 | """Project Euler Problem 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.
"""
from __future__ import print_function
def main():
total = 0
for x in range(1000):
if... | true |
32dbf5f4b0b91fd3ca02d4a9b7425bec2109f6de | BootcampersCollective/Coders-Workshop | /Contributors/AdamVinueza/linked_list/linked_list.py | 2,735 | 4.25 | 4 | class Node():
'''A simple node class for doubly-linked lists.'''
__slots__ = [ 'key', 'next', 'prev' ]
def __init__(self, value):
self.key = value
self.next = None
self.prev = None
class LinkedList():
'''A doubly-linked list, with iteration and in-place reverse and rotation.'''... | true |
5ab3c1fbdada734e9299656debd3db8f810924a5 | nt3rp/Project-Euler | /completed/q14.py | 1,642 | 4.1875 | 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 1... | true |
7605db9a9ea25bb5dd333dfbb7eafb0561916792 | Puhalenthi/-MyPythonBasics | /Python/Other/BubbleSort.py | 1,201 | 4.125 | 4 | class IncorrectItemEnteredError(BaseException):
pass
def BubbleSort():
nums = []
done = False
sorting = True
while done == False:
try:
num = int(input('Give me a number to add to the sorting list: '))
except:
print('Please enter a valid integer')
... | true |
48ae6b659509b290375de9f0f4b7528eb1a91121 | Mathew5693/BasicPython | /oldmcdonalds.py | 308 | 4.15625 | 4 | #Programming exercise 4
#Mathew Apanovich
#A program to out put the sum of all cubes of n natural numbers
def cude(n):
x = 0
for i in range(1,n+1,1):
x = x+ i**3
return x
def main():
n = eval(input("Please enter natural number:"))
z = cude(n)
print(z)
| true |
cba67abc8d0af5f4be041c5333719662298806bc | k/Tutorials | /Python/ex3.py | 773 | 4.375 | 4 | print "I will now count my chickens:"
# calculate and print the number of Hens
print "Hens", 25 + 30 / 6
# calculate and print the number of Roosters
print "Roosters", 100 - 25 * 3 % 4
print "Now I will count the eggs:"
# calculate the eggs
print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
print "Is it true that 3 + 2 < 5 - 7?... | true |
1424c2432a573562eea0621166e1381f40ed36d5 | larafonse/exploring_linked_lists | /part1.py | 1,801 | 4.375 | 4 | # Initializing Linked List
class LinkedList:
# Function to initialize the linked list class
def __init__(self):
self.head = None # Initialize the head of linked list as
# Function to add passed in Node to start linked list
def addToStart(self, data):
tempNode = Node(data) # create a new... | true |
c6e1466fc73cbaef1481da95dd28bf8e72789382 | Laveenajethani/python_problemes | /count_word_lines_char.py | 398 | 4.28125 | 4 | # program for count the words,lines,chracter in text files
#!/usr/bin/python3
num_lines=0
num_words=0
num_chracter=0
with open('text.txt','r') as f:
for line in f:
wordlist=line.split()
num_lines +=1
num_words +=len(wordlist)
num_chracter +=len(line)
print("number of lines:")
print(num_lines)
print("number... | true |
059c5b50ad5631101544c5d0e397c77b7d14c3eb | mak2salazarjr/python-puzzles | /geeksforgeeks/isomorphic_strings.py | 1,337 | 4.4375 | 4 | """
http://www.geeksforgeeks.org/check-if-two-given-strings-are-isomorphic-to-each-other/
Two strings str1 and str2 are called isomorphic if there is a one to one mapping
possible for every character of str1 to every character of str2. And all occurrences
of every character in ‘str1’ map to same character in ‘str2’
... | true |
856b2a53c2142f58a860ee7dbe59b8fa6a08b115 | 1337Python/StudyTime | /Objects.py | 1,369 | 4.15625 | 4 |
class NonObject:
None #This is Python syntax for noop aka no-op or 'no operation'
class Object:
def __init__(self):
self.name = "Unamed"
self.age = "-1"
print("Constructed Object!")
def __del__(self):
print("Destructed Object!")
class NamedObject:
def __init__... | true |
5387e6e5ddbdd0679841add55d3c5a47899fc461 | MarkMikow/CodingBat-Solutions-in-Python-2.7 | /Logic-2/round_sum.py | 742 | 4.15625 | 4 | '''For this problem, we'll round an int value up to the next multiple
of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20.
Alternately, round down to the previous multiple of 10 if its rightmost
digit is less than 5, so 12 rounds down to 10. Given 3 ints, a b c, return
the sum of their rounded values. ... | true |
512ccc51d8dde88dfd52450e50fba426ee175fae | MarkMikow/CodingBat-Solutions-in-Python-2.7 | /Logic-2/make_bricks.py | 844 | 4.21875 | 4 | '''
We want to make a row of bricks that is goal inches long.
We have a number of small bricks (1 inch each) and
big bricks (5 inches each). Return True if it is possible to make the
goal by choosing from the given bricks. This is a little harder
than it looks and can be done without any loops.
'''
def make_brick... | true |
ba3fa9a21bed8e08360f9b39fbe3f30a63f78cfe | nolngo/Frequency-counter | /HashTable.py | 1,047 | 4.25 | 4 | from LinkedList import LinkedList
class HashTable:
def __init__(self, size):
self.size = size
self.arr = self.create_arr(size)
def create_arr(self, size):
""" Creates an array (list) of a given size
and populates each of its elements with a LinkedList object """
array = []
... | true |
88ffa4e639f58584e943b7b78d5992701de6ed22 | basti42/advent_of_code_2017 | /day1/day1.py | 1,207 | 4.25 | 4 | #!/usr/bin/env python3
import sys
"""
Advent of Code - Day 1:
Part 1 --> SOLVED
Part 2 --> SOLVED
"""
def sum_of_matches(numbers):
"""calculate the sum of all numbers that match the next"""
matches = 0
for i,n in enumerate(numbers):
if n == numbers[i-1]:
matches += int(n)
... | true |
35b8cae406fb052b17ac400bbd22d93af679999a | Mohanishgunwant/Home_Tasks | /problem2.py | 455 | 4.375 | 4 |
#Create a program that asks the user for a number and then prints out a list of all the divisors of that number.
# (If you don’t know what a divisor is, it is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.)
def list_divisor(x):
lis = []
f... | true |
e67c0dcb9c17cabd20f9896fe33d1f236b6e02ad | sharonzz/Programming-For-Everybody.coursera | /assignment7.2.py | 796 | 4.28125 | 4 | #7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475
#Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below... | true |
bed359932d354615b7849676da7d04476dd72132 | jswetnam/exercises | /ctci/ch9/robot.py | 1,395 | 4.15625 | 4 | # CTCI 9.2:
# Imagine a robot sitting in the upper left corner of an X by Y grid.
# The robot can only move in two directions: right and down. How many
# possible paths are there for the robot to go from (0, 0) to (X, Y)?
# Imagine that certain spots are off-limits. Design an algorithm for the
# robot to go from the ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.