blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
c4acbc2cc9cbbe534af749af6b6ceb44ee854b6f | kcthogiti/ThinkPython | /Dice.py | 352 | 4.1875 | 4 |
import random
loop_control = "Yes"
Min_num = int(raw_input("Enter the min number on the dice: "))
Max_num = int(raw_input("Enter the Max number on the dice: "))
def print_rand():
return random.randrange(Min_num, Max_num)
while loop_control == "Yes":
print print_rand()
loop_control = raw_input("Do you want to c... | true |
6275eae9107c2d92a9df5f2c8749389434917a82 | SDrag/weekly-exercises | /exercise1and2.py | 1,450 | 4.375 | 4 | ###################
### Exercise 1: ###
###################
def fib(n):
"""This function returns the nth Fibonacci number."""
i = 0
j = 1
n = n - 1
while n >= 0:
i, j = j, i + j
n = n - 1
return i
# Test the function with the following value.
x = 18
ans = fib(x)
print("Fibonac... | true |
2d94305898adc3a1227bc7790f1d769c4da93426 | gautam06/Python | /py5_StdDataTypes.py | 2,933 | 4.21875 | 4 | #Python Standard DataTypes
print "Numbers String List Tuple Dictionary"
print "Numbers -> int (-1,786,-0x260,0x69), float(15.20,-25.1,-32.3e100), complex(3.14j, .876j, 4.53e-7j)"
print ""
#Number Examples
print ("\n-------------------------------------")
print ("Number Exaples");
print ("------------------------... | true |
41a907c8a5062f01e3a671521178e70de9a91ad5 | sahibseehra/Python-and-its-Applications | /Python+data sciences+sql+API/7.py | 237 | 4.15625 | 4 | #declaring list:
l=[]
n=input("enter no of students")
n=int(n)
for i in range(0,n):
name=input("enter student name=")
l.append(name)#if there is no list , then elements are appended on the next memory location
print(l)
| true |
0fa5ad12cd25202d70e1a2e06a6bccb2d62e1f97 | kburr6/Python-Projects | /Python Basics/Strings and Lists/append_first_to_last.py | 252 | 4.15625 | 4 | # Input series of comma-separated strings
s = input('Please enter a series of comma-separated strings: ')
# Split on comma+space to create the list
l = s.split(', ')
# Append the first element to list l and then print the list
l.append(l[0])
print(l)
| true |
91cad9a7f2bc9c5680e9b18d38df530a15d2b2f4 | kburr6/Python-Projects | /Python Basics/Numpy_Examples/numpy_boolean_indexing.py | 405 | 4.125 | 4 | import numpy as np
def elements_twice_min(arr):
"""
Return all elements of array arr that are greater than or equal to 2 times
the minimum element of arr.
Parameters
----------
arr: NumPy array (n, m)
Returns
-------
NumPy Array, a vector of size between: 0 and (n * m) - 1
"""... | true |
6e423f0f7678f06dd5de0e7235c4afa5295358e1 | apoorvasharma007/networks | /geolocationserver.py | 2,618 | 4.125 | 4 | #Apoorva Sharma
'''
In this program I have written a simple server script which will listen for a connection from a remote client. To locate the remote client I need his IP Address. When the server accepts a connection request by .accept() call, it returns a new socket descriptor for connecting to the client and ADDRE... | true |
631574b48da15331f564f48abfba61c69360e2b8 | charlesluch/Code | /Py4eSpec/01-Py4e/myCode/computePay.py | 966 | 4.34375 | 4 | # 4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay.
# Award time-and-a-half for the hourly rate for all hours worked above 40 hours.
# Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation.
#... | true |
224a0428bfa61a020187e8f7ccc18d503761bd68 | elaverdiere1/100_days_code | /day1_name_generator.py | 419 | 4.5 | 4 | #1. Create a greeting for your program.
print("Welcome to Band Name Generator")
#2. Ask the user for the city that they grew up in.
city = input("what is the name of the city you grew up in?\n")
#3. Ask the user for the name of a pet.
pet = input("what is a name of a pet you owned?\n")
#4. Combine the name of their cit... | true |
f861a0d32f7f3169b44a4d49ebba770b18012f4a | dona126/Python-Programming | /Basics/conditionals.py | 521 | 4.28125 | 4 | #Use of if,elif and else statements.
#Example 1
age=int(input("Enter age:"))
if(age>18):
print("Hey, i can vote!")
elif(age==0):
print(":)")
else:
print("I can't vote.")
#Example 2
score =float( input("Enter Score: "))
if score>=0.0 and score<=1.0:
if( score >= 0.9):
print("A Grade")
elif( score... | true |
acb20a11f7ea9c0c258726621c975bdf1b3e1f98 | dona126/Python-Programming | /Practice/valleyCount.py | 694 | 4.5 | 4 | # A hiker moves a step UP or a step DOWN. Start and end at sea level.
# Mountain- start with step UP and end with step DOWN.
# Valley- start with step DOWN and end with step UP.
# Find number of valleys walked through.
# Uses;
# U for UP
# D for DOWN
#Input:
#path="U D D D U D U U"
#Output:1
#
def valleyCount(pat... | true |
31c114bff52bcfe0ca5c9cc5bf951ff266efd639 | msipola/CBM101 | /K_Mathematical_Modeling/Section 3/solutionExercise1.py | 1,188 | 4.375 | 4 | from IPython.display import display, Latex
print("First, we expand the expression of the random variable of which we want to compute the expectation value:")
display(Latex('$ (N-<N>)^2 = N^2-2*N*<N>+<N>^2$'))
print("because <N> is just a number.")
print("")
print("Then we compute the expectation value of the sum o... | true |
da4115f4f762b550a6fb2bd07b451294a5de68b9 | yamada46/Python_class | /Lab2.py | 1,157 | 4.1875 | 4 | '''
Module 8 - Lab 2
1 1 unread reply. 1 1 reply.
Instructions:
When you try to open a file that doesn't exist on your file system the open function raises a nice error called FileNotFoundError
```bash
>>> open('some_file_location.txt', 'r')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File... | true |
b70765edd48e29f40027e612e2d2af9e07d528e0 | yamada46/Python_class | /Mod5_Lab3.py | 1,603 | 4.34375 | 4 | #! /Users/gailyamada/PycharmProjects/ITFDN2018/venv/bin/python3
'''
Module 5 - Lab 3
Denise Elizabeth Mauldin
Let's do some analysis of the Seattle Wage Data CSV file
Make sure you have downloaded the data from here:
https://catalog.data.gov/dataset/city-of-seattle-wage-data/resource/1b351da9-d1a9-48e4-850c-a1af51c4... | true |
994964e186d4034cccb1f89d1a78feff148e7717 | yamada46/Python_class | /Mod3_Lab2.py | 1,191 | 4.25 | 4 | '''
Mod3_Lab2
make a variable with one animal
find unique letter
give user letters + 3 guesses
compare each guess to unique letters
print out the matches
'''
# Make a list of animal
animal = "raccoon"
unique = set(animal)
#print(unique)
# store guesses
guessed_letter = set()
num_guess = len(unique)
#print(num_guess)... | true |
94d518d89abbcdab41f6354a1a9735568fc58399 | dbbudd/Python-Experiments | /AI/EasyAI_examples/Mastermind1.py | 2,729 | 4.21875 | 4 | #!/usr/bin/env python
#!/usr/bin/env python
"""Python Mastermind
Program that tests your skills at the game Mastermind.
"""
import random
instructions = """
=== The Mastermind game ===
Object of the Game
The computer picks a sequence of 4 pegs, each one being one of any of six colors.
The object of the game is t... | true |
8b7206d46407012cbf76fae9dc6b8294dbfad69a | justinclark-dev/CSC110 | /code/Chapter-12/fibonacci.py | 460 | 4.125 | 4 | # This program uses recursion to print numbers
# from the Fibonacci series.
def main():
print('The first 10 numbers in the')
print('Fibonacci series are:')
for number in range(1, 11):
print(fib(number))
# The fib function returns the nth number
# in the Fibonacci series.
def fib(n):
if n ... | true |
8199f930e624b3fff1407da55bb68b7b94265303 | justinclark-dev/CSC110 | /sample-programs/week2/circle.py | 975 | 4.5625 | 5 |
# circle.py
# Program to calculate area and circumference of a circle.
# NOTE: we import the math module so we can use the built-in definition for pi.
# The output section demonstrates formatting numbers for output;
# notice how the format function performs appropriate rounding.
# CSC 110
# 9/25/2011, updated 10/4/20... | true |
70d689c1704d84da2b580c62c9ce96946ef0184d | justinclark-dev/CSC110 | /code/Chapter-5/draw_circles.py | 761 | 4.34375 | 4 | import turtle
def main():
turtle.hideturtle()
circle(0, 0, 100, 'red')
circle(-150, -75, 50, 'blue')
circle(-200, 150, 75, 'green')
# The circle function draws a circle. The x and y parameters
# are the coordinates of the center point. The radius
# parameter is the circle's radius. The color parameter... | true |
4d670180768a15612fb0e713a9c84f91467ebc23 | justinclark-dev/CSC110 | /sample-programs/week7/sin_cos_solution.py | 1,675 | 4.25 | 4 | # sin_cos_solution2017.py
# One possible solution for the trapezoid / sin_cos_squared lab exercise.
# CSC 110
# Winter, 2017
import math # import statement needed for math.pi, math.sin() and math.cos()
def main():
# Part 1a:
print('\nPart 1a: The area shown on the table row is ' \
+ format(area... | true |
881d7d16bd126bd54adc97dd4fdc80f34bb758ff | justinclark-dev/CSC110 | /sample-programs/week2/representational_error.py | 2,519 | 4.25 | 4 |
# representational_error.py
#
# A demonstration of representational error
# CSC 110
# Sp'12
message = """The sequence of Python statements in this file demonstrates that even very
simple calculations, such as repeatedly adding 0.1 to a number, can result
in very small errors in the result. This kind of error is no... | true |
ec3ed0d9d053666f982aeb763eab95f7abc0ff93 | justinclark-dev/CSC110 | /code/Chapter-5/random_numbers.py | 256 | 4.15625 | 4 | # This program displays a random number
# in the range of 1 through 10.
import random
def main():
# Get a random number.
number = random.randint(1, 10)
# Display the number.
print('The number is', number)
# Call the main function.
main()
| true |
e67622cc50ed79eb5b7fd439f432c4b9735d6b8d | justinclark-dev/CSC110 | /code/Chapter-3/sort_names.py | 388 | 4.5 | 4 | # This program compare strings with the < operator.
# Get two names from the user.
name1 = input('Enter a name (last name first): ')
name2 = input('Enter another name (last name first): ')
# Display the names in alphabetical order.
print('Here are the names, listed alphabetically.')
if name1 < name2:
print(na... | true |
0e5bb675ace9199be4ead4f5fbf03e2dd78f226e | justinclark-dev/CSC110 | /code/Chapter-5/hypotenuse.py | 453 | 4.4375 | 4 | # This program calculates the length of a right
# triangle's hypotenuse.
import math
def main():
# Get the length of the triangle's two sides.
a = float(input('Enter the length of side A: '))
b = float(input('Enter the length of side B: '))
# Calculate the length of the hypotenuse.
c = math.hypot(... | true |
9c924b4fec9a4cad771cb19b9c08e66fe91e14e5 | justinclark-dev/CSC110 | /code/Chapter-10/coin_argument.py | 503 | 4.15625 | 4 | # This program passes a Coin object as
# an argument to a function.
import coin
# main function
def main():
# Create a Coin object.
my_coin = coin.Coin()
# This will display 'Heads'.
print(my_coin.get_sideup())
# Pass the object to the flip function.
flip(my_coin)
# This might display 'H... | true |
b4dcce09936d8277e06e00eccc9ce8ed71496e35 | justinclark-dev/CSC110 | /code/Chapter-2/string_input.py | 219 | 4.34375 | 4 | # Get the user's first name.
first_name = input('Enter your first name: ')
# Get the user's last name.
last_name = input('Enter your last name: ')
# Print a greeting to the user.
print('Hello', first_name, last_name)
| true |
3c0421300920f0a4cad73d4433b93b4e6bd6e2de | justinclark-dev/CSC110 | /code/Chapter-6/modify_coffee_records.py | 1,960 | 4.4375 | 4 | # This program allows the user to modify the quantity
# in a record in the coffee.txt file.
import os # Needed for the remove and rename functions
def main():
# Create a bool variable to use as a flag.
found = False
# Get the search value and the new quantity.
search = input('Enter a description to ... | true |
a7c1397b07bbcb2ee45c221f089e39526f836981 | justinclark-dev/CSC110 | /sample-programs/week4/sort_names.py | 539 | 4.5625 | 5 | # sort_names.py
#
# This program demonstrates how the < operator can
# be used to compare strings.
# from Tony Gaddis
def main():
# Get two names from the user.
name1 = input('Enter a name (last name first): ')
name2 = input('Enter another name (last name first): ')
# Display the names in alphabe... | true |
4146805a276701f7682d09357f1fbb17d9601418 | justinclark-dev/CSC110 | /lab-activity-3.py | 1,054 | 4.28125 | 4 | # CSC 110 - Lab Activity #3
# Simple Functions with Parameters
# Section 03
# Justin Clark
# 1/22/2020
# Part 1:
# ==============
# print(s, a, b, c)
# output: apple 3 6 12
# output: banana 4 5 13
# output: cherry 6 3 15
# output: date 5 3 13
# output: elderberry 5 3 13
# output: fig 6 2 14
# output... | true |
310e714493f57c69ee45f848374b9a6909a84328 | justinclark-dev/CSC110 | /Labs/class-examples-3.6.2020.py | 517 | 4.125 | 4 |
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for letter in alphabet:
print(letter, end=', ')
original_string = 'abcdefghijklmnopqrstuvwxyz'
# reverse order of string (short way)
new_string = original_string[::-1]
print(new_string)
# reverse order of string (long way)
for i in range(len(original_string)-1,-1,-1):
... | true |
75a0bfe6189a61afdb89d6a28d78302b42e16eda | justinclark-dev/CSC110 | /code/Chapter-4/spiral_circles.py | 476 | 4.625 | 5 | # This program draws a design using repeated circles.
import turtle
# Named constants
NUM_CIRCLES = 36 # Number of circles to draw
RADIUS = 100 # Radius of each circle
ANGLE = 10 # Angle to turn
ANIMATION_SPEED = 0 # Animation speed
# Set the animation speed.
turtle.speed(ANIMATION_SPEED)
# Draw 3... | true |
b4e83529f04bc831ce02e89b28681a9b3e8e11dd | justinclark-dev/CSC110 | /sample-programs/week7/read_numbers.py | 779 | 4.15625 | 4 | # read_numbers.py
#
# Sample program to read numbers from a file, count them and sum them.
# Assumes each line in the file contains a valid number.
# CSC 110
# Winter 2012
# open the file 'numbers.txt' for reading
infile = open('numbers.txt', 'r')
total = 0 # initialization
count = 0 # initialization
line = infile... | true |
6b9b30272ef0b9e1741a6e182a9961500cecceca | justinclark-dev/CSC110 | /code/Chapter-8/split_date.py | 394 | 4.59375 | 5 | # This program calls the split method, using the
# '/' character as a separator.
def main():
# Create a string with a date.
date_string = '11/26/2012'
# Split the date.
date_list = date_string.split('/')
# Display each piece of the date.
print('Month:', date_list[0])
print('Day:', date_li... | true |
887d47441759e233f45ddcc1bbf6d72fdd40a79b | justinclark-dev/CSC110 | /code/Chapter-4/squares.py | 319 | 4.21875 | 4 | # This program uses a loop to display a
# table showing the numbers 1 through 10
# and their squares.
# Print the table headings.
print('Number\tSquare')
print('--------------')
# Print the numbers 1 through 10
# and their squares.
for number in range(1, 11):
square = number**2
print(number, '\t', square)
| true |
8a0a76bb8df53578f3c391bd0a149210ecb1dbbf | rds123/python_code_practice | /primenum.py | 501 | 4.1875 | 4 | def is_prime(num):
for i in range(2, num):
if (num % i) == 0:
return False
return True
num = int(input("Enter a number: "))
check_prime = is_prime(num)
if check_prime:
print('Your number is a Prime')
else:
print('Your number is not a Prime')
C:\Users\Rahul\PycharmPro... | true |
3f9bd65c73111bff677c280204bf576ff2dcbb9b | zhangted/trees-graphs-python | /sorting.py | 1,259 | 4.28125 | 4 | #bubble sort
def bubbleSort(array):
#go left to right, switch values if left is < right
#do repeatedly until no swaps made on 1 runthrough
swapped = True
while swapped == True:
swaps = 0
for i in range(len(array)):
if i+1 < len(array):
if array[i] > array[i+1]:
swap(i,i+1,array)
swap... | true |
d177804a33ca4990f9aae45192a1cf698dc578c6 | vipulshah31120/PythonClassesByCM | /Homework/04-02-2021/tuple.py | 399 | 4.1875 | 4 | #A tuple consists of a number of values separated by commas
t = 12345, 6789, "vipul"
print (t[0])
print (t[2])
t = (12345, 6789, "vipul")
# Tuples may be nested:
u = t, (1,2,3,4)
print(u)
# Tuples are immutable
#t[0] = 55
print(t) #TypeError: 'tuple' object does not support item assignment
# but they... | true |
c91f58c7408b30a0dabec081672fbe939416e3a2 | Ishan1717/CodingSchool | /calc.py | 2,971 | 4.6875 | 5 | #Overall function that when called actually executes the calculator. This calculator should display a list of options to the user: whether they want to add, multiply, divide, substract a set of numbers. Additionally, the user should have the options to exponentiate a number, take a number to an nth root, or quit the ca... | true |
f9a6db7ed20a3239f624cebf30eb2953400756f2 | cynthiachuang72/Python-Bootcamp | /Beginner/Pizza_Order/main.py | 798 | 4.1875 | 4 | print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want (S, M, or L)? ")
add_pepperoni = input("Do you want pepperoni (Y or N)? ")
extra_cheese = input("Do you want extra cheese (Y or N)? ")
additional_price = 0
if (extra_cheese == 'Y' or extra_cheese == 'y'):
additional_price += 1
i... | true |
a3ceeed3025eb5641d7871f23f7d6f7a074765a2 | Dejesusj9863/CTI110 | /M5HW2_DeJesusJose.py | 705 | 4.125 | 4 | # CTI 110
# M5HW2 - Running Total
# Jose De Jesus
# October 12, 2017
# user enters numbers and once the user inputs a negative number
# the program will stop asking and then add the numbers excluding the negative
def main():
# Variables
total = 0
sum = 0
# User input for number
in... | true |
2e9927050cf5e54af8575e5d03dd5422ef1dee22 | Dejesusj9863/CTI110 | /M5T1_Turtle_Bonus_DeJesusJose.py | 1,434 | 4.1875 | 4 | # CTI 110
# M5T1 - Bonus
# Jose De Jesus
# October 19, 2017
# Create a snowflake with turtle
import turtle # Allows me to use turtles
wn = turtle.Screen() # Creates a playground for turtles
wn.bgcolor("lightblue") ... | true |
7127ca22d1fa3d3cd9a40a09bea386e9feb284da | ELKHALOMAR/py_snippets | /exo9.py | 1,003 | 4.15625 | 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”
#Keep trac... | true |
830bc292cfc30261a2a405d9a38a019e2d4b9665 | vini-2002/LeetCode-Solutions | /Array/23.Merge k Sorted Lists/Python Solution/Solution.py | 1,194 | 4.125 | 4 | """
23.Merge k Sorted Lists
Link:- https://leetcode.com/problems/merge-k-sorted-lists/
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
Example 1:
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1... | true |
ce6d1668b168f4644dd4103e96ce3b6ddab50aea | anshulrts/pythonconcepts | /05_Functions.py | 880 | 4.375 | 4 | # Functions in Python start with def keyword
# The return value of a Python function can be any object.
# Everything in python is an object. So you functions can return numeric, collections, user
# defined objects, classes, functions even modules & packages.
# They always return a value, even if you don't specify a ret... | true |
118bd314c9d6bc4e055c9b621617393821438d0f | Ritikajain18/Problem-Solving | /Designer PDF Viewer.py | 960 | 4.125 | 4 | '''
When you select a contiguous block of text in a PDF viewer, the selection is highlighted
with a blue rectangle. In this PDF viewer, each word is highlighted independently.
In this challenge, you will be given a list of letter heights in the alphabet and a string.
Using the letter heights given, determine the ... | true |
394502005f25b506fd08218bbb55dda6894fc110 | Ritikajain18/Problem-Solving | /Grading_Students.py | 1,131 | 4.21875 | 4 | '''
HackerLand University has the following grading policy:
Every student receives a grade in the inclusive range from 0 to 100.
Any grade less than 40 is a failing grade.
Sam is a professor at the university and likes to round each student's grade according to
these rules:
If the difference between the gr... | true |
5901182dde67dad51e43cf1118f8da175bab0db5 | Ritikajain18/Problem-Solving | /Staircase.py | 534 | 4.46875 | 4 | '''
Consider a staircase of size n :
#
##
###
####
Observe that its base and height are both equal to n, and the image is
drawn using # symbols and spaces. The last line is not preceded by any spaces.
Write a program that prints a staircase of size n .'''
import math
import os
import random
impo... | true |
d7e00d150d41fe04bdf5b18c3a9c285de188d228 | llenroc/facebook-interview-question-data | /python/monotobnic.py | 464 | 4.28125 | 4 | ## Given an array of integers, we would like to determine whether the array is monotonic (non-decreasing/non-increasing) or not.
## https://www.geeksforgeeks.org/python-program-to-check-if-given-array-is-monotonic/ -- One solution available here
# Monotonic -
def isMonotonic(A):
return (all(A[i] <= A[i + 1] for i... | true |
b4be11ac7af53ac94a422bfba1accbd8557fdc46 | jakehoare/leetcode | /python_1_to_1000/354_Russian_Doll_Envelopes.py | 2,407 | 4.25 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/russian-doll-envelopes/
# You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit
# into another if and only if both the width and height of one envelope is greater than the width and height... | true |
8b9ea814605ce85ab31ea9bd73aca1ddb5e7bad3 | jakehoare/leetcode | /python_1_to_1000/831_Masking_Personal_Information.py | 2,738 | 4.21875 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/masking-personal-information/
# We are given a personal information string S, which may represent either an email address or a phone number.
# We would like to mask this personal information according to the following rules:
# 1. Email address:
#... | true |
a15a9664cfdb3ab2b29be58fa6a81b226fbd5319 | jakehoare/leetcode | /python_1_to_1000/520_Detect_Capital.py | 1,272 | 4.125 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/detect-capital/
# Given a word, you need to judge whether the usage of capitals in it is right or not.
# We define the usage of capitals in a word to be right when one of the following cases holds:
# All letters in this word are capitals, like "U... | true |
0eca912eb359b3f343f06bda2874208395d5db17 | jakehoare/leetcode | /python_1_to_1000/678_Valid_Parenthesis_String.py | 1,629 | 4.15625 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/valid-parenthesis-string/
# Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this
# string is valid. We define the validity of a string by these rules:
# 1. Any left parenthesis '(' mus... | true |
0bf9cba8b0bfdc9a5657c4f81fb2a00d4474b074 | jakehoare/leetcode | /python_1_to_1000/147_Insertion_Sort_List.py | 1,268 | 4.125 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/insertion-sort-list/
# Sort a linked list using insertion sort.
# Maintain a sorted part of the list. For each next node, find its correct location by iterating along sorted section.
# Time - O(n**2)
# Space - O(1)
# Definition for singly-link... | true |
052eacf4b9b260e9f144446f172b81216946933c | jakehoare/leetcode | /python_1001_to_2000/1213_Intersection_of_Three_Sorted_Arrays.py | 842 | 4.15625 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/intersection-of-three-sorted-arrays/
# Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order,
# return a sorted array of only the integers that appeared in all three arrays.
# Count the frequency across all arrays.
#... | true |
1c6284e36e312ce42ee7fc7aa7a19f6e191e6b11 | jakehoare/leetcode | /python_1_to_1000/545_Boundary_of_Binary_Tree.py | 2,267 | 4.125 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/boundary-of-binary-tree/
# Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary
# includes left boundary, leaves, and right boundary in order without duplicate nodes.
# Left boundary is d... | true |
30ff3d4d8f4a67a2520ada5f65fbba374bcbc995 | jakehoare/leetcode | /python_1_to_1000/101_Symmetric_Tree.py | 1,208 | 4.15625 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/symmetric-tree/
# Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
# Check if left and right subtrees are both present or not, then if root values are equal. Then recurse on their
# subtrees being m... | true |
85c4ba76b35aaeaef8c0a5b8e2a17cc17f4c279f | jakehoare/leetcode | /python_1_to_1000/284_Peeking_Iterator.py | 1,234 | 4.125 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/peeking-iterator/
# Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that
# supports the peek() operation -- i.e. returns the element that will be returned by the next call to next().
#... | true |
bbe3bfbeac20116cecb0b9736753ec1a8a1b216a | jakehoare/leetcode | /python_1_to_1000/885_Spiral_Matrix_III.py | 2,281 | 4.3125 | 4 | _author_ = 'jake'
_project_ = 'leetcode'
# https://leetcode.com/problems/spiral-matrix-iii/
# On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) facing east.
# Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the
# grid is at the last row and col... | true |
e9be4b70f91f85c2deed3a16283ed3de7871a295 | Davin-Rousseau/ICS3U-Assignment-4-Python | /question_12.py | 861 | 4.15625 | 4 | #!/usr/bin/env python3
# Created by: Davin Rousseau
# Created on October 2019
# This program asks user to enter classes held and attended
# and tells them if they can write an exam or not
def main():
# This function calculates if student can write exam
# input
number = input("Enter number of classes hel... | true |
6641466adb3ad7ec5d7c19691f3598a91465d092 | fantian669/web | /python/painting.py | 1,273 | 4.5 | 4 | # 转载于 http://www.kidscoderepo.com/python.html
#"Recursive Star"
# in Python you have to pay attention to the indentions as they are regrouping blocks of code!
import turtle
def star(turtle, n,r):
# draw a star with n branches of length d
for k in range(0,n):
turtle.pendown()
turtle.forward(r)
... | true |
29f0dded2b2b061bd3792dbeefa614a8aaa5a076 | KFOAS/automate-the-boring-stuff | /find_files_by_size/find_files_by_size.py | 1,412 | 4.25 | 4 | #! /usr/bin/env python3
# find_files_by_size.py - finds files along a specified path larger than
# a specified threshold in size
import os
def find_large_files(path, threshold):
"""
Finds all files whose size is greater than or equal to threshold and
prints their absolute path and size to the conso... | true |
1b6d6d4a9fc4c1aa3be7f9cea43c10171e76130f | HarrisonBacordo/MegaProject | /Text/Palindrome Checker.py | 498 | 4.34375 | 4 | string_to_reverse = input("Welcome to the palindrome checker! Type in any length of string, and I'll"
" check if it's a palindrome\n")
reverse = []
is_palindrome = True
for i in range(len(string_to_reverse), 0, -1):
reverse.extend(string_to_reverse[i-1])
for i in range(len(string_to_rever... | true |
4f02c2a17a40e4ec3fdc3031fa67e05fb57c9c54 | jmstudyacc/Cisco_DevNet | /devasc/DevNet_Fundamentals/APIs/http_post_urllib.py | 1,983 | 4.21875 | 4 | """
A virtual library exists.
You need query what the books are in the virtual library
You've queried the books, but now it's time to ADD a book, how do?
"""
# Perhaps you cannot download other libraries and only have the standard Python library
# You should then use the 'urllib' library that is native to Python
impo... | true |
e8f5519ad7b100d6e096dc33e58f8bf7bac2956f | jmstudyacc/Cisco_DevNet | /devasc/3_designing_software/singleton_example.py | 1,302 | 4.15625 | 4 | """
Singleton patterns are useful as they enable global access to an object, without creating a global variable.
Globals may seem a neat way to resolve the issue, but they run the significant threat of being overridden.
Other content may be erroneously stored in the GLOBAL variable causing unknown amounts of damage. T... | true |
9a7b75c650843ab4bf99a528c8588afac5a06f2f | rohitpawar4507/Zensar_Python | /File_Handling/Files.py | 731 | 4.5 | 4 | print("Creating a file for the first time.")
#If you open a file in mode x , the file is created and opened for writing – but only if it doesn't already exist
'''f1 = open("file1.txt","x") # create a new file
print(f1)
if f1:
print("File created Successfully")
else:
print("The file is not created")
'''
#... | true |
10754746c14c3fce54d95a4b5e75cf81e457c1c7 | rohitpawar4507/Zensar_Python | /Dicitionary.py | 2,195 | 4.1875 | 4 | ''' Dictionary :: Collection of different element in key value pairs enclosed in {} seprated by comas
It is mutable object .
# Key -- value pair -- Both number and string are used for key as well as value
'''
# Create a dicitionary
print("The Program for Dictionary!!!")
print("Creating a dictionary and adding eleme... | true |
da0210641908a142375622b05233274c8d90926c | rohitpawar4507/Zensar_Python | /OOPS/Circele_method.py | 681 | 4.1875 | 4 | # Methods : It is regular function
# Self : similar to this keyword in java. -> reference to the current object
print("Creating a circle class..!")
class Circle:
def __init__(self):
self.radius =1
def area(self):
return 2*3.14*self.radius
print("Creating the object...")
c=Circle()
print("Ra... | true |
490a3d103acac647eefc9d1a7a115266fd906a93 | rohitpawar4507/Zensar_Python | /Exception_Handling/Exception2.py | 936 | 4.28125 | 4 | #finally block
'''
try
except
finally
first except block execute and then finally executed
'''
try:
print('Inside try block ')
try:
a = int(input('Enter no :'))
b = int(input('Enter b :'))
c = a / b
print('a/b=%d' % c)
except NameError:
print('Except for inner try ')... | true |
5fb3169cff2fa78c90a8bb0ad0ac8ba23b21e689 | tri2sing/PyFP | /higher_order_functions/min_max.py | 1,362 | 4.3125 | 4 | '''
Created on Dec 19, 2015
@author: Sameer Adhikari
'''
# Examples demonstrating the use of max and min as a higher-order function.
def getx(point):
x, y, z = point
return x
def gety(point):
x, y, z = point
return y
def getz(point):
x, y, z = point
return z
# The pattern in these points i... | true |
08cd6a1815bd9cc6557500934ea1c85af609aa29 | RawnaKirahs/InternShip | /Day5_Tasks.py | 772 | 4.34375 | 4 | TASKS :
1)Create a function getting two integer inputs from user. & print the following:
Addition of two numbers is +value
Subtraction of two numbers is +value
Division of two numbers is +value
Multiplication of two numbers is +value
2. Create a function covid( ) & it should accept patient name, and b... | true |
63cbbb1bc4da7e3bdd972e3ed32030e42af5875f | HariKumarValluru/Python | /ContinueBreakElse/continueBreak.py | 955 | 4.25 | 4 | # Continue example
# shoppingList = ['milk', 'pasta', 'eggs', 'spam', 'bread', 'rice']
# for item in shoppingList:
# if item == 'spam':
# continue
# print('Buy '+item)
# Break example 1
#
# shoppingList = ['milk', 'pasta', 'eggs', 'spam', 'bread', 'rice']
# for item in shoppingList:
# if item == '... | true |
dc4f94d6ca74c5501bb2abacbcd74db10633c54d | PauliSpin/HintsAndTips | /unpack.py | 743 | 4.65625 | 5 | x = [1, 2, 3, 4, 5]
print(*x) # prints 1 2 3 4 5
# * is theunpack operator and print(*x) prints unpack and prints out the elements of the list
# This is used in arguments to functions and can be used
# to pass an unlimited number of arguments
def func(*args):
print(args)
func(2, 3) # prints the tup... | true |
22a55344060e289a52f60efbc46a30c83d2c8dbf | patelrohan750/python_tutorials_codewithharry | /python_tutorials_code/tut11_example_Apni_dictonary.py | 279 | 4.25 | 4 | # Exrersice:1
# create a dictionary and take input from user and return the meaning of taht word in dictonary
dict = {"A": "Apple", "B": "Ball", "C": "Cat", "D": "Dog", "E": "Elephant"}
search = input("Enter Word: ")
print(f'your word meaning is: {dict[search.upper()]}')
| true |
12d4951b82f2b1abac1ccfd9d88f7486fb9f29be | a-falcone/puzzles | /adventofcode/2021/05a.py | 2,580 | 4.40625 | 4 | #!/usr/bin/env python3
"""
--- Day 5: Hydrothermal Venture ---
You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce large, opaque clouds, so it would be best to avoid them if possible.
They tend to form in lines; the submarine helpfully produces a list of nearby lines of ve... | true |
aa46d0f91d883a1b316a74b286ff256b2a0a0dba | a-falcone/puzzles | /adventofcode/2019/04b.py | 1,781 | 4.21875 | 4 | #!/usr/bin/env python3
"""
You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the password on a sticky note, but someone threw it out.
However, they do remember a few key facts about the password:
It is a six-digit number.
The value is within the range given in yo... | true |
9fcd0c3e42f5301f69993e2530065e2dda9722d4 | rawg/levis | /levis/util/hilbert.py | 2,251 | 4.125 | 4 | """
Utilities to map between a 1D Hilbert curve and 2D Euclidian space.
See also:
- https://en.wikipedia.org/wiki/Hilbert_curve
- https://people.sc.fsu.edu/~jburkardt/py_src/hilbert_curve/hilbert_curve.html
- https://en.wikipedia.org/wiki/Moore_curve
"""
from __future__ import division
#from builtins import object
im... | true |
a2ef075616b8bad4f60045ddda5e00e65161e4c6 | vdduong/numerical-computation | /maze_walk.py | 1,197 | 4.40625 | 4 | # maze walking
# 0: empty cell
# 1: unreacheable cell e.g. wall
# 2: ending cell
# 3: visited cell
grid = [[0, 0, 0, 0, 0, 1],\
[1, 1, 0, 0, 0, 1],\
[0, 0, 0, 1, 0, 0],\
[0, 1, 1, 0, 0, 1],\
[0, 1, 0, 0, 1, 0],\
[0, 1, 0, 0, 0, 2]]
# the search function accepts the coordinates... | true |
5ad8073abbff41b8a0f8611b5eb937dc132bafa5 | cmaliwal/encryption-In-Python | /encrption_using_ord_and_char.py | 249 | 4.28125 | 4 | #encryption using ord() and char()
message = raw_input ("Enter a message to encrypt: ").upper()
encrypted = ""
for letter in message :
if letter == " ":
encrypted += " "
else:
encrypted += chr(ord(letter)+5)
print (encrypted) | true |
30448a7b4f868d52f1cb67b668d55bb1a1cc77f3 | bpandey-CS/Algorithm | /problem-solving7.py | 529 | 4.1875 | 4 | # For a given sentence, return the average word length.
# Note: Remember to remove punctuation first.
def average_word_length(sentence: str):
# remove the punctuation fromt he sentences
unlikable_chars = ['!','.','?', "'", ",", ";", "."]
for uc in unlikable_chars:
sentence.replace(uc,'')
len_o... | true |
038fdd194d209b5c867b3388536d9f4db73b34b8 | valmsmith39a/u-data-structures-algorithms | /tries.py | 2,188 | 4.125 | 4 | """
Trie: Type of Tree
Spell check: word is valid or not
One solution is hashmap of all known words
O(1) to see if the word exists,
but O(n * m) space
n: number of words
m: length of the word
Trie: decrease memory usage, improve time performance
"""
basic_trie = {
'a': {
'd': {
'd': {
... | true |
f6dd1a7f7b90b36406d9d136279d50b3fa93575f | liumengjun/script-exercise | /py/random_red_package.py | 1,136 | 4.125 | 4 | import random
'''
# 微信或支付宝,随机红包(拼手气红包)算法
'''
def random_red_package(total: float, num: int):
if total * 100 < num:
raise Exception("total is too small")
if num == 1:
yield total
else:
# total * 100, unit is fen of RMB。each one has 1 fen at least
rest = total * 100
fo... | true |
a0fa4727e2731b7374341473531b3ed1f5f8e4d0 | Shaunwei/hysteria_mode | /leetcode/LinkedList/Reverse Linked List II.py | 768 | 4.34375 | 4 | '''
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
'''
from utils import *
def reverse_btw(head, m, n):
prev = dummy = N... | true |
ba35d814e24e21dc83c304a35933b79f35f77ff9 | howardc72150/programming_assessment | /04_ask_area_perimeter.py | 1,011 | 4.3125 | 4 | # Component 3
# Asks the user if they want the program to calculate
# the area or perimeter of the shape.
# Initialize variables
accepted_inputs = ['perimeter', 'area']
# Check if user input is a valid method.
def check_input(question):
error = "Please enter either area or perimeter."
valid = False
whil... | true |
8bbcda0b8746baa03ea6d967bae2be5b0853fb12 | JessicaDeMota/CSCI-135 | /5 whole integers.py | 593 | 4.21875 | 4 | #Jessica De Mota Munoz
#jessica.demotamunoz86@myhunter.cuny.edu
#October,3rd,2019
#import a turtle to be able to draw and do a graphic
#get user input
#ask user for 5 whole integers
#for each number turn the turtle left and the turtle move toward 100
import turtle
jd = turtle.Turtle()
#we have to create a for loop t... | true |
7f23b5c699cad4f4a7f30661ea327d0201a9dfe6 | damiansp/completePython | /bee/01basics/basics.py | 689 | 4.34375 | 4 | #!/usr/bin/env python3
import cmath # complex math
# Getting Input from User
meaning = input('The meaning of life: ')
print('%s, is it?' %meaning)
x = int(input('x: ')) # 3 only?
y = int(input('y: '))
print('xy = %d' %(x * y))
# cmath and Complex Numbers
print(cmath.sqrt(-1))
print((1 + 3j) * (9 + 4j))
#name = raw... | true |
acd235819785d72bdc6a4e2ea94a0517094b0ddd | WayneZhao1/MyApps | /TicTacToe/tic_tac_toe.py | 2,875 | 4.21875 | 4 | '''
Author: Wayne Zhao
This is a Tic Toc game. Requirements:
. 2 players should be able to play the game (both sitting at the same computer)
. The board should be printed out every time a player makes a move
. You should be able to accept input of the player position and then place a symbol on the board
'''
#i... | true |
d840f131cf9d99f52824192c557b9fdf88d9ab68 | RokonUZ/Python_OOPS | /class_and_instance_variable.py | 2,472 | 4.8125 | 5 | # instance variables are different for different objects
# that is they can be assigned different values for different objects
# and if we change one object it is not going to change the other object
# but if we want a variable in such a way that if we change it's value then
# it should be changed for all other variab... | true |
c8e2bb2b63a655bba28bf757482ba6a59d610a29 | RokonUZ/Python_OOPS | /basics.py | 1,114 | 4.53125 | 5 | # working on basics of the python OOP's concepts
class Computer:
def __init__(self, cpu, ram):
# this is the constructor in python
# generally we use this for initializing the variables because thats what the
# constructor does
# main advantage or we can say that the behaviour of t... | true |
ec8a469ced63be5ab90e41aadae2849d5cd04bfd | sjethi/Email-Demo | /EmailDemo.py | 1,866 | 4.15625 | 4 | #! /usr/bin/python
# this is a python email sending demo
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
print("composing!")
print("Welcome to Your name's email system!")
you = input("Please input recipient's address:\n")
# me == my email address
# you == recipient's... | true |
7f32e5b9b10dc2808100d1375870e20a731584c4 | yyogeshchaudhary/PYTHON | /4oct/defaultArrgumet.py | 557 | 4.25 | 4 | # /usr/bin/python
'''
Default Arrgument:
def functionName(var1, var2, var3=10)
var3=10 : is called as default arrgument and we can call function with 2 or 3 parameters
if we call the function with 3 parameter then it will override the value of var3 with given value
every default parameter should be trailing param... | true |
6470c1ac40bdb0694f525f3796da2cd29e6f0950 | yunusarli/Quiz | /questions.py | 1,717 | 4.21875 | 4 | #import sqlite3 module to keep questions in a database.
import sqlite3
# Questions class
class Questions(object):
def __init__(self,question,answer,options=tuple()):
self.question = question
self.answer = answer
self.options = options
def save_question_and_answer(self):... | true |
30ed215f931ffdcde9dc2e8853f15a00a66b6e00 | Wajahat-Ahmed-NED/WajahatAhmed | /harry diction quiz.py | 253 | 4.1875 | 4 | dict1={"set":"It is a collection of well defined objects",
"fetch":"To bring something",
"frail":"weak",
"mutable":"changeable thing"}
ans=input("Enter any word to find its meaning")
print("The meaning of ",ans,"is",dict1[ans]) | true |
fd38fc531606f37eb343d17e9ddf100667ea508c | Reena-Kumari20/Dictionary | /w3schoolaccessing_items.py | 870 | 4.28125 | 4 | #creating a dictionary
thisdict={
"brand":"ford",
"model":"mustang",
"year":1964
}
print(thisdict["brand"])
print(thisdict.get("brand"))
#dictionary_length
#to determine how many items a dictinary has,use the len()function.
print(len(thisdict))
#dictionary items-data types
thisdict={
"brand":"ford",
"ele... | true |
3044aa9396d2a3481d652a64f99db78253d88d71 | KrShivanshu/264136_Python_Daily | /Collatz'sHypothesis.py | 420 | 4.125 | 4 | """ Write a program which reads one natural number and executes
the above steps as long as c0 remains different from 1.
We also want you to count the steps needed to achieve the goal.
Your code should output all the intermediate values of c0, too.
"""
c0 = int(input("Enter a number: "))
step = 0
while c0!=1:
if ... | true |
0f46661eb4208c064f2badee1a0322bae583b6fa | johnsogg/play | /py/tree.py | 1,997 | 4.34375 | 4 | class Tree:
"""A basic binary tree"""
def __init__(self):
self.root = None
def insert(self, node):
if (self.root == None):
self.root = node
else:
self.root.insert(node)
def bulk_insert(self, numbers):
for i in numbers:
n = Node(i... | true |
53b033db25faa95074a34e44b1fc095a5abd7824 | ltoshea/py-puzzles | /lowestprod.py | 805 | 4.1875 | 4 | """Create a function that returns the lowest product of 4 consecutive numbers in a given string of numbers
This should only work is the number has 4 digits of more. If not, return "Number is too small".
lowest_product("123456789")--> 24 (1x2x3x4)
lowest_product("35") --> "Number is too small"
lowest_product("1234111")-... | true |
625b5c1642c07a17d591b3af07c99cb65ab2070c | DipanshKhandelwal/Unique-Python | /PythonTurtle/turtle_circle/turtle_circle.py | 1,053 | 4.3125 | 4 | import turtle
''' this moves turtle to make a square
even tells us how to configure our turtle like changing its speed ,color
shape etc'''
def turtle_circle():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
''' Inputs be like :
turtle... | true |
ac0b9c7cbd00ba13b6f5409556cafaf60460ba96 | Tabsdrisbidmamul/PythonBasic | /Chapter_9_classes/02 three_restaurant.py | 1,260 | 4.40625 | 4 | class Restaurant:
"""a simple to stimulate a restaurant"""
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
"""will define what the restaurant is"""
print(self.restauran... | true |
35d6f1f370cdf61b6bf1f496e08d0ea329d64995 | Tabsdrisbidmamul/PythonBasic | /Chapter_8_functions/15 import_modules.py | 301 | 4.1875 | 4 | import math as maths # import maths module
def area_of_a_circle(radius):
"""finds area of a circle, argument is radius"""
area = round(pi * radius, 2)
return area
pi = maths.pi
# call function, which will give me the area of a circle
circle_0 = area_of_a_circle(50)
print(circle_0)
| true |
c17a03c48b288270bf1bb671f8dca1fa6fbace24 | Tabsdrisbidmamul/PythonBasic | /Chapter_10_files_and_exceptions/01 learning_python.py | 766 | 4.34375 | 4 | # variable to hold file name
file = 'learning_python.txt'
# use open function to open file, and print the contents three times
with open(file) as file_object:
content = file_object.read()
print(content, '\n')
print(content, '\n')
print(content, '\n')
print('indent\n')
# open the file and read through each line a... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.