blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
4c05bf6d559bd0275323dbdb217edc1a2208f59c | geekidharsh/elements-of-programming | /arrays/generate_primes.py | 613 | 4.1875 | 4 | # Take an integer argument 'n' and generate all primes between 1 and that integer n
# example: n = 18
# return: 2,3,5,7,11,13,17
def generate_primes(n):
# run i, 2 to n
# any val between i to n is prime, store integer
# remove any multiples of i from computation
primes = []
#generate a flag array for all elem... | true |
51a3ae2e607f52ab2c79c59344699e52030e1c15 | justindarcy/CodefightsProjects | /isCryptSolution.py | 2,657 | 4.46875 | 4 | #A cryptarithm is a mathematical puzzle for which the goal is to find the correspondence between letters and digits,
#such that the given arithmetic equation consisting of letters holds true when the letters are converted to digits.
#You have an array of strings crypt, the cryptarithm, and an an array containing the ma... | true |
9c01fc72c243846886a7e1f44e5a0ebcce008f7b | sgirimont/projecteuler | /euler1.py | 1,153 | 4.15625 | 4 | ###################################
# Each new term in the Fibonacci sequence is generated by adding the previous two terms.
# By starting with 1 and 2, the first 10 terms will be:
#
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#
# By considering the terms in the Fibonacci sequence whose values do not exceed four million,
... | true |
e9acdbfd9ab5a29c06f1e27abcd1d384611c5cf0 | chizhangucb/Python_Material | /cs61a/lectures/Week2/Lec_Week2_3.py | 2,095 | 4.21875 | 4 | ## Functional arguments
def apply_twice(f, x):
"""Return f(f(x))
>>> apply_twice(square, 2)
16
>>> from math import sqrt
>>> apply_twice(sqrt, 16)
2.0
"""
return f(f(x))
def square(x):
return x * x
result = apply_twice(square, 2)
## Nested Defintions
# 1. Every user-defined func... | true |
16021ebd861f8d23781064101d52eba228a6f800 | mldeveloper01/Coding-1 | /Strings/0_Reverse_Words.py | 387 | 4.125 | 4 | """
Given a String of length S, reverse the whole string
without reversing the individual words in it.
Words are separated by dots.
"""
def reverseWords(s):
l = list(s.split('.'))
l = reversed(l)
return '.'.join(l)
if __name__ == "__main__":
t = int(input())
for i in range(t):
string = str(i... | true |
0053bde8153d3559f824aed6a017c528410538ea | JaredD-SWENG/beginnerpythonprojects | /3. QuadraticSolver.py | 1,447 | 4.1875 | 4 | #12.18.2017
#Quadratic Solver 2.4.6
'''Pseudocode: The program is designed to solve qudratics. It finds it's zeros and vertex.
It does this by asking the user for the 'a', 'b', and 'c' of the quadratic.
With these pieces of information, the program plugs in the variables into the quadratic formula and the formula... | true |
c1b024fe6518776cbeaabb614ca1fa63813b02b7 | wellqin/USTC | /PythonBasic/base_pkg/python-06-stdlib-review/chapter-01-Text/1.1-string/py_02_stringTemplate.py | 1,422 | 4.1875 | 4 | ### string.Template is an alternative of str object's interpolation (format(), %, +)
import string
def str_tmp(s, insert_val):
t = string.Template(s)
return t.substitute(insert_val)
def str_interplote(s, insert_val):
return s % insert_val
def str_format(s, insert_val):
return s.format(**insert_val)
... | true |
988ab3ba48c2d279c3706a2f12224f3793182a14 | wellqin/USTC | /DesignPatterns/behavioral/Adapter.py | 1,627 | 4.21875 | 4 | # -*- coding:utf-8 -*-
class Computer:
def __init__(self, name):
self.name = name
def __str__(self):
return 'the {} computer'.format(self.name)
def execute(self):
return self.name + 'executes a program'
class Synthesizer:
def __init__(self, name):
self.name = name
... | true |
a47e31222de348822fbde57861341ea68a4fa5fb | Ph0tonic/TP2_IA | /connection.py | 927 | 4.15625 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
class Connection:
"""
Class connection which allow to link two cities, contains the length of this connection
"""
def __init__(self, city1, city2, distance):
""" Constructor
:param city1: City n°1
:param city2: City n°2... | true |
92e296b5132802978932b62ddab03030d636785d | elsandkls/SNHU_IT140_itty_bitties | /example_1_list.py | 1,593 | 4.34375 | 4 |
# Get our lists from the command line
# It's okay if you don't understand this right now
import sys
list1 = sys.argv[1].split(',')
list2 = sys.argv[2].split(',')
#
# Print the lists.
#
# Python puts '[]' around the list and seperates the items
# by commas.
print(list1)
print(list2)
#
# Note that this list has thre... | true |
7add89c47bb6e5b3a49504244acc952a91040d31 | MasudHaider/Think-Python-2e | /Exer-5-3(1).py | 555 | 4.21875 | 4 | def is_triangle(length1, length2, length3):
case1 = length1 + length2
case2 = length1 + length3
case3 = length2 + length3
if length1 > case3 or length2 > case2 or length3 > case1:
print("No")
elif length1 == case3 or length2 == case2 or length3 == case1:
print("Degenerate triangle")
... | true |
afc0ab954176bdcbbb49b4415431c49278c9628c | kchow95/MIS-304 | /CreditCardValidaiton.py | 2,340 | 4.15625 | 4 | # Charlene Shu, Omar Olivarez, Kenneth Chow
#Program to check card validation
#Define main function
def main():
input_user = input("Please input a valid credit card number: ")
#Checks if the card is valid and prints accordingly
if isValid(input_user):
print(getTypeCard(input_user[0]))
print("The number is valid"... | true |
7ba0531979d8aed9f9af85d74a83cd2b5120426f | PythonTriCities/file_parse | /four.py | 637 | 4.3125 | 4 | #!/usr/bin/env python3
'''
Open a file, count the number
of words in that file using a
space as a delimeter between character
groups.
'''
file_name = 'input-files/one.txt'
num_lines = 0
num_words = 0
words = []
with open(file_name, 'r') as f:
for line in f:
print(f'A line looks like this: \n{line}')
... | true |
d2fd477b8c9df119bccb17f80aceda00c61cd82d | Sai-Sumanth-D/MyProjects | /GuessNumber.py | 877 | 4.15625 | 4 | # first importing random from lib
import random as r
# to set a random number range
num = r.randrange(100)
# no of chances for the player to guess the number
guess_attempts = 5
# setting the conditions
while guess_attempts >= 0:
player_guess = int(input('Enter your guess : '))
# for checking ... | true |
dbef91a7ddfd4100180f9208c3880d9311e2c94c | Arlisha2019/HelloPython | /hello.py | 1,319 | 4.34375 | 4 | #snake case = first_number
#camel case =firstNumber
print("Hello")
#input function ALWAYS returns a String data type
#a = 10 # integer
#b = "hello" # String
#c = 10.45 # float
#d = True # boolean
#convert the input from string to int
#first_number = float(input("Enter first number: "))
#second_number = float(input("En... | true |
ac42e69bac982862edcbed8567653688ee07f186 | GaganDureja/Algorithm-practice | /Vending Machine.py | 1,686 | 4.25 | 4 | # Link: https://edabit.com/challenge/dKLJ4uvssAJwRDtCo
# Your task is to create a function that simulates a vending machine.
# Given an amount of money (in cents ¢ to make it simpler) and a product_number,
#the vending machine should output the correct product name and give back the correct amount of change.
# The... | true |
47f8c6b8f6c8b01f0bc66d998fdd4c039bf91572 | Tallequalle/Code_wars | /Task15.py | 728 | 4.125 | 4 | #A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, because it uses the letters A-Z at least once (case is irrelevant).
#Given a string, detect whether or not it is a pangram. Return True if it i... | true |
091718f2cf95ce96ff8d3aa2704068d25e650121 | wsargeant/aoc2020 | /day_1.py | 1,383 | 4.34375 | 4 | def read_integers(filename):
""" Returns list of numbers from file containing list of numbers separated by new lines
"""
infile = open(filename, "r")
number_list = []
while True:
num = infile.readline()
if len(num) == 0:
break
if "\n" in num:
num = num... | true |
08e800c3cdcbfaa6f37a0aa98863a39d8260242c | AsiakN/flexi-Learn | /sets.py | 1,880 | 4.34375 | 4 | # A set is an unordered collection with no duplicates
# Basic use of sets include membership testing and eliminating duplicates in lists
# Sets can also implement mathematical operations like union, intersection etc
# You can create a set using set() or curly braces. You can only create an empty set using the set(... | true |
330e62b9b6ff037ff06d0e9a1dc6aa3a930095f0 | Alfred-Mountfield/CodingChallenges | /scripts/buy_and_sell_stocks.py | 881 | 4.15625 | 4 | """
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design
an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
"""
def ma... | true |
35e9d5de6afa12398a59af95f454097f3231d4ad | SaikumarS2611/Python-3.9.0 | /Packages/Patterns_Packages/Symbols/Rectangle.py | 926 | 4.34375 | 4 | def for_rectangle():
"""Shape of 'Rectangle' using Python for loop """
for row in range(6):
for col in range(8):
if row==0 or col==0 or row==5 or col==7:
print('*', end = ' ')
else:
... | true |
b7cf0ad56f664cab16423ec3baeaea62603d29bb | claraqqqq/l_e_e_t | /102_binary_tree_level_order_traversal.py | 1,178 | 4.21875 | 4 | # Binary Tree Level Order Traversal
# Given a binary tree, return the level order traversal of its
# nodes' values. (ie, from left to right, level by level).
# For example:
# Given binary tree {3,9,20,#,#,15,7},
# 3
# / \
# 9 20
# / \
# 15 7
# return its level order traversal as:
# [
# [3],
# [... | true |
cdd09dafb35bc0077d004e332ab48436810224a7 | claraqqqq/l_e_e_t | /150_evaluate_reverse_polish_notation.py | 1,079 | 4.28125 | 4 | # Evaluate Reverse Polish Notation
# Evaluate the value of an arithmetic expression in Reverse Polish Notation.
# Valid operators are +, -, *, /. Each operand may be an integer or another expression.
# Some examples:
#
# ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
# ["4", "13", "5", "/", "+"] -> (4 + (13 / 5))... | true |
ec541b14059808cf538ba11ffa9645488d70f4f4 | BuseMelekOLGAC/GlobalAIHubPythonHomework | /HANGMAN.py | 1,602 | 4.1875 | 4 | print("Please enter your name:")
x=input()
print("Hello,"+x)
import random
words = ["corona","lung","pain","hospital","medicine","doctor","ambulance","nurse","intubation"]
word = random.choice(words)
NumberOfPrediction = 10
harfler = []
x = len(word)
z = list('_' * x)
print(' '.join(z), end='\n')
while Num... | true |
cc0b8ef1943eb8b6b5b42870be3387bbde4f8001 | MindCC/ml_homework | /Lab02/Question/lab2_Point.py | 2,008 | 4.46875 | 4 | # -*- coding: cp936 -*-
'''
ID:
Name:
'''
import math
class Point:
'''
Define a class of objects called Point (in the two-dimensional plane).
A Point is thus a pair of two coordinates (x and y).
Every Point should be able to calculate its distance
to any other Point once the second point is speci... | true |
d29faa39dec07a25caa6383e0ecbe35edebbb4c5 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/minimumDominoRotationsForEqualRow.py | 2,392 | 4.4375 | 4 | """
Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rota... | true |
1b399e72edc812253cacad330840ed59cf0194c9 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/diameterOfBinaryTree.py | 1,290 | 4.3125 | 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.
Example:
Given a binary tree
1
/ \
2 3
/ \
... | true |
f490e6054c9d90343cab89c810ca2c649d8138fe | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/mergeIntervals.py | 1,167 | 4.125 | 4 | """
Merge Intervals
Given a collection of intervals, merge all overlapping intervals.
Example 1:
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2:
Input: [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,... | true |
99e25be34833e876da74bb6f53a62edf745be9a5 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/sortedSquares.py | 2,053 | 4.25 | 4 | """
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.
Example 1:
Input: [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Example 2:
Input: [-7,-3,2,3,11]
Output: [4,9,9,49,121]
Note:
1 <= A.length <= 10000
-10000 <= A[i] <= 10... | true |
33e938d5592965fa2c772c5c958ced297ee18955 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/flipEquivalentBinaryTree.py | 1,531 | 4.1875 | 4 | """
Flip Equivalent Binary Trees
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.
Write a function that deter... | true |
302f7ed1d4569abaf417efddff2c2b1721146207 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/maxStack.py | 2,794 | 4.25 | 4 | """
Max Stack
Design a max stack that supports push, pop, top, peekMax and popMax.
push(x) -- Push element x onto stack.
pop() -- Remove the element on top of the stack and return it.
top() -- Get the element on the top.
peekMax() -- Retrieve the maximum element in the stack.
popMax() -- Retrieve the maximum element i... | true |
5851ff675353f950e8a9a1c730774a35ab54b8db | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/stringConversion.py | 2,321 | 4.25 | 4 | """
Given 2 strings s and t, determine if you can convert s into t. The rules are:
You can change 1 letter at a time.
Once you changed a letter you have to change all occurrences of that letter.
Example 1:
Input: s = "abca", t = "dced"
Output: true
Explanation: abca ('a' to 'd') -> dbcd ('c' to 'e') -> dbed ('b' to '... | true |
de1cdd7c24ce9e56af7baaf562ad915960eb246d | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/uniquePaths.py | 1,433 | 4.15625 | 4 | """
Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths ... | true |
e81fb3440413a2ca42df459fec604df7d2aad8b8 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/largestSubarrayLengthK.py | 1,764 | 4.1875 | 4 | """
Largest Subarray Length K
Array X is greater than array Y if the first non matching element in both
arrays has a greater value in X than Y.
For example:
X = [1, 2, 4, 3, 5]
Y = [1, 2, 3, 4, 5]
X is greater than Y because the first element that does not match is larger in X.
and if
A = [1, 4, 3, 2, 5] and K = 4... | true |
2b4e64d837993111fde673235c80dc26e3ded912 | AusCommsteam/Algorithm-and-Data-Structures-and-Coding-Challenges | /Challenges/reconstructItinerary.py | 2,112 | 4.375 | 4 | """
Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.
Note:
If there are multiple valid itineraries, you should ... | true |
768b7b2bb0dd863b28c6ff657a3819fc4ae6162a | akuks/Python3.6---Novice-to-Ninja | /Ch9/09-FileHandling-01.py | 634 | 4.21875 | 4 | import os
# Prompt User to Enter the FileName
fileName = str(input("Please Enter the file Name: "))
fileName = fileName.strip()
while not fileName:
print("Name of the File Cannot be left blank.")
print("Please Enter the valid Name of the File.")
fileName = str(input("Please Enter the file Name: "))
f... | true |
848ff8ae6cb99f3f6b768df53ebd4d9fd9486cfe | akuks/Python3.6---Novice-to-Ninja | /Ch8/08-tuple-01.py | 204 | 4.125 | 4 | # Create Tuple
tup = (1, 2, 3, "Hello", "World")
print(tup)
# Looping in Tuple
for item in tup:
print (item)
# in operator
b = 4 in tup
print(b)
# Not in Operator
b = 4 not in tup
print (b)
| true |
bbed894c316e17e8cdbde0ed2d0db28ddd6d2285 | pbscrimmage/thinkPy | /ch5/is_triangle.py | 1,108 | 4.46875 | 4 | '''
is_triangle.py
Author: Patrick Rummage
[patrickbrummage@gmail.com]
Objective:
1. Write a function is_triangl that takes three integers as
arguments, and prints either "yes" or "no" depending on
whether a triangle may be formed from the given lengths.
2. Write a function that promp... | true |
a3338b41d3399b462b32674111f28e465782f6f2 | abbye1093/AFS505 | /AFS505_U1/assignment3/ex16.py | 1,309 | 4.4375 | 4 | #reading and writing files
#close: closes the file, similar to file > save
#read: reads contents of files
#readline: reads just one readline
#truncate: empties the file
#write('stuff') : writes 'stuff' to file
#seek(0): moves the read/write location to the beginning of the files
from sys import argv
script,... | true |
72d72c40a3279d64be8b7677e71761aed1b7155f | ggggg/PythonAssignment- | /exchange.py | 452 | 4.1875 | 4 | # get currency
print('enter currency, USD or CAD:')
currency = input().upper()
# get the value
print('Enter value:')
value = float(input())
# usd
if (currency == 'USD'):
# make calculation and output result
print('The value in CAD is: $' + str(value * 1.27))
# cad
elif (currency == 'CAD'):
# make calculation an... | true |
efea3fc1186254cd2a2b40171114de6af466a8cd | angelaannjaison/plab | /15.factorial using function.py | 312 | 4.21875 | 4 | def fact(n):
f=1
if n==0:print("The factorial of ",n,"is 1")
elif(n<0):print("factorial does not exit for negative numbers")
else:
for i in range(1,n+1):
f=f*i
print("The factorial of ",n,"is",f)
n=int(input("To find factorial:enter a number = "))
fact(n) | true |
754c02472453ab001c18bb13f5118aa0851ada80 | angelaannjaison/plab | /17.pyramid of numbers.py | 258 | 4.15625 | 4 | def pyramid(n):
for i in range(1,n+1):#num of rows
for j in range(1,i+1):#num of columns
print(i*j,end=" ")
print("\n")#line space
n=int(input("To construct number pyramid:Enter number of rows and columns: "))
pyramid(n) | true |
e500b5ef5f72359ba07c06ed10ec2b3e12dabfb6 | angelaannjaison/plab | /to find largest of three numbers.py | 297 | 4.1875 | 4 | print("To find the largest among three numbers")
A = int(input("Enter first number = "))
B = int(input("Enter second number = "))
C = int(input("Enter third number = "))
if A>B and A>C:
print(A," is greatest")
elif B>C:
print(B," is greatest")
else:
print(C,"is greatest")
| true |
8e3aeedca99b9abff8282876fbf5b655c1f10a76 | mtouhidchowdhury/CS1114-Intro-to-python | /Homework 3/hw3q4.py | 787 | 4.46875 | 4 | #homework 3 question 4
#getting the input of the sides
a = float(input("Length of first side: "))
b = float(input("Length of second side: "))
c = float(input("Length of third side: "))
if a == b and b == c and a ==c :# if all sides equal equalateral triangle
print("This is a equilateral triangle")
elif ... | true |
e2836dded795cfd45e297f05d467e04c35901858 | mtouhidchowdhury/CS1114-Intro-to-python | /Homework 7/hw7q3.py | 1,710 | 4.1875 | 4 |
#importing module
import random
#generating a random number and assign to a variable
randomNumber = random.randint(1,100)
#set number of guesses to 0 and how many remain to 5
numberGuesses= 0
guessRemain = 5
#first guess
userGuess = int(input("please enter a number between 1 and 100: "))
# minus from guess ... | true |
a12107517ff64eb1332b2dcfcbe955419bc5d935 | kelvin5hart/calculator | /main.py | 1,302 | 4.15625 | 4 | import art
print(art.logo)
#Calculator Functions
#Addition
def add (n1, n2):
return n1 + n2
#Subtraction
def substract (n1, n2):
return n1 - n2
#Multiplication
def multiply (n1, n2):
return n1 * n2
#Division
def divide(n1, n2):
return n1 / n2
opperators = {
"+": add,
"-":substract,
"*": multiply,... | true |
36f1263ebdbaf546d5e6b6ad874a0f8fc51ef65a | andredupontg/PythonInFourHours | /pythonInFourHours.py | 1,628 | 4.1875 | 4 | # Inputs and Outputs
"""
name = input("Hello whats your name? ")
print("Good morning " + name)
age = input("and how old are you? ")
print("thats cool")
"""
# Arrays
"""
list = ["Volvo", "Chevrolet", "Audi"]
print(list[2])
"""
# Array Functions
"""
list = ["Volvo", "Chevrolet", "Audi"]
list.insert(1, "Corona")
list.remo... | true |
f4ac6f727eda468a18aaaeb59489940150419e63 | Tanushka27/practice | /Class calc.py | 423 | 4.125 | 4 | print("Calculator(Addition,Subtraction,Multiplication and Division)")
No1=input("Enter First value:")
No1= eval(No1)
No2= input("Enter Second value:")
No2= eval(No2)
Sum= No1+No2
print (" Sum of both the values=",Sum)
Diff= No1-No2
print("Difference of both values=",Diff)
prod= No1*No2
print("Product of both the values... | true |
9ab6fc2ba3ae33bc507d257745279687926d62d2 | khushbooag4/NeoAlgo | /Python/ds/Prefix_to_postfix.py | 1,017 | 4.21875 | 4 | """
An expression is called prefix , if the operator appears in the expression before the operands. (operator operand operand)
An expression is called postfix , if the operator appears in the expression after the operands . (operand operand operator)
The program below accepts an expression in prefix and outputs the cor... | true |
9adc4c2e16a6468b7c39231425c0c7f2a3b6f843 | khushbooag4/NeoAlgo | /Python/ds/Sum_of_Linked_list.py | 2,015 | 4.25 | 4 | """
Program to calculate sum of linked list.
In the sum_ll function we traversed through all the functions of the linked list and calculate
the sum of every data element of every node in the linked list.
"""
# A node class
class Node:
# To create a new node
def __init__(self, data):
self.data = data
... | true |
ca903edb902b818cd3cda5ad5ab975f12f99d467 | khushbooag4/NeoAlgo | /Python/search/three_sum_problem.py | 2,643 | 4.15625 | 4 | """
Introduction:
Two pointer technique is an optimization technique which is a really clever way of using
brute-force to search for a particular pattern in a sorted list.
Purpose:
The code segment below solves the Three Sum Problem. We have to find a triplet out of the
given li... | true |
8d08dac477e5b8207c351650fef30b64da52c64a | khushbooag4/NeoAlgo | /Python/math/roots_of_quadratic_equation.py | 1,544 | 4.34375 | 4 | ''''
This is the simple python code for finding the roots of quadratic equation.
Approach : Enter the values of a,b,c of the quadratic equation of the form (ax^2 bx + c )
the function quadraticRoots will calculate the Discriminant , if D is greater than 0 then it will find the roots and print them otherwise it will ... | true |
e88f786eb63150123d9aba3a3dd5f9309d825ca1 | khushbooag4/NeoAlgo | /Python/math/positive_decimal_to_binary.py | 876 | 4.59375 | 5 | #Function to convert a positive decimal number into its binary equivalent
'''
By using the double dabble method, append the remainder
to the list and divide the number by 2 till it is not
equal to zero
'''
def DecimalToBinary(num):
#the binary equivalent of 0 is 0000
if num == 0:
print('0000')
r... | true |
170fef88011fbda1f0789e132f1fadb71ebca009 | khushbooag4/NeoAlgo | /Python/cp/adjacent_elements_product.py | 811 | 4.125 | 4 | """
When given a list of integers,
we have to find the pair of adjacent
elements that have the largest product
and return that product.
"""
def MaxAdjacentProduct(intList):
max = intList[0]*intList[1]
a = 0
b = 1
for i in range(1, len(intList) - 1):
if(intList[i]*intList[i+1] > max):
... | true |
99f2401aa02902befcf1ecc4a60010bb8f02bc32 | khushbooag4/NeoAlgo | /Python/other/stringkth.py | 775 | 4.1875 | 4 | '''
A program to remove the kth index from a string and print the remaining string.In case the value of k
is greater than length of string then return the complete string as it is.
'''
#main function
def main():
s=input("enter a string")
k=int(input("enter the index"))
l=len(s)
#Check whether the ... | true |
a5336ab6b2ac779752cab97aee3dcca16237a4d7 | dkrajeshwari/python | /python/prime.py | 321 | 4.25 | 4 | #program to check if a given number is prime or not
def is_prime(N):
if N<2:
return False
for i in range (2,N//2+1):
if N%i==0:
return False
return True
LB=int(input("Enter lower bound:"))
UB=int(input("Enter upper bound:"))
for i in range(LB,UB+1):
if is_prime(i):
print(i... | true |
204a83101aee7c633893d87a111785c3884829de | dkrajeshwari/python | /python/bill.py | 376 | 4.125 | 4 | #program to calculate the electric bill
#min bill 50rupee
#1-500 6rupees/unit
#501-1000 8rupees/unit
#>1000 12rupees/unit
units=int(input("Enter the number of units:"))
if units>=1 and units<=500:
rate=6
elif units>=501 and units<=1000:
rate=8
elif units>1000:
rate=12
amount=units*rate
if amount<50:
amou... | true |
458273bb73e4b98f097fbb87cfa531f994f55fc7 | vaishnavi59501/DemoRepo1 | /samplescript.py | 2,635 | 4.59375 | 5 | #!/bin/python3
#this scipt file contains list,tuple,dictionary and implementation of functions on list,tuple and Dictionary
#list
#list is collection of objects of different types and it is enclosed in square brackets.
li=['physics', 'chemistry', 1997, 2000]
list3 = ["a", "b", "c", "d"]
print(li[1]) #accessing first ... | true |
46d85c6a471072788ab8ec99470f0b27e9d1939d | cscosu/ctf0 | /reversing/00-di-why/pw_man.py | 1,614 | 4.125 | 4 | #!/usr/bin/env python3
import sys
KEY = b'\x7b\x36\x14\xf6\xb3\x2a\x4d\x14\x19'
SECRET = b'\x13\x59\x7a\x93\xca\x49\x22\x79\x7b'
def authenticate(password):
'''
Authenticates the user by checking the given password
'''
# Convert to the proper data type
password = password.encode()
# We... | true |
438658b5f7165211e7ec5dec55b63097c5852ede | alshore/firstCapstone | /camel.py | 527 | 4.125 | 4 | #define main function
def main():
# get input from user
# set to title case and split into array
words = raw_input("Enter text to convert: ").title().split()
# initialize results variable
camel = ""
for word in words:
# first word all lower case
if word == words[0]:
word = word.lower()
# add word to re... | true |
33735735d54ebe3842fca2fa506277e2cd529734 | georgemarshall180/Dev | /workspace/Python_Play/Shakes/words.py | 1,074 | 4.28125 | 4 | # Filename:
# Created by: George Marshall
# Created:
# Description: counts the most common words in shakespeares complete works.
import string
# start of main
def main():
fhand = open('shakes.txt') # open the file to analyzed.
counts = dict() # this is a dict to hold the words and the number of them.
... | true |
ddbedd13893047ab7611fe8d1b381575368680a6 | ryanSoftwareEngineer/algorithms | /arrays and matrices/49_group_anagrams.py | 1,408 | 4.15625 | 4 | '''
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically
using all the original letters exactly once.
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["... | true |
57cd15146c5a663a0ccaa74d2187dce5c5dc6962 | PabloLSalatic/Python-100-Days | /Days/Day 2/Q6.py | 498 | 4.1875 | 4 | print('------ Q 6 ------')
# ?Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
# ?Suppose the following input is supplied to the program:
# ?Hello world
# ?Practice makes perfect
# *Then, the output should be:
# *HELLO WORLD
# *PRACT... | true |
7902ec6be552b5e44af3e0c73335acd52c7cb3e7 | 44858/lists | /Bubble Sort.py | 609 | 4.28125 | 4 | #Lewis Travers
#09/01/2015
#Bubble Sort
unsorted_list = ["a", "d", "c", "e", "b", "f", "h", "g"]
def bubble_sort(unsorted_list):
list_sorted = False
length = len(unsorted_list) - 1
while not list_sorted:
list_sorted = True
for num in range(length):
if unsorted_l... | true |
90b59d5607388d4f18382624219a9fcfd7c9cf17 | LorenzoY2J/py111 | /Tasks/d0_stairway.py | 675 | 4.3125 | 4 | from typing import Union, Sequence
from itertools import islice
def stairway_path(stairway: Sequence[Union[float, int]]) -> Union[float, int]:
"""
Calculate min cost of getting to the top of stairway if agent can go on next or through one step.
:param stairway: list of ints, where each int is a cost of ap... | true |
15242cc4f007545a85c3d7f65039678617051231 | LorenzoY2J/py111 | /Tasks/b1_binary_search.py | 841 | 4.1875 | 4 | from typing import Sequence, Optional
def binary_search(elem: int, arr: Sequence) -> Optional[int]:
"""
Performs binary search of given element inside of array
:param elem: element to be found
:param arr: array where element is to be found
:return: Index of element if it's presented in the arr, N... | true |
7941328e4cb2d286fefd935541e2dab8afde61c0 | SACHSTech/ics2o1-livehack---2-Maximilian-Schwarzenberg | /problem2.py | 771 | 4.59375 | 5 | """
-------------------------------------------------------------------------------
Name: problem2.py
Purpose: To check if the inputted sides form a triangle.
Author: Schwarenberg.M
Created: 23/02/2021
------------------------------------------------------------------------------
"""
# Welcome message
print("Welcome ... | true |
9b3495345e4f4ad9648dcca17a8288e62db1220e | sriniverve/Python_Learning | /venv/tests/conditions.py | 271 | 4.21875 | 4 | '''
This is to demonstrate the usage of conditional operators
'''
temperature = input('Enter the temperature:')
if int(temperature) > 30:
print('This is a hot day')
elif int(temperature) < 5:
print('This is a cold day')
else:
print('This is a pleasant day') | true |
1140a8dd58988892ecca96673ffe3d2c1bf44564 | sriniverve/Python_Learning | /venv/tests/guessing_number.py | 395 | 4.21875 | 4 | '''
This is an example program for gussing a number using while loop
'''
secret_number = 9
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:
guess_number = int(input('Guess a number: '))
guess_count += 1
if guess_number == secret_number:
print('You guessed it right. You Win!!!')
... | true |
01b3319010f240b6ddfdd0b5ae3e07f201a9a046 | sriniverve/Python_Learning | /venv/tests/kg2lb_converter.py | 285 | 4.21875 | 4 | '''
This program is to take input in KGs & display the weight in pounds
'''
weight_kg = input('Enter your weight in Kilograms:') #prompt user input
weight_lb = 2.2 * float(weight_kg) #1 kg is 2.2 pounds
print('You weight is '+str(weight_lb)+' pounds')
| true |
23d110cff79eb57616586da7f78c7ac6d4e7a957 | vmmc2/Competitive-Programming | /Sets.py | 1,369 | 4.4375 | 4 | #set is like a list but it removes repeated values
#1) Initializing: To create a set, we use the set function: set()
x = set([1,2,3,4,5])
z = {1,2,3}
#To create an empty set we use the following:
y = set()
#2) Adding a value to a set
x.add(3)
#The add function just works when we are inserting just 1 element into our ... | true |
768ce4a45879ad23c94de8d37f33f7c8c50dca24 | AmangeldiK/lesson3 | /kall.py | 795 | 4.1875 | 4 | active = True
while active:
num1 = int(input('Enter first number: '))
oper = input('Enter operations: ')
num2 = int(input('Enter second number: '))
#dict_ = {'+': 'num1 + num2', '-': 'num1 - num2', '*': 'num1 * num2', '/': 'num1 / num2'}
if oper == '+':
print(num1+num2)
elif oper == '-... | true |
230616616f10a6207b4a407b768afaabb846528a | SynthetiCode/EasyGames-Python | /guessGame.py | 744 | 4.125 | 4 | #This is a "Guess the number game"
import random
print('Hello. What is your nombre?')
nombre = input()
print('Well, ' + nombre + ', I am thining of a numero between Uno(1) y Veinte(20)')
secretNumber =random.randint(1,20)
#ask player 6 times
for guessesTaken in range(0, 6):
print ('Take a guess:' )
guess = int(inpu... | true |
fb038cc7201cd3302a5eeedf9fd86511d6ff2cf6 | mdanassid2254/pythonTT | /constrector/hashing.py | 422 | 4.65625 | 5 | # Python 3 code to demonstrate
# working of hash()
# initializing objects
int_val = 4
str_val = 'GeeksforGeeks'
flt_val = 24.56
# Printing the hash values.
# Notice Integer value doesn't change
# You'l have answer later in article.
print("The integer hash value is : " + str(hash(int_val)))
print("The stri... | true |
0e6b136b69f36b75e8088756712889eb45f1d24a | Kaden-A/GameDesign2021 | /VarAndStrings.py | 882 | 4.375 | 4 | #Kaden Alibhai 6/7/21
#We are learning how to work with strings
#While loop
#Different type of var
num1=19
num2=3.5
num3=0x2342FABCDEBDA
#How to know what type of date is a variable
print(type(num1))
print(type(num2))
print(type(num3))
phrase="Hello there!"
print(type(phrase))
#String functions
num=len(phrase)
print(p... | true |
f7aac03275b43a35f790d9698b94e76f93207e7d | abokareem/LuhnAlgorithm | /luhnalgo.py | 1,758 | 4.21875 | 4 | """
------------------------------------------
|Luhn Algorithm by Brian Oliver, 07/15/19 |
------------------------------------------
The Luhn Algorithm is commonly used to verify credit card numbers, IMEI numbers, etc...
Luhn makes it possible to check numbers (credit card, SIRET, etc.) via a control key (... | true |
f4e4beb1d2975fd523ca7dd744aa7a96e686373a | WeiyiDeng/hpsc_LinuxVM | /lecture7/debugtry.py | 578 | 4.15625 | 4 | x = 3
y = 22
def ff(z):
x = z+3 # x here is local variable in the func
print("+++ in func ff, x = %s; y = %s; z = %s") %(x,y,z)
return(x) # does not change the value of x in the main program
# to avoid confusion, use a different symbol (eg. u) instead of x in the function
pr... | true |
f0778146abc57271d1587461b9893289fd65dc86 | bedoyama/python-crash-course | /basics/ch4__WORKING_WITH_LISTS/2_first_numbers.py | 358 | 4.375 | 4 | print("range(1,5)")
for value in range(1, 5):
print(value)
print("range(0,7)")
for value in range(0, 7):
print(value)
print("range(7)")
for value in range(7):
print(value)
print("range(3,7)")
for value in range(3, 7):
print(value)
print("range(-1,2)")
for value in range(-1, 2):
print(value)
num... | true |
8b8e3c886a6d3acf6a0c7718919c56f354c3c912 | bedoyama/python-crash-course | /basics/ch5__IF_STATEMENTS/3_age.py | 338 | 4.15625 | 4 | age = 42
if age >= 40 and age <= 46:
print('Age is in range')
if (age >= 40) and (age <= 46):
print('Age is in range')
if age < 40 or age > 46:
print('Age is older or younger')
age = 39
if age < 40 or age > 46:
print('Age is older or younger')
age = 56
if age < 40 or age > 46:
print('Age is o... | true |
2b03e816c33cfdcfd9b5167de46fda66c7dda199 | angelavuong/python_exercises | /coding_challenges/grading_students.py | 981 | 4.125 | 4 | '''
Name: Grading Students
Task:
- If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
- If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
Example:
grade = 84 will be rounded to 85
grade = 29 will ... | true |
570b9f3e710d94baf3f4db276201a9c484da4a71 | angelavuong/python_exercises | /coding_challenges/count_strings.py | 573 | 4.125 | 4 | '''
Name: Count Sub-Strings
Task:
Given a string, S, and a substring - count the number of times the substring appears.
Sample Input:
ABCDCDC
CDC
Sample Output:
2
'''
def count_substring(string,sub_string):
counter = 0
length = len(sub_string)
for i in range(len(string)):
if (string[i] == sub_st... | true |
aa378a188bce0e97a0545221e65f148838b3650c | angelavuong/python_exercises | /coding_challenges/whats_your_name.py | 536 | 4.1875 | 4 | '''
Name: What's Your Name?
Task: You are given the first name and last name of a person on two different lines. Your task is to read them and print the following:
Hello <firstname> <lastname>! You just delved into python.
Sample Input:
Guido
Rossum
Sample Output:
Hello Guido Rossum! You just delved into python.
'... | true |
d5d229788bf6391a3be21f75c54166a1b836b3e4 | 6reg/pc_func_fun | /rev_and_normalized.py | 519 | 4.15625 | 4 | def reverse_string(s):
reversed = ""
for i in s:
reversed = i + reversed
return reversed
def normalize(s):
normalized = ""
for ch in s:
if ch.isalpha():
normalized += ch.lower()
return normalized
def is_palindrome(s):
normalized = normalize(s)
rev = reverse_... | true |
cd916150b60d80e1def43eb10aaafd65429badb1 | lumeng/repogit-mengapps | /data_mining/wordcount.py | 2,121 | 4.34375 | 4 | #!/usr/bin/python -tt
## Summary: count words in a text file
import sys
import re # for normalizing words
def normalize_word(word):
word_normalized = word.strip().lower()
match = re.search(r'\W*(\w+|\w\W+\w)\W*', word_normalized)
if match:
return match.group(1)
else:
return word_no... | true |
f65486941b6ee5852a4aaf2bf6547b7d5d863dd9 | blei7/Software_Testing_Python | /mlist/binary_search.py | 1,682 | 4.3125 | 4 | # binary_search.py
def binary_search(x, lst):
'''
Usage: The function applies the generic binary search algorithm to search if the value
x exists in the lst, and returns a list contains: TRUE/FAlSE depends on whether the x value has been found,
x value, and x position indice in list
Argume... | true |
612c8ca841d8da2fc2e8e00f1a14fb22126d1277 | sumanmukherjee03/practice-and-katas | /python/top-50-interview-questions/ways-to-climb-stairs/main.py | 2,336 | 4.1875 | 4 | # Problem : Given a staircase of n steps and a set of possible steps that we can climb at a time
# named possibleSteps, create a function that returns the number of ways a person can take to reach the
# top of the staircase.
# Ex : Input : n = 5, possibleSteps = {1,2}
# Output : 8
# Explanation : Possible ways ar... | true |
14adf897de38f2d27bc32c8bc7d298b9f1ffbbed | ChrisStreadbeck/Python | /learning_notes/lambdas.py | 440 | 4.1875 | 4 | #Lambda is a tool used to wrap up a smaller function and pass it to other functions
full_name = lambda first, last: f'{first} {last}'
def greeting(name):
print(f'Hi there {name}')
greeting(full_name('kristine', 'hudgens'))
#so it's basically a short hand function (inline) and it allows the name to be called
# si... | true |
f91112d5f2d441cb357b52d77aa72c74d586fc73 | Shady-Data/05-Python-Programming | /studentCode/Recursion/recursive_lines.py | 928 | 4.53125 | 5 | '''
3. Recursive Lines
Write a recursive function that accepts an integer argument, n. The function should display
n lines of asterisks on the screen, with the first line showing 1 asterisk, the second line
showing 2 asterisks, up to the nth line which shows n asterisks.
'''
def main():
# Get an intger... | true |
630e3b1afa907f03d601774fa4aec19c8ae1fbbb | Shady-Data/05-Python-Programming | /studentCode/cashregister.py | 1,718 | 4.3125 | 4 | '''
Demonstrate the CashRegister class in a program that allows the user to select several
items for purchase. When the user is ready to check out, the program should display a list
of all the items he or she has selected for purchase, as well as the total price.
'''
# import the cash register and retail item class mo... | true |
443db5f0cfbc98abc074444ad8fccdf4a891491c | Shady-Data/05-Python-Programming | /studentCode/CellPhone.py | 2,681 | 4.53125 | 5 | """
Wireless Solutions, Inc. is a business that sells cell phones and wireless service.
You are a programmer in the company’s IT department, and your team is designing a program to manage
all of the cell phones that are in inventory. You have been asked to design a class that represents
a cell phone. The data that sh... | true |
915a6111d78d3bd0566d040f9342ddb59239c467 | Shady-Data/05-Python-Programming | /studentCode/Recursion/recursive_printing.py | 704 | 4.46875 | 4 | '''
1. Recursive Printing
Design a recursive function that accepts an integer argument, n, and prints the numbers 1
up through n.
'''
def main():
# Get an integer to print numbers up to
stop_num = int(input('At what number do you want this program to stop at: '))
# call the recursive print number a... | true |
c4d39fadba7f479ce554198cd60c7ce4574c2d6b | Shady-Data/05-Python-Programming | /studentCode/Recursion/sum_of_numbers.py | 874 | 4.40625 | 4 | '''
6. Sum of Numbers
Design a function that accepts an integer argument and returns the sum of all the integers from 1 up
to the number passed as an argument. For example, if 50 is passed as an argument, the function will
return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum.
'''
de... | true |
96387763eafc4c2ee210c866e43f30ebd9fbb6b5 | Vinod096/learn-python | /lesson_02/personal/chapter_4/14_pattern.py | 264 | 4.25 | 4 | #Write a program that uses nested loops to draw this pattern:
##
# #
# #
# #
# #
number = int(input("Enter a number : "))
for r in range (number):
print("#", end="",sep="")
for c in range (r):
print(" ", end="",sep="")
print("#",sep="")
| true |
d4420e85272e424bdf66086eda6912615d805096 | Vinod096/learn-python | /lesson_02/personal/chapter_3/09_wheel_color.py | 1,617 | 4.4375 | 4 | #On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are
#as follows:
#• Pocket 0 is green.
#• For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered
#pockets are black.
#• For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered
#po... | true |
6411437fe4e73b46d8756a61d44f929a83c8dbf7 | Vinod096/learn-python | /lesson_02/personal/chapter_6/03_line_numbers.py | 386 | 4.34375 | 4 | #Write a program that asks the user for the name of a file. The program should display the
#contents of the file with each line preceded with a line number followed by a colon. The
#line numbering should start at 1.
count = 0
file = str(input("enter file name :"))
print("file name is :", file)
content = open(file, 'r'... | true |
b09e8d2cd18d517e904889ecf2809f1f1392e7eb | Vinod096/learn-python | /lesson_02/personal/chapter_4/12_population.py | 1,321 | 4.71875 | 5 | #Write a program that predicts the approximate size of a population of organisms. The
#application should use text boxes to allow the user to enter the starting number of organisms,
#the average daily population increase(as a percentage), and the number of days the
#organisms will be left to multiply. For example, assu... | true |
f5a8090ff67003d79e2f431256d4b277381c8dd7 | Vinod096/learn-python | /lesson_02/personal/chapter_3/01_Day.py | 757 | 4.40625 | 4 | #Write a program that asks the user for a number in the range of 1 through 7. The program
#should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday,
#3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should
#display an error message if the user enters a number tha... | true |
7feb19a5121eeb321f0b2a187852cae0becb4c4f | Vinod096/learn-python | /lesson_02/personal/chapter_2/ingredient.py | 1,022 | 4.40625 | 4 | total_no_of_cookies = 48
cups_of_sugar = 1.5
cups_of_butter = 1
cups_of_flour = 2.75
no_of_cookies_req = round(int(input("cookies required :")))
print("no of cookies required in roundup : {0:2f} ".format(no_of_cookies_req))
req_sugar = (no_of_cookies_req / total_no_of_cookies) * cups_of_sugar
print("no of cups of suga... | true |
dd42d5e406efde3b62d76588eeb37a7470edafe8 | Vinod096/learn-python | /lesson_02/personal/chapter_8/01_initials.py | 463 | 4.5 | 4 | #Write a program that gets a string containing a person’s first, middle, and last names,and then display their first, middle, and last initials. For example, if the user enters John William Smith the program should display J. W. S.
first_name = str(input("Enter First Name : "))
middle_name = str(input("Enter Middle N... | true |
ad1f65388986962de297bba5f1219809634fccd3 | Vinod096/learn-python | /lesson_02/personal/chapter_4/09_ocean.py | 380 | 4.28125 | 4 | #Assuming the ocean’s level is currently rising at about 1.6 millimeters per year, create an
#application that displays the number of millimeters that the ocean will have risen each year
#for the next 25 years.
rising_oceans_levels_per_year = 1.6
years = 0
for i in range (1,26):
years = rising_oceans_levels_per_ye... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.