blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
ce0cfdebf310432f6641ef77c298ebefefa2d2d6 | gihs-rpc/01-Sleeping-In | /challenge-1-sleeping-in-MoseliaTemp3/1.1 ~ Sleeping In.py | 1,612 | 4.34375 | 4 | #Repeatedly used things defined here for ease of modification.
EndBool = "\n (Y/N) > "
Again = "Incorrect input."
#Begin Program.
while True:
print("\n")
#Is tomorrow a school day?
SchoolTomorrow = input("Do you have school tomorrow?" + EndBool)
print()
#Repeat question until answe... | true |
05b72faac13f324605cb62bf3c1fff7258260e28 | itsamanyadav/Python | /unittest使用.py | 2,237 | 4.4375 | 4 | #断言 编写代码时,我们总是会做出一些假设,断言就是用于在代码中捕捉这些假设,可以将断言看作是异常处理的一种高级形式。
#assert代表断言,假设断言的条件为真,如果为假诱发AssertionError
#assert 断言的条件,错误的提升
# a = 0
# assert a,"a is false"
# print(a)
#上面的断言代码类似下面的if语句
# a = 1
# if not a:
# raise AssertionError("a is false")
# print(a)
# import unittest
#
# #unittest使用的方法
# class OurTest(unittest.... | false |
2d9ca18c7b90af0ac266f5f8b8b684492c2bbc4e | laurendayoun/intro-to-python | /homework-2/answers/forloops.py | 2,846 | 4.40625 | 4 | """
Reminders:
for loop format:
for ELEMENT in GROUP:
BODY
- ELEMENT can be any variable name, as long as it doesn't conflict with other variables in the loop
- GROUP will be a list, string, or range()
- BODY is the work you want to do at every loop
range format is:
range(start, stop, step) or range(st... | true |
e8412e95f1b1b094e5d24c286c18f240e72401be | taruntalreja/Training_Toppr | /Python Basics/OOPs Concepts/class_object.py | 700 | 4.25 | 4 | class Sparrow:
# class attribute
species = "bird"
# instance attribute
def __init__(self, name, age):
self.name = name
self.age = age
#instance method
def eats(self,food):
return "{} eats {}".format(self.name,food)
# instantiate the Parrot class
fanny = Sparrow("Fanny... | false |
a345955cc7dabc0e6551f6f0e47e88b36c43ad26 | Leomk1998/AyudantiasFP-ESPOL | /FP2020-2/Clase01/Ayudantia1.py | 2,158 | 4.1875 | 4 | # 23/10/2020
# Ayudante: Leonardo Mendoza
#Ejercicio 1
"""
f = int(input("Escriba un temperatura en grados Farhenheit: "))
c = ((f-32)*5)/9
print("%d grados Farhenheit son %f grados centigrados"%(f,c)) # %d numeros enteros %s strings %f numeros decimales
"""
#Ejercicio 2
"""
numero = int(input("Ingrese un numero:... | false |
8a93636bd5b7b955f431bc4f351583b742fe14cf | senavarro/function_scripts | /functions.py | 947 | 4.40625 | 4 | #Create a function that doubles the number given:
def double_value(num):
return num*2
n=10
n=double_value(n)
print(n)
--------------------------------------
#Create a recursive function that gets the factorial of an undetermined number:
def factorial(num):
print ("Initial value =", num)
if num > 1:
num = n... | true |
d48b8e88545ebcf87820f63294285c9b0d370331 | kingdunadd/PythonStdioGames | /src/towersOfHanoi.py | 2,977 | 4.34375 | 4 | # Towers of Hanoi puzzle, by Al Sweigart al@inventwithpython.com
# A puzzle where you must move the disks of one tower to another tower.
# More info at https://en.wikipedia.org/wiki/Tower_of_Hanoi
import sys
# Set up towers A, B, and C. The end of the list is the top of the tower.
TOTAL_DISKS = 6
HEIGHT = TOTAL_DISK... | true |
0b0329ee3244562c8c7aa7abb3068f2c06737bde | codesheff/DS_EnvTools | /scripts/standard_functions.py | 706 | 4.21875 | 4 | #!/usr/bin/env python3
def genpassword(forbidden_chars:set={'!* '} , password_length:int=8) -> str:
"""
This function will generate a random password
Password will be generated at random from all printable characters.
Parameters:
forbidden_chars: Characters that are not allowed in the pass... | true |
97defbcbd96034d5ac170250340d05d18732da78 | willpxxr/python | /src/trivial/sorting/quicksort.py | 2,527 | 4.25 | 4 | from math import floor
from typing import List
def _medianOf3(arr: List, begin: int, end: int) -> (int, int):
"""
Brief: Help method to provide median of three functionality to quick sort
An initial pivot is selected - then adjusted be rotating the first index, center index
and end index... | true |
52d309fa9f4cca8b527da7850fca9256a34c2b6c | hannahbishop/AlgorithmPuzzles | /Arrays and Strings/rotateMatrix.py | 1,244 | 4.25 | 4 | def rotate_matrix(matrix, N):
'''
Input:
matrix: square, 2D list
N: length of the matrix
Returns:
matrix, rotated counter clockwise by 90 degrees
Example:
Input:
[a, b]
[c, d]
Returns:
[b, d]
[a, c]
Efficiency:... | true |
e72fe631c3633f59c643e7a58de5ab3c9c564eb9 | Ziiv-git/HackerRank | /HackerRank23.py | 1,987 | 4.1875 | 4 | '''
Objective
Today, we’re going further with Binary Search Trees. Check out the Tutorial tab for learning materials and an instructional video!
Task
A level-order traversal, also known as a breadth-first search, visits each level of a tree’s nodes from left to right, top to bottom. You are given a pointer, , pointing... | true |
53cecd207777cb4b81667a0869fc3318f8673f47 | mciaccio/pythonCode | /udacityPythonCode/classes/inheritance.py | 2,075 | 4.34375 | 4 |
# class name first letter uppercase "P"
class Parent():
# constructor
def __init__(self, last_name, eye_color):
print("Parent Constructor called\n")
self.last_name = last_name
self.eye_color = eye_color
# super class instance method
def show_info(self):
prin... | true |
8ad0f485fbad4f5edc9df95ba3a4b21257add7bc | ashwin-magalu/Python-OOPS-notes-with-code | /access.py | 713 | 4.28125 | 4 | class Employee:
name = "Ashwin" # public member
_age = 27 # protected member
__salary = 10_000 # private member --> converted to _Employee__salary
def showEmpData(self):
print(f"Salary: {self.__salary}")
class Test(Employee):
def showData(self):
print(f"Age: {self._age}")
#... | true |
5761bda1dc5763f3e0acae42b4b98c928c84fb19 | pr0d33p/PythonIWBootcamp | /Functions/7.py | 422 | 4.21875 | 4 | string = "The quick Brow Fox"
def countUpperLower(string):
lowerCaseCount = 0
upperCaseCount = 0
for letter in string:
if letter.isupper():
upperCaseCount += 1
elif letter.islower():
lowerCaseCount += 1
print("No. of Upper case characters: {}".format(upperCase... | true |
c5c7b363243db27bacf7ff7405229cf0edf77018 | jodaruve/Parcial | /ejercicio 68.py | 818 | 4.125 | 4 | ## 68
print("Este programa le mostrara la cantidad de nmeros positivos, negativos, pares, impares y multiplos de ocho ingresados. Recuerde que cuando no desee ingresar ms nmeros debe escribir -00")
t_positivos=0
t_negativos=0
t_pares=0
t_impares=0
mult=0
num=float(input("Por favor ingrese un numero "))
while num!=-00:
... | false |
2df2b53ec9f62cb221fe8ac78e13b9d14a9ad3df | NurbekSakiev/Essential_Algorithms | /merge_Sort.py | 550 | 4.15625 | 4 | // Algorithms
// Merge Sort
// author: Nurbek Sakiev
def mergeSort(list_):
if (len(list_) <= 1):
return list_
mid = len(list_)//2
first = mergeSort(list_[:mid])
second = mergeSort(list_[mid:])
return list(merge(first,second))
def merge(list1, list2):
i=j=0
last = []
while (i <len(list1) and j<len(list2)):
... | false |
8ec919cee9c1ce1c5a1a92e94e661e153449b5cd | axisonliner/Python | /del_files.py | 1,854 | 4.125 | 4 | # Script for deleting files from a folder using the command line:
# command line: python del_files.py arg1 arg2
# - arg1 = folder path
# - arg2 = file extention
# Example: python del_files.py C:\Desktop\folder_name .exr
import os
import sys
import math
def get_size(filename):
st = os.stat(filename)
... | true |
2a0f013ad2aac2a67e9eafb1fa8a009d9aa663a8 | ESROCOS/tools-pusconsole | /app/Utilities/Database.py | 2,907 | 4.375 | 4 | import sqlite3 as sq3
from sqlite3 import Error
class Database(object):
"""
This class represents a database object. It implements
some methods to ease insertion and query tasks
"""
def __init__(self, dbname: str):
"""
This is the constructor of the class
:param dbname: The... | true |
e7eea0e92c5c8cf7c537f545b05a17a819b4d108 | pab2163/pod_test_repo | /Diana/stock_market_challenge.py | 1,221 | 4.25 | 4 | # Snippets Challenge
# Playing with the stock market.
# Write code to take in the name of the client as the user input
name = input("Hi there!\nWhat is your name?: ")
print("Hello "+ name + "!" )
# Write code to get user input savings" and personalize message with "name"
savings =int(input("What are your curren... | true |
d3db4c2dbb599de13e7396db16f96912d335b126 | Abdullahalmuhit/BT_Task | /BT_Solution.py | 548 | 4.125 | 4 | value = int (input("How many time you want to run this program?: "))
def check_palindromes(value):
charecter = input("Enter Your One Character: ")
my_str = charecter+'aDAm'
# make it suitable for caseless comparison
my_str = my_str.casefold()
# reverse the string
rev_str = reversed(my_st... | true |
9297bd49c2a7ddd20007b3d0f599ce7a15cfa670 | rajatkashyap/Python | /make_itemsets.py | 564 | 4.21875 | 4 | '''Exercise 3 (make_itemsets_test: 2 points). Implement a function, make_itemsets(words). The input, words, is a list of strings. Your function should convert the characters of each string into an itemset and then return the list of all itemsets. These output itemsets should appear in the same order as their correspond... | true |
8095f1c33d099fcdad65003a2f4add5d07bd5090 | orionbearduo/Aizu_online_judge | /ITP1/ITP_1_6_A.py | 539 | 4.28125 | 4 | """
Reversing Numbers
Write a program which reads a sequence and prints it in the reverse order.
Input
The input is given in the following format:
n
a1 a2 . . . an
n is the size of the sequence and ai is the ith element of the sequence.
Output
Print the reversed sequence in a line. Print a single space character be... | true |
0935e6a46fdd933261931fa71727206015745918 | orionbearduo/Aizu_online_judge | /ITP1/ITP_1_5_C.py | 824 | 4.28125 | 4 | """
Print a Chessboard
Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
Note that the top left corner should be drawn by '#'.
Input
T... | true |
bdff89efc61f5158b6d87dd6b5eeb5f11e91b898 | orionbearduo/Aizu_online_judge | /ITP1/ITP_1_8_A.py | 245 | 4.3125 | 4 | # Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
# Sample Input
# fAIR, LATER, OCCASIONALLY CLOUDY.
# Sample Output
# Fair, later, occasionally cloudy.
n = str(input())
print(n.swapcase())
| true |
dd8e680dc6602a27517af06f09319447b4256735 | renuit/renu | /factor.py | 226 | 4.125 | 4 | n=int(input("Enter a number:"))
fact=1
if(n<0):
print("No factorial for -Ve num")
elif(n==0):
print("factorial of 0 is 1")
else:
for i in range(1,n+1):
fact=fact*i
print("factorial of", n,"is",fact)
| true |
7c94602bbc0ce53124f4e2c892c85d24dcbd0331 | garima-16/Examples_python | /occurrence.py | 260 | 4.4375 | 4 | #Program to find the occurrences of a character in a string
string1=input("enter any string ")
ch=input("enter a character ")
count=0
for i in string1:
if ch==i:
count+=1
print("number of occurrences of character in string ",count)
| true |
c310929561622e694202ce37ffcd91d77ef4551c | Dinesh-Sivanandam/Data-Structures | /Linked List/insert_values.py | 1,664 | 4.375 | 4 | #Creating the class node
class Node:
def __init__(self, data=None, next=None):
self.data = data
self.next = next
#Creating the class for linked list
class LinkedList:
#this statement initializes when created
#initializing head is none at initial
def __init__(self):
... | true |
8cf94f263fe14f4f2487f41f0446e8b968f3f9c6 | maor90b/Bartov | /project2-master/package1/דוגמה 4 תנאים.py | 911 | 4.28125 | 4 | grade =int(input("enter number: "))
if grade<0 or grade>100:
print("the grade is between 0 and 100")
if grade>=0 and grade<=100: # דרך נוספת
if 90<=grade<=100:
print("very good")
if grade<90 and grade>=80:
print("good")
if grade<80 and grade>=70:
print("ok")
if grade<70
... | false |
0693111789c72af4db96730c3caa7b0cf4422571 | sachinasy/oddevenpython | /prac1.py | 268 | 4.34375 | 4 | # program to identify the even/odd state of given numbers
# function to print oddeven of given number
#oddeven function
number = int(input("enter a number: "))
if number % 2== 0:
print ("the entered number is even")
else:
print ("the entered number is odd")
| true |
e3459e66daea9d2747d6b5e5f05db326b8f2a127 | epangar/python-w3.exercises | /String/1-10/5.py | 343 | 4.125 | 4 | """
5. Write a Python program to get a single string from two given strings,
separated by a space and swap the first two characters of each string.
"""
def style_str(str1, str2):
answer1 = str2[0:2] + str1[2:]
answer2 = str1[0:2] + str2[2:]
answer = answer1 + " " + answer2
return answer
print(s... | true |
3f12cfba4069f64e2c4218935ae0649fbb5d05bd | epangar/python-w3.exercises | /String/1-10/2.py | 327 | 4.28125 | 4 | """
2. Write a Python program to count the number of characters (character frequency) in a string.
"""
def count_char(str):
dict = {}
for i in range(0, len(str)):
key = str[i]
if key in dict:
dict[key] += 1
else:
dict[key] = 1
return... | true |
2afa17246ba3754f0694b361e4d8f6cbc0df047d | pdshah77/Python_Scripts | /Input_Not_Required/PreFixMapSum.py | 776 | 4.28125 | 4 | '''
Write a Program to Implement a PrefixMapSum class with the following methods:
insert(key: str, value: int): Set a given key's value in the map. If the key already exists, overwrite the value.
sum(prefix: str): Return the sum of all values of keys that begin with a given prefix.
Developed By: Parth Shah
Python ... | true |
35615a6933af9421794d96c35d06310a87ac0562 | Flact/python100 | /Codes/day_02.py | 2,417 | 4.3125 | 4 |
# it will print "H"
# print("Hello"[0])
# ---------------------------
# type checking
# num_char = len(input("What is your name? "))
# this print function will throw a erorr
# print("Your name has " + num_char + " Characters")
# -----------------------------------------------------
# print(type(num_char))
# the fi... | true |
edd17e6ae441888ea4ea37c64c203075231f5e79 | Flact/python100 | /Codes/day_05/loop_with_range.py | 292 | 4.28125 | 4 |
# for number in range(1, 10):
# print(number) # this will print 1 - 9 (not include 10, but include 1)
# this will print 1 - 10 numbers step by 3
# for number in range(1, 11, 3):
# print(number)
# total up to 100
total = 0
for num in range(1, 101):
total += num
print(total)
| true |
f229875b6fbae36c226b1df10b1ec46a724d3383 | kalpanayadav/python | /cosine.py | 802 | 4.34375 | 4 | def myCos(x):
'''
objective: to compute the value of cos(x)
input parameters:
x: enter the number whose cosine value user wants to find out
approach: write the infinite series of cosine using while loop
return value: value of cos(x)
'''
epsilon=0.00001
multBy=-x**2
term=1
... | true |
91556089e400cd90ab55f495d2103f93eed3da35 | namratab94/LeetCode | /flipping_an_image.py | 1,428 | 4.125 | 4 | '''
Problem Number: 832
Difficulty level: Easy
Link: https://leetcode.com/problems/flipping-an-image/
Author: namratabilurkar
'''
'''
Example 1:
Input: [[1,1,0],[1,0,1],[0,0,0]]
Output: [[1,0,0],[0,1,0],[1,1,1]]
Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
Then, invert the image: [[1,0,0],[0,1,0],[... | false |
5eea6c767938f2599f4cef18c1fe1d6b746aa3e1 | Hollow-user/Stepik | /unit3/task6.py | 515 | 4.15625 | 4 |
"""
Напишите программу, которая подключает модуль math и, используя значение числа π из этого модуля,
находит для переданного ей на стандартный ввод радиуса круга периметр этого круга и выводит его на
стандартный вывод.
Sample Input:
10.0
Sample Output:
62.83185307179586
"""
import math
r = float(input())
p = ma... | false |
8967563182a4074837916a98d18613789071cdb5 | ikemerrixs/Au2018-Py210B | /students/jjakub/session03/list_lab.py | 1,244 | 4.28125 | 4 | #!/usr/bin/env python3
### Series 1
list_fruit = ["Apples", "Pears", "Oranges", "Peaches"]
print(list_fruit)
user_fruit = input("Which fruit would you like to add? ")
list_fruit.append(user_fruit)
print(list_fruit)
user_num = input("Provide the number of the fruit to return: ")
print(user_num + " " + list_fruit[int(... | false |
35fe7adbad7d0928347a52e7bc91f0fd2b4662a5 | ikemerrixs/Au2018-Py210B | /students/arun_nalla/session02/series.py | 1,900 | 4.375 | 4 | #!use/bin/env python
def fibo(n):
'''Write a alternative code to get the nth value of the fibonacci series using type (list)
0th and 1st position should return 0 and 1 and indexing nth position should
return SUM of previous two numbers'''
if n ==0: return 0
elif n ==1: return 1
my_list = [0,1]
... | true |
c69af38ba8fc630402d9e5415d128a00948cb973 | ikemerrixs/Au2018-Py210B | /students/ejackie/session04/trigrams.py | 843 | 4.3125 | 4 | #!/usr/bin/env python3
import sys
from collections import defaultdict
words = "I wish I may I wish I might".split()
def build_trigrams(words):
"""
build up the trigrams dict from the list of words
returns a dict with:
keys: word pairs
values: list of followers
"""
trigrams = defau... | true |
6886b16e533f10be42a0cf60f0a8381c805eb6ad | KarmanyaT28/Python-Code-Yourself | /59_loopq4.py | 424 | 4.21875 | 4 | # Write a program to find whether a given number is prime or not
number=int(input("enter your number which has to be checked"))
# i=2
# for i in range(2,number):
# if(number%i==0):
# break
# print("Not a prime number")
prime = True
for i in range(2,number):
if(number%i==0):
pri... | true |
812e5fb56f013781312790cd6b4a2a20cc255647 | KarmanyaT28/Python-Code-Yourself | /17_playwithstrings.py | 1,014 | 4.40625 | 4 | # name = input("Enter your name\n")
# print("Good afternoon, " + name)
# ---------------------------------------------------------------------------
# Write a program to fill in a letter template given below
# letter = '''Dear <Name> , you are selected ! <DATE>'''
# letter = '''
# Greetings from TalkPy.or... | true |
027170862720a141e62cd700cc30dc11db0a3b73 | KarmanyaT28/Python-Code-Yourself | /45_conditionalq3.py | 542 | 4.25 | 4 | # A spam comment is defined as a text containing following keywords:
# "make a lot of money" , "buy now","subscribe this",
# "click this".
# Write a program to detect these spams.
text= input("Enter the text")
spam = False
if("make a lot of money" in text):
spam = True
elif("buy now" in text):
sp... | true |
a0b6a8921da7aa3562a1441fbe826bf528aa5ed6 | RealMrRabbit/python_workbook | /exercise_3.py | 2,794 | 4.5 | 4 | #Exercise 3: Area of a Room
#(Solved—13 Lines)
#Write a program that asks the user to enter the width and length of a room. Once
#the values have been read, your program should compute and display the area of the
#room. The length and the width will be entered as floating point numbers. Include
#units in your prompt an... | true |
6a003911cc1f0f89c481611305ffc7b7d8359f53 | Vikramjitsingh0001/assingnments | /assingnment_4.py | 2,482 | 4.15625 | 4 | #Q1
a=(1,2,3,4,5,'car','bike') #take tupil which contains different types of data type
print(len(a)) #print the lenth of tupil eg number of varriable
#Q2
v=(1,5,3,7,33,9) #take a tupil which contain n number
print(max(v)) #from n numbers find the largest one from tupi... | false |
ad060056fb45d250683cf24300c69c5fc5527dbb | Nubstein/Python-exercises | /Condicionais e Loop/Ex6.py | 512 | 4.125 | 4 | #Faça um programa que pergunte o preço de três produtos e informe qual produto você deve comprar,
#sabendo que a decisão é sempre pelo mais barato.
p1=float(input("Insira o preco do produto 1: R$ "))
p2=float(input("Insira o preco do produto 2: R$ "))
p3=float(input("Insira o preco do produto 3: R$ "))
if p1<p... | false |
cf35e65f5ed0def55723e846fea1366d42d61a5b | Nubstein/Python-exercises | /Strings/Ex8_strings.py | 490 | 4.25 | 4 | #Verificação de CPF.
# Desenvolva um programa que solicite a digitação de um número de CPF
# no formato xxx.xxx.xxx-xx e indique se é um número válido ou inválido
# através da validação dos dígitos verificadores edos caracteres de formatação.
cpf=input(" Insira o numero de cpf no formato xxx.xxx.xxx-xx ")
if (cp... | false |
91be40cb62c28dc236b72ffbcc967239531c4eec | Nubstein/Python-exercises | /Repeticao/Ex1_repet.py | 326 | 4.25 | 4 | #Faça um programa que peça uma nota, entre zero e dez.
# Mostre uma mensagem caso o valor seja inválido
# e continue pedindo até que o usuário informe um valor válido.
nota=float(input("Insira uma nota entre 0 e 10: "))
while nota<0 or nota>10:
nota=float(input("Valor incorreto! A nota deve ser de 0 á 10 ")) | false |
e2fcaedd0a0ac22274ada8167ad5c6050f78bc9e | Nubstein/Python-exercises | /Funcoes/Ex11_funcao.py | 436 | 4.34375 | 4 | # Exercício 3 - Crie uma função que receba como parâmetro uma lista de 4 elementos, adicione 2 elementos a lista e
# imprima a lista
def funcaoex3 (lista): #defina a função
print(lista.append (5)) # insira os elementos que quer adicionar
print(lista.append (6))
lista1=[1,2,3,4] #ide... | false |
12853d4c6fbd6325541bce74c1307871c28bf8f9 | z0k/CSC108 | /Exercises/e2.py | 1,960 | 4.1875 | 4 | # String constants representing morning, noon, afternoon, and evening.
MORNING = 'morning'
NOON = 'noon'
AFTERNOON = 'afternoon'
EVENING = 'evening'
def is_a_digit(s):
''' (str) -> bool
Precondition: len(s) == 1
Return True iff s is a string containing a single digit character (between
'0' and '9' i... | true |
f23776b0ea7d95b86dc0ab31d15f208657050d50 | Tavheeda/python-programs | /lists.py | 1,882 | 4.25 | 4 | # fruits = ['apple','orange','mango','apple','grapes']
# print(fruits)
# print(fruits[1])
# import math
# for fruit in fruits:
# print(fruit)
# numbers = [1,2,3,4,5,8,9,10]
# print(numbers[2:5])
# print(numbers[3:])
# for number in numbers:
# print(number)
# i = 0
# while i < len(numbers):
# print(numbers[i])
# ... | true |
a57ab223342720dbd0dd8b49e95a0bc849b307e3 | marcelosoliveira/trybe-exercises | /Modulo_4_Ciencia da Computacao/Bloco 35: Programação Orientada a Objetos e Padrões de Projeto/dia_1: Introdução à programação orientada a objetos/conteudo/primeira_entidade.py | 816 | 4.1875 | 4 | class User:
def __init__(self, name, email, password):
""" Método construtor da classe User. Note que
o primeiro parâmetro deve ser o `self`. Isso é
uma particularidade de Python, vamos falar mais
disso adiante!"""
self.name = name
self.email = email
self.pass... | false |
125f1dfaffb6403114b58246d6f16dd7f10c76f6 | marcelosoliveira/trybe-exercises | /Modulo_4_Ciencia da Computacao/Bloco 38: Estrutura de Dados II: Listas, Filas e Pilhas/dia_2: Deque/exercicios/exercicio_3.py | 1,179 | 4.25 | 4 | # Exercício 3: Desafio do Palíndromo - Uma palavra é um palíndromo se a sequência de
# letras que a forma é a mesma, quer seja lida da esquerda para a direita ou vice-versa.
# Crie um algorítimo que, ao receber uma sequencia de caracteres, indique se ela é
# ou não um palíndromo. Para este exercício iremos considerar ... | false |
1d675bd4f0271c09a8998b7ea02f4b2d3110b6cf | powerlego/Main | /insertion_sort.py | 1,053 | 4.125 | 4 | """
file: insertion_sort.py
language: python3
author: Arthur Nunes-Harwitt
purpose: Implementation of insertion sort algorithm
"""
def insertion_sort(lst):
"""
insertionSort: List( A ) -> NoneType
where A is totally ordered
effect: modifies lst so that the elements are in order
"""
for m... | true |
a0dbb5f621dd2a58469e0d26bf9190f45dfc86d8 | Rossorboss/Python_Functions_Prac | /map,filter,lambda.py | 2,621 | 4.5625 | 5 | #map, lambda statements
def square(num):
return num ** 2
my_nums = [1,2,3,4,5]
for x in map(square,my_nums): #the map function allows it to be used numerous times at once
print(x)
# Luke i am your father example--using map to call all 3 at the same time
def relation_to_luke(name):
if name == 'Darth Vad... | true |
67065afeef4f82ff240a6920f642cc739a486010 | dearwendy714/web-335 | /week-8/Portillo_calculator.py | 645 | 4.625 | 5 | # ============================================
# ; Title: Assignment 8.3
# ; Author: Wendy Portillo
# ; Date: 9 December 2019
# ; Modified By: Wendy Portillo
# ; Description: Demonstrates basic
# ; python operation
# ;===========================================
# function that takes two parameters(numbers) and adds th... | true |
84f611ef059a51b87074835a430eedf3da9f346c | davestudin/Projects | /Euler Problems/Euler Problems/Question 6.py | 529 | 4.34375 | 4 | from math import *
input = int(raw_input("Enter sum of the desired Pythagorean Triple: "))
def pythag(sum):
a,b,c=0.0,0.0,0.0
for a in range (1,sum):
for b in range(a,sum):
c=sqrt(a*a+b*b)
if c%1==0 and a%1==0 and b%1==0:
if (a+b+c)==sum:
return 'The Pythagorean triple with sides that add up to '+... | true |
4b3f447c832012f1baf5aa17d52049ba1a6a442e | asharma567/practice_problems | /codeeval/easy/longest_word.py | 988 | 4.1875 | 4 | '''
https://www.codeeval.com/open_challenges/111/
'''
import sys
def find_longest_word_greedy(sent):
#Greedy: O(n)
if sent == '' : return None
longest_word = None
for word in sent.split():
if not longest_word or longest_word < len(word):
longest_word = word
return ... | false |
0e06bc1f938f34183388ac64c76def7a328c4ba1 | BNHub/Python- | /Made_Game.py | 495 | 4.40625 | 4 | #1. Create a greeting for your program.
print("Welcome to the best band name game!")
#2. Ask the user for the city that they grew up in.
city = input("What is name of the city you grew up in?\n")
#3. Ask the user for the name of a pet.
pet_name = input("What's your pet's name?\n")
#4. Combine the name of their ci... | true |
1689f5917ee66e8fbdc904983a506f0afdfb06fc | tochukwuokafor/my_chapter_4_solution_gaddis_book_python | /bug_collector.py | 285 | 4.15625 | 4 | NUMBER_OF_DAYS = 5
total = 0
for day in range(NUMBER_OF_DAYS):
print('Enter the number of bugs collected on day #' + str(day + 1) + ': ', sep = '', end = '')
bugs_collected = int(input())
total += bugs_collected
print('The total number of bugs collected is', total) | true |
0d1890ddd1b000d26c4f5433970f2db1dc26090a | tochukwuokafor/my_chapter_4_solution_gaddis_book_python | /average_word_length.py | 372 | 4.25 | 4 | again = input('Enter a sentence or a word: ')
total = 0
words_list = []
while again != '':
words = again.split()
for word in words:
words_list.append(word)
total += len(word)
again = input('Enter another sentence or another word: ')
average = total / len(words_list)
print('The aver... | true |
742ecea8c97e08e476b86cd4f5dcc38cab2bb947 | era153/pyhton | /her.py | 456 | 4.21875 | 4 | name=int(input("no days employee1 work"))
print("no days hour" , name)
name1=int(input("no of hour employee1 work in first day"))
print("no days hour" , name1)
name2=int(input("no days hour employee1 work in second day"))
print("no days hour" , name2)
name3=int(input("no hour employee1 work in third day"))
print("no da... | true |
9cb8f89c34398fac7ee7d01a90c67f776eb9c5f7 | Linkney/LeetCode | /SwordOffer/O27.py | 2,023 | 4.40625 | 4 | # Again 2020年11月12日17:08:14 二叉树
"""
请完成一个函数,输入一个二叉树,该函数输出它的镜像。
例如输入:
4
/ \
2 7
/ \ / \
1 3 6 9
镜像输出:
4
/ \
7 2
/ \ / \
9 6 3 1
"""
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
sel... | false |
e6e5ebeb12fa3fb2a199ca2eff6ed08acee9953a | Linkney/LeetCode | /SwordOffer-3/O11.py | 1,420 | 4.1875 | 4 | """
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。
例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一个旋转,该数组的最小值为1。
示例 1:
输入:[3,4,5,1,2]
输出:1
示例 2:
输入:[2,2,2,0,1]
输出:0
"""
class Solution:
# def minArray(self, numbers: List[int]) -> int:
# 寻找逆序对
def minArray(self, numbers):
for index in range(l... | false |
18b42aa3c505c566d905393bce4c031ce26320bc | Linkney/LeetCode | /SwordOffer/O26.py | 1,938 | 4.28125 | 4 | # Again 2020年11月11日11:12:00 二叉树匹配
"""
输入两棵二叉树A和B,判断B是不是A的子结构。(约定空树不是任意一个树的子结构)
B是A的子结构, 即 A中有出现和B相同的结构和节点值。
例如:
给定的树 A:
3
/ \
4 5
/ \
1 2
给定的树 B:
4
/
1
返回 true,因为 B 与 A 的一个子树拥有相同的结构和节点值
示例 1:
输入:A = [1,2,3], B = [3,1]
输出:false
示例 2:
输入:A = [3,4,5,1,2], B = [4,1]
输出:true
"""
# Definition ... | false |
db03e6f78b9d00381d5a99494591c51d37273f82 | Linkney/LeetCode | /LeetCodeAnswer/O11.py | 645 | 4.15625 | 4 | """
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。
例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一个旋转,该数组的最小值为1。
示例 1:
输入:[3,4,5,1,2]
输出:1
示例 2:
输入:[2,2,2,0,1]
输出:0
"""
# def minArray(self, numbers: List[int]) -> int:
class Solution:
def minArray(self, numbers):
# 憨傻题
for i in range(len(num... | false |
1504008a8d33a1bc1fcd9dcca04fcb05221e1eb6 | hiteshpindikanti/Coding_Questions | /DCP/DCP140.py | 950 | 4.125 | 4 | """
This problem was asked by Facebook.
Given an array of integers in which two elements appear exactly once and all other elements appear exactly twice, find the two elements that appear only once.
For example, given the array [2, 4, 6, 8, 10, 2, 6, 10], return 4 and 8. The order does not matter.
Follow-up: Can you... | true |
9484cc99d76ae1d45dced6765fb9d850210ed1bc | hiteshpindikanti/Coding_Questions | /DCP/DCP9.py | 1,348 | 4.21875 | 4 | """
This problem was asked by Airbnb.
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers.
Numbers can be 0 or negative.
For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, and 5. [5, 1, 1, 5] should return 10,
since we pick 5 and 5.
Follow-up: Can you do this ... | true |
1f7e0f8e5af1f2f26af8d46cfdc55a235fed2168 | hiteshpindikanti/Coding_Questions | /DCP/DCP61.py | 512 | 4.25 | 4 | """
This problem was asked by Google.
Implement integer exponentiation. That is, implement the pow(x, y) function, where x and y are integers and returns x^y.
Do this faster than the naive method of repeated multiplication.
For example, pow(2, 10) should return 1024.
"""
def pow(base: int, power: int) -> int:
... | true |
fcedd0fd56b0b84c51738c5e1fff640a6d79ffd5 | hiteshpindikanti/Coding_Questions | /DCP/DCP46.py | 1,148 | 4.1875 | 4 | """
This problem was asked by Amazon.
Given a string, find the longest palindromic contiguous substring. If there are more than one with the maximum length, return any one.
For example, the longest palindromic substring of "aabcdcb" is "bcdcb". The longest palindromic substring of "bananas" is "anana".
"""
from copy ... | true |
890055af08088ea6a059a404b41f58f5a858cd0c | hiteshpindikanti/Coding_Questions | /DCP/DCP102.py | 684 | 4.125 | 4 | """
This problem was asked by Lyft.
Given a list of integers and a number K, return which contiguous elements of the list sum to K.
For example, if the list is [1, 2, 3, 4, 5] and K is 9, then it should return [2, 3, 4], since 2 + 3 + 4 = 9.
"""
from queue import Queue
def get_sublist(l: list, k: int) -> list:
... | true |
7134e0ee6a87054c906298ed87461d2e0d7af0eb | hiteshpindikanti/Coding_Questions | /DCP/DCP99.py | 1,089 | 4.15625 | 4 | """
This problem was asked by Microsoft.
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example, given [100, 4, 200, 1, 3, 2], the longest consecutive element sequence is [1, 2, 3, 4]. Return its length: 4.
Your algorithm should run in O(n) complexity.
"""
de... | true |
56fe3e955cecc18c2ce1fb1542cfe33b9847ad76 | hiteshpindikanti/Coding_Questions | /LeetCode/72.py | 1,567 | 4.125 | 4 | """
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
You have the following three operations permitted on a word:
Insert a character
Delete a character
Replace a character
"""
import heapq
def edit_distance(word1: str, word2: str) -> int:
if len(word... | false |
793efcdcacb8e3d8865cfcca067fd02c52479fda | hiteshpindikanti/Coding_Questions | /DCP/DCP57.py | 1,263 | 4.15625 | 4 | """
This problem was asked by Amazon.
Given a string s and an integer k, break up the string into multiple lines such that each line has a length of k or less. You must break it up so that words don't break across lines. Each line has to have the maximum possible amount of words. If there's no way to break the text up... | true |
0c03e2f41fce4059b7b56ba1433af5ad221e4c3b | justinembawomye/python-fun | /conditionals.py | 265 | 4.25 | 4 | conditional statements
x = 1
y = 5
if x < y:
print('x is less than y')
else:
print('x is not less than y')
# Else if
if x < y:
print('x is less than y')
elif x > y:
print('x is greater than y')
else:
print('x is equal to y')
| false |
b2e4f714b5309331cf1be2e1c3acc9827f1edb99 | INF1007-2021A/c03_ch4_exercices-NickLopz | /exercice.py | 1,570 | 4.375 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def is_even_len(string: str) -> bool:
total = len(string)
if total%2 == 0:
return True
def remove_third_char(string: str) -> str:
list1 = list(string)
del(list1[2])
string = ''.join(list1)
return string
def replace_char(string: str, old... | false |
1bec2c55f061c3fd1f367ba492d0b580950583e3 | santosh1561995/python-practice | /python-variables.py | 429 | 4.125 | 4 | print("For the datatypes in python an variable declaration")
#in python data type will be calculated automtically no need to declare explicitly
#integer type
x=5
print(x)
#float
f=5.5
print(f)
#multiple assignment to variable
a=b=c=10
print(a,b,c)
#assign values in one line
a,b=1,"India"
print(a,b)
#Swapping t... | true |
69cba86251ad064401c15b3a52c496026f0e8d3a | aliensmart/in_python_algo_and_dat_structure | /Code_1_1.py | 738 | 4.46875 | 4 | print('Welcome to GPA calculator')
print('Please enter all your letter grades, one per line')
print('Enter a blank line to designate the end.')
#map from letter grade to point value
points = {
'A+':4.0,
'A':4.0,
'A-':3.67,
'B+':3.33,
'B':3.0,
'B-':2.67,
'C+':2.33,
'C':2.0,
'C':1.67... | true |
5a60265d56d150d6934174bdfc59481c84073191 | Mukesh656165/Listobj | /tricklist4.py | 1,364 | 4.53125 | 5 | #nested list
a_list = ['a', ['bb', ['ccc', 'ddd'], 'ee', 'ff'], 'g', ['hh', 'ii'], 'j']
# to access single item which is in this case[a,g,j]
print(a_list[0],a_list[2],a_list[4])
#to access [bb,[ccc,ddd],ee,ff]
print(a_list[1])
#to access [hh,jj]
print(a_list[3])
#to access bb
print(a_list[1][0])
#to access [ccc,ddd]
p... | false |
792c526926b6d81f5ea0eb32bb87e1415959baa4 | yangliu2/cards | /cards/card.py | 1,063 | 4.15625 | 4 | class Card:
def __init__(self, suit, value):
self.suit = suit
self.value = value
self.rank = -1
self.name = self.convert_value_to_name(value)
def __str__(self):
"""give back string name"""
return f"{self.name} of {self.suit}"
def __repr__(self):
ret... | false |
633cf9adaadad858607db184e9495e9a69d41937 | aZuh7/Python | /oop.py | 1,440 | 4.25 | 4 | # Python Object-Oriented Programming
class Employee:
raise_amount = 1.04
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + "." + last + "@company.com"
Employee.num_of_emps += 1
def f... | true |
567c3b801b9679d4b30733df891d558e947fb65a | archisathavale/training | /python/basic_progs/min_max_nums.py | 904 | 4.3125 | 4 | #funtion of finding the minimum number
def find_min_val(array):
# assigning 1st element of array to minval
minval=array[0]
# traversing through the array
for element in array:
# to check whether the next element is smaller than the current
if element < minval:
# if yes assigning that number to minval
... | true |
cee62cc8bd73c1f9be83e55fdc5e4c4ceb920a55 | archisathavale/training | /python/Archis/addressbook.py | 790 | 4.1875 | 4 | addressbook={}
# Empty Dictionary
# Function of adding an address
# email is the key and name is the value
def add_address(email , name):
addressbook [email] = name
#print (addressbook)
return (email, name)
# Function of deleting an address
# only key is enough to delete the value in a dictionary
def dele_address(... | true |
93d48b9b89f9ebaabe098bf46fcea589a96cd384 | GuySK/6001x | /minFixPaymentCent.py | 2,218 | 4.125 | 4 | # This program calculates the minimum fixed payment to the cent
# for cancelling a debt in a year with the interest rate provided.
# minFixPaymentCent.py
#
def annualBalance(capital, annualInterestRate, monthlyPayment):
'''
Calculates balance of sum after one year of fixed payments.
Takes capital, interst r... | true |
e19161d4378b326e7c2e9f2c0a570d1952f9fd2b | GuySK/6001x | /PS6/Answer/reverseString.py | 524 | 4.46875 | 4 | def reverseString(aStr):
"""
Given a string, recursively returns a reversed copy of the string.
For example, if the string is 'abc', the function returns 'cba'.
The only string operations you are allowed to use are indexing,
slicing, and concatenation.
aStr: a string
returns: a reversed... | true |
4e7410fee77d106caab46c92cb6e9d978bfb4376 | GuySK/6001x | /PS6/Answer/buildCoder.py | 661 | 4.40625 | 4 | def buildCoder(shift):
"""
Returns a dict that can apply a Caesar cipher to a letter.
The cipher is defined by the shift value. Ignores non-letter characters
like punctuation, numbers, and spaces.
shift: 0 <= int < 26
returns: dict
"""
import string
lowcase = string.ascii_lowercase
... | true |
2d9b308bb95891e46a2f5d6cf8b9a46e7f18e54b | GuySK/6001x | /PS4/Answers/bestWord.py | 839 | 4.28125 | 4 | def bestWord(wordsList):
'''
Finds the word with most points in the list.
wordsList is a list of words.
'''
def wordValue(word):
'''
Computes value of word. Word is a string of lowercase letters.
'''
SCRABBLE_LETTER_VALUES = {
'a': 1, 'b': 3, 'c': 3, 'd':... | true |
cec85a8e1acb2412389030e89ec6722bd9c83fbb | Mariappan/LearnPython | /codingbat.com/list_2/centered_average.py | 977 | 4.125 | 4 | # Return the "centered" average of an array of ints, which we'll say is the mean average of the values,
# except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value,
# ignore just one copy, and likewise for the largest value.
# Use int division to produce the fin... | true |
3bd5b189e5a3beb450efad8e39a346d7cd9300c3 | lynellf/learing-python | /collections/slices.py | 1,944 | 4.4375 | 4 | # Sometimes we don't want an entie list or string, just a part.
# A slice is a new list or string made from a previous list or string
favorite_things = ['raindrops on roses', 'whiskers on kittens', 'bright coppeer kettles', 'warm woolen mittens',
'bright paper packages tied up with string', 'cream ... | true |
5fd6323dab3a5e3221775e1be76bab49f7f3f68f | lynellf/learing-python | /python_basics/numbers.py | 587 | 4.34375 | 4 | # Numeric Data
three = 1 + 2
print('The number %s' %(three))
# Rounding numbers
_float = 0.233 + .442349
rounded = round(_float)
print('A number is %s, and a rounded number is %s' %(_float, rounded))
# Converting strings to numbers
string_num = '12'
int_num = int(string_num)
float_num = float(string_num)
string_num_t... | true |
6203dd89bad719a8003dd573f08865acb6301e10 | arsummers/python-data-structures-and-algorithms | /challenges/comparator/comparator.py | 1,060 | 4.3125 | 4 | """
Comparators are used to compare two objects. In this challenge, you'll create a comparator and use it to sort an array. The Player class is provided in the editor below. It has two fields:
name: a string.
score: an integer.
Given an array of n Player objects, write a comparator that sorts them in order of decreasi... | true |
b937852ce70a3d673ec5d34f7d9b9f6f87a73617 | arvakagdi/Basic-Algos | /IterativeBinarySearch.py | 1,139 | 4.25 | 4 | def binary_search(array, target):
'''
Write a function that implements the binary search algorithm using iteration
args:
array: a sorted array of items of the same type
target: the element you're searching for
returns:
int: the index of the target, if found, in the source
... | true |
e030ab9fb1bb852ddaf84ccf10408a57eb543912 | deek11/practice_python | /CheckTicTacToe.py | 950 | 4.1875 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
""" This script is used to find a winner of Tic Tac Toe from a 3x3 matrix.
"""
def main():
mx = [['x', 'x', 'x'],
[0, 'o', 0],
['o', 0, 'x']]
winner = find_winner(mx)
if winner != 0:
print "Winner = {0}".format(winner)
else:
... | false |
16f1014c570a7fc288f820f38343e2caf8ef3e07 | deek11/practice_python | /OddEven.py | 286 | 4.1875 | 4 | def find_odd_even(num):
if num % 2 == 0:
return True
return False
def main():
num = input("Enter number : ")
if find_odd_even(num):
print "{0} is even".format(num)
else:
print "{0} is odd".format(num)
if __name__ == '__main__':
main() | false |
0d27c9844e556d3ae480c4b33b5e20bab7f61164 | deek11/practice_python | /RockPaperScissors.py | 1,502 | 4.3125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
""" This script is used to Make a two-player Rock-Paper-Scissors game.
"""
def main():
print "Rock Paper Scissors!"
print "Rules :- \n" \
"0 - Rock \n" \
"1 - Paper \n" \
"2 - Scissors"
continue_play = "y"
while continue_pla... | false |
01dd8d67ceaad408cb442d882cf3c4c08f3eb445 | eduardomrocha/dynamic_programming_problems | /tabulation/python/06_can_construct.py | 1,574 | 4.25 | 4 | """Can construct.
This script implements a solution to the can construct problem using tabulation.
Given a string 'target' and a list of strings 'word_bank', return a boolean indicating
whether or not the 'target' can be constructed by concatenating elements of 'word_bank'
list.
You may reuse elements of 'word_bank'... | true |
326a3bc0283e5864a9b7f1930410749884f3fdbc | eduardomrocha/dynamic_programming_problems | /tabulation/python/08_all_construct.py | 2,053 | 4.34375 | 4 | """All construct.
This script implements a solution to the all construct problem using tabulation.
Given a string 'target' and a list of strings 'word_bank', return a 2D list containing
all of the ways that 'target' can be constructed by concatenating elements of the
'word_bank' list. Each element of the 2D list shou... | true |
f6d6484b84550580fe2941e92fee20054c66d468 | aakhedr/algo1_week2 | /part3/quickSort3.py | 2,470 | 4.21875 | 4 | def quickSort(A, fileName):
quickSortHelper(A, 0, len(A) - 1, fileName)
def quickSortHelper(A, first, last, fileName):
if first < last:
pivot_index = partition(A, first, last, fileName)
quickSortHelper(A, first, pivot_index - 1, fileName)
quickSortHelper(A, pivot_index + 1, las... | true |
f66e6d8773c886adb6c1932f8904ef545b2e2476 | YuSheng05631/CrackingInterview | /ch4/4.5.py | 1,184 | 4.15625 | 4 | """
Implement a function to check if a binary tree is a binary search tree.
"""
import Tree
def isBST(bt):
if bt.left is None and bt.right is None:
return True
if bt.left is not None and bt.left.data > bt.data:
return False
if bt.right is not None and bt.right.data < bt.data:
retur... | true |
1c428f7cf06fa3b6113b2571221becade498a030 | fire-ferrets/cipy | /cipy/alphabet/alphabet.py | 1,452 | 4.46875 | 4 | """
The Alphabet class provides a general framework to embed alphabets
It takes a string of the chosen alphabet as attribute. This provides
the encryption and decryption functions for the ciphers with a performance
boost.
"""
class Alphabet():
def __init__(self, alphabet):
"""
Initialise an Alpha... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.