blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
2827c8423400bfe3d5c7992fd80d1a8d321dbd9f | pmmorris3/Code-Wars-Solutions | /5-kyu/valid-parentheses/python/solution.py | 471 | 4.25 | 4 | def valid_parentheses(string):
bool = False
open = 0
if len(string) == 0:
return True
for x in string:
if x == "(":
if bool == False and open == 0:
bool = True
open += 1
if x == ")" and bool == True:
if open - 1 == 0:
... | true |
bff81845806f726c9ebf0c35c407076314d711ff | borodasan/python-stady | /duel/1duel/1duel.py | 483 | 4.4375 | 4 | def p(p):
for i in range(0,5,2): #The range() function defaults to increment the sequence by 1,
#however it is possible to specify the increment
#value by adding a third parameter: range(0, 5, 2)
#Assignment operators are used to assign values to... | true |
a67e31b47c7be597942229d2f9046e4b7dc4e283 | borodasan/python-stady | /python-collections-arrays/set.py | 1,504 | 4.65625 | 5 | #A set is a collection which is unordered and unindexed.
#In Python sets are written with curly brackets.
print("A set is a collection which is")
print("unordered and unindexed".upper())
print("In Python sets are written with curly brackets.")
#Create a Set
print("Create a Set:")
thisset = {"apple", "banana", "cherry... | true |
423736de6e6515f77cec66aefb7941ba34c623ae | shane806/201_Live | /13. More Lists/live.py | 297 | 4.15625 | 4 | matrix = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 1, 2, 3],
[4, 5, 6, 7]]
def create_new_2d_list(height, width):
pass
def main():
# how do I get at the 9?
# how do I loop through the third row?
# how do I loop through the second column?
pass
main()
| true |
5158eedff805fe1a02c30ccc26fbe4027407d813 | untalinfo/holbertonschool-higher_level_programming | /0x0B-python-input_output/100-append_after.py | 570 | 4.125 | 4 | #!/usr/bin/python3
"""
Module
"""
def append_after(filename="", search_string="", new_string=""):
"""
Inserts a line of text to a file
Args:
filename (str, optional)
search_string (str, optional) Defaults to "".
new_string (str, optional) Defaults to "".
"""
with open(file... | true |
85eb2ffc8676179e4c6f23062f20a19e0d0a1906 | HATIMj/MyPythonProblems | /Divisor.py | 1,138 | 4.125 | 4 | #DIVISOR OR NOT
try: #trying the below inputs
n=int(input("Enter the total number of apples:--"))#Taking an input of number of apples
mn=int(input("Enter the minimum no. of students:--")) #Taking the input of minimum number of students
mx=int(i... | true |
6ea2887ac7d1679ca5663d773c288bbfc38b40cf | emmanuelnyach/python_basics | /algo.py | 818 | 4.25 | 4 | # num1 = input('enter first number: ')
# num2 = input('enter second number: ')
#
# sum = float(num1) + float(num2)
#
# print('the sum of {} and {} is {}'.format(num1, num2, sum))
# finding the largest num in three
#
# a = 8
# b = 4
# c = 6
#
# if (a>b) and (a>c):
# largest=a
# elif (b>a) and (b>c):
# l... | true |
03d5fa4ff4dece6cb4e00d200257353e66ce478d | elementbound/jamk-script-programming | /week 4/listsum.py | 738 | 4.125 | 4 | # 4-3) list calculation with type detection
#
# calculate sum and average of elements in the list
# ignore all values in the list that are not numbers
#
# initializing the list with the following values
#
# list = [1,2,3,4,5,6,7,8,9,20,30, "aa", "bee", 11, "test", 51, 63]
def is_int(val):
try:
val = int(va... | true |
bb510d0b1d3e9b30af489969971b3702c03eaf25 | Steven-Chavez/self-study | /python/introduction/numbers.py | 848 | 4.28125 | 4 | # Author: Steven Chavez
# Email: steven@stevenscode.com
# Date: 9/4/2017
# File: numbers.py
''' Expression is used like most other languages.
you are able to use the operators +, -, *, and /
like you would normally use them. You can also group
the expressions with parentheses ()'''
# addition, subtraction, multipli... | true |
7fb4ede2dbd7ba97c78af7fa5cedcef8fcbf7baf | rakesh0180/PythonPracties | /TupleEx.py | 506 | 4.21875 | 4 | items = [
("p1", 4),
("p2", 2),
("p3", 5)
]
# def sort_item(item):
# return item[1]
# print(item.sort(key=sort_item))
# print(item)
# using lambada we avoid above two statement
items.sort(key=lambda item: item[1])
print(items)
# map
x = list(map(lambda item: item[1], items))
print("map", x)
# fil... | true |
7d1d9a1997ec0ad4df02b524784e424cd8a31d95 | devcybiko/DataVizClass | /Week3/RockPaperScissors.py | 812 | 4.125 | 4 | import random
while True:
options = ["r", "p", "s"]
winning_combinations = ["rs", "sp", "pr"]
### for rock, paper, scissors, lizard, spock...
# options = ["r", "p", "s", "l", "x"]
# winning_combinations = ["sp", "pr", "rl", "lx", "xs", "sl", "lp", "px", "xr", "rs"]
user_choice = input(options)
... | true |
62e75902fa73c4b3cf3c0efbbeff4e928cb80119 | BENLINB/Practice-assignment-for-Visual-Studio | /Generate username.py | 536 | 4.125 | 4 | #Problem2
#writing programm that would prompt the username in the format Domain Name-Username.
print("#######################################")
print("WELCOME TO DBS CONSOLE")
print("#######################################")
#asking the user to input his credentials
student=input("enter username")
index= s... | true |
599ecf8e936096c23c02615562f20d5eaf8a2b0e | prince5609/Leet_Code | /Max_Deapth_Binary_Tree.py | 579 | 4.15625 | 4 | # Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes
# along the longest path from the root node down to the farthest leaf node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
sel... | true |
a0d4f9f823847403700707ce540fa1b6e7aef386 | Nitin-K-1999/Python_script | /Sample Script 1.py | 504 | 4.34375 | 4 | # A list of cricket team is given below. Print the number of possible matches between each of them. Also print each possible match in the format team1 vs team2.
team_list = ['CSK','RCB','Sun Risers','Deccan Chargers','Mumbai Indians']
matches = []
for index in range(len(team_list)) :
for team in team_list[i... | true |
8978220700fcf7ed48d7b0840bebd70696ee3fd8 | VRamazing/UCSanDiego-Specialization | /Assignment 2/fibonacci/fibonacci.py | 359 | 4.15625 | 4 | # Uses python3
# Task. Given an integer n, find the nth Fibonacci number F n .
# Input Format. The input consists of a single integer n.
# Constraints. 0 ≤ n ≤ 45.
def calc_fib(n):
if n==0:
return 0
elif n==1:
return 1
else:
arr=[1,1]
for i in range(2,n):
arr.append(arr[i-1]+arr[i-2])
return arr[n-1]
n... | true |
077db2a0f5904ba96886cc827b25c8d384e7e1b7 | VRamazing/UCSanDiego-Specialization | /Assignment 3/greedy_algorithms_starter_files/fractional_knapsack/fractional_knapsack.py | 2,169 | 4.15625 | 4 | # Uses python3
import sys
# Task. The goal of this code problem is to implement an algorithm for the fractional knapsack problem.
# Input Format. The first line of the input contains the number n of items and the capacity W of a knapsack.
# The next n lines define the values and weights of the items. The i-th line c... | true |
cbeb6a4b06cd9f36bf351c269ca71de0793e2081 | ktandon91/DataStructures | /3. DyPro/rod_price.py | 1,021 | 4.28125 | 4 | """
Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n.
Determine the maximum value obtainable by cutting up the rod and selling the pieces.
For example, if length of the rod is 8 and the values of different pieces are given as following,
then the maximum obt... | true |
82234bc9ffaa3acb0a0bb64d040ec8e249789414 | iamshubhamsalunkhe/Python | /basics/Continueandbreak.py | 336 | 4.4375 | 4 | #continue is used to skip a iteration and jump back to other iteration
"""
for i in range(1,11,1):
if(i==5):
continue
print(i)
"""
'''
##break is used to break a iteration or stop a iteration at specific point
for i in range(1,11,1):
if(i==5):
continue
if(i==8):
break
... | true |
d54773b3f32729d8076b34ada3d07c1be629e2b3 | standrewscollege2018/2020-year-13-python-classwork-OmriKepes | /classes and objects python.py | 1,650 | 4.625 | 5 | ''' This program demonstrates how to use classes and objects.'''
class Enemy:
''' The enemy class has life, name, and funcations that do something.'''
def __init__(self, name, life):
'''This funcation runs on instantiation and sets up all attributes.'''
self._life = life
self._name = na... | true |
4873d8070a2d54482d0ea387eb1c901cfba8ef9e | Will-is-Coding/exercism-python | /pangram/pangram.py | 503 | 4.21875 | 4 | import re
def is_pangram(posPangram):
"""Checks if a string is a pangram"""
lenOfAlphabet = 26
"""Use regular expression to remove all non-alphabetic characters"""
pattern = re.compile('[^a-zA-Z]')
"""Put into a set to remove all duplicate letters"""
posPangram = set(pattern.sub('', posPangr... | true |
23eb4288c74348e898b5e987f8755ebf2cc2db62 | Liam-Pigott/python_crash_course | /11-Advanced_Python_Modules/defaultdict.py | 769 | 4.15625 | 4 | from collections import defaultdict
# defaultdict is a dictionary-like object which provides all methods provided by a dictionary but takes a first argument (default_factory)
# as a default data type for the dictionary. Using defaultdict is faster than doing the same using dict.set_default method.
# A defaultdict wil... | true |
aad7fec002bf6717bb2a7e6389c964ec6344cd4a | Liam-Pigott/python_crash_course | /02-Statements/control_flow.py | 1,768 | 4.15625 | 4 | # if, elif and else
if True:
print("It's True")
else:
print("False")
loc = 'Bank'
if loc == 'Work':
print('Time to work')
elif loc == 'Bank':
print('Money maker')
else:
print("I don't know")
name = 'Liam'
if name == 'Liam':
print("Hello Liam")
elif name == 'Dan':
print('Hi Dan')
else:
... | true |
6f2d440071bdacdb59adc4409561dfb6b63683d3 | ksannedhi/practice-python-exercises | /Ex11.py | 618 | 4.34375 | 4 | '''Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a prime number is a number that has no divisors.).
You can (and should!) use your answer from Exercise 4 to help you. Take this opportunity to practice using functions.'''
def find_prime_or_not(num):
d... | true |
bbe653b8a4f428b0c7abc5ede7939455abdf2a06 | ksannedhi/practice-python-exercises | /Ex15.py | 532 | 4.4375 | 4 | '''Write a program (using functions!) that asks the user for a long string containing multiple words.
Print back to the user the same string, except with the words in backwards order. For example, say I type the string:
My name is Michele
Then I would see the string:
Michele is name My'''
def reverse_words(inp... | true |
993033a674b3d7a44cc8aacb6f9910d84c8b4531 | pzinz/sep_practice | /22_HarvardX_w01_03.py | 2,199 | 4.25 | 4 | # Static typing mean that the type checking is performed during compile time
# dynamic typing means that the type checking is performed at run time
# Varible, objects and references
# x = 3 ; Python will first create the object 3 and then create the variable X and then finally reference x -> 3
# list defined as foll... | true |
ec68888812b15838438f33bcb97c68e3dac62ba2 | malekhnovich/PycharmProjects | /Chapter5_executing_control/Chapter6_dictionaries/tuple_example.py | 1,336 | 4.59375 | 5 | '''
IF DICTIONARY KEYS MUST BE TYPE IMMUTABLE WHILE LIST TYPE IS MUTABLE
YOU CAN USE A TUPLE
TUPLE CONTAINS A SEQUENCE OF VALUES SEPERATED BY COMMAS AND ENCLOSED IN PARENTHESIS(()) INSTEAD OF BRACKETS([])
'''
#THIS IS A TUPLE BECAUSE THE PARENTHESIS ARE ROUND RATHER THAN SQUARE
#SQUARE PARENTHESIS WOULD BE A LIST
#THE ... | true |
b42ace7c28ad5224af073ba6703128d6f80bfae5 | ses1142000/python-30-days-internship | /day 10 py internship.py | 1,313 | 4.3125 | 4 | Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import re
>>> string = "a-zA-Z0-9"
>>> if re.findall(r'/w',string):
print("the string contains a set of char")
else:
print("the string does... | true |
9e90c8c11d9352283cd731aec48de88038b64f88 | JanusClockwork/LearnPy | /Py3Lessons/python_ex05.py | 1,597 | 4.125 | 4 | name = 'Janus Clockwork' #according to my computer lol
age = 26
height = 65 #inches. Also, why is height spelled like that. I before E except after C? My ass.
weight = 114 #lbs. also I AM GROWIIINNNG
eyes = 'gray' #'Murrican spelling
teeth = 'messed up'
hair = 'brown'
favePet = 'cats'
faveAnime = 'Yowamushi Pedal'
fav... | true |
d389a579ea1360932b5af127018b9b35e66ecc3b | paluchasz/Python_challenges | /interview_practice_hackerank/Arrays/Minimum_Swaps.py | 2,389 | 4.21875 | 4 | '''Find minimum number of swaps in an array of n elements. The idea is that the min
number of swaps is the sum from 1 to number of cycles of (cycle_size - 1). E.g
for [2,4,5,1,3] we have 2 cycles one between 5 and 3 which is size 2 and requires 1 swap
and one between 2 4 and 1 which is of size 3 and requires 2 swaps. S... | true |
cba55fed10f53f69c2860cf020507a736827532e | paluchasz/Python_challenges | /interview_practice_hackerank/Warm_up_problems/Counting_Valleys.py | 961 | 4.28125 | 4 | '''This program has a series of Ds and Us, we start at sea level and end at sea level, we
want to find the number of valleys, ie number of times we go below sea level (and back to 0)'''
import math
import os
import random
import re
import sys
# Complete the countingValleys function below.
def countingValleys(n, s):
... | true |
3608c44ab2d527502b864be1e13af76a126a55f7 | ekaterinaYashkina/simulated_annealing_PMLDL | /Task2/utils.py | 1,659 | 4.15625 | 4 | import math
from geopy.distance import lonlat, distance
"""
Calculates the distance between the two nodes using euclidean formula
neighbours - list of tuples, nodes coordinates
first, second - indices of elements in neighbours list, between which the distance should be computed
"""
def euclidean_dist(first, second... | true |
8aa19aece7c856c53348b9f18a895d8a6999f2bc | Lynch08/MyWorkpands | /Code/Labs/LabWk4/isEven.py | 249 | 4.1875 | 4 | # Author: Enda Lynch
# tell the user if they input an odd or even number
number = int(input("Enter an integer:"))
if (number % 2) == 0 :
print ("{} is an even number" . format(number))
else:
print ("{} is not an even number" . format(number))
| true |
38400be20795cf6cbdb634a9e6ad55ee7c719f8d | Lynch08/MyWorkpands | /Code/Labs/LabWk4/guess3.py | 568 | 4.25 | 4 | # generates random number for user to guess
# Author: Enda Lynch
# import random module and set limit between 1 and 100
import random
numberToGuess = random.randint(0,100)
#string for user
guess = int(input("Please guess the number between 1 and 100:"))
##'while' sets loop and 'if' and 'else' give prompts
while gue... | true |
2618d88acba70b47d7b374bcd1864ab3eeed50cf | Lynch08/MyWorkpands | /Code/Labs/LabWk3/div.py | 347 | 4.125 | 4 | #Author: Enda Lynch
# Division programme with remainder
#enter values using inputs to devide on integer by another
X = int(input('Enter number: '))
Y = int(input('Divided by: '))
# '//' gives divides the integers and '%' gives the remainder
B = X//Y
C = X%Y
#display work
print("{} divided by {} is equal to {} rema... | true |
a4b94d07c019eba3b5d741dd14ebd0b478b107a5 | CptObviouse-School-Work/SDEV220 | /module3/6.5.py | 354 | 4.21875 | 4 | '''
Jesse Duncan
SDEV 220
Programming Assignment: 6.5
Due June 17, 2018
'''
def displaySortedNumbers(num1, num2, num3):
numbers = [num1, num2, num3]
numbers.sort()
print("The sorted numbers are " + str(numbers[0]), str(numbers[1]), str(numbers[2]))
num1, num2, num3 = eval(input("Enter three numbers: "))
... | true |
2e225d616432eabeddd4a1913cbc82b7013f7fd2 | CptObviouse-School-Work/SDEV220 | /module2/4.15.py | 1,400 | 4.125 | 4 | '''
Jesse Duncan
SDEV 220
Exercise 4.15 Game: Lottery
Due June 10, 2018
'''
import random
# Generate a lottery number
lottery = random.randint(0, 999)
# Prompt the user to enter a guess
guess = eval(input("Enter your lottery pick (three digits): "))
#Get digits from lottery
removeLastDigit = lottery // 10
firstDigit... | true |
e02be49d885d049f820771a4cd6ee1b3c045453d | lsrichert/LearnPython | /ex3.py | 2,909 | 4.65625 | 5 | # + plus does addition
# - minus does subtraction
# / slash does division
# * asterisk does multiplication
# % percent is the modulus; this is the remainder after dividing one number
# into another i.e. 3 % 2 is 1 because 2 goes into 3 once with 1 left over
# < less-than
# > greater-than
# <= less-than-equal
# >= great... | true |
a0aff6ea7d696b27594019f2bc9207ef5f875291 | jaindinkar/PoC-1-RiceUniversity-Sols | /Homework1/Q10-sol.py | 2,161 | 4.25 | 4 | class BankAccount:
""" Class definition modeling the behavior of a simple bank account """
def __init__(self, initial_balance):
"""Creates an account with the given balance."""
self.balance = initial_balance
self.fees = 0
def deposit(self, amount):
"""Deposits the amount in... | true |
36c7857bf6cb4087456e70307643515040ae8352 | phoenix14113/TheaterProject2 | /main.py | 2,029 | 4.3125 | 4 |
import functions
theater = functions.createTheater(False)
NumberOfColumns = len(theater)
NumberOfRows = len(theater[0])
while True:
# print the menu
print("\n\n\n\n")
print("This is the menus.\nEnter the number for the option you would like.\n")
print("1. Print theater layout.")
print("2. Purch... | true |
429b4627202ef18b85b7d088f8972f984d4f872a | NelsonJyostna/Array | /Array_12.py | 1,250 | 4.15625 | 4 | #python array Documentation
#https://docs.python.org/3.1/library/array.html
#See these videos
#https://www.youtube.com/watch?v=6a39OjkCN5I
#https://www.youtube.com/watch?v=phRshQSU-xAar
#import array as ar
#from array import *
#h=ar.array('i',[1,6,5,8,9])
#print(h)
from array import *
h=array('i',[1,6... | true |
2b5afb0c23f01c5cd78462e373b86c2985bc0b81 | tarunna01/Prime-number-check | /Prime number check.py | 271 | 4.15625 | 4 | num = int(input("Enter the number to check for prime"))
mod_counter = 0
for i in range(2, num):
if num % i == 0:
mod_counter += 1
if mod_counter != 0:
print("The given number is not a prime number")
else:
print("The given number is a prime number")
| true |
bfd09644dc48fca95bbcb7cc513c6345be15d1b4 | judegarcia30/cvx_python101 | /02_integer_float.py | 910 | 4.40625 | 4 | # Integers are whole numbers
# Floats are decimal numbers
num = 3
num_float = 3.14
print(type(num))
print(type(num_float))
# Arithmetic Operators
# Addition: 3 + 2
# Subtraction: 3 - 2
# Multiplication: 3 * 2
# Division: 3 / 2
# Floor Division: 3 // 2
# Exponent: 3 ** 2
# Modulus: ... | true |
0e3f7d61c853088014a4c90cca82f09e08b7fc6a | Aphinith/Python101 | /dataTypes/loops.py | 469 | 4.59375 | 5 | # example of for loop
item_list = [1, 2, 3, 4, 5]
# for item in item_list:
# print(item)
# example of while loop
i = 1
# while i < 5:
# print('This is the value of i: {}'.format(i))
# i = i +
# examples of using range
first_range = list(range(0,10))
# print(first_range)
# for x in range(0,20):
# print('test... | true |
f0ec0a36fef58a10d02dae1cb042a156cc0248b2 | zakaleiliffe/IFB104 | /Week Work/Week 3/IFB104-Lecture03-Demos/01-stars_and_stripes.py | 2,566 | 4.3125 | 4 | #---------------------------------------------------------------------
#
# Star and stripes - Demo of functions and modules
#
# To demonstrate how functions can be used to structure code
# and avoid duplication, this program draws the United States
# flag. The U.S. flag has many duplicated elements -
# the repeated st... | true |
f2ed50358ac9a0e776a08353f5fcb47e43c33416 | zakaleiliffe/IFB104 | /Week Work/week 10/BUilding IT/Questions/2-alert_print_date.py | 2,393 | 4.59375 | 5 | #---------------------------------------------------------
#
# Alert date printer
#
# The following function accepts three positive
# numbers, expected to denote a day, month and year, and
# prints them as a date in the usual format.
#
# However, this function can be misused by providing
# numbers that don't form a val... | true |
281669198fd194e77dc2380c416d6ffb32d76c68 | zakaleiliffe/IFB104 | /Week Work/Week 4/Building IT Systems/IFB104-Lecture04-Demos/5-keyboard_input.py | 781 | 4.3125 | 4 | # Keyboard input
#
# This short demo highlights the difference between Python's raw_input
# and input functions. Just run this file and respond to the prompts.
text = raw_input('Enter some alphabetic text: ')
print 'You entered "' + text + '" which is of type', type(text)
print
number = raw_input('Enter a number: ')
... | true |
4c51cbab748aa26bdab3322a4427a9b097672e6b | zakaleiliffe/IFB104 | /Week Work/WEEK 6/Building IT systems/Week06-Questions/1-line_numbering.py | 1,893 | 4.46875 | 4 | #----------------------------------------------------------------
#
# Line numbering
#
# Define a function which accepts one argument, the name of a
# text file and prints the contents of that file line by line.
# Each line must be preceded by the line number. For instance,
# the file 'joke.txt' will be printed as fol... | true |
0ebc0fa0ed1b48382ef36c87f6aab350e3f02636 | zakaleiliffe/IFB104 | /Week Work/week 2/Building IT systems/demo week 2/IFB104-Lecture02-Demos/3-draw_Pacman.py | 1,257 | 4.4375 | 4 | #---------------------------------------------------------------------
#
# Demonstration - Draw Pacman
#
# As an introduction to drawing using Turtle graphics, here we'll
# draw a picture of the pioneering computer games character, Pacman.
# (Why Pacman? Because he's easy to draw!)
#
# Observation: To keep the code sho... | true |
05bd4cd46abc7ac340def95d084dde7f997d65e0 | zakaleiliffe/IFB104 | /Week Work/week 2/Building IT systems/week 2 quetions/Week02-questions/Done/3_random_min_and_max.py | 2,344 | 4.4375 | 4 | #------------------------------------------------------------------------#
#
# Minimum and Maximum Random Numbers
#
# In this week's exercises we are using several pre-defined
# functions, as well as character strings and lists. As a simple
# exercise with lists, here you will implement a small program which
# generat... | true |
1fd51daff7b2075a7371b380abddb323ea3cba72 | zakaleiliffe/IFB104 | /Week Work/Week 3/Week03-questions/DONE/3_stars_and_stripes_reused.py | 1,891 | 4.3125 | 4 | #--------------------------------------------------------------------
#
# Stars and stripes reused
#
# In the lecture demonstration program "stars and stripes" we saw
# how function definitions allowed us to reuse code that drew a
# star and a rectangle (stripe) multiple times to create a copy of
# the United States fl... | true |
689cb7e9c11aedc04d083eadf29b2a1a5521bf10 | anantkaushik/algoexpert | /Binary-Search.py | 581 | 4.1875 | 4 | """
Problem Link: https://www.algoexpert.io/questions/Binary%20Search
Write a function that takes in a sorted array of integers as well as a target integer. The function should use the Binary Search algorithm
to find if the target number is contained in the array and should return its index if it is, otherwise -1.
""... | true |
95b94e2744fae0f5fc3554f57aa514f980bdbd17 | anantkaushik/algoexpert | /Two-Number-Sum.py | 718 | 4.25 | 4 | """
Problem Link: https://www.algoexpert.io/questions/Two%20Number%20Sum
Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum.
If any two numbers in the input array sum up to the target sum, the function should return them in an array, in sorted order.
If no ... | true |
3b94901914ba40d20a29f0b89b2c6e8b42bf2e8a | garimasilewar03/Python_Task | /9.py | 976 | 4.4375 | 4 | '''Write a program such that it asks users to “guess the lucky number”. If the correct number is guessed the program stops, otherwise it
continues forever.
number = input("Guess the lucky number ")
while 1:
print ("That is not the lucky number")
number = input("Guess the lucky number ")
Modify the... | true |
34f88b64105e960ae15d83589f7f808497d3e6e3 | Dansultan/python_fundamentals-master | /04_conditionals_loops/04_07_search.py | 358 | 4.28125 | 4 | '''
Receive a number between 0 and 1,000,000,000 from the user.
Use while loop to find the number - when the number is found exit the loop and print the number to the console.
'''
number = int(input("Please choose a number between 1 and 1,000,000 : "))
i = 0
while i <= 1000000:
i+=1
if i == number:
... | true |
05f89d81c140e24536a8370a3a9ba5faa6a0d2f1 | Dansultan/python_fundamentals-master | /04_conditionals_loops/04_01_divisible.py | 362 | 4.5 | 4 | '''
Write a program that takes a number between 1 and 1,000,000,000
from the user and determines whether it is divisible by 3 using an if statement.
Print the result.
'''
number = int(input("Please enter a number between 1 and 1,000,000,000 :"))
if number%3 == 0:
print("Your number is divisible by 3")
else:
... | true |
2430c5d0ad1b3c340be21963928f26b576552196 | acecoder93/python_exercises | /Week1/Day5/PhoneBook_App.py | 2,024 | 4.40625 | 4 | # Phone Book App
print ('Welcome to the latest version of hthe Electronic Phone Book')
print ('Please see the list below of all of the options that are available.')
print ('''Electronic Phone Book
---------------------
1. Look up an Entry
2. Set an entry
3. Delete an entry
4. L... | true |
76384fcd407b5d010b9bb56bac5f23c71aa45a0d | chloe-wong/leetcodechallenges | /088_Merge_Sorted_Array.py | 1,281 | 4.28125 | 4 | """
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing order.
The final sorted array should not be returned by the function, ... | true |
a5bfc3163002084e274f971292f7fd5fe51916b6 | sardar1023/myPyGround | /OOP_impl.py | 2,227 | 4.53125 | 5 | #Python is amazing language. You can also implement OOPs concepts through python
#Resource: https://www.programiz.com/python-programming/object-oriented-programming
####Creat a class object and method####
class Parrot:
species = "bird"
def __init__(self,name,age):
self.name = name
self.age =... | true |
99962d1c4eba31c6cc61e686fa475dc46c87699f | praveenkumarjc/tarzanskills | /loops.py | 250 | 4.125 | 4 | x=0
while x<=10:
print('x is currently',x)
print('x is still less than 10')
x=x+1
if x==8:
print('breaking because x==8')
break
else:
print('continuing....................................')
continue | true |
6996d908c879d262226ff1601ba70f714c861714 | Olb/python_call_analysis | /Task2.py | 2,634 | 4.15625 | 4 | """
Read file into texts and calls.
It's ok if you don't understand how to read files
"""
import csv
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
texts = list(reader)
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
calls = list(reader)
"""
TASK 2: Which telephone number spent the ... | true |
59858e66eb9e86f1503fe9afb90d1186226a569a | richardmanasseh/hort503 | /lpthw/ex4.py | 1,427 | 4.40625 | 4 | # Ex 4: Variables and Names
# Variables are "words" that hold a value
FRUIT = peach #
# The operand to the left of the = operator (FRUIT) is the name of the variable
# The operand to the right (peach) is the value stored in the variable.
# A variable is similar to the memory functionality found in most calc... | true |
6c3532589b88192fd0ff2b029cb0f9fd631aaf22 | richardmanasseh/hort503 | /lpthw/ex7.py | 940 | 4.1875 | 4 | # More Printing & Formatting
print("Mary had a little lamp.")
print("Its fleece was white as {}. ".format('snow'))
print("And everywhere that Mary went.")
print("." * 10) # Prints string (".") ten times
# By default python’s print() function ends with a newline, because it comes with a parameter called ‘end’.
# By def... | true |
9fed24a2a440c14883e062c59ea8d402a52e772c | richardmanasseh/hort503 | /lpthw/ex29.py | 2,422 | 4.25 | 4 | # What If
# At the end of each working day,the balance of a bank account is considered...
# IF the account is overdrawn, charges are applied to the account.
# So we ask the question: is the account overdrawn? Yes (=True) or No (=False)
# Algorithm:
# Step 1 Define your problem: we apply charges to a bank accoun... | true |
75bb09a361e33624f85c545e37210a78639f9d1b | richardmanasseh/hort503 | /Assignments/lpthw/Assignment02/ex13.py | 987 | 4.125 | 4 | from sys import argv
script, first, second, third = argv
# module sys is not imported, rather just argv has been imported as a variable.
# Python modules can get access to code from another module by importing the file/function using import
# sys = system library, contains some of the commands one needs in order to ... | true |
2a303f20dfe2844ea99580423d4e18af81d6c5ee | richardmanasseh/hort503 | /Assignments/lpthw/Assignment02/ex7.py | 968 | 4.3125 | 4 | print("Mary had a little lamp.")
print("Its fleece was white as {}. ".format('snow'))
print("And everywhere that Mary went.")
print("." * 10) # what'd that do? Prints string ten times
# By default python’s print() function ends with a newline.
# # Python’s print() function comes with a parameter called ‘end’. By defau... | true |
a18a42ff4815c6954e5c4cdf8ea1a172f7d16cd4 | richardmanasseh/hort503 | /Assignments/Assignment04/ex21.py | 1,115 | 4.34375 | 4 | # Functions Can Return Something
# The print() function writes, i.e., "prints", a string in the console.
# The return statement causes your function to exit and hand back a value to its caller.
def add(a, b): # this (add) function is called with two parameters: a and b
print(f"ADDING {a} + {b}") # we print what our... | true |
eaba342178fd0cd9efd60ed6816a213412396edf | richardmanasseh/hort503 | /lpthw/ex33.py | 1,525 | 4.3125 | 4 | # While-Loops
# The while loop tells the computer to do something as long as the condition is met
# it's construct consists of a block of code and a condition.
# It works like this: " while this is true, do this "
i = 1 # intially i =1
while i <= 10: # loop condition, interpreter first checks if this condtion is tru... | true |
57a0315522093751af054ca900fbd16c4ab30f8b | shruti310gautam/python-programming | /function.py | 291 | 4.25 | 4 | #You are given the year, and you have to write a function to check if the year is leap or not.
def is_leap(year):
leap = False
if (year%4 == 0 and year%100 != 0) or (year%400 == 0) :
leap = True
return leap
#Sample Input=1990
#Sample Output=False
| true |
f485c5a58c0774d0ef5ec230ebf62361849d7a3f | wgatharia/csci131 | /5-loops/exercise_3.2.py | 411 | 4.40625 | 4 | """
File: exercise_3.2.py
Author: William Gatharia
This code demonstrates using a while loop.
"""
#loop and print numbers from 1 to 10 using a while loop
number = 1
while True:
print(number)
#increment number
#short hand for increasing number by 1
#number += 1
number = number + 1
#... | true |
08ef8f971812f815cf41a5b56050eb3bfeaf3917 | abdullaheemss/abdullaheemss | /My ML Projects/Data Visualization Exercises/01 - Understanding plotting.py | 626 | 4.125 | 4 | # ---------------------------------------------------------
# Understand basics of Plotting
# ---------------------------------------------------------
# Import pyplot from matplotlib
import matplotlib.pyplot as plt
# Create data to plot
x_days = [1,2,3,4,5]
y_price1 = [9,9.5,10.1,10,12]
y_price2 = [11,12,... | true |
ab8f166f68cb1bb13fa24aa3fe0d140809f6f5bf | webclinic017/data-pipeline | /linearRegression/lrSalesPredictionOnAddData.py | 1,026 | 4.375 | 4 | # https://towardsdatascience.com/introduction-to-linear-regression-in-python-c12a072bedf0
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import statsmodels.formula.api as smf
# Import and display first five rows of advertising dataset
advert = pd.read_csv('advertising.csv')
print(advert.h... | true |
e84d6844fa2d7c63fa300054a797152dffe3b322 | adarsh161994/python | /part 2.py | 811 | 4.40625 | 4 | # Addition of strings
# stri = "My name is"
# name = " Adarsh"
# print(stri + name)
# How to make temp
# name1 = "ADARSH"
# name2 = "YASH"
# temp = "This is {} and {} is my best friend".format(name1, name2)
# print(temp)
# Now introducing 'f' string It is also doing same thing which we have done above.
# ITS also... | true |
95451780778a80ba364d857addb9e23ac67b856f | spradeepv/dive-into-python | /hackerrank/domain/artificial_intelligence/bot_building/bot_saves_princess.py | 2,769 | 4.3125 | 4 | """
Princess Peach is trapped in one of the four corners of a square grid. You
are in the center of the grid and can move one step at a time in any of the
four directions. Can you rescue the princess?
Input format
The first line contains an odd integer N (3 <= N < 100) denoting the size of
the grid. This is followed ... | true |
ccfe895e27c01f03f8a277528d35f306d89e56ea | spradeepv/dive-into-python | /hackerrank/domain/artificial_intelligence/bot_building/bot_clean_large.py | 2,103 | 4.40625 | 4 | """
In this challenge, you must program the behaviour of a robot.
The robot is positionned in a cell in a grid G of size H*W. Your task is
to move the robot through it in order to clean every "dirty" cells.
Input Format
The first line contians the position x and y of the robot.
The next line contains the height H a... | true |
7c54a3e4de30e706ff577367a5ed608d93b6233f | spradeepv/dive-into-python | /hackerrank/domain/python/sets/intro_mickey.py | 975 | 4.40625 | 4 | """
Task
Now, lets use our knowledge of Sets and help 'Mickey'.
Ms. Gabriel Williams is a botany professor at District College. One day, she asked her student 'Mickey' to compute an average of all the plants with distinct heights in her greenhouse.
Formula used:
Average=SumofDistinctHeightsTotalNumberofDistinctHeigh... | true |
3e09c61d5a62a3e00412522aa5e0895402696f87 | spradeepv/dive-into-python | /hackerrank/domain/python/built_in/any_or_all.py | 1,386 | 4.3125 | 4 | """
any()
This expression returns True if any element of the iterable is true.
If the iterable is empty, it will return False.
Code
----
any([1>0,1==0,1<0])
True
any([1<0,2<1,3<2])
False
all()
This expression returns True if all of the elements of the iterable are
true. If the iterable is empty, it will return Tr... | true |
abc4b59db59660232c5ee767870f41b686fe526b | spradeepv/dive-into-python | /hackerrank/domain/python/numpy/min_max.py | 1,838 | 4.5625 | 5 | """
Problem Statement
min
The tool min returns the minimum value along a given axis.
import numpy
my_array = numpy.array([[2, 5],
[3, 7],
[1, 3],
[4, 0]])
print numpy.min(my_array, axis = 0) #Output : [1 0]
print numpy.min(my_array, ax... | true |
7c5c86da342258cbe51310f7ef859ec7e25dc73c | spradeepv/dive-into-python | /hackerrank/domain/python/regex/validating-named-email.py | 1,589 | 4.4375 | 4 | """
Problem Statement
You are given N names and email addresses. Your task is to print the names
and email addresses if they are valid.
A valid email address follows the rules below:
- Email must have three basic components: username @ website name . extension.
- The username can contain: alphanumeric characters, -,.... | true |
33e672ec8d42bf4f655a9eb08d406108b041f025 | zuzanadostalova/The-Python-Bible-Udemy | /6_Section_Conditional_logic.py | 667 | 4.28125 | 4 | # 30. lesson - Future lesson overview
# 31. lesson - Booleans
# Boolean is not created through typing its value - we get it from doing logical comparison
print(2<3)
# Output: True
print(2>3)
# Output: False
print(type(2<3))
# Output: <class 'bool'>
# print(2 = 3)
# Output: Error - cannot assign to literal
print(2 ... | true |
0caac48689854309f5e867a07cd148287a9a376e | zuzanadostalova/The-Python-Bible-Udemy | /8_Section_For_loops.py | 1,918 | 4.46875 | 4 | # 50. lesson - For loops
# most useful loops
# "for" loops - variable (key) - changing on each cycle of the loop
# and iterable (students.keys()) - made up from elements
# In each cycle, the variable becomes the next value in the iterable
# operation on each value
# range function - set up number, create number iterabl... | true |
1ef901e075f7b922099badb7e1a62ea826317a21 | gidpfeffer/CS270_python_bootcamp | /2-Conditionals/2_adv.py | 866 | 4.21875 | 4 | """
cd into this directory
run using: python 2_adv.py
"""
a = 10
if a < 10:
print("a is less than 10")
elif a > 10:
print("a is greater than 10")
else:
print("a is 10")
# also could do
if a == 10:
print("a is 10")
# or
if a is 10:
print("a is 10")
# is checks for object equality where == does value equality
#... | true |
8a96f25f94b5f008c11075e2667f8b34ae850f04 | gidpfeffer/CS270_python_bootcamp | /4-Functions/2_optional_args.py | 979 | 4.3125 | 4 | """
cd into this directory
run using: python 2_optional_args.py
"""
def printName(firstName, lastName=""):
print("Hi, " + firstName + lastName)
# uses default lastname
printName("Gideon")
# uses passed in lastname
printName("Gideon", " Pfeffer")
def printNameWithAge(firstName, lastName="", age=25):
print("Hi, " ... | true |
07f33784f2e4962b190adc616d93048cac1f33ff | todorovventsi/Software-Engineering | /Programming-Fundamentals-with-Python/functions-exercises/03. Characters in Range.py | 424 | 4.1875 | 4 | def print_chars_in_between(char1, char2):
result = ""
if ord(char1) > ord(char2):
for char in range(ord(char2) + 1, ord(char1)):
result += chr(char) + " "
else:
for char in range(ord(char1) + 1, ord(char2)):
result += chr(char) + " "
return result
first_char = i... | true |
ad772b77b29d2c780c2361ed6041b3b8c63c0259 | todorovventsi/Software-Engineering | /Python-Advanced-2021/05.Functions-advanced-E/04.Negative_vs_positive.py | 444 | 4.15625 | 4 | def compare_negatives_with_positives(nums):
positives = sum(filter(lambda x: x > 0, nums))
negatives = sum(filter(lambda x: x < 0, nums))
print(negatives)
print(positives)
if positives > abs(negatives):
return "The positives are stronger than the negatives"
return "The negatives are stro... | true |
c1436658b05474f63d7b99cf949878a9e63b5c35 | keurfonluu/My-Daily-Dose-of-Python | /Solutions/42-look-and-say-sequence.py | 844 | 4.125 | 4 | #%% [markdown]
# A look-and-say sequence is defined as the integer sequence beginning with a single digit in which the next term is obtained by describing the previous term. An example is easier to understand:
#
# Each consecutive value describes the prior value.
# ```
# 1 #
# 11 # one 1's
# 21 # two 1's
#... | true |
104cf3da661d2a8b84736b8312876bdcc912126c | jugshaurya/Learn-Python | /2-Programs-including-Datastructure-Python/5 - Stack/balanceParenthesis.py | 1,003 | 4.21875 | 4 | '''
Balanced Paranthesis
Given a string expression, check if brackets present in the expression are balanced or not. Brackets are balanced if the bracket which opens last, closes first.
You need to return true if it is balanced, false otherwise.
Sample Input 1 :
{ a + [ b+ (c + d)] + (e + f) }
Sample Output 1 :
true
S... | true |
67601147a8b88309baf61fdc1f5f81a769b8dc0c | solomonbolleddu/LetsUpgrade--Python | /LU Python Es Day-4 assignment.py | 1,471 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# # Assignment - 4 Day - 4
# 1) write a program to find all the occurences of the substring in the given string along with the index value
# I have used list comprehension + startswith() to find the occurences ***
# In[2]:
a=input("Enter The String\n")
b=input("Enter The Subs... | true |
eb64252481f0ed81477e05e82455d7109655f57f | decareano/python_repo_2019 | /else_if_testing.py | 408 | 4.25 | 4 | people = 30
cars = 40
buses = 15
if cars > people:
print("we should take the cars.")
elif cars < people:
print("we should not take the cars")
else:
print("dont know what to do")
if buses > cars:
print("too many buses")
elif buses < cars:
print("maybe we can take the buses")
else:
print("still cannot decide")
i... | true |
79f4733b669473de0a81c2b90fce55c4d965fcb1 | Kulsoom-Mateen/Python-programs | /abstract_method.py | 608 | 4.15625 | 4 | class Book():
def __init__(self,title,author):
self.title=title
self.author=author
# @abstractmethod
def display(): pass
class MyBook(Book):
def __init__(self,title,author,price):
self.title=title
self.author=author
self.price=price
def display(self):
... | true |
e9649cb521f4196efde0276015cf6dd313084475 | JordanSiem/File_Manipulation_Python | /ExtractAllZipFolders.py | 1,640 | 4.34375 | 4 | import os
import zipfile
print("This executable is used to extract documents from zip folders. A new folder will be created with the zip folder "
"name + 1. This program will process through the folder structure and unzip all zip folders in subdirectories.")
print("")
print("Instructions:")
print("-First,... | true |
2dc01f62020a8487c74a689ba41d48c55914f913 | davidkellis/py2rb | /tests/basic/for_in2.py | 539 | 4.375 | 4 | # iterating over a list
print('-- list --')
a = [1,2,3,4,5]
for x in a:
print(x)
# iterating over a tuple
print('-- tuple --')
a = ('cats','dogs','squirrels')
for x in a:
print(x)
# iterating over a dictionary
# sort order in python is undefined, so need to sort the results
# explictly before comparing output... | true |
daecf43082ccdca104974cb6299a019c74572610 | LukeO1/HackerRankCode | /CrackingTheCodingInterview/MergeSortCountingInversions.py | 1,699 | 4.125 | 4 | #!/bin/python3
"""Count the number of inversions (swaps when A[i] > B[j]) while doing merge sort."""
import sys
#Use global variable to count number of inversions
count = 0
def countInversions(arr):
global count
split(arr)
return count
def split(arr):
#If arr has more than one element, then split
... | true |
b25c2afc65fc0e03da050bf3362a5cf04474214a | t-christian/Python-practice-projects | /characterInput.py | 2,249 | 4.34375 | 4 | # From http://www.practicepython.org/
# Create a program that asks the user to enter their name and their age.
# Print out a message addressed to them that tells them the year that they will turn 100 years old.
# Stupid library to actually get the date
# TODO: figure out how to properly use datetime
import datetime
#... | true |
7c9ec57ae7dc314826604b9eb864413053023db8 | githubflub/data-structures-and-algorithms | /heap_sort.py | 2,167 | 4.34375 | 4 | ''' 1. Create an unsorted list
2. print the unsorted list
2. sort the list
3. print the sorted list
'''
def main():
myList = [4, 3, 1, 0, 5, 2, 6, 3, 3, 1, 6]
print("HeapSort")
print(" in: " + str(myList))
# sort list
myList = heapSort(myList)
print("out: " + str(myList))
def he... | true |
e9e50f5f8f47e36df2d4e5eb562d4adf3f9f061b | Pavan7411/Revising_python | /mf.py | 1,880 | 4.25 | 4 |
def line_without_moving():
import turtle
turtle.forward(20)
turtle.backward(20)
def star_arm():
import turtle
line_without_moving()
turtle.right(360 / 5)
def hexagon():
import turtle #import turtle module for the below code to make sense
x=50 #length of polyg... | true |
83b109bf6219348908a8f0e43b2fab2f69348b4e | Pavan7411/Revising_python | /Loop_7.py | 519 | 4.625 | 5 | import turtle #import turtle module for the below code to make sense
turtle.shape("turtle") #changing the shape of the turtle from arrow to turtle
x=10 #size of circle
n=40 #n sided regular polygon
th = 360/n #th is the external angle made by sides
... | true |
73a12e7f11ed70feddd44a4cc22a0129dbf2980d | Pavan7411/Revising_python | /Loop_6.py | 395 | 4.40625 | 4 | import turtle #import turtle module for the below code to make sense
turtle.shape("turtle") #changing the shape of the turtle from arrow to turtle
x=40 #size of square
for j in range(36): #for loop for drawing multiple squares
for i in range(4): #for loop for drawing a squ... | true |
5c88f3c0963bc2ecfa8e0c550567a9d43c018dd1 | spencer-mcguire/Sprint-Challenge--Algorithms | /recursive_count_th/count_th.py | 1,118 | 4.34375 | 4 | '''
Your function should take in a single parameter (a string `word`)
Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters.
Your function must utilize recursion. It cannot contain any loops.
'''
def count_th(word):
# return how many times 'th' exists in a give... | true |
92b4f6d127a5ab6bd50f08c4c3d7b9c4ed1cc868 | ldorourke/CS-UY-1114 | /O'Rourke_Lucas_Polynomials.py | 1,647 | 4.15625 | 4 | '''
Lucas O'Rourke
Takes a second degree polynomial and prints out its roots
'''
import math
a = int(input("Please enter value of a: "))
b = int(input("Please enter value of b: "))
c = int(input("Please enter value of c: "))
if a is 0 and b is 0 and c is 0:
print("The equation has infinite infinite number of solut... | true |
a2180fb2c112c0f1914f9be93e6cd07c9834a261 | titoeb/python-desing-patterns | /python_design_patterns/factories/abstract_factory.py | 2,253 | 4.53125 | 5 | """The abstract Factory
The abstract factory is a pattern that is can be applied when the object creation becomes too convoluted.
It pushes the object creation in a seperate class."""
from __future__ import annotations
from enum import Enum
from abc import ABC
# The abstract base class.
class HotDrink(ABC):
def c... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.