blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
4bea2aa9f65dc46094022529b2666bd0ebd4a252 | chinatsui/DimondDog | /algorithm/exercise/hash_table/find_two_squares_sum.py | 943 | 4.3125 | 4 | """
Given a number 'num', find another two numbers 'a' and 'b' to make pow(a,2) + pow(b,2) = num, then return [a,b]
If there doesn't exist such a pair of numbers, return an empty array.
Example 1:
Input: 58.
Output: [3, 7]
Explanation: 3^2 + 7^2 = 58
Example 2:
Input: 12.
Output: []
Explanation: There doesn't exist a... | true |
079df767f942e053cc7c3da2ac52b214e2f76dd9 | chinatsui/DimondDog | /algorithm/exercise/dfs/flatten_binary_tree_to_linked_list.py | 1,324 | 4.21875 | 4 | """
LeetCode-114
Given a binary tree, flatten it to a linked list in-place.
For example, given the following tree:
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
"""
from algorithm.core.binary_tree import Bin... | true |
7fba688e38fd71770a82e5fd1b679b3310b07eb0 | JeremyJMoss/NumberGuessingGame | /main.py | 837 | 4.125 | 4 | import random
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100")
randomNum = random.randint(1, 101);
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ")
if difficulty == "easy":
attempts = 10
else:
attempts = 5
game_over = False
while game_over == False... | true |
c907b392e1ee740c0f8d88935014170850865099 | award96/teach_python | /B-variables.py | 1,489 | 4.53125 | 5 | """
Variables are necessary to keep track of data, objects, whatever. Each variable
in Python has a name and a pointer. The name is how you call the variable ('a' in the lines below)
and the pointer 'points' to the object in memory. The pointer can change as you reassign the variable (as I do below)
This is import... | true |
be8450d8e7bd73004d0e181703dc1175e1309139 | nebkor/lpthw | /ex32.py | 870 | 4.59375 | 5 | the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'appricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
# this first kind of for-loop goes through a list
for number in the_count:
print "This is the count %d" % number
# same as above
for fruit in fruits:
print "A fruit of type: ... | true |
9ceec7eae46ff248dbcdcfa1146738bea6b517cc | nebkor/lpthw | /ex20.py | 2,230 | 4.25 | 4 | # import sys.argv into the global namespace as argv
from sys import argv
# assign script to the 0th entry in the argv array and input_file
# to the 1th entry in the argv array
script, input_file = argv
# Define the function "print_all()" which takes an argument as f
def print_all(f):
print f.read() # print... | true |
ad25f8423417bd2f9de0ea80ae9c97bc53635969 | nebkor/lpthw | /joe/ex15.py | 1,594 | 4.625 | 5 | # import sys.argv into the global namespace as argv
from sys import argv
# assign to the 'script' variable the value of argv[0],
# assign to the 'filename' variable the value of argv[1]
script, filename = argv
# assign to the 'txt' variable the value returned by the
# function "open()", which was called with the vari... | true |
4272bcf4fdcdee3dfeada312f6e5325d6bc70760 | Dylan-Lebedin/Computer-Science-1 | /Homework/test_debug2.py | 2,868 | 4.1875 | 4 | """
This program includes a function to find and return
the length of a longest common consecutive substring
shared by two strings.
If the strings have nothing in common, the longest
common consecutive substring has length 0.
For example, if string1 = "established", and
string2 = "ballistic", the function re... | true |
9956f0ea9beb16499bd04955fef4a03c471577e9 | BassP97/CTCI | /Hard/surroundedRegions.py | 1,912 | 4.15625 | 4 | """
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions
surrounded by 'X'.
A region is captured by flipping all 'O's into 'X's in that surrounded region.
Example:
X X X X
X O O X
X X O X
X O X X
After running your function, the board should be:
X X X X
X X X X
X X X X
X O X X
"""
#searches ... | true |
87a7fea85665c6937299d627e8f48b742e35e359 | BassP97/CTCI | /Med/mergeTimes.py | 1,123 | 4.21875 | 4 | """
Write a function merge_ranges() that takes a list of multiple meeting
time ranges and returns a list of condensed ranges.
For example, given:
[(0, 1), (3, 5), (4, 8), (10, 12), (9, 10)]
your function would return:
[(0, 1), (3, 8), (9, 12)]
Do not assume the meetings are in order. The meeting times are c... | true |
d6181901165881a52d73d399e7939c1300118b1f | BassP97/CTCI | /Med/reverseLLInplace.py | 456 | 4.25 | 4 | """
Write a function for reversing a linked list. Do it in place.
Your function will have one input: the head of the list.
Your function should return the new head of the list.
Here's a sample linked list node class:
"""
def revLL(head):
if head.next is None:
return head
curr = head.next
prev =... | true |
838b2e05a36c9c8df569a7c01e631711e6dba849 | BassP97/CTCI | /Med/shortEncoding.py | 716 | 4.40625 | 4 | """
Given a list of words, we may encode it by writing a reference string S and a list of indexes A.
For example, if the list of words is ["time", "me", "bell"], we can write it as S = "time#bell#"
and indexes = [0, 2, 5].
Then for each index, we will recover the word by reading from the reference string from that i... | true |
f42be0825f831246d8fb0dae883522ca8281bbba | BassP97/CTCI | /2021 prep/zigZagOrder.py | 1,165 | 4.125 | 4 | """
Given a binary tree, return the zigzag level order traversal
of its nodes' values. (ie, from left to right, then right to
left for the next level and alternate between).
For example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as:
[
... | true |
26c13d5967797a8dbd118c174099395213d62b03 | BassP97/CTCI | /Easy/diameterOfBinaryTree.py | 636 | 4.15625 | 4 | """
Given a binary tree, you need to compute the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any two
nodes in a tree. This path may or may not pass through the root.
Note - too lazy to implement a real tree so logic will have to do
"""
class Solution(ob... | true |
721a58fcb536b1692f35c9337676f6855200c61e | BassP97/CTCI | /Med/validateBST.py | 1,034 | 4.15625 | 4 | """
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.
The right subtree of a node contains only nodes with keys greater than the node's key.
Both the left and righ... | true |
fa876691a18d78065d3af8a9aff74eb8a14ccede | anishLearnsToCode/python-training-1 | /solution-bank/loop/solution_8.py | 368 | 4.1875 | 4 | """
WAP that prompts the user to input a positive integer. It should then output a message
indicating whether the number is a prime number.
"""
number = int(input())
is_prime = True
for i in range(2, number):
if number % i == 0:
print('composite number')
is_prime = False
break
if is_prime... | true |
909a76f6f26af2922d5de1e25247bf11ed1e805f | anishLearnsToCode/python-training-1 | /solution-bank/loop/solution_6.py | 210 | 4.21875 | 4 | """
WAP that prompts the user to input an integer and then outputs the number with the digits reversed.
For example, if the input is 12345, the output should be 54321.
"""
number = input()
print(number[::-1])
| true |
400e46df1e58b1a6914e2e72e63ba6323e9e04f8 | josephwalker504/python-set | /cars.py | 1,470 | 4.125 | 4 | # Create an empty set named showroom.
showroom = set()
# Add four of your favorite car model names to the set.
showroom = {"model s", "camaro", "DB11", "B7"}
print(showroom)
# Print the length of your set.
print("length of set",len(showroom))
# Pick one of the items in your show room and add it to the set again.
... | true |
91edad8c1a7978d660c77fcc7606c71e96773fe8 | shereenElSayed/python-github-actions-demo | /src/main.py | 885 | 4.15625 | 4 | #!/usr/bin/python3
import click
from src import calculations as calc
@click.command()
@click.option('--name', prompt='Enter your name',
help='The person to greet.')
def welcome(name):
"""Simple program that greets NAME for a total of COUNT times."""
click.echo(f'Hello {name}')
@click.command()... | true |
cb14a75694c303c8ced888a2dbb06d95cf424a82 | niranjanvl/test | /py/misc/word_or_not.py | 611 | 4.40625 | 4 | #--------------------------
# for each of the given argument
# find out if it is a word or not
#
# Note : Anything not a number is a Word
#
# word_or_not.py 12 1 -1 abc 123b
# 12 : Not a Word
# 1 : Not a Word
# -1 : Not a Word
# abc : Word
# 123b : Word
#--------------------------
import sys
values = sys.argv[1:]
... | true |
737013cf2ef608e5a672dbcbb129137ade18f9e9 | niranjanvl/test | /py/misc/gen_odd_even.py | 2,505 | 4.34375 | 4 | '''
Generate odd/even numbers between the given numbers (inclusive).
The choice and the range is given as command line arguments.
e.g.,
gen_odd_even.py <odd/even> <int> <int>
odd/even : can be case insensitive
range can be ascending or descending
gen_odd_even.py odd 2 10
3, 5, 7, 9
gen_odd_even.py odd 10 ... | true |
82ef0d627b03c478a1988b33cc7f81cb04493380 | niranjanvl/test | /py/misc/power.py | 438 | 4.28125 | 4 | import sys
def pow(x,y):
#x to the power of y
result = 1
if y > 0:
#repetitive multiplication
i = 0
while i < y:
result *= x
i += 1
elif y < 0:
#repetitive division
i = y
while i < 0:
result /= x
i += 1
... | true |
41099a375c5cbe212a9d4dafe8d98f6fd3c341db | abhishekboy/MyPythonPractice | /src/main/python/04Expressions.py | 934 | 4.125 | 4 | a =12
b =3
print (a+b) # 15
print(a-b) # 9
print(a*b) # 36
print(a/b) # 4.0
print(a//b) #interger division,rounder down to minus infinity
print(a % b) #modulo : remainder after interger division
print(a**b) #a power b
print() #print empty line
# in below code a/b can't be used as it will ... | true |
b05d92cbbb972902b5fb5b6ca213408d6d8b77a9 | Mjayendr/My-Python-Learnings | /discon.py | 1,409 | 4.375 | 4 | # This program converts distance from feet to either inches, yards or meters.
# By: Jay Monpara
def main():
print
invalid = True
while invalid:
while True:
try: # using try --- except statements for numeric validation
distance = raw_input("Enter the distance in feet: ") # prompt user to... | true |
66ce742e5725c7d94a6e119ae5fbe050d6ec5d0e | Mjayendr/My-Python-Learnings | /Temperatur C to F.py | 644 | 4.375 | 4 | #A program to convert temperature from degree celcius to Degree farenheit.
# By Jay Monpara
def Main():
print
Celcius = input("What is the temperature in celcius?") # provoke user to input celcius temperature.
Fahrenheit = (9.0/5.0) * Celcius + 32 # process to convert celcius into fahrenheit
pri... | true |
fc62d6f18d7bd1e3ff07e8640c79e1216999b294 | markser/InClassGit3 | /wordCount.py | 643 | 4.28125 | 4 | # to run the program
# python3 wordCount.py
# then input string that we want to retrieve the number of words in the given string
def wordCount(userInputString):
return (len(userInputString.split()))
def retrieve_input():
userInputString = (input('Input a string to determine amount of words: '))
if len(us... | true |
43e89a01a12c0e2d0ccf2731e8edefa283daff37 | mageoffat/Python_Lists_Strings | /Rotating_List.py | 1,291 | 4.4375 | 4 | # Write a function that rotates a list by k elements.
# For example [1,2,3,4,5,6] rotated by two becomes [3,4,5,6,1,2].
# Try solving this without creating a copy of the list.
# How many swap or move operations do you need?
num_list = [1,2,3,4,5,6,7,8,9] # my numbered list
val = 0 # value
def rotation(num_... | true |
13ecd656f3fe1fa576935a259ee42f8c180c22b2 | akimmi/cpe101 | /poly.py | 591 | 4.1875 | 4 | import math
# the purpose of this function is add the values inside the list
# list, list --> list
def poly_add2(p1, p2):
a= p1[0] + p2[0]
b= p1[1] + p2[1]
c= p1[2] + p2[2]
return [a, b, c]
# the purpose of this function is to multiply the values inside the list (like a polynomial) by using the distrib... | true |
18d665eba87ae845d1184dd5a6a59dbd81a00286 | the-last-question/team7_pythonWorkbook | /Imperial Volume.py | 1,838 | 4.59375 | 5 | # Write a function that expresses an imperial volume using the largest units possible. The function will take the
# number of units as its first parameter, and the unit of measure (cup, tablespoon or teaspoon) as its second
# parameter. Return a string representing the measure using the largest possible units as the ... | true |
82cda6b117d2bc918b8d675313db9f7a5b6314ba | sunyumail93/Python3_StepByStep | /Day02_IfElse/Day02_IfElse.py | 653 | 4.15625 | 4 | #!/usr/bin/python3
#Day02_IfElse.py
#Aim: Solve the missing/extra input problem using if/else statement. Use internal function len(), print()
#This sys package communicate Python with terminal
import sys
Total_Argument=len(sys.argv)-1 #sys.argv[0] is the script name
if Total_Argument == 0:
print("Please input two... | true |
484fdb72be152019168cdf842edc31148ce5eb85 | RiqueBR/refreshed-python | /Monday/basics.py | 1,157 | 4.53125 | 5 | # You can write comments using a # (hash) or a block with """ (three double quotes)
# Module is a different name for a file
# Variables are also called identifiers
a = 7
print(a)
"""
Python won't have major issues with differentiate whole interger and floats
"""
b = 9.3
print(int(b)) # Take the interger of a float (... | true |
f45aa98e5010666f1b0b16da119452b43db0de09 | chgeo2000/Turtle-Racing | /main.py | 2,104 | 4.28125 | 4 | import turtle
import time
import random
WIDTH, HEIGHT = 500, 500
COLORS = ['red', 'green', 'blue', 'cyan', 'yellow', 'black', 'purple', 'pink']
def get_number_of_racers():
"""
This function asks the user for the number of racers
:return: int, number of racers
"""
while True:
... | true |
28b4020cbd612ffc2b7f16ac2ba44e39f5ff4ab8 | tomatchison/CTI | /P4LAB1_Atchison.py | 661 | 4.40625 | 4 | # Write a program using turtle to draw a triangle and a square with a for loop
# 25 Oct 2018
# CTI-110 P4T1a: Shapes
# Tom Atchison
# Draw a square and a triangle using turtle.
# Use a while loop or a for loop.
# Start turtle.
import turtle
# See turtle on screen.
wn=turtle.Screen()
# Give turtle optio... | true |
4a4300f301d976b8bb1b7a96e6727f12c501ec83 | tomatchison/CTI | /P4LAB3_Atchison.py | 737 | 4.1875 | 4 | # Create my initials using turtle
# 25 Oct 2018
# CTI-110 P4T1b: Initials
# Tom Atchison
# Start turtle.
import turtle
import random
# See turtle on screen.
wn=turtle.Screen()
wn.bgcolor("green")
# Give turtle optional name.
sid=turtle.Turtle()
sid.speed(20)
# Give turtle shape.
sid.shape ("turtle... | true |
54290f9350ad833ee6165b2715d5fdcca2e61b8c | mvanorder/forecast-forecast_old | /overalls.py | 1,095 | 4.125 | 4 | ''' general use functions and classes '''
def read_list_from_file(filename):
""" Read the zip codes list from the csv file.
:param filename: the name of the file
:type filename: sting
"""
with open(filename, "r") as z_list:
return z_list.read().strip().split(',')
def key_list(... | true |
f2d03a02a7e8c0beeb5ebdf2448a95c6d3cbc18a | zzzzzzzlmy/MyLeetCode | /125. Valid Palindrome.py | 440 | 4.125 | 4 | '''
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
'''
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype:... | true |
50abfc53edeb131cbd64dcfca42baca644c3b9c5 | Joshcosh/AutomateTheBoringStuffWithPython | /Lesson_15.py | 1,665 | 4.40625 | 4 | # %%
# 1 | methods and the index method
spam = ['hello', 'hi', 'howdy', 'heyas']
spam.index('hello') # the index method
spam.index('heyas')
spam.index('asdfasdf') # exception
# %%
# 2 | in the case a value apears more than once - the index() method returns the first item's index
spam = ['Zophie', 'Pooka', 'Fat-tail', ... | true |
39629ce760dc9f089ba7566febb9c1bfb2c60921 | Some7hing0riginal/lighthouse-data-notes | /Week_1/Day_2/challenge2.py | 1,305 | 4.3125 | 4 | """
#### Rules:
* Rock beats scissors
* Scissors beats paper
* Paper beats rock
#### Concepts Used
* Loops( for,while etc.)
* if else
#### Function Template
* def compare(user1_answer='rock',user2_answer='paper')
#### Error Handling
* If the user_answer input is anything other than 'rock','paper' or 'scissors' re... | true |
1e7499929fdbe5b458524329ec9b45230a0b31ac | zhast/LPTHW | /ex5.py | 635 | 4.46875 | 4 | name = 'Steven Z. Zhang'
age = 18
height = 180 # Centimeters
weight = 175 # Pounds
eyes = 'Dark Brown'
teeth = 'White'
hair = 'Brown'
# The f character in the function lets you plug in a variable with curly brackets
print(f"Let's talk about {name}.") # In this case, its name
print(f"He's {height} centimeters tall")
... | true |
ff13fde0d24c6d8b175496fe127cdee185588557 | MaleehaBhuiyan/pythonBasics | /notes_and_examples/o_two_d_lists_and_nested_loops.py | 1,053 | 4.125 | 4 | #2d lists and nested loops
number_grid = [
[1,2,3],
[4,5,6],
[7,8,9],
[0]
]
#selecting individual elements from the grid, this gets the number 1, goes by row and then column
print(number_grid[0][0])
#nested for loop to print out all the elements in this array
for row in number_grid: #this will o... | true |
e76afe86418c782f16baf1d54a22b66254bb9fd7 | kjmjr/Python | /python/prime2.py | 513 | 4.25 | 4 | #Kevin McAdoo
#2-1-2018
#Purpose: List of prime numbers
#number is the variable for entering input
number = int(input('Enter a number and the computer will determine if it is prime: '))
#the for loop that tests if the input is prime
for x in range (2, number, x - 1):
if (number % x != 0):
print (nu... | true |
cf5de27304a6ae16c9219c902bba602979340412 | kjmjr/Python | /python/list_processing.py | 807 | 4.25 | 4 | #Kevin McAdoo
#2-21-2018
#Chapter 7 homework
print ('List of random numbers: ')
#list of random numbers
myList = [22, 47, 71, 25, 28, 61, 79, 57, 89, 3, 29, 41, 99, 86, 75, 98, 4, 31, 22, 33]
print (myList)
def main():
#command for the max function
high = max(myList)
print ('Highest number: ',... | true |
6b461d8563f05832a796b79b4a84999447d98436 | kjmjr/Python | /algorithm_workbench_problems.py | 860 | 4.40625 | 4 | #Kevin McAdoo
#Purpose: Class assignment with if/else statements/ the use of and logical operators
#1-24-2018
#3. The and operator works as a logical operator for testing true/false statements
#where both statements have to be true or both statments have to be false
#4 The or operator works as another logical ... | true |
7300bf857322e6298d6f30e4b15affbcb752afe0 | kjmjr/Python | /python/Test 1.py | 949 | 4.125 | 4 | #Kevin McAdoo
#2-14-2018
#Test 1
#initializing that one kilometer is equal to 0.621 miles
one_kilo = 0.621
#the define main function is calling the def get_kilometers (): and def km_to_miles(): functions
def main():
#user inputs his number here and float means the number he/she uses does not have to be a w... | true |
595d3f99cbe522aaaf59a724de0d202dd32bbd44 | praveenpmin/Python | /tuples.py | 1,370 | 4.46875 | 4 | # Creating non-empty tuples
# One way of creation
tup='Python','Techy'
print(tup)
# Another for doing the same
tup= ('Python','Techy')
print(tup)
# Code for concatenating to tuples
tuple1=(0,1,2,3)
tuple2=('Python','Techy')
# Concatenating two tuples
print(tuple1+tuple2)
# code fore creating nested loops
tuple3=(tup... | true |
d9aca0f48d29458fde3174259a840b5ccf535355 | praveenpmin/Python | /operatoverload1.py | 212 | 4.4375 | 4 | # Python program to show use of
# + operator for different purposes.
print(1 + 2)
# concatenate two strings
print("Geeks"+"For")
# Product two numbers
print(3 * 4)
# Repeat the String
print("Geeks"*4) | true |
c74901d9e80c204115ead86d6377750fd6ca8609 | praveenpmin/Python | /listmethod2.py | 521 | 4.71875 | 5 | # Python code to demonstrate the working of
# sort() and reverse()
# initializing list
lis = [2, 1, 3, 5, 3, 8]
# using sort() to sort the list
lis.sort()
# displaying list after sorting
print ("List elements after sorting are : ", end="")
for i in range(0, len(lis)):
print(lis[i], end=" ")
print("\r")... | true |
6fa1af52a4965d5b74ed3274a2b0f2e7aafe7192 | praveenpmin/Python | /inherit1.py | 715 | 4.34375 | 4 | # Python code to demonstrate how parent constructors
# are called.
# parent class
class Person( object ):
# __init__ is known as the constructor
def __init__(self, name, idnumber):
self.name = name
self.idnumber = idnumber
def display(self):
print(self.name)
print(self.idnumber)
#... | true |
c2f887c4e61320c71677beab7e8b81ce285cf8e8 | praveenpmin/Python | /Array1.py | 2,642 | 4.46875 | 4 | # Python code to demonstrate the working of array
import array
# Initializing array with array values
arr=array.array('i',[1,2,3])
# Printing original array
print("The new created array is:",end="")
for i in range(0,3):
print(arr[i],end="")
print("\r")
# using append to insert value to end
arr.append(4)
# prin... | true |
ccd1785e19f8fbc77c086eee6c3e774ef363d7ef | HosseinSheikhi/navigation2_stack | /ceiling_segmentation/ceiling_segmentation/UNET/VGG16/VGGBlk.py | 2,915 | 4.34375 | 4 | """
Effectively, the Layer class corresponds to what we refer to in the literature as a "layer" (as in "convolution layer"
or "recurrent layer") or as a "block" (as in "ResNet block" or "Inception block").
Meanwhile, the Model class corresponds to what is referred to in the literature as a "UNET"
(as in "deep learning ... | true |
179a2434a5f74bc68dc20538808418e7de18da2c | KiteQzioom/Module-4.2 | /Module 4.2.py | 372 | 4.1875 | 4 |
def isPalindrome(word):
length = len(word)
inv_word = word[::-1]
if word == inv_word:
answer = True
else:
answer = False
print(answer)
"""
The function isPalindrome takes an input of a string and checks if it is a palindrome. It outputs the answer in boolean as True or False... | true |
914c64272ef4e56be777df07db7ace7768cf30fc | AsemAntar/codewars_problems | /add_binary/add_binary.py | 899 | 4.28125 | 4 | def add_binary(a, b):
sum = a + b
return bin(sum)[2:]
'''
====================================================================================================
- writing the same function without the builtin bin method.
- Here we will follow a brute force approach.
- we follow the following method:
--> divide ... | true |
dd41527eebb329e606afa1c55db40f304c5124f1 | AsemAntar/codewars_problems | /create_phone_number/phone_number.py | 1,033 | 4.25 | 4 | # Author: Asem Antar Abdesamee
# Problem Description:
"""
Write a function that accepts an array of 10 integers (between 0 and 9),
that returns a string of those numbers in the form of a phone number.
Example: create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) --> (123) 456-7890
"""
'''
============================... | true |
8dc831b049dd861d1cf468b8a971833b6d1659fa | ege-erdogan/comp125-jam-session-01 | /solutions/problem_07.py | 761 | 4.21875 | 4 | '''
COMP 125 - Programming Jam Session #1
November 9-10-11, 2020
-- Problem 7 --
Given a positive integer n, assign True to is_prime if n has no factors other than 1 and itself. (Remember, m is a factor of n if m divides n evenly.)
'''
import math
n = 5
is_prime = True
# There is a whole literature of primality test... | true |
b7f6dfb5b8cff9d58efcdfa21259ff7a35f6231c | OyvindSabo/Ardoq-Coding-Test | /1/HighestProduct.py | 2,834 | 4.40625 | 4 | #Given a list of integers, this method returns the highest product between 3 of those numbers.
#If the list has fewer than three integers, the method returns the product of all of the elements in the list.
def highestProduct(intList):
negativeList = []
positiveList = []
for integer in sorted(intList):
if i... | true |
eb85fed448859e906df0baceda09beee9ce16d15 | HaNuNa42/pythonDersleri-Izerakademi | /python kamp notları/while.py | 344 | 4.15625 | 4 | # while
number = 0
while number < 6:
print(number)
number += 1
if number == 5:
break
if number == 3:
continue
print("hello world")
print("************************")
for number in range(0,6):
if number == 5:
break
if number == 3:
continue
... | true |
903fa4b1f636803dd1f0d5459926a97e53207380 | MingjuiLee/ML_PracticeProjects | /02_SimpleLinearRegression/main.py | 1,595 | 4.125 | 4 | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# Import dataset
dataset = pd.read_csv('Salary_Data.csv')
print(dataset.info()) # check if there is missing value
X = dataset.iloc[:, :-1].valu... | true |
7fc45fdb496f88a3d9737b2d6ff20b7f77d9ca50 | 4GeeksAcademy/master-python-exercises | /exercises/013-sum_of_digits/solution.hide.py | 296 | 4.375 | 4 | #Complete the function "digits_sum" so that it prints the sum of a three digit number.
def digits_sum(num):
aux = 0
for x in str(num):
aux= aux+int(x)
return aux
#Invoke the function with any three-digit-number
#You can try other three-digit numbers if you want
print(digits_sum(123)) | true |
0627bc29400b783ed5bf32bd83ba5de53b3e152d | bjarki88/Projects | /prof1.py | 525 | 4.15625 | 4 | #secs = int(input("Input seconds: ")) # do not change this line
#hours = secs//(60*60)
#secs_remain = secs % 3600
#minutes = secs_remain // 60
#secs_remain2 = secs % 60
#seconds = secs_remain2
#print(hours,":",minutes,":",seconds) # do not change this line
max_int = 0
num_int = int(input("Input a number: ")) # D... | true |
20198edc2742d160db704a992dd544f1627d5ac4 | B-Tech-AI-Python/Class-assignments | /sem-4/Lab1_12_21/sets.py | 680 | 4.28125 | 4 | print("\n--- Create a set ---")
set_one = {1, 3, 5, 7}
print(set_one)
print(type(set_one))
print("\n--- Add member(s) in a set ---")
set_two = {2, 3, 5, 7}
print(set_two)
print("Adding 11 to current set:", end=" ")
set_two.add(11)
print(set_two)
print(type(set_two))
print("\n--- Remove item(s) from a set ---")
to_r... | true |
43d015b115f8b396ef4fc919ff2ccfa4b737ac97 | B-Tech-AI-Python/Class-assignments | /sem-3/Lab_File/exp_1.py | 892 | 4.21875 | 4 | # %%
# WAP to understand the different basic data types and expressions
print("Integer")
int_num = 1
print(int_num, "is", type(int_num))
# %%
print("Float")
float_num = 1.0
print(float_num, "is", type(float_num))
# %%
print("Complex Number")
complex_num = 1 + 8j
print(complex_num, "is", type(complex_num))
# %%
print... | true |
ff3134c834c903218aafa07dc0961f138b426015 | Bhavyasribilluri/python | /nom.py | 219 | 4.46875 | 4 | #to find largest number
list= []
num= int(input("Enter number of elements in the list:"))
for i in range(1, num + 1):
ele = int(input("Enter elements: "))
list.append(ele)
print("Largest element is:", max(list)) | true |
af0ffc4ef074f2facdcdc90a0c5167dde4caea67 | Isisr/assignmentOrganizer | /assignmentOrganizer.py | 1,597 | 4.34375 | 4 | '''
Created on Feb 10, 2019
@author: ITAUser
ALGORTHM:
1) Make a .json text file that will store our assignments
2) IMport our .json file into our code
3) Create user input for finding assignments
4) Find the users assignments in our data
-If the users input is in our data
-The users input isn't in our data
'... | true |
8aedac9cc35461ba6258502c0d04b84c98760bc7 | Mybro1968/AWS | /Python/02Basics/example/03Number.py | 342 | 4.1875 | 4 | from decimal import *
number1 = int(input("What is the number to be divided? "))
number2 = int(input("What is the number to divided by? "))
print(number1, " / ", number2, " = ", int(number1 / number2))
print(number1, " / ", number2, " = ", float(number1 / number2))
print(number1, " / ", number2, " = ", Decimal... | true |
0f2920f5267dcc5b41d469e363af037264c5d342 | Mybro1968/AWS | /Python/05Files/Exercise/01WriteTeams.py | 392 | 4.125 | 4 | # Purpose : writes a file with input for up to 5 names
file = open("teams.txt","w")
count = int(input("how many teams would you like to enter? "))
#team_name = input("Please enter a team name: ")
for n in range(count):
if count !=0:
team_name = input("Please enter a team name: ") + "\n"
... | true |
6b06b17601db13468cb668d63df1582e33c5de0b | zzwei1/Python-Fuzzy | /Python-Tutorial/Numerology.py | 2,629 | 4.15625 | 4 | #!usr/bin/python
# Function to take input from Person
def input_name():
""" ()->int
Returns sum of all the alphabets of name
"""
First_name= input("Enter the first Name")
Middle_name= input("Enter the middle Name")
Last_name= input("Enter the last Name")
count1=count_string(First_name)
... | true |
20b5b26e28989a0bd3d98cdcbeaf3583351eeef5 | jkatem/Python_Practice | /FindPrimeFactors.py | 431 | 4.15625 | 4 |
# 1. Find prime factorization of a given number.
# function should take in one parameter, integer
# Returns a list containing all of its prime factors
def get_prime_factors(int):
factors = list()
divisor = 2
while(divisor <= int):
if (int % divisor) == 0:
factors.append(divisor)
... | true |
a677d4055dbe59dec016fe09756f57176d7ddc6c | amanmishra98/python-programs | /assign/14-class object/class object10.py | 577 | 4.1875 | 4 | #2.define a class Account with static variable rate_of_interest.instance variable
#balance and accountno. Make function to set values in instance object of account
#,show balance,show rate_of_interest,withdraw and deposite.
class Account:
rate_of_interest=eval(input("enter rate of interest\n"))
def info(se... | true |
8265c18a5344c85d76ca67601d613501cd660841 | alessandraburckhalter/Exercises | /ex-07-land-control.py | 498 | 4.1875 | 4 | # Task: Make a program that has a function that takes the dimensions of a rectangular land (width and length) and shows the land area.
print("--" * 20)
print(" LAND CONTROL ")
print("--" * 20)
# Create a function to calculate the land area
def landArea(width, length):
times = width * length
prin... | true |
5b8fe72fd81b5ebb09d48774e3259dc5b69c05d7 | bazerk/katas | /tree_to_list/tree_to_list.py | 939 | 4.25 | 4 | def print_tree(node):
if not node:
return
print node.value
print_tree(node.left)
print_tree(node.right)
def print_list(node, forwards=True):
while node is not None:
print node.value
node = node.right if forwards else node.left
def transform_to_list(node, prev=None):
i... | true |
2928aac960286ff38dae1ca85e50c0d0ba653111 | cvhs-cs-2017/practice-exam-IMissHarambe | /Loops.py | 282 | 4.34375 | 4 | """Use a loop to make a turtle draw a shape that is has at least 100 sides and
that shows symmetry. The entire shape must fit inside the screen"""
import turtle
meme = turtle.Turtle()
for i in range (100):
meme.forward(1)
meme.right(3.3)
input()
| true |
fbcc409e7bdf235598c1db86b34f4a5ad4b146b5 | furtiveJack/Outils_logiciels | /projet/src/utils.py | 1,768 | 4.21875 | 4 | from enum import Enum
from typing import Optional
"""
Utility methods and variables for the game.
"""
# Height of the window (in px)
HEIGHT = 1000
# Width of the window (in px)
WIDTH = 1000
# Shift from the side of the window
ORIGIN = 20
NONE = 0
H_WALL = 1
V_WALL = 2
C_WALL = 3
MINO = 4
class CharacterType(Enum):
... | true |
69422e8bcf009b6bff2355220506721adc178cad | JasmineEllaine/fit1008-cpp-labs | /3-lab/task1_a.py | 1,180 | 4.25 | 4 | # Task 1a
# Read input from user (int greater than 1582)
# If leap year print - is a leap year
# Else print - is not a leap year
def main():
""" Asks for year input and prints response accordingly
Args:
None
Returns:
None
Raises:
No Exceptions
Preconditions:
... | true |
bec90b0361b19f66e15bfef6d5abacd2bddc9970 | msm17b019/Project | /DSA/Bubble_Sort.py | 677 | 4.1875 | 4 | def bubble_sort(elements):
size=len(elements)
swapped=False # if no swapping take place in iteration,it means elements are sorted.
for i in range(size-1):
for j in range(size-1-i): # (size-i-1) as last element in every iteration is getting sorted.
if elements[j]>elements[j+1]:
... | true |
bb05a9044f8fdaca1ca78ec9d7f63f2840cc9866 | hampusrosvall/leetcode | /merge_linked_lists.py | 2,340 | 4.28125 | 4 | """
P C
l1: 1 -> 6 -> 7 -> 8
N
l2: 2 -> 3 -> 4 -> 5 -> 9 -> 10
The idea is to insert the nodes of the second linked list into the first one.
In order to perform this we keep track of three pointers:
1) prevNode (points to the previous node in the insertion list)
2) currentNode (points... | true |
b9a617f0880e2997d7319464c1c7c5aa7ff3395e | blueclowd/leetCode | /python/1042-Flower_planting_with_no_adjacent.py | 1,257 | 4.1875 | 4 | '''
Description:
You have N gardens, labelled 1 to N. In each garden, you want to plant one of 4 types of flowers.
paths[i] = [x, y] describes the existence of a bidirectional path from garden x to garden y.
Also, there is no garden that has more than 3 paths coming into or leaving it.
Your task is to choose a flower ... | true |
0b23ebf4c19a7d6dc6fbea5e184b61d1d6116854 | blueclowd/leetCode | /python/0101-Symmetric_tree.py | 1,458 | 4.15625 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
# Iterative
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
if not root:
return True
... | true |
c77a6dd6090ddd15e50741841a66cb05e8db771a | shashbhat/Internship_Data_Analytics | /Assignment/Day 1/6.py | 387 | 4.375 | 4 | '''
6. Write a program to accept a number from the user; then display the reverse of the entered number.
'''
def reverse_num(num):
'''
Reverses a number and returns it.
'''
rev = 0
while num != 0:
rev = rev * 10 + num % 10
num = num // 10
return rev
num = int(input("Enter a numb... | true |
4ac7158db07e3d5ce9de5125b646eee70fec24b3 | milind1992/CheckIO-python | /Boolean Algebra.py | 1,713 | 4.5 | 4 | OPERATION_NAMES = ("conjunction", "disjunction", "implication", "exclusive", "equivalence")
def boolean(x, y, operation):
if operation=="conjunction":
#"conjunction" denoted x ∧ y, satisfies x ∧ y = 1 if x = y = 1 and x ∧ y = 0 otherwise.
return x*y
elif operation=="disjunction":
#"disjunc... | true |
47ad2084d09c9be3ffae5d20f34cac14b96f85e3 | CodeAltus/Python-tutorials-for-beginners | /Lesson 3 - Comments, input and operations/lesson3.py | 269 | 4.21875 | 4 | # Taking user input
dividend = int(input("Enter dividend: "))
divisor = int(input("Enter divisor: "))
# Calculation
quotient = dividend // divisor
remainder = dividend % divisor
# Output results
print("The quotient is", quotient)
print("The remainder is", remainder)
| true |
c86b788a0d4bab42f59fde14c1d3a35b034171a1 | GedasLuko/Python | /Chapter 5 2/program52.py | 673 | 4.15625 | 4 | #Gediminas Lukosevicius
#October 8th, 2016 ©
#import random function
#build numbers function first
#create accumulator
#create a count in range of five numbers
#specify five numbers greater than ten but less than thirty
#create a total for five numbers assignment
#display five random numbers and total as specified
#bu... | true |
1527cdb327c0d59506154813384d32718ceb1864 | GedasLuko/Python | /chapter 2/program24.py | 587 | 4.5 | 4 | #Gediminas Lukosevicius
#September 1st, 2016 ©
#This program will convert an improper fraction to a mixed number
#Get Numerator
#Get Denominator
#Convert improper fraction to mixed number
#Dislpay the equivalent mixed number with no space either side of the / symbol
numerator = int(input('Please enter the numerator: '... | true |
53c1bd002b7c652df805e6ea2cd1991746508aef | GedasLuko/Python | /write_numbers.py | 510 | 4.375 | 4 | #Gediminas Lukosevicius
#October 24th, 2016 ©
#This program demonstrates how numbers must be converted to strings before they are written to a text file.
def main():
outfile = open('numbers.txt', 'w')
num1 = int(input('Enter a number: '))
num2 = int(input('Enter another number: '))
num3 = int(input('... | true |
25e2f64d1c80edac30dfb37bf57035cc2b3d1e1d | zsoltkebel/university-code | /python/CS1028/practicals/p2/seasons.py | 868 | 4.25 | 4 | # Author: Zsolt Kébel
# Date: 14/10/2020
# The first day of seasons of the year are as follow:
# Spring: March 20
# Summer: June 21
# Fall: September 22
# Winter: December 21
# Display the season associated with the date.
month = "Mar"
date = 23
if month == "Jan" or month == "Feb":
print("Winter")
elif month ==... | true |
cacbf029b45a960fa30b175e3f0bafe66ebfaab6 | gschen/where2go-python-test | /1200-常用算法/其他/111_二叉树的最小深度.py | 1,288 | 4.15625 | 4 | # https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/
from typing import *
import unittest
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def levelOrderBottom(self, root: TreeNode)... | true |
5253599aa98ef4900197ef5616ceb94936048fe2 | K23Nikhil/PythonBasicToAdvance | /Program13.py | 507 | 4.125 | 4 | #Write a program that asks the user how many Fibonnaci numbers to generate and then generates them.
# Take this opportunity to think about how you can use functions.
startIndex = 0
endIndex = 10
FabSer = []
i = 1
if startIndex ==1:
FabSer.append(startIndex)
FabSer.append(startIndex)
else:
FabS... | true |
8929a0b3e7d0dcbf04f6bc907de9f9aece86c9d1 | spoorthyandhe/project-98 | /game.py | 885 | 4.34375 | 4 | import random
print(" Number guessing game :")
number = random.randint(1,9)
chances = 0
print ("Guess a number (between 1 and 9): ")
# while loop to count the umbers of changes
while chances <5:
guess = int(input("Enter your guess: "))
#compare the user enteres number with the number
if gue... | true |
ef05347532b0eab4ddede67797e8a39725fefc07 | Mfrakso/Week3 | /FiberOptic If_Statements.py | 1,895 | 4.4375 | 4 | '''
File: FiberOptic If_Statments.py
Name: Mohammed A. Frakso
Date: 14/12/2019
Course: DSC_510 - Introduction to Programming
Desc: Programe calculates the need of fiber optic cable and evaluate a bulk discount for a user
Usage : This program is built to take the 'Company Name' and 'required length(in feet)' of optic c... | true |
ea17d0d98e64c444106d0c018c8ac171a84c3b32 | pangyang1/Python-OOP | /Python OOP/bike.py | 794 | 4.15625 | 4 | class Bike():
"""docstring for Bike."""
def __init__(self,price,max_speed,miles):
self.price = price
self.max_speed =max_speed
self.miles = 0
def displayinfo(self):
print "The price is $" + str(self.price) + ". The max speed is " + str(self.max_speed) + ". The total miles are... | true |
b38b3a2082f4da3dc269982aab04ac935a5e96bd | IeuanOwen/Exercism | /Python/triangle/triangle.py | 1,087 | 4.25 | 4 | import itertools
def valid_sides(sides):
"""This function validates the input list"""
if any(side == 0 for side in sides):
return False
for x, y, z in itertools.combinations(sides, 3):
if (x + y) < z or (y + z) < x or (z + x) < y:
return False
else:
return True
def... | true |
9f865f967c9a164b95c49e5f84b17d5d0204c5f8 | IeuanOwen/Exercism | /Python/prime-factors/prime_factors.py | 428 | 4.1875 | 4 | """Return a list of all the prime factors of a number."""
def factors(startnum):
prime_factors = []
factor = 2 # Begin with a Divisor of 2
while startnum > 1:
if startnum % factor == 0:
prime_factors.append(factor)
startnum /= factor # divide the startnum by the factor
... | true |
375e0bf125558618bb74238ec40264ce59ca9344 | Jeevan-Palo/oops-python | /Polymorphism.py | 1,050 | 4.5 | 4 | # Polymorphism achieved through Overloading and Overriding
# Overriding - Two methods with the same name but doing different tasks, one method overrides the other
# It is achieved via Inheritance
class Testing:
def manual(self):
print('Automation Tester with 5 years Experience')
class ManualTest(Testing)... | true |
cc50929915eae260da1160b515b30cbea4268108 | MicheSi/Data-Structures | /binary_search_tree/sll_queue.py | 2,213 | 4.1875 | 4 | class Node:
def __init__(self, value=None, next_node=None):
# the value at this linked list node
self.value = value
# reference to the next node in the list
self.next_node = next_node
def get_value(self):
return self.value
def get_next(self):
return self.next_node
def set_next(self, n... | true |
572e08a21a64a898d60e2bd26bec4f350da44d65 | his1devil/lintcode-note | /flattenlist.py | 449 | 4.1875 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
class Solution(object):
"""
Given a list, each element in the list can be a list or integer.
Flatten it into a simply list with integers.
递归
"""
def flatten(self, nestedList):
result = []
if isinstance(nestedList, int):
... | true |
cd54caff7a61f615fd855cc9a012871652fb4c2a | his1devil/lintcode-note | /rotatestring.py | 1,055 | 4.25 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
class Solution(object):
"""
Given a string and an offset, rotate string by offset. (rotate from left to right)
offset=2 => "fgabcde"
"""
def rotateString(self, s, offset):
# 防止offset越界,offset 对len(s)取模
if s is None or len(s) == 0:
... | true |
6c78661c73b2892e248eff64a7395e6b1e84359b | paulmagnus/CSPy | /mjenkins-programs/windchill.py | 447 | 4.3125 | 4 | def windChill():
print 'Welcome to the windchill calculator!'
temperature = input("Enter the temperature: ")
windspeed = input("Enter the wind speed: ")
windchill = 35.74 + (0.6215 * temperature) - (35.75 * (windspeed ** 0.16)) + (0.4275 * temperature * (windspeed ** 0.16))
print 'At ' + str(temperature) + ' degre... | true |
fd8809831149570c0750c8d612f2bd99c0d31479 | katyduncan/pythonintro | /lesson2/8IntegersFloats.py | 409 | 4.1875 | 4 | # Check data type
print(type(3))
print(type(4.3))
# whole number float
print(type(4.))
# operation involving int and float always results in float
print(3 + 2.5)
# cut decimal off float to convert to int
print(int(49.7))
# 49 no rounding occurs
# add .0 to convert int to float
print( float(3520 + 3239))
# 6759.0
#... | true |
a57f59a87013bed7f79d9524af8858e8c48c024d | Bumskee/-Part-2-Week-2-assignment-21-09-2020 | /Problem 2.py | 483 | 4.15625 | 4 | """Problem 2 finding the average score tests of 3 students"""
#Assigning the value for the student scores
student1 = 80
student2 = 90
student3 = 66.5
#Function for finding the average out of those student scores
def findAverage(student1, student2, student3):
scoreAverage = (student1 + student2 + student3) / 3
... | true |
63d1c825ba44f094558ed37759d9f9d018a7a484 | samanthaalcantara/codingbat2 | /Logic-1/caught_speeding.py | 758 | 4.28125 | 4 | """
Date: 06 12 2020
Author: Samantha Alcantara
Question:
You are driving a little too fast, and a police officer stops you.
Write code to compute the result, encoded as an int value: 0=no ticket,
1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0.
If speed is between 61 and 80 inclusive, the res... | true |
19a6de32c4a6c72a5dbd89ad23600d9de5893ce6 | peterhchen/runBookAuto | /code/example/01_Intro/05_Age.py | 539 | 4.4375 | 4 | #!/usr/bin/python3
# Display different format based on age.
# Age 1 to 18: Important
# Age 21, 50, or >= 65: Important
# All othera Ages: Not important
# Get age and store in age
age = eval (input('Enter age: '))
# if age >= 1 and <= 18: important
if (age >= 1) and (age <= 18):
print ("Important")
# if age == ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.