blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
273a89d8a1cdacd050949614756f6f6f54722eee | L0ganhowlett/Python_workbook-Ben_Stephenson | /65 Compute the Perimeter of a Polygon.py | 505 | 4.25 | 4 | #65: Compute the Perimeter of a Polygon
import math
dist=lambda x,y,w,z:float(math.sqrt(((w-x)**2)+((z-y)**2)))
perimeter=0.0
x=input("Enter the x-coordinate:")
y=input("Enter the y-coordinate:")
w=x
z=y
while x!="":
a=x
b=y
x=input("Enter the x-coordinate:")
y=input("Enter the y-coordinate:... | false |
802259a7fc26d6bb9eeb002c75cbb489d34e5b31 | L0ganhowlett/Python_workbook-Ben_Stephenson | /49 Ritcher Scale.py | 940 | 4.21875 | 4 | # 49 Ritcher Scale
a = float(input("Enter the magnitude: "))
if a < 2.0:
print("Magnitude of ",a," earthquake is considered Micro earthquake")
elif 2.0 <= a < 3.0:
print("Magnitude of ",a," earthquake is considered Very minor earthquake")
elif 3.0 <= a < 4.0:
print("Magnitude of ",a," earthquake is ... | false |
84cf3eee10b3ffd05bcb2930ee134646da979cb7 | moisotico/Python-excercises | /excersices/lists/queue_linked_list.py | 1,352 | 4.375 | 4 | # Represents the node of list.
class Node:
def __init__(self, data):
self.data = data
self.next = None
class CreateList:
# Declaring tle pointer as null.
def __init__(self):
self.head = Node(None)
self.tail = Node(None)
# method to add element to linked list queue
... | true |
de1cc3bf61e9fea5b0f108804f7a0b45da0ba4dc | python240419/07.06.2019 | /foreach.py | 317 | 4.125 | 4 |
names = ['yossi', 'dana','orli', 'yosef']
print(names)
# for loop
# foreach name in named do
#for name in reversed(names):
for name in names:
#print(f'{name} is type {type(name)}')
if name == 'orli':
break # exit the loop
print(f'{name}')
if name == 'dana':
print('this is dana')
| false |
69f281633daafdebdb472d1db228660eb9344164 | Ndkkqueenie/hotel-guest | /guest.py | 2,502 | 4.59375 | 5 | #Let's say we have a text file containing current visitors at a hotel.
# We'll call it, guests.txt. Run the following code to create the file.
# The file will automatically populate with each initial guest's first name on its own line.
guests = open("guests.txt", "w")
initial_guests = ["Bob", "Andrea", "Manuel", "Pol... | true |
a1a5b7049dbf72c07391b584fcc43609393d9636 | eclairsameal/TQC-Python | /第4類:進階控制流程/PYD408.py | 243 | 4.125 | 4 | even = 0
odd = 0
for i in range(10):
n = int(input())
if n%2==0:
even+=1
else:
odd+=1
print("Even numbers: {}".format(even))
print("Odd numbers: {}".format(odd))
"""
Even numbers: _
Odd numbers: _
""" | false |
21edc9be5705343c347caaba952e3c26da5f6781 | eclairsameal/TQC-Python | /第2類:選擇敘述/PYD202.py | 226 | 4.40625 | 4 | x = int(input())
if x%3==0 and x%5==0:
print(x,"is a multiple of 3 and 5.")
elif x%3==0:
print(x,"is a multiple of 3.")
elif x%5==0:
print(x,"is a multiple of 5.")
else:
print(x,"is not a multiple of 3 or 5.") | true |
594d46ab05cf2c2aa160bc7a331ee448f19b69fc | rdsim8589/holbertonschool-higher_level_programming | /0x06-python-test_driven_development/4-print_square.py | 458 | 4.28125 | 4 | #!/usr/bin/python3
"""
This is the "Print Square" module
The Print Square module supplies the simple function\
to print a square of # of a size
"""
def print_square(size):
"""
Return the square of # of size x size
"""
if not isinstance(size, int):
raise TypeError("size must be an integer")
... | true |
f28d2166344842ed4018a25f78aa1accfa9bd03e | zabilsabri/Sum-Of-Odd-Series | /Odd Number Sequence.py | 321 | 4.125 | 4 | _foundby_ = "zabilsabri"
n = 9 # YOUR ODD NUMBER INPUT
answer = 1
if n % 2 == 0: # CHECK IF YOUR INPUT NUMBER ODD OR EVEN
print("ODD")
else:
for i in range(n):
if i % 2 != 0: # OMIT ALL EVEN NUMBER
answer = answer + i
answer += 2 # ADD 2 EVERY LOOPING
print(answer... | false |
702df8cff2c17e2685aac36a4384b8b499bf7e05 | bhavikjadav/Python_Crash_Course_Eric_Matthes_Chapter_4 | /4.9_Cube Comprehension.py | 273 | 4.25 | 4 | #!/usr/bin/env python
# coding: utf-8
# # 4-9. Cube Comprehension: Use a list comprehension to generate a list of the first 10 cubes.
# In[1]:
# This is call Comprehension of a list.
cubes = [value**3 for value in range(1, 10)]
# In[2]:
print(cubes)
# In[ ]:
| true |
14732573cc07a9067e3362c35343bd1755b4d707 | LogeshRe/Python-Utilities | /Filelist.py | 810 | 4.1875 | 4 | # This Program is to get the List of files in a folder
# On Running it opens file explorer.
# Choose the folder you want.
# Once again explorer opens.
# Give a name for file and save it as txt.
# The file contains the list of all files in the folder.
# 23/12/18
from tkinter.filedialog import askdirectory
from tkin... | true |
d3c8c439fcecd822f0c85be872905a7a8200ce5b | lingsitu1290/code-challenges | /random_problems.py | 1,818 | 4.1875 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# Write a program that asks the user to enter 10
# words, one at a time. The program should then
# display all 10 words in alphabetical order. Write
# this program using a loop so that you don't have to
# write any additional lines of code if you were to
# change the prog... | true |
53d90eeda0e524a06cc008b24fda1a8343c78131 | lingsitu1290/code-challenges | /three_int_sum_to_zero.py | 1,428 | 4.3125 | 4 | # Pixlee Whiteboarding
def three_int_sum_to_zero1(lst):
"""
Determine if any 3 integers in an array sum to 0.
#>>> three_int_sum_to_zero1([0,1,2,-1,3,5,2,-2])
#True
#>>> three_int_sum_to_zero1([2,3,4,5,-1,2])
#False
>>> three_int_sum_to_zero1([2,0,1,9,0])
False
"""
for i, n... | false |
f4b55e2ea2389bf8dd460a526c99ce0ba16225cf | lingsitu1290/code-challenges | /flip_the_bit.py | 1,552 | 4.15625 | 4 | # Various ways to return 1 if 0 is given and return 0 if 1 is given
def flip_the_bit(num):
"""
>>> flip_the_bit(1)
0
>>> flip_the_bit(0)
1
"""
if num == 0:
return 1
else:
return 0
#switch, break, return
def flip_the_bit(num):
"""
>>> flip_the_bit(1)
0
... | true |
3dd89365fb041b8a6f6581059c8fd761a6c3036e | ARUN14PALANI/Python | /PizzaOrder.py | 1,051 | 4.1875 | 4 | print("Welcome to AKS Pizza Stall!")
pizza_size = input(str("Please mention your pizza size 'S/M/L': "))
add_peproni = input("Do you need add peproni in your pizza? Mention (y/n): ")
add_cheese = input("Do you need add extra cheese in your pizza? Mention (y/n): ")
bill_value = 0
print(add_peproni.lower())
print(pizza_s... | true |
b42b11517300a0271107d0206f050dde24ca3bf1 | ChiragTutlani/DSA-and-common-problems | /Algorithms/dijkstra_algorithm.py | 1,565 | 4.1875 | 4 | # Three hash tables required
# 1. Graph
# 2. Costs
# 3. Path/Parent Node
graph = {
"start":{
"a":6,
"b":2
},
"a":{
"finish":1
},
"b":{
"a":3,
"finish":5
},
"finish":{}
}
# print(graph)
inf = float("inf")
costs = {
"a": 6,
... | true |
96254fbc29edc870dbf9e6db304f997f0147ef93 | mjuniper685/LPTHW | /ex6.py | 1,156 | 4.375 | 4 | #LPTHW Exercise 6 Strings and Text
#create variable types_of_people with value of 10 assigned to it
types_of_people = 10
#Use string formatting to add variable into a string stored in variable x
x = f"There are {types_of_people} types of people."
#create variable binary and assign it a string
binary = "binary"
#create ... | true |
560e6d3b7fd09e72105961df949917c6198ae7de | henriqueotogami/microsoft-learn-studies | /Atributos da Classe - Aula 39/main.py | 584 | 4.40625 | 4 | class A:
#Variável de classe ou atributo da classe
vc = 123
#criando objeto, ou melhor, intanciando a classe
a1 = A()
a2 = A()
#Acessando o atributo da classe criado em cada objeto
print(a1.vc)
print(a2.vc)
#Acessando o atributo da classe na estrutura da classe
print(A.vc)
#Alterando "de fora" o valor do a... | false |
6b92d4b843d9754a6206e9d93e5348a769719895 | Oskorbin99/Learn_Python | /Other/Lamda.py | 520 | 4.15625 | 4 | # Simple lambda-functions
# add = lambda x, y: print(x+y)
# add(5, 4)
# But it is not good because do not assign a lambda expression, use a def
def add_def(x, y): print(x+y)
add_def(5, 4)
# Use lambda for sort
tuples = [(1, 'd'), (2, 'b'), (4, 'a'), (3, 'c')]
print(sorted(tuples, key=lambda x: x[1]))
p... | true |
162e1267cc8ad48fd285455eca25720328adfa09 | Oskorbin99/Learn_Python | /Сlass/Variable.py | 500 | 4.1875 | 4 | class Dog:
num_legs = 4 # <- Переменная класса
def __init__(self, name):
self.name = name # <- Переменная экземпляра
jack = Dog('Джек')
jill = Dog('Джилл')
print(jack.name, jill.name)
print(jack.num_legs, jill.num_legs)
Dog.num_legs = 3
print(jack.num_legs, jill.num_legs)
# True wa... | false |
eab8aa205f7463c74d64ecf91d1d1c053deda762 | barmalejka/Advanced_Python | /hw2/pt1.py | 598 | 4.21875 | 4 | import operator
def calc(x, y, operation):
try:
x = float(x)
y = float(y)
except ValueError:
return 'Inputs should be numbers. Please try again.'
operations = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv}
if ... | true |
985440717e2e19291a05f9afe5b9f7bda9d5ccfa | manas1410/Python-addition | /Addition.py | 419 | 4.15625 | 4 | #program to find the addition of two numbers
#takes the input of 1st number from the user and stores it in num1
num1 = int(input("Please enter your number num1:"))
#takes the input of 2nd number from thwe user and stores it in num2
num2 = int(input("Please enter your number num2:"))
#stores the addition of two numb... | true |
a5d29c3be92b2eb4bc8cd2f2fbf8faf8cb37f0d6 | dorayne/Fizzbuzz | /fizzbuzz.py | 1,595 | 4.125 | 4 | #!/usr/bin/env python
# initialize default values for variables
start_c = 1
end_d = 101
div_a = 3
div_b = 5
def error_check(test):
# convert input to integer, exit program if input is not a number
try:
tested = int(test)
return tested
except:
print "Invalid input, please try again ... | true |
829259503dfa0153bcd851bb901474d436a595ff | KRSatpute/GreyAtom-Assignments | /25Nov2017/map_func_run.py | 1,128 | 4.125 | 4 | """
Write a higher order generalized mapping function that takes a list and
maps every element of that list into another list and return that list
ex:
i) Given a list get a new list which is squares of all the elemments of the
list
ii) Given a list get a list which has squares of all the even numbers and
cubes of all... | true |
4bb91fc31df7ba6caf08dc214bae1132bccd3be0 | C-CCM-TC1028-111-2113/homework-2-SofiaaMas | /assignments/04Maximo/src/exercise.py | 354 | 4.125 | 4 | def main():
#escribe tu código abajo de esta línea
num1=int(input('Inserta el primer número'))
num2=int(input('Inserta el segundo número'))
num3=int(input('Inserta el tercer número'))
if num2<num1>num3:
print(num1)
elif num1<num2>num3:
print(num2)
elif num1<num3>num2:
print(mun3)
pass
if __na... | false |
fb3abdd0cd80c80246907fdccc11fa1c2c3af742 | sanjanprakash/Hackerrank | /Languages/Python/Python Functionals/map_lambda.py | 367 | 4.1875 | 4 | cube = lambda x: x*x*x # complete the lambda function
def fibonacci(n):
# return a list of fibonacci numbers
arr = []
if (n > 0) :
if (n >= 2) :
arr = [0,1]
while (n > 2) :
arr.append(arr[-1] + arr[-2])
n -= 1
else :
arr =... | true |
2663bd81905b0b3d0b5a0d1a69acc6c190456821 | DanielMSousa/beginner-projects | /1. BMI Calculator/Calculadora IMC.py | 867 | 4.1875 | 4 | """
Created on Thu Jun 17 21:54:11 2021
@author: daniel
"""
print('###################################################')
print(' BMI Calculator ')
print('###################################################')
print()
print("This program can't substitute any doctor or health profession... | true |
db190d1765bb1b92e6d41c918c351c1ca5a661bc | jwsander/CS112-Spring2012 | /hw08/basic_funcs.py | 1,637 | 4.4375 | 4 | #!/usr/bin/env python
# Create a greeter
def greeter(name):
if name == str(name):
print "hello,", name.lower()
elif name == int(name):
print "hello,", name
#User Input (Optional):
#name = raw_input("What's your name?")
#greeter(name)
# Draw a box
def box(w,h):
#Limitations
if w =... | false |
d663e2af3f922141c364ecc842dfb337b6f1ea9a | brianpendleton-zz/anagram | /scripts/find_anagrams.py | 674 | 4.25 | 4 | """
Script to find anagrams given an input word and a filepath to a text file of
known words.
Argparse or Optparse could be used, but no current requirements for optional
flags or features to the script.
"""
from anagram import find_anagrams, load_words_file
import sys
def main(word, filepath):
valid_words = lo... | true |
2bd8767bf274053e614965265ac628b3a5c255f8 | colingdc/project-euler | /4.py | 489 | 4.15625 | 4 | # coding: utf-8
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
# Find the largest palindrome made from the product of two 3-digit numbers.
def is_palindrome(n):
return str(n) == str(n)[::-1]
palindromes = []
for i in range(1... | true |
e09b68fe95f607bf91a6aae1bddbec12185e7ff0 | antdevelopment1/dictionaries | /word_summary.py | 656 | 4.3125 | 4 | # Prints a dictionary containing the tally of how many
# times each word in the alphabet was used in the text.
# Prompts user for input and splits the result into indiviual words.
user_input = input("Please provide a string to be counted by words: ").split(" ")
diction = {} # Creates an empty dictionary.
for word i... | true |
b117c4ffe9a092727d29ec759efb4b99b1ef3944 | ivaben/lambdata | /lambdata_maltaro/df_utils.py | 578 | 4.40625 | 4 | """
utility functions for working with DataFrames
"""
import pandas
import numpy
TEST_DF = pandas.DataFrame([1, 2, 3])
def add_list_to_dataframe(mylist, df):
"""
Adds a list to pandas dataframe as a new column. Then returns the extended
dtaframe.
"""
df["new_column"] = mylist
return df
de... | true |
82b46061e0d4a3bec5fda8586ded8598926cc36e | Indi44137/Functions | /Revision 4.py | 312 | 4.125 | 4 | #Indi Knighton
#6/12/2014
#Revision 4
import math
temperature = int(input("Please enter the teperature in fahrenheit: "))
def convert_to_celsius(temperature):
fahrenheit = temperature
celsius = (fahrenheit - 32) * (5/9)
print(celsius)
return celsius
convert_to_celsius(temperature)
| false |
51440d306d7272a3b6a18f79515d37366c4c624e | melissed99/driving-route-finder | /dijkstra.py | 1,023 | 4.125 | 4 | def least_cost_path(graph, start, dest, cost):
"""Find and return a least cost path in graph from start vertex to dest vertex.
Efficiency: If E is the number of edges, the run-time is
O( E log(E) ).
Args:
graph (Graph): The digraph defining the edges between the
vertices.
start: The ve... | true |
aef1daa1692f2536688c27101e11b4a830767599 | spicywhale/LearnPythonTheHardWay | /ex8.py | 747 | 4.375 | 4 | #assigns the variable
formatter = "{} {} {} {}"
#changes formatter's format to function. This allows me to replace the {} in line 2 with 4 other values, be it lines of text, numbers or values.
#prints formatter with 4 different values
print(formatter.format(1, 2, 3, 4))
#prints formatter with 4 different values
print(f... | true |
10e46dfa1367cc2ff2d4cdee5de17e1327468b34 | CarJos/funcionespy | /9.py | 845 | 4.1875 | 4 | '''9. Construir una función que reciba un entero y le calcule su factorial sabiendo que el
factorial de un número es el resultado de multiplicar sucesivamente todos los enteros
comprendidos entre 1 y el número dado. El factorial de 0 es 1. No están definidos los
factoriales de números negativos.
'''
def factorial(enter... | false |
9545460a2aead536e4ee5ab78f74b31584012464 | amandathedev/Python-Fundamentals | /03_more_datatypes/1_strings/04_05_slicing.py | 412 | 4.40625 | 4 | '''
Using string slicing, take in the user's name and print out their name translated to pig latin.
For the purpose of this program, we will say that any word or name can be
translated to pig latin by moving the first letter to the end, followed by "ay".
For example: ryan -> yanray, caden -> adencay
'''
name = inpu... | true |
1995310414b904bbc19de4c6709f1dc1049b20f0 | amandathedev/Python-Fundamentals | /02_basic_datatypes/02_01_cylinder.py | 315 | 4.21875 | 4 | '''
Write the necessary code calculate the volume and surface area
of a cylinder with a radius of 3.14 and a height of 5. Print out the result.
'''
import math
radius = 3.14
height = 5
volume = math.pi * (radius ** 2) * height
volume = round(volume, 2)
print("The volume of the cyliner is " + str(volume) + ".") | true |
3f3c65621a8c08e005a3efe10aeb16c43524a08a | amandathedev/Python-Fundamentals | /12_string_formatting/12_01_fstring.py | 1,791 | 4.34375 | 4 | '''
Using f-strings, print out the name, last name, and quote of each person in the given dictionary,
formatted like so:
"The inspiring quote" - Lastname, Firstname
'''
famous_quotes = [
{"full_name": "Isaac Asimov", "quote": "I do not fear computers. I fear lack of them."},
{"full_name": "Emo Philips", "quo... | true |
4fd88f7c40fd99638e7b0ec03a4e353927d57f50 | amandathedev/Python-Fundamentals | /03_more_datatypes/4_dictionaries/04_19_dict_tuples.py | 471 | 4.40625 | 4 | '''
Write a script that sorts a dictionary into a list of tuples based on values. For example:
input_dict = {"item1": 5, "item2": 6, "item3": 1}
result_list = [("item3", 1), ("item1", 5), ("item2", 6)]
'''
# http://thomas-cokelaer.info/blog/2017/12/how-to-sort-a-dictionary-by-values-in-python/
import operator
input_... | true |
3cad7c59eb9cb4fe0e7ee41c01abe41b51c11669 | danielzengqx/Python-practise | /1 min/binary search.py | 708 | 4.125 | 4 | #Binary search -> only for the sorted array
#time complexity -> O(logn)
array = [1, 2, 3, 4, 5]
def BS(array, start, end, value):
mid = (start + end) / 2
if start > end:
print "None"
return
if array[mid] == value:
print mid
return
elif array[mid] > value:
BST(array, start, mid-1, value)
elif array[mi... | true |
7176d418d1a0dc3f60f8d419d73174ab0184f160 | danielzengqx/Python-practise | /CC150 5th/CH9/9.1.py | 866 | 4.15625 | 4 | #a child is running up a staircase with n steps, and can hop either 1 step, 2 step, 3 step at a time
#Implement a method to count how many possible ways the child can run up the stairs
def stair(n, counter):
if n == 0:
counter[0] += 1
return
if n < 1:
return
else:
stair(n-1, counter)
stair(... | true |
02a416d2aee37a0bfebd86a33ef35d98c3891e82 | danielzengqx/Python-practise | /2016 interview/r practise/messaging.py | 2,026 | 4.125 | 4 | # 第一轮
# 给定一段英文消息,以及一个固定的长度,要求将消息分割成若干条,每条的最后加上页码如 (2/3),然后每条总长度不超过给定的固定长度。典型的应用场景就是短信发送长消息。
# 经过询问之后得到更多详细要求及假设:
# (1)消息数量尽可能少,不必凑整句,可以在任意空格处分页;
# (2)这个固定长度可能非法,比如某个词很长导致一条消息放不下,要判断并抛出异常;
# (3) 假设空格分割,不会出现连着两个空格的情况。
#implementation step
#First -> detect the white space, store a list of string
#checking t... | false |
fd9d02de7d3f099f5d4267804fe5c7a4b8ee4a69 | danielzengqx/Python-practise | /CC150 5th/CH2/2.5 best solution.py | 2,564 | 4.125 | 4 | # Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.
# EXAMPLE
# input: A -> B -> C -> D -> E -> C [the same C as earlier]
# output: C
# 1), assume we have two types of runners, first, slow runner(s1) and fast runner (s2). s1 increment by 1 and s2 increment by 2
# 2)... | true |
b1e6b5ea5c807000c7c463917b25bcc09812385f | danielzengqx/Python-practise | /CC150 5th/CH5/5.2.py | 781 | 4.125 | 4 | #Given a (decimal - e.g. 0.72) number that is passed in as a string, print the 32 bits binary rep- resentation. If the number can not be represented accurately in binary, print “ERROR”
# the number base 5th version, the number is between 0 to 1, the max number is 1 - 2^(-32)
# 1), There are two types of binary repres... | true |
e3fa4d976c1d6c1b6decfa4c0d24962076d5f829 | danielzengqx/Python-practise | /CC150 5th/CH5/5.8.py | 1,589 | 4.21875 | 4 | #1, screen is stored as a single array of bytes.
#2, width of screen can be divided by 8 pixels or 1 byte
#3, eight consecutive pixels to store in one byte
#4, height of the screen can be derived from
#---------the width of screen
#---------the length of a single array
#---------height = the length of a single arra... | true |
1cb1e67c83c2ed46f228e1deea7359f2c3974fc5 | Makhanya/PythonMasterClass | /OOP2/specialMethods.py | 2,056 | 4.5625 | 5 | """
Special Methods
2.(Polymorphism) The same operation works for different kinds of objects
How does the following work in Python
8 + 2 #10
"8" + "2" #82
The answer is "special method"
Python classes have special(also known as "magic... | true |
ef4ff8fd0f38d7aae7463c629e9b3775dcc671a5 | Makhanya/PythonMasterClass | /TuplesSets/loopingTuple.py | 392 | 4.53125 | 5 | # Looping
# We can use a for loop to iterate over a tuple just like a list!
# names = (
# "Colt", "Blue", "Rusty", "Lassie"
# )
# for name in names:
# print(name)
# months = ("January", "February", "March", "April", "May", "June",
# "July", "August", "September", "October", "November", "December")
... | true |
483a6e8f975974e3b754109e4b72b18c0783e1b6 | Makhanya/PythonMasterClass | /TuplesSets/tuple.py | 524 | 4.21875 | 4 | # Tuples are commonly used for Unchanging data:
months = ("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
# Tuple can be used as keys in dictionaries
locations = {
(35.68995, 39.6917): "Tokyo Office",
(40.7128, 74.0060): "New Y... | true |
27d974269a5d178efe810beddf8efc2a7db0f4c3 | Makhanya/PythonMasterClass | /TuplesSets/Sets.py | 1,399 | 4.625 | 5 | # Sets
# Sets are like formal mathematical sets
# Sets do not have duplicate values
# Elements in sets aren't ordered
# You cannot access items in a set by index
# Sets can be useful if you need to keep track of a collection of
# elements, but don;t care about ordering, Keys or... | true |
533a4e9756f3090eab131ff9e12277d2dfca9d09 | Makhanya/PythonMasterClass | /Lambdas/minAndmax.py | 1,212 | 4.25 | 4 | """
Max
Return the largest item in a iterable or the largest of
two or more arguments
# max (strings, dicts with same keys)
print(max([3, 4, 1, 2])) # 4
print(max([1, 2, 3, 4])) # 4
print(max(["awesome"])) # w
print(max({1: 'a', 3: 'c', 2: 'b'})) ... | false |
91d5ed77a512286ff516c5967b07a6c71f8e0cff | Pernillo918/CursoPython | /ht1.py | 1,241 | 4.59375 | 5 | '''
Ejercicio1
Escribir un programa que pida al usuario un número entero y muestre por pantalla un triángulo
rectángulo como el de más abajo, de altura el número introducido.
Ejemplo
El usuario ingresa el numero 5
*
**
***
****
*****
'''
print("")
print("Bienvendio al programa, este es el Ejercicio 1")... | false |
27ab1bab32d6bdc3f021bf7ca29e7d2821c32dac | fgokdata/exercises-python | /coursera/functions.py | 515 | 4.125 | 4 | def printAll(*args): # All the arguments are 'packed' into args which can be treated like a tuple
print("No of arguments:", len(args))
for argument in args:
print(argument)
#printAll with 3 arguments
printAll('Horsefeather','Adonis','Bone')
#printAll with 4 arguments
printAll('Sidecar','Long Island','M... | true |
983437a9e05194097f02d0f154dc8e9a5419d7d6 | Puqiyuan/Example-of-Programming-Python-Book | /chapter1/person_alternative.py | 1,357 | 4.34375 | 4 | """
a complete instance example of OOP in python.
test result:
pqy@sda1:~/.../chapter1$ python person_start.py
Bob Smith 40000
Smith
44000.0
"""
class Person:
"""
a general person: data + logic
"""
def __init__(self, name, age, pay = 0, job = None):
self.name = name
self.age = age
... | true |
291cabb8919366b24c0ff339d2897ae55ba3c386 | vivianakinyi/Coding-Interviews-Prep | /kth_largest.py | 887 | 4.34375 | 4 | # Find kth largest elements in an unsorted array
def kth_largest(arr, k):
print "In kth largest"
mergeSort(arr)
# Split the array to kth item
print arr[:k]
# for i in range(k):
# print arr[i]
# Descending order i.e from largest to smallest
def mergeSort(arr):
if len(arr) > 1:
mid = len(arr) // 2
l... | false |
da1d96284276b485582823b463700d9956e01725 | KahlilMonteiro-lpsr/class-samples | /6-3CaesarsCipher/applyCipher.py | 1,349 | 4.34375 | 4 | # applyCipher.py
# A program to encrypt/decrypt user text
# using Caesars Cipher
#
# Author: rc.monteiro.kahlil [at] leadps.org
import string
# makes a mapping of alphabet to decoded alphabet
# arguments: key
# returns: dictionary of mapped letters
def createDictionary(key):
alphabet = list(string.ascii_lowercase)
a... | true |
90b8498a0612e66df9743ed07a3521a145c8d918 | bhayru01/Python-Exercises | /addFloatNumbers.py | 1,723 | 4.5 | 4 | ####### File Exercise from the book "Python For Everyone" by Horstmann #######
"""
Write a program that asks the user to input a set of floating-point values.
When the user enters a value that is not a number,
give the user a second chance to enter the value.
After two chances, quit reading input.
Add all correct... | true |
f31b5a47fd89394ef9725443e3aa463b79bc9c50 | bhayru01/Python-Exercises | /NumberOfCharsWordsLines.py | 1,537 | 4.3125 | 4 | ####### File Exercise from the book "Python For Everyone" by Horstmann #######
"""
p7.5
Write a program that asks the user for a file name
and prints the number of:
characters, words, and lines in that file.
"""
file = open("input.txt", "w")
file.write("Mary had a little lamb\nWhose fleece was whit... | true |
b5060a2f70653672895b2225e76c2bf1ddc2e573 | cervthecoder/scratch_code | /begginning_cerv/user input.py | 243 | 4.28125 | 4 |
name = input("Enter your name: ") #user put here some infromation which is stored inside a variable
age = input ("enter your age: ")
print("Hello " +name+ "! Your age is "+age+".") #prints the variables plus some other information (string)
| true |
15e424f10556b081b77b9033d89abdc0051f60af | cervthecoder/scratch_code | /begginning_cerv/if statement.py | 307 | 4.21875 | 4 |
is_male = False #make a true/false value
is_tall = False
if is_male and is_tall:
print("You're a male and tall")
elif is_male and not(is_tall):
print("You're a short male")
elif not (is_male) and is_tall:
print("You're a tall female")
else:
print("You're a female and not tall")
| true |
3e82cdc424ff7701097af941d10ff294173fce1f | elducati/bootcampcohort19 | /fizz_buzz.py | 397 | 4.1875 | 4 | def fizz_buzz(num):
#checks if number is divisible by 3 and 5
if num % 3 == 0 and num % 5 == 0:
return 'FizzBuzz'
#checks if number if number is divisible by 5
elif num % 5 == 0:
return 'Buzz'
#checks if number is divisible by 3
elif num % 3 == 0:
return 'Fizz'
#r... | false |
9e15be4deb11a9e2810d5fb3bd9beb7769a2d345 | rrdietsch/Python-Classes | /hello world.py | 847 | 4.25 | 4 | #########################################
# Aprendiendo python
# by: el dicky
#########################################
#test
import os
os.system('cls')
'''
first_name = "Ricardo"
#print(first_name)
first_name = "michelle"
print(first_name)
'''
#dictionary
nombres = ["juan", "Luis", "Ricardo"]
#tuple
nombres = ("... | false |
3a11b81f210e012e7fce39a2d40387e8d2dd7dc3 | CODavies/Python_Dietel | /Chapter2/Multiples_Of_A_Number.py | 274 | 4.15625 | 4 | first_Number = int(input('Enter first number: '))
second_Number = int(input('Enter second number: '))
if second_Number % first_Number == 0:
print(first_Number, " is a multiple of ", second_Number)
if second_Number % first_Number != 0:
print("The are not multiples") | true |
94d45fbfca9b0bebc195843f95e2c9328c08040d | lirui-ML/my_leetcode | /Algorithms/234_Palindrome_Linked_List/Palindrome_Linked_List.py | 2,162 | 4.21875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
描述:回文链表
请判断一个链表是否为回文链表。
示例 1:
输入: 1->2
输出: false
示例 2:
输入: 1->2->2->1
输出: true
进阶:
你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/palindrome-linked-list
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
"""
# Definition for singly-linked li... | false |
cfdec71e99f0b3a80db0681d590e988193bbc783 | HarshRangwala/Python | /python practice programs/GITpractice31.py | 1,437 | 4.65625 | 5 | # -*- coding: utf-8 -*-
"""
Created on Fri Jun 15 14:36:13 2018
@author: Harsh
"""
'''
Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).
Hints:
Use ** operator to get power of a number.
Use range() for loops.
Use list.append() to add value... | true |
b519c13d65845d3b859878a27608f8bdd1eda9e2 | HarshRangwala/Python | /python prc/PRACTICAL1E.py | 1,102 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jun 5 18:26:47 2018
@author: Harsh
"""
def Armstrong():
num=int(input("Please Input here::"))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
... | true |
d573c3a0f4641b652c6a421630ae6273c2520683 | HarshRangwala/Python | /python practice programs/GITpractice16.py | 431 | 4.3125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Jun 9 23:30:39 2018
@author: Harsh
"""
'''
Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers.
Suppose the following input is supplied to the program:
1,2,3,4,5,6,7,8,9
Then, the output should be:
1,3,5,7... | true |
27d7b880c1caf75afd0896a6d1ef6dac88659a5f | NareTorosyan/Python_Introduction_to_Data_Science | /src/first_month/Homeworks/task_1_2_1_lists.py | 440 | 4.34375 | 4 | #1 Write a Python program to get the largest number from a list.
x = [9,8,5,6,4,3,2,1]
x.sort()
print(x[-1])
#2 Write a Python program to get the frequency of the given element in a list to.
x =[1,2,3,4,5,6,7,8,9,9,9,9,9]
print(x.count(9))
#3 Write a Python program to remove the second element from a given list, if w... | true |
c0f5fc4c97b304d5f862491ee2bd91e6b7a4ecdb | tuantvk/python-cheatsheet | /src/python-example/set.py | 1,182 | 4.15625 | 4 | #!/usr/bin/python
# set
set1 = {"Weimann", "Dickens", "Lakin"}
print(set1)
# output:
# {'Weimann', 'Lakin', 'Dickens'}
# check if "Weimann" is present in the set
set2 = {"Weimann", "Dickens", "Lakin"}
print("Weimann" in set2)
# output:
# True
# add
set3 = {"Weimann", "Dickens", "Lakin"}
set3.add("Schneider")
... | false |
9dd831fc2689ea4f88ccabfcfc1625872360131e | tuantvk/python-cheatsheet | /src/python-example/string.py | 1,350 | 4.4375 | 4 | #!/usr/bin/python
str1 = 'Hello World!'
str2 = "I love Python"
print("str1[0]: ", str1[0])
print("str2[7:]: ", str2[7:])
# output:
# str1[0]: H
# str2[7:]: Python
# display multiline
str3 = """
Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standa... | true |
ad987950a320d893b0b71089f95bdabe34176a87 | skywalker-young/LeetCode-creepy | /unique-path.py | 1,666 | 4.25 | 4 | """
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 are there?
Not... | true |
16c43c5c88baeaf413f7a3ba03f07a2767d29988 | KrisZ1234/Python_various | /quadratic.py | 1,484 | 4.125 | 4 | import math
print("------ a*x**2 + b*x + c = 0 ------- ")
inp1_str = input("Type a -> ")
inp2_str = input("Type b -> ")
inp3_str = input("Type c -> ")
def solutions(a,b,c):
""" inputs: 3 float numbers
Does the proper calculations (for ALL scenarios)
and prints the solutions """
D = (b**2) - (4*a... | false |
18e0e1c83373e8fe96430fbb141330e06c143f1b | AishwaryaVelumani/Hacktober2020-1 | /rock paper scissors.py | 1,668 | 4.25 | 4 | import random
def result(your_score,comp_score):
if your_score>comp_score:
print("Congratulations! You won the match. Play again!")
elif your_score == comp_score:
print("The match is a tie! Play again!")
else :
print("Opps! You lost the match. Try again!")
def win(you... | true |
0a32ce525ca251902664bd79f3eef7d295a4a747 | Soleviso/pythonProject1 | /calculator.py | 283 | 4.125 | 4 | x = int(input("Eingabe Zahl x: "))
y = int(input("Eingabe Zahl y: "))
operation = input("Rechenaufgabe (+, -, /, *): ")
if operation == "+":
print(x + y)
if operation == "-":
print(x - y)
if operation == "/":
print(x / y)
if operation == "*":
print(x * y)
| false |
733464c49bc5ee51d3e2a4cc29f29f3a1db9171d | carlosalf9/InvestigacionPatrones | /patron adapter python/class Adapter.py | 544 | 4.1875 | 4 |
class Adapter: """ Adapts an object by replacing methods. Usage: motorCycle = MotorCycle() motorCycle = Adapter(motorCycle, wheels = motorCycle.TwoWheeler) """
def __init__(self, obj, **adapted_methods):
"""We set the adapted methods in the object's dict"""
self.obj = obj
self.__dict__.update(adapted_met... | true |
e029b1def2a907109eeaf9cb9434edec6eb40ddc | naistangz/codewars_challenges | /7kyu/shortestWord.py | 332 | 4.5625 | 5 | """
Instructions
- Simple, given a string of words, return the length of the shortest word(s).
- String will never be empty and you do not need to account for different data types.
"""
def find_short(s):
convert_to_list = list(s.split(" "))
shortest_word = min(len(word) for word in convert_to_list)
return s... | true |
fd90a725870c45b4a1c848893ad1dbf394ec5240 | naistangz/codewars_challenges | /7kyu/simpleConsecutivePairs.py | 1,639 | 4.28125 | 4 | """
Instructions
In this Kata your task will be to return the count of pairs that have consecutive numbers as follows:
pairs([1,2,5,8,-4,-3,7,6,5]) = 3
The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5]
--the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1
--the second pair is ... | true |
43a739e5ab9392456bde250693f404050234d895 | hamiltoz9192/CTI-110 | /P4HW2_Hamilton.py | 340 | 4.125 | 4 | #CTI-110
#P4HW2 - Running Total
#Zachary Hamilton
#July 6, 2018
#This program creates a running total ending when a negative number is entered.
total = 0
userNumber = float(input("Enter a number?:"))
while userNumber > -1:
total = total + userNumber
userNumber = float(input("Enter a number?:"))
pr... | true |
435b5497d7968cc076d860e436f4d9b7f109e336 | AShuayto/python_codewars | /data_reverse.py | 1,043 | 4.1875 | 4 | '''
A stream of data is received and needs to be reversed. Each segment is 8 bits long, meaning the order of these segments need to be reversed, for example:
11111111 00000000 00001111 10101010
byte1 byte2 byte3 byte4
should become:
10101010 00001111 00000000 11111111
byte4 byte3 byte2 ... | true |
3d22a01a1504c7c5240aeeccedbab2f4226517d2 | tmajest/project-euler | /python/p9/p9_2.py | 702 | 4.15625 | 4 | # A Pythagorean triplet is a set of three natural numbers, a b c, for which,
# a^2 + b^2 = c^2
#
# For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
#
# There exists exactly one Pythagorean triplet for which a + b + c = 1000.
# Find the product abc.
import math
def isPythagoreanTriplet(a, b):
c = math.sqrt(a*a + ... | false |
7ecb0c43bd717c3bd54369dca6fd2e6c0ec5d502 | nastyav0411/coding-challenge | /recursive_element_calc.py | 452 | 4.3125 | 4 |
def recursive_element_calc( n ): # recursive function calculates n_th element of the sequence
if n == 1:
return 2
elif n == 2:
return 2
else:
return recursive_element_calc( n - 1 ) + recursive_element_calc( n - 2 )
if __name__ == '__main__':
n = 15 ... | false |
cdaffc0412348680b67122b1a959ab448a4809eb | Md-Monirul-Islam/Python-code | /Advance-python/Constructor with Super Method-2.py | 531 | 4.21875 | 4 | #Constructor with Super Method or Call Parent Class Constructor in Child Class in Python
class Father:
def __init__(self):
self.money = 40000
print("Father class constructor.")
def show(self):
print("Father class instance method.")
class Son(Father):
def __init__(self):
super... | true |
293a10483534470b8ab48647a6c29ea49ca647e0 | Md-Monirul-Islam/Python-code | /Advance-python/Abstract Class Abstract Method and Concrete Method in Python-2.py | 531 | 4.125 | 4 | from abc import ABC,abstractmethod
class DefenceForce:
@abstractmethod
def area(self):
pass
def gun(self): #concreate method.
print("Gun->>AK47")
class Army(DefenceForce):
def area(self):
print("Army area->>Land")
class AirForce(DefenceForce):
def area(self):
print("... | false |
49c90b63c2ad1b5a59b98e74b62c815f44a5bdff | ruiliulin/liuliu | /习题课/Python视频习题课/高级语法训练/习题课23 Tk练习/习题课23 Tk练习1.py | 779 | 4.15625 | 4 | # encoding:utf-8
# 用Tkinter写一个小游戏随机生成我们需要的名字
import tkinter as tk
import random
window = tk.Tk()
def random1():
s1 = ["cats", "hippos", "cakes"]
s = random.choice(s1)
return s
def random2():
s2 = ["eats", "has", "likes", "hates"]
s = random.choice(s2)
return s
def button_click():
name =... | false |
2c91529b8b53c07adb1466be2b673aaf921efa6a | lrakai/python-newcomer-problems | /src/challenge_three.py | 893 | 4.5 | 4 | def list_uniqueness(the_list):
'''
Return a dictionary with two key-value pairs:
1. The key 'list_length' stores the lenght of the_list as its value.
2. The key 'unique_items' stores the number of unique items in the_list as its value.
Arguments
the_list: A list
Examples
l = [1, 2, 2... | true |
02e9d39c87c4456b5f5b3cfd8ed53b98db430328 | flik/python | /iterator.py | 576 | 4.53125 | 5 | #Return an iterator from a tuple, and print each value:
mytuple = ("apple", "banana", "cherry")
myit = iter(mytuple)
#myit = mytuple
print(next(myit)) # next() will not work without iter() conversion.
print(next(myit))
print(next(myit))
mystr = "banana"
for x in mystr:
print(x)
"""
#Strings are also iter... | true |
f232098adaba4d48f648697aa53b81e4faed8af3 | flik/python | /class.py | 850 | 4.46875 | 4 | class MyClass:
x = 5
y = 9
p1 = MyClass()
print(p1.y)
#------- other example
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
#print(p1.name)
#print(p1.age)
# ---third example with self use
class Person:
def __init__(self, name, age):
self.na... | false |
ade463aad6ee764d4627acc5927eb64d535135bc | ziminika/prak__5 | /task2/5/5.py | 2,790 | 4.1875 | 4 | from collections import defaultdict
import sys
# Description of class Graph:
# The Graph is a dictionary of dictionaries.
# The keys are nodes, and the values are dictionaries,
# whose keys are the vertices that are associated with
# a given node, and whose values are the weight of the edges.
# Non-oriented Gra... | true |
c8537ec4db97f54f6eab90aa26b3b0f03a79b3d2 | ziminika/prak__5 | /task2/4/4.py | 2,361 | 4.125 | 4 | from collections import defaultdict
from collections import deque
import sys
# Description of class Graph:
# The Graph is a dictionary of lists.
# The keys are nodes, and the values are lists,
# consisting of nodes that have a path fron a given node.
# Oriented Graph
class Graph:
# Сreating a Graph object
def _... | true |
e34199254a7fea1aea5f3e02310652c367f1897c | YaoJMa/CS362-HW3 | /Yao_Ma_HW3_Leap_Year.py | 483 | 4.28125 | 4 | #Asks user for a input for what year
year = int(input("Enter a year: "))
#Checks the conditions if the year is divisible by 400
if year%400==0:
print("It is a leap year")
#Checks the conditions if the year is divisible by 100 and 400
elif year%100==0 and year%400!=0:
print("It is not a leap year")
#C... | true |
26602c6aeda22ee4cd53bb346f9c96604200ef73 | vitthalpadwal/Python_Program | /hackerrank/preparation_kit/greedy_algorithms/max_min.py | 1,761 | 4.28125 | 4 | """
You will be given a list of integers, , and a single integer . You must create an array of length from elements of such that its unfairness is minimized. Call that array . Unfairness of an array is calculated as
Where:
- max denotes the largest integer in
- min denotes the smallest integer in
As an example, con... | true |
ab76daedef7fc55f293b31010b84f62472d2e028 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/super_reduces_strings.py | 1,456 | 4.34375 | 4 | """
Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one op... | true |
c5606deae4b3f8ac7e867c48c2d00c71317d78ab | vitthalpadwal/Python_Program | /hackerrank/decorator_standardize_mobile_no.py | 1,332 | 4.65625 | 5 | """
Let's dive into decorators! You are given mobile numbers. Sort them in ascending order then print them in the standard format shown below:
+91 xxxxx xxxxx
The given mobile numbers may have , or written before the actual digit number. Alternatively, there may not be any prefix at all.
Input Format
The first... | true |
268afaf374055a83b932122edd77f75d2b8abb14 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/strong_password.py | 2,906 | 4.375 | 4 | """
Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria:
Its length is at least .
It contains at least one digit.... | true |
082b98374cec16d6f9aee1670ae6c5a3fcbac0f5 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/caesar_cipher.py | 2,003 | 4.59375 | 5 | """
Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and ... | true |
741eac7bd97af4a06ae3c38252654b88cb9c0e73 | VitaliiRevenko/PytonLessonsForBeginnerBeetRootAcademy | /lesson_10/task1.py | 701 | 4.21875 | 4 | '''
Task 1
A Person class
Make a class called Person. Make the __init__() method take firstname, lastname, and age as parameters
and add them as attributes. Make another method called talk() which makes prints a greeting from the person containing
, for example like this: “Hello, my name is Carl Johnson and I’m ... | true |
24390631ccf66c46fbee54cd5c1068a74b0b2791 | VitaliiRevenko/PytonLessonsForBeginnerBeetRootAcademy | /lesson_22/task4.py | 752 | 4.3125 | 4 | # Task 4
#
# def reverse(input_str: str) -> str:
# """
# Function returns reversed input string
# reverse("hello") == "olleh"
# True
# reverse("o") == "o"
# True
# def reverse(input_str: str) -> str:
# if len(input_str) == 1:
# return input_str
# return input_str[-1... | false |
a450d7febe14eacf228fa011272cd6d9fe78983e | robbailiff/maths-problems | /gapful_numbers.py | 937 | 4.1875 | 4 | """
A gapful number is a number of at least 3 digits that is divisible by the number formed by the first and last digit of the original number.
For Example:
Input: 192
Output: true (192 is gapful because it is divisible 12)
Input: 583
Output: true (583 is gapful because it is divisible by 53)
Input: 210
Output: fals... | true |
18756becf16c3252294155a8b01c82acba7a8fd4 | charugarg93/LearningML | /04_List.py | 1,219 | 4.59375 | 5 |
books = ['kanetkar', 'ritchie', 'tanenbaum']
print(books[2])
# in python you can also have negative indices
# -1 denotes last element of the list, -2 denotes second last item of the list and so on
print("Experimenting with negative indices ::: "+ books[-3])
books.append("galvin")
print(books)
# extend method is us... | true |
6b181ec8bd9d686fa14459e0b89dcfb96743dd69 | arunk38/learn-to-code-in-python | /Python/pythonSpot/src/3_database_and_readfiles/1_read_write/read_file.py | 397 | 4.125 | 4 | import os.path
# define a filename.
filename = "read_file.py"
# open the file as f
# The function readlines() reads the file.
if not os.path.isfile(filename): # check for file existence
print("File does not exist: " + filename)
else:
with open(filename) as f:
content = f.read().splitlines()
# sho... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.