blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
559b25244991703f4f70032df9516bd4b28048b7 | elminson/hackerrank | /find-pair-of-numbers/solution.py | 794 | 4.21875 | 4 | # Input: A list / array with integers. For example:
# [3, 4, 1, 2, 9]
# Returns:
# Nothing. However, this function will print out
# a pair of numbers that adds up to 10. For example,
# 1, 9. If no such pair is found, it should print
# "There is no pair that adds up to 10.".
def pair10(given_list):
a = []
... | true |
fc930865974fb10e85e4793868954262a736c3b9 | morrrrr/CryptoMasters | /11_Diffie-Hellman_key_agree.py | 1,804 | 4.15625 | 4 | import math
from sympy import nextprime
# UTILS
def exponentiation_by_squaring(base, exponent) :
res = 1
while exponent > 0 :
if exponent & 1 == 1:
res = (res * base)
exponent = (exponent - 1) // 2
base = (base * base)
else:
exponent ... | true |
c86cda934adc71beb1e3a8e94b3e17e4f59e10f9 | prathap442/python-basica | /if_method.py | 409 | 4.125 | 4 | num1 = 100
num2 = 100
if num1 > num2:
print('the num1 is greater than num2')
elif(num2 > num1):
print('the num2 is greater than num1')
else:
print('the num1 is equal to num2')
# and operator usage
# if (num1 > num2) and (num2 > num1):
# print('num1 can\'t predict what kind you are')
# elif(num1 > num2)
# pr... | false |
e62a10bb91d6210ac2cbce790ec2a995d867c4e2 | mtholder/eebprogramming | /lec2pythonbasics/factor.py | 991 | 4.28125 | 4 | #!/usr/bin/env python
import sys
if len(sys.argv) != 2:
sys.exit(sys.argv[0] + ": Expecting one command line argument -- the integer to factor into primes")
n = int(sys.argv[1])
if n < 1:
sys.exit(sys.argv[0] + "Expecting a positive integer")
if n == 1:
print 1
sys.exit(0)
def get_smallest_prime_fac... | true |
e4ba425daaa585b36e16ce7d12bd071e4843e9e4 | shiningPanther/Project-Euler | /Problem2.py | 1,118 | 4.15625 | 4 | '''
Problem 2:
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, find the sum of the even-value... | true |
f4c33344856ee099cca55c02b9c4bec38dfd841f | st-pauls-school/python | /5th/turtles-intro/turtle-intro.py | 1,674 | 4.4375 | 4 | #the turtle library
import turtle
# run (F5) this file
# type one of the function names from the shell
# note that if you close the turtle window, you will need to re-run this
# to make new functions, copy the simple() function and replace the text in between the comments to do
# the different new mov... | true |
e5b991906748f48551b8036f7fdb10b4b98b03e4 | yuhan1212/coding_practice | /coding_practice_private/binary_tree_traversal/depth_first/postorder.py | 1,274 | 4.1875 | 4 | # Construct Node class
class Node(object):
def __init__(self, value):
self.value = value
self.left = None
self.right = None
# Construct BinaryTree class
class BinaryTree(object):
def __init__(self, root):
self.root = Node(root)
# Instanciate a tree:
tree = BinaryTree(1)... | true |
9aac2cf63015eaea8939a87c23f6e213176a261d | yuhan1212/coding_practice | /coding_practice_private/binary_tree_traversal/breadth_first/levelorder.py | 1,576 | 4.125 | 4 | # Construct Node class
class Node(object):
def __init__(self, value):
self.value = value
self.left = None
self.right = None
# Construct BinaryTree class
class BinaryTree(object):
def __init__(self, root):
self.root = Node(root)
# Instanciate a tree:
tree = BinaryTree(1)... | true |
d9ed648b9f57c03cbe17743590720fb0213c3f2b | brucekkk/python_scripts | /txt_operate.py | 1,053 | 4.28125 | 4 | # -*- coding: utf-8 -*-
'''
Created on 2019.11.19
@author: BMA
this is a script to modify txt file, including replace one word and
delete some column. Notice that if we give 1 to the delete column,it means
printing first column, 2 means printing first and second columns, etc.
'''
file_path = '10-1.txt' # change fi... | true |
97b815570d2524c5ecd78a8d52ebc18276a45f97 | mingyyy/crash_course | /week2/martes/7-5.py | 637 | 4.125 | 4 | '''
7-5. Movie Tickets: A movie theater charges different ticket prices depending on a person’s age .
If a person is under the age of 3, the ticket is free; if they are between 3 and 12, the ticket is $10;
and if they are over age 12, the ticket is $15 .
Write a loop in which you ask users their age, and then tell them... | true |
be43bcf5880b9f59cbddfa6052de53120aaef7cc | mingyyy/crash_course | /week1/ChangingGuestList.py | 1,149 | 4.40625 | 4 | '''
3-5. Changing Guest List: You just heard that one of your guests can’t make the dinner,
so you need to send out a new set of invitations . You’ll have to think of someone else to invite .
• Start with your program from Exercise 3-4 .
Add a print statement at the end of your program stating the name of the guest w... | true |
d46f4f18129728b15fa6a391e17344a459898628 | mingyyy/crash_course | /week2/viernes/class_9_6.py | 857 | 4.53125 | 5 | '''
9-6. Ice Cream Stand: An ice cream stand is a specific kind of restaurant .
Write a class called IceCreamStand that inherits from the Restaurant class you wrote in Exercise 9-1 (page 166)
or Exercise 9-4 (page 171) . Either version of the class will work; just pick the one you like better .
Add an attribute called ... | true |
655652ddbc5ff290cbb0a1fe70aaf06d8bcbd2c0 | mingyyy/crash_course | /week2/viernes/class_9_8.py | 981 | 4.3125 | 4 | '''
9-8. Privileges: Write a separate Privileges class .
The class should have one attribute, privileges, that stores a list of strings as described in Exercise 9-7 .
Move the show_privileges() method to this class .
Make a Privileges instance as an attribute in the Admin class .
Create a new instance of Admin and use ... | true |
73700d1140b8d8e53f91a673248435bde5f65007 | mingyyy/crash_course | /week2/jueves/class_9_3.py | 1,033 | 4.59375 | 5 | '''
9-3. Users: Make a class called User . Create two attributes called first_name and last_name,
and then create several other attributes that are typically stored in a user profile .
Make a method called describe_user() that prints a summary of the user’s information .
Make another method called greet_user() that pri... | true |
7617579a48dabff19c4bc3ddb7e7e7822db5ff03 | mingyyy/crash_course | /week2/miercoles/8-3.py | 555 | 4.59375 | 5 | '''
8-3. T-Shirt: Write a function called make_shirt() that accepts a size and the text of a message
that should be printed on the shirt .
The function should print a sentence summarizing the size of the shirt and the message printed on it .
Call the function once using positional arguments to make a shirt .
Call the f... | true |
c0a2fbaebf0efe9c0eae3dea677264bd759e6b91 | mingyyy/crash_course | /week1/GuestList.py | 472 | 4.21875 | 4 | '''
3-4. Guest List: If you could invite anyone, living or deceased, to dinner,
who would you invite? Make a list that includes at least three people you’d like to invite to dinner .
Then use your list to print a message to each person, inviting them to dinner .
'''
guests = ["Buddha", "Guassian", "Poisson"]
for i in... | true |
8ea04f8f0537d507c15511a4a103f8b1a2fbf6f1 | mingyyy/crash_course | /week3/lunes/chap10_10.py | 1,169 | 4.125 | 4 | '''
10-10. Common Words: Visit Project Gutenberg (http://gutenberg.org/ ) and find a few texts you’d like to analyze .
Download the text files for these works, or copy the raw text from your browser into a text file on your computer .
You can use the count() method to find out how many times a word or phrase appears in... | true |
de8d56410cc1457009f7edd91f8880af8dacbc2b | mingyyy/crash_course | /week2/miercoles/8-9.py | 314 | 4.15625 | 4 | '''
8-9. Magicians: Make a list of magician’s names . Pass the list to a function called show_magicians(),
which prints the name of each magician in the list .
'''
def show_magicians(l):
rs = " "
for i in l:
rs += (i + " ")
return rs
print(show_magicians(["Martin", "Melissa", "Michael"])) | false |
3f0d2e755d26bc66570fb3fd1d2076d61982229e | Illugi317/forritun | /mimir/assignment2/3.py | 518 | 4.1875 | 4 | '''
Write a program that reads in 3 integers and prints out the minimum of the three.
'''
num1 = int(input("First number: ")) # Do not change this line
num2 = int(input("Second number: ")) # Do not change this line
num3 = int(input("Third number: ")) # Do not change this line
# Fill in the missing code below
... | true |
29fce86b38d0a1d2e25c61a7b388ecd7cc2d9ed0 | Illugi317/forritun | /mimir/13/1.py | 1,241 | 4.21875 | 4 | '''Write a program that asks for a name and a phone number from the user and stores the two in a dictionary as key-value pair.
The program then asks if the user wants to enter more data (More data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits. Finally, it stores the dictiona... | true |
19271efb3151367a8411a66d29fa72376a7b5ba9 | Illugi317/forritun | /mimir/10/2.py | 890 | 4.1875 | 4 | '''
Write a program that makes a list of the unique letters in an input sentence. That is, if the letter "x" is used twice in a sentence, it shouild only appear once in your list. Neither punctuation nor white space should appear in your list. The letters should appear in your list in the order they appear in the in... | true |
ed5273b38d45704cd164f2fafd939e8e57264a66 | Illugi317/forritun | /mimir/17/2.py | 1,432 | 4.125 | 4 | '''
2. Sentence
5 points possible
Implement a class called Sentence that has a constructor that takes a string, representing the sentence, as input. The class should have the following methods:
get_first_word(): returns the first word as a string
get_all_words(): returns all words in a list.
replace(inde... | true |
0d5a143820fe0c434b581faadfafa31ff9fe4e3b | Illugi317/forritun | /mimir/assignment3/3.py | 364 | 4.125 | 4 | '''
Write a program using a while statement,
that given a series of numbers as input,
adds them up until the input is 10 and then prints the total.
Do not add the final 10.
'''
summ = 0
while True:
num = int(input("Input an int: ")) # You can copy this line but not change it
if num == 10:
... | true |
dcc6bf25956533d61c25830783d07cefd4c83090 | Illugi317/forritun | /mimir/assignment1/3.py | 330 | 4.15625 | 4 | '''
Write a program that:
Takes an integer n as input
Adds n doubled to n tripled and prints out the result
Examples:
If the input is 2, the result is 10
If the input is 3, the result is 15
If the input is 4, the result is 20
'''
n_str = int(input('Input n: '))
print(n_str*2 + ... | true |
2bf3b0acc2f35b2c7df93af116c8c8722336d1e1 | Illugi317/forritun | /mimir/assignment1/5.py | 551 | 4.46875 | 4 | '''
BMI is a number calculated from a person's weight and height. The formula for BMI is:
weight / height2
where weight is in kilograms and heights is in meters
Write a program that prompts for weight in kilograms and height in centimeters and outputs the BMI.
'''
weight_str = input("Weight (kg): ") # d... | true |
66321184d6f6c1a8d910920b83bc7968f22d0695 | Illugi317/forritun | /mimir/assignment4+/2.py | 1,849 | 4.6875 | 5 | '''
Let's attempt to draw a sine wave using the print() statement.
Sine waves are usually drawn horizontally (left to right)
but the print() statement creates output that is ordered from top to bottom.
We'll therefore draw our wave vertically.
Our program shall accept two arguments:
number_of_cycles - whi... | true |
33b46891082bf7233f853dfc38d160b03cccce69 | Illugi317/forritun | /mimir/12/3.py | 1,140 | 4.4375 | 4 | '''
This program builds a wordlist out of all of the words found in an input file and prints all of the unique words found in the file in alphabetical order. Remove punctuations using 'string.punctuation' and 'strip()' before adding words to the wordlist.
Make your program readable!
Example input file test.txt:
the ... | true |
e3c862ed88c6d2c707f8f09d6658758ba7863ce5 | Pixelsavvy72/PythonProblems | /coin toss.py | 930 | 4.125 | 4 | import random
count = 0
heads = 0
tails = 0
headsInARow = 0
tailsInARow = 0
most = 0
least = 0
prompt = "Enter a number > "
print "How many times would you like to flip the coin?"
times = int(raw_input(prompt))
while count < times:
flip = random.randrange(1,3,1)
if flip == 1:
heads += 1
hea... | false |
50ba6f395942e3da9f0e75658894b09b5eccc03f | ms-shakil/Data-Structure | /Binary_Tree.py | 2,765 | 4.125 | 4 | class Node:
def __init__(self,data):
self.data = data
self.left = None
self.right = None
def __repr__(self):
return repr(self.data)
def add_left(self,value):
self.left = value
def add_right(self,value):
self.right = value
def Tree():
two =Node... | false |
2f1aff649c38537c56124dd7b9c3d712f6f232ce | spencerhhall/phone-codes | /convert.py | 1,058 | 4.15625 | 4 | # Dictionary containing the number associated with each part of the alphabet
ASSOCIATIONS = {"abc": 2, "def": 3, "ghi": 4, "jkl": 5,"mno": 6,"pqrs": 7,"tuv": 8, "wxyz": 9}
# wordlist: array that contains all words from the wordlist that are the desired length
def convertToNumbers(wordlist):
combos = {}
for word in ... | true |
b6d1f075e6a8af8cdc5e2186079b992100edae66 | howinator/CS303E | /6-31.py | 1,602 | 4.25 | 4 | def main():
import time
time = time.time()
year, month, days, hours, minutes, seconds = convert_seconds(time)
print ("Current date and time is ", month, " ", days, ", ", year, hours, ":",
minutes, ":", seconds)
def convert_seconds (time):
secondsInYear = 365 * 24 * 60 * 60
num... | false |
b36d2bbf9bc1c219b9d6191eb912b13012a227bb | samirsaravia/Python_101 | /Bootcamp_2020/challenges/question_2.py | 251 | 4.125 | 4 | """
Question 2
Write python code that will create a dictionary containing key, value pairs that
represent the first 12 values of the fibonacci sequence
"""
s = 35
a = 0
b = 1
d = dict()
for i in range(s + 1):
d[i] = a
a, b = b, a + b
print(d)
| true |
056ca0c2bd5d5f3a6ff11e9fbf28b6f8445f1a8c | samirsaravia/Python_101 | /Bootcamp_2020/files_and_functions/challenges/3.py | 335 | 4.3125 | 4 | """
Question 3
Write a function to calculate a to the power of b. If b is not given
its default value should be 2.Call it power
"""
def power(a, b=2):
"""
:return: returns the power of a**b. by default b is 2
"""
return a ** b
print(f'4 to the power of 3 gives {power(4,3)}')
print(f'Inputting 4 give... | true |
a2ed12a50b06d55b03f368e100582a7e1a242dc1 | rezende-marcus/Pythonteste | /aula08.py | 263 | 4.15625 | 4 | import emoji
#from math import sqrt, floor
#import math
#num = int(input('Digite um número: '))
#raiz = sqrt(num)
#raiz = math.sqrt(num)
#print('A raiz de {} é igual a {:.2f}'.format(num, raiz))
#print('A raiz de {} é igual a {:.2f}'.format(num, floor(raiz)))
| false |
bec2a04cf084a5bfb87db165cc6c1b16a8ff0369 | Smoow/MIT-UNICAMP-IPL-2021 | /solutions/p2_1.py | 994 | 4.1875 | 4 | def square(x):
"""
Calculate the square of a number.
Args:
x [int, float]: numerical argument to be squared.
Returns:
Square of x.
"""
return x ** 2
def fourth_power(x):
"""
Calculate the fourth power of a number.
Args:
x [int, float]: numerical a... | false |
e15b9185e9c602cda06553aa7dc9aca671acdf6f | PythonStudy/CorePython | /Exercise/Chapter8/8_4_PrimeNumbers.py | 861 | 4.5 | 4 | #coding=utf-8
"""
Prime Numbers. We presented some code in this chapter to determine a number’s largest factor or if it is prime. Turn this
code into a Boolean function called isprime() such that the input is a single value, and the result returned is True if
the number is prime and False otherwise.
"""
def i... | true |
e14d8667012aa8a66efe76bcff3b2a459633a2b2 | PythonStudy/CorePython | /Exercise/Chapter8/8_7_PefectNumber.py | 1,193 | 4.125 | 4 | #coding = 'utf-8'
#Exercise 8.7
"""
Perfect Numbers. A perfect number is one whose factors (except
itself) sum to itself. For example, the factors of 6 are 1, 2, 3, and 6.
Since 1 + 2 + 3 is 6, it (6) is considered a perfect number. Write a
function called isperfect() which takes a single integer input
and ou... | true |
6764bb9e4f541c46872550d6f60f04b3c4c8c141 | KHungeberg/Python-introcourse | /C4Assignment4E (2).py | 1,008 | 4.125 | 4 | # Assignment 4E: Bacteria growth:
import numpy as np
import math as ma
# Write a program that simulates the bacteria growth hour by hour and stops when the number of bacteria exceeds
# some fixed number, N. Your program must return the time t at which the population first exceeds N. Even
# though the actual numbe... | true |
80f5f93884735da50dcf50c2438a400a2f387974 | KHungeberg/Python-introcourse | /C3Assignment3C.py | 701 | 4.1875 | 4 | #ASSIGNMENT 3C
# Write a function that takes as input two unit vectors v1 and v2 representing two lines, and computes the acute
# angle between the lines measured in radians.
# First we import math and numpy
import math as m
import numpy as np
# The formula for calculating the angle between 2 unitvector... | true |
e77faccfbf6c28f62145b4a70414217f7ca9a873 | jamiebrynes7/advent-of-code-2017 | /day_3/challenge1.py | 1,037 | 4.125 | 4 | import sys
import math
def main():
# Get input arguments.
try:
target_square = int(sys.argv[1])
except IndexError:
print("Usage: python challenge1.py <target_square>")
exit(1)
# Get the closest perfect odd square root (defines dimensions of the square)
closest... | true |
de22af72c9b8d49040639b5e4c05c78ef9b15a9e | rohitraghavan/D05 | /HW05_ex09_01.py | 674 | 4.15625 | 4 | #!/usr/bin/env python3
# HW05_ex09_01.py
# Write a program that reads words.txt and prints only the
# words with more than 20 characters (not counting whitespace).
##############################################################################
# Imports
# Body
def read_check_words():
"""This method reads a file and p... | true |
62aac78ddb481d0a40391b4eaeeb1e0a894531c5 | kazenski-dev/01_ling_progr_cesusc | /N1_exercicio_02.py | 1,976 | 4.46875 | 4 | """
Crie um classe Funcionário com os atributos nome, idade e salário. Deve ter
um método aumenta_salario. Crie duas subclasses da classe funcionário,
programador e analista, implementando o método nas duas subclasses. Para
o programador some ao atributo salário mais 20 e ao analista some ao salário
mais 30, mostrando ... | false |
0af43e944a3d5ac7680c69af69908361c95f545b | philipesko/LearningPython14 | /Lesson1/CompareStringToString.py | 491 | 4.125 | 4 | def compareStr (a, b):
if type(a) is str and type(b) is str:
print(0)
if a == b:
print(1)
elif len(a) > len(b) and not a == b:
print(2)
elif b == 'learn' and not a == b:
print(3)
else: print("This is not stri... | false |
21bd0fa289fe626e6d52a6328225af89bbac7217 | tomvangoethem/toledo | /03_find_triplets/find_triplets.py | 1,285 | 4.125 | 4 | """
Write a program that takes a list of integer numbers as input.
Determine the number of sets of 3 items from the list, that sum to 0.
E.g. if the list = [5, -2, 4 , -8, 3], then there is one such triplet: 5 + (-8) + 3 = 0.
For larger lists, the number of triplets probably will be much higher.
If the list would con... | true |
5f7582dc194423187d59d370056439e6c1ebfd3a | Jhonatanpasos/Introprogramacion | /Talleres/Tallercondicionales2.py | 1,331 | 4.25 | 4 | #--------------------------------Ejercicios condicionales---------------------------------#
#1. Dados dos numeros, determine si son iguales o cual es el mayor
#2. Pida la edad del usuario y muestre en pantalla la siguiente información:
# - Si tiene menos de 18 años diga que es menor de edad
# - Desde 18 has... | false |
6ab1c7ca59e057eb8468408324a67ea728ed1e8e | Jhonatanpasos/Introprogramacion | /Clases/Operaciones.py | 817 | 4.25 | 4 | #Le otorgamos un valor a las variables
numeroA = 87
numeroB = 83
#Realizamos una suma entre las variables
sumar = numeroA + numeroB
print ("el resutado de la suma es", sumar)
print (f"la suma dio {sumar} exitosamente")
#Realizamos una resta entre las variables
restar = numeroA - numeroB
print ("el resutado de la resta ... | false |
22909c205fde49807b154925facd55aee51edc55 | MCHARNETT/Simple-Projects | /fibonacci.py | 618 | 4.5 | 4 | # -*- coding: utf-8 -*-
"""
Created on Wed Jul 26 11:07:59 2017
@author: harne
"""
import sys
def fibonacciSeries(n):
''' n is the range of values that the program will calculate
the series up to.
returns a list of the fibbonaci numbers in that range.
'''
fibbonaci_numbers = [1, 1]
... | true |
1539fb30613474a6a14579b40bca98431b3cab79 | YeashineTu/HelloWord | /game.py | 859 | 4.21875 | 4 | #!/usr/bin/python
#-*- coding utf-8 -*-
#date:20171011
#author:tyx
#==== 点球小游戏 ====
def isRight(value,list):
if value not in direction:
print('Your direction is not right,input again')
return False
else:
return True
def isEqual(value1,value2):
if(value1==value2[0]):
print("sorry,you lost the score")
retur... | true |
dd104ea65ffd608e4d34783422e77e3aab2caf5b | lostarray/LeetCode | /027_Remove_Element.py | 1,127 | 4.15625 | 4 | # Given an array and a value, remove all instances of that value in place and return the new length.
#
# Do not allocate extra space for another array, you must do this in place with constant memory.
#
# The order of elements can be changed. It doesn't matter what you leave beyond the new length.
#
# Example:
# Given i... | true |
71b64e10176d739cd899624a4ece18d2369a4053 | Aehlius/CS-UY_1134 | /HW/HW4/ia913_hw4_q4.py | 1,154 | 4.28125 | 4 | import BST_complete
def create_chain_bst(n):
# this function creates a degenerate tree with all right children from 1 to n
chain_tree = BST_complete.BST()
for i in range(n):
# since the loop will insert larger values as it continues, all children will be right
chain_tree.insert(i+1)
re... | true |
283214a2ea9b857cf20e782d328d9ae32baee10a | JasperMi/python_learning | /test/chapter_04/test2.py | 447 | 4.40625 | 4 | # range(1,6):生成1-5的数字
for value in range(1, 6):
print(value)
# list():将其中的值转换为列表
numbers = list(range(1, 6))
print(numbers)
# 生成1-10之间的偶数
even_numbers = list(range(2, 11, 2))
print(even_numbers)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
# 获得数字列表中的最大值
print(max(numbers))
# 获得数字列表中的最小值
print(min(numbers))
# 获得数字列表的和
p... | false |
04ec80a89fb31219728371330989b67900b00977 | JasperMi/python_learning | /chapter_04/pizzas.py | 416 | 4.21875 | 4 | pizzas = ['seafood pizza', 'cheese pizza', 'beef pizza']
# 创建副本
friends_pizzas = pizzas[:]
pizzas.append('chicken pizza')
friends_pizzas.append('corn pizza')
# for pizza in pizzas:
# print("I like " + pizza)
print("My favorite pizzas are:")
for pizza in pizzas:
print(pizza)
print("\nMy friends favorite pizz... | true |
511c7189863776d385c52fdb088c37d1555a87fc | sushmita-2001/Python-p2p-programming-classes | /calc.py | 685 | 4.4375 | 4 | print('Welcome to the calculator world!!')
print('Please type the math operation you want to complete')
print("+ for addition \n - for subraction \n * for multiplication \n / for division \n ** for power \n % for modulus")
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '... | true |
e0a8234f3f2c1eb5e0c20c24f561971ad4d701e7 | nakinnubis/abiola_akinnubi_test | /QuestionIsOverlapProgram python version/isoverlap.py | 1,267 | 4.25 | 4 | import sys
#this lambda converts string to float since python does not have decimal
tofloat = lambda x:float(x)
#this converts inputs to array but calls the tofloat method on each inputs
def InputToArray(inpt):
values = []
listvalue = inpt.split(',')
for inp in listvalue:
values.append(tofloat(inp))... | true |
c721ff8e28c36253644f4893cf75f6a69e0040ed | prafful/python_jan_2020 | /32_threads.py | 818 | 4.25 | 4 | """
thread as smallest unit of execution!
multithreading
thread module (depreceated) (python 3+ has _thread to support backward compatibility!)
threading module
"""
import _thread
import time
def callMeForEachThread(threadName, delay):
counter = 0
while counter<=5:
print(threadName," ... | true |
42c32fe289ab0c5534b4332592cd6e88371e05a6 | prafful/python_jan_2020 | /22_oops_class.py | 960 | 4.28125 | 4 | '''
class
instance attributes
class attributes
self
__init__
'''
#create custom class in python
class Vehicle:
vehicleCount = 0
#constructor
def __init__(self, color, vtype):
print("I am in constructor!")
self.color = color
self.vtype = vtype
Vehicle.vehicleCount += 1
... | true |
81b05a94802aba0c980133a86297c4fccfedaae8 | junjiegithub/hello_world | /brother_wu_19/test/3test.py | 1,404 | 4.28125 | 4 | '''
函数的定义:
1,具备某一功能的代码段
2.可以重复使用
函数的定义语法:
def 函数名称():
函数体(实现功能的代码段)
注意:函数体的缩进
函数的调用
调用语法
没有参数:
函数名称()
有函数:
函数名称(实参值)
丰富你的函数-返回值
语法:
:return[变量]
def 函数的名称(参数):
函数体(实现功能的代码段)
:return 变量(没有变量,返回None)
1.返回值可以是任何类型的变量
2.返回值也可以是表达式
3,可以返回一个/多个变量,可以用逗号隔开或者元祖
4,函数体执行过程中,遇到retur... | false |
5c6f3e64420a0c773c93c7e3c7711544a52a3c76 | yeazin/python-test-tutorial-folder | /csv input tutorial/reading csv.py | 496 | 4.21875 | 4 | #reading CSV file
import csv
with open('csvfile.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
dates=[]
colors=[]
for row in readCSV:
'''
print('')
print(row[0],row[1],row[2],row[3])
'''
color=row[3]
date=[0]
dates.append(date)
colors.append(color)
print(dates)
print(colors)
... | true |
ac563df061b4ac6abd833d73f5bcfa66cd06851a | ngirmachew/data-structures-algorithms-1 | /CtCI/Ch.1 - Arrays & Strings/1.6string_compression.py | 769 | 4.28125 | 4 | def string_compression(input_string):
# takes care of upper and lower case -> all to lower
# example: given aabcccccaaa shoud return -> a2b1c5a3
input_string = input_string.lower()
count = 1
# string that is used to store the compressed string
compressed_str = ""
for i in range(len(input_str... | true |
72f459eb7ab8ac7a7cd719077e51f6e404b08eae | CristianMoraS/Metodos_Ordenamiento_Python | /Métodos de Ordenamiento/Algoritmos - Metodos/QuickSort.py | 2,784 | 4.1875 | 4 | import random # Importamos la clase random para los datos randomicos.
import time # Se importa la clase time, para saber el tiempo de ejecucion del programa.
# El siguiente es el método de ordenamiento QuickSort, acepta como parametro una lista (array), la cual es la
# Traduccion de nuestros datos, almacenados po... | false |
26d65ef77f47517779fe29dfed53ddeb883f4841 | manupachauri1023/manupachauri1023 | /manu leap year.py | 309 | 4.1875 | 4 | year = int(input("enter the year")
if year%4==0 and year % 100 !=0:
print("it is a leap year")
elif year % 100 ==0:
print("it is not leap year")
elif year % 400 ==0:
print("it is a leap year")
else:
print("it is not a leap year)
| false |
3efb6832abc42063722faa7e3fe006e06978abbf | mollyocr/learningpython | /practicepython/exercise6.py | 1,057 | 4.46875 | 4 | ### 2018-10-29 mollyocr
#### practicepython.org exercise 6: string lists
## Ask the user for a string and print out whether this string is a palindrome or not. (A palindrome is a string that reads the same forwards and backwards.)
string_to_eval = input("Hi! Enter a string. I'll tell you if it's a palidrome or not. "... | true |
75d3fed54c68a294785a43e57f068d2bee765c5c | mollyocr/learningpython | /practicepython/exercise4.py | 1,340 | 4.4375 | 4 | #### 2018-10-25 mollyocr
#### practicepython.org exercise 4: divisors
## Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (A divisor is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.)
... | true |
73f3882babca313f137eff0892e8ef9ebc41bf2a | imushir/qxp_python_class_july_2019 | /QuickxpertPython-master/13042019/class/example_scdnd.py | 2,058 | 4.3125 | 4 | class Employee:
"""
This Employee class
"""
company_name = "Quickxpert" # class variable
def __init__(self):
"""
This is constructor of class Employee.
Initializes the attribute values.
:returns: None
:rtype: None
:author: Qxpert
"""
... | true |
e7f673bf317a07788ef32be89ed6f81f3669b9e4 | hsingh08/Python-Programming | /Source Codes/Lecture 1 Excersies/areaof circle.py | 224 | 4.125 | 4 | import math
num1String = input('Please enter the radius of the circle: ')
Radius = int(num1String)
AOC=math.pi*Radius*Radius
CF=2*math.pi*Radius
print ("Area of the Circle is",AOC)
print ("Circumference of the Circle is",CF) | true |
b66153a0db603adce890f8d50bd248b01bf5fc00 | aditp928/cyber-secruitiy- | /4-OldFiles/Unit03-Python/2/Activities/02-Ins_IntroToDictionaries/dictionaries.py | 1,260 | 4.625 | 5 | # Creating a dictionary by setting a variable equal to "keys" and "values" contained within curly brackets
pet = {
# A key is a string while the value can be any data type
"name": "Misty",
"breed": "Mutt",
"age": 12
}
print(pet)
# A single value can be collected by referencing the dictionary and then u... | true |
9b5f0f216ed287ff1e2267aa856958a9ae7fa303 | aditp928/cyber-secruitiy- | /1-Lesson-Plans/Unit03-Python/4-Review/Activities/11-Par_Inventory/Unsolved/inventory_collector.py | 574 | 4.5 | 4 | # TODO: Create an empty dictionary, called inventory
# TODO: Ask the user how many items they have in their inventory
# TODO: Use `range` and `for` to loop over each number up to the inventory number
# TODO: Inside the loop, prompt the user for the name of an item in their inventory ("What's the item? ")
# TODO: The... | true |
ab2f60bce0d8db79d03bb4b9c9d9816c05ecd5ff | aditp928/cyber-secruitiy- | /1-Lesson-Plans/Unit03-Python/2/Activities/07-Stu_FirstFunctions/Solved/Length.py | 221 | 4.21875 | 4 | # function to get the length of an item
def length(item):
count = 0
for i in item:
count = count + 1
return count
print(length("hello"))
print(length("goodbye"))
print(length(["hello", "goodbye"]))
| true |
3b15c02306cdef261e92a40b878fdacec5c135b2 | aditp928/cyber-secruitiy- | /4-OldFiles/Unit03-Python/2/Activities/08-Ins_WritingFiles/WriteFile.py | 819 | 4.34375 | 4 | # Not only can Python read files, it can also write to files as well
# The open() function is used once more but now "w" is used instead of "r"
diary_file = open("MyPersonalDiary.txt", "w")
parts_of_entry = ["Dear Diary,", "\n",
"Today I learned how to write text into files using Python!",
... | true |
516293e2fd7545225d84ff047c0bb3a0c86668e3 | aditp928/cyber-secruitiy- | /4-OldFiles/Unit03-Python/1/Activities/06-Ins_ForLoops/ForLoops.py | 1,044 | 4.4375 | 4 | hobbies = ["Rock Climbing", "Bug Collecting", "Cooking", "Knitting", "Writing"]
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
# Looping through the values in a list
for hobby in hobbies:
print(hobby)
print("-------------")
# It is possible to loop through the length of a list numerically to... | true |
6fa93041b3158f07fd1ae5ac7a55cc3af2838e84 | MargoshKKa/roman_numbers_converter | /main.py | 1,039 | 4.28125 | 4 | from converters.to_roman_converter import arabic_to_roman
from converters.to_arabic_converter import roman_to_arabic
def menu():
value = ''
while value != 'e':
value = input('''
What do you want to do?
e - exit the program
r - convert roman to arabic
a - convert arabic to roman
''')
... | false |
853baa71b9e872547c8bd04cc6186da5dd62c3f9 | UmarAlam27/Python_beginner_learning_ | /faulty calc by nikhil.py | 1,592 | 4.3125 | 4 | #Exercise
#Design a calculator which will correctly solve all the problems except..
#..the following ones
# 45 * 3 = 555, 56 + 9 = 77, 56/6=4
# ...Your program should take operator and the two numbers as input from user and return the result
# making a faulty calculator
while(True):
print ("Enter r... | true |
407511e14db6518f72240a8143a94ba7bdf1984a | unalenes1/python | /class3.py | 586 | 4.21875 | 4 | #Overloading / Aşırı Yükleme
#Vektor Adında Sınıfımızı Oluşturuyoruz
class Vector:
def __init__(self,a,b): # Yapıcı Fonksiyonumuzu Oluşturuyoruz
self.a = a #a değerlerimizi eşleştiriyoruz
self.b = b #b değerlerimizi Eşleştiriyoruz
def __str__(self): #__str__ Sınıfımıza a ya bu cevabı ver... | false |
ab2d511cd408d4bc7cf645a9088a9fc095ca89ae | SatishEddhu/Deep-Analytics | /Python Basics/dictionary.py | 712 | 4.28125 | 4 | # Dictionary is a mutable object
map1 = {"key1":10, "key2":20, "key3":30}
type(map1) # dict
print map1
map1.keys()
# Two ways of getting values from map
map1.get("key3")
map1["key3"]
# modifying map has a concise syntax
map1["key4"] = 70 # adding new key
map1["key2"] = 90 # can also modify values of existing keys
#... | true |
874e299ee655dcfa3163d9dbcc186dc6fe0f8ce6 | dougbarrows/pfb2019_dougs_files | /problem_sets/Python_02/p2_11.py | 351 | 4.46875 | 4 | #!/usr/bin/env python3
number = 50
if number > 0:
print("positive")
if number < 50:
print(" and less than 50")
if number % 2 == 0:
print("and it is even")
else:
print("and it is odd")
if number > 50:
if number % 3 == 0:
print("is larger than 50 and divisible by3..!")
elif number < 0:
print("negat... | false |
ba19426155017d3320c68bb3682c0a11f12bb0f6 | FarazMannan/Roulette | /Roulett.py | 1,546 | 4.375 | 4 | # random number gen.
import random
# intro to the game
print("")
# adding and subrtacting system
# bank
bank = 500
# asking the player to enter one of 3 color choices (input)
keep_gambling = True
while keep_gambling == True:
color_selected = input("What color would you like to pick? ")
color_selected = ... | true |
90ccf10cb639c66df875fa03cbba2aa42d10fab4 | mparab01/Python_Assignment | /Assignment1.py | 1,409 | 4.40625 | 4 |
# coding: utf-8
# Q. Print only the words that start with s in this sentence
# In[1]:
s = 'Print only the words that start with s in this sentence'
# In[2]:
for i in s.split():
if i[0]=='s':
print i
# Q. Use range to print all even numbers from 0 to 10
# In[4]:
l = range(0,11,2)
print l
# ... | true |
8c995a9cf354f361d5acd4f424b2feb1f02688f6 | moni310/function_Questions | /3_or_5_sum.py | 257 | 4.15625 | 4 | def limit(parameter):
n=num
sum=0
while 0<n:
number=int(input("enter the number"))
if number%3==0 or number%5==0:
sum=sum+number
n=n-1
print(sum)
num=int(input("enter the number"))
limit( num) | true |
9f29a197c7637ee528024896ba3ddf0c417148ca | moni310/function_Questions | /string_length.py | 350 | 4.125 | 4 | def string_function(name,name1):
if len(name)>len(name1):
print(name,"name length is more than name1")
elif len(name)<len(name1):
print(name1,"name1 length is more than name")
else:
print("name1 and name is equal")
name=input("enter the any alpha")
name1=input("enter the any alpha")
... | true |
54deb48c6c2f13d940817f8a3d8cca0656b32e0b | tylercrosse/DATASCI400 | /lab/01-03/L02-2-ListDict.py | 1,897 | 4.40625 | 4 | """
# UW Data Science
# Please run code snippets one at a time to understand what is happening.
# Snippet blocks are sectioned off with a line of ####################
"""
# DataStructures (built-in, multi-dimensional)
# Documentation on lists and other data structures
# https://docs.python.org/3/tutorial/datas... | true |
83d3f06d181c8b3ab1e0f3d9ab961eb4b730a3ce | tylercrosse/DATASCI400 | /lab/04/L04-B-1-DataTypes.py | 1,536 | 4.21875 | 4 | """
# UW Data Science
# Please run code snippets one at a time to understand what is happening.
# Snippet blocks are sectioned off with a line of ####################
"""
""" Data Types """
# Create an integer
x = 7
# Determine the data type of x
type(x)
#################
# Add 3 to x
x + 3
#######... | true |
7c551f2f830d950126c1095262818ddc1e0d51c5 | tylercrosse/DATASCI400 | /assignments/TylerCrosse-L04-NumericData.py | 1,629 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Lesson 04 Assignment
Create a new Python script that includes the following for your Milestone 2 data set:
- Import statements
- Load your dataset
- Assign reasonable column names, the data set description
- Median imputation of the missing numeric values
- Outlier re... | true |
8c692414bfd4ca0d1af8c086e8944b552c27cedf | JnthnTrn/my-first-python-project | /Set.py | 972 | 4.1875 | 4 | # names = {"tyler", "jacky", "ramiro", "kingsley"}
# print("jacky" in names)
#names[0] makes no sense
#looping through set with a for loop
#for name in names:
#elements in sets cannot be changed
#Changing a list
#names = ["tyler", "jacky", "ramiro", "kingsley"]
# names[2] = "jordan"
#adding new elements to a set: ... | true |
25c6fa624f1b915e388b49beafff4add2d5a8421 | Nadineioes/compsci-jmss-2016 | /tests/t1/sum2.py | 322 | 4.125 | 4 | # copy the code from sum1.py into this file, THEN:
# change your program so it keeps reading numbers until it gets a -1, then prints the sum of all numbers read
numbers = []
num = 0
while num != -1:
num = input('number: ')
num = int(num)
if num != -1:
numbers.append(num)
sum = sum(numbers)
print(su... | true |
dbf2b0caf4936965364dfbc0892131978aafe05f | Niloy009/Python-Learning | /hello_you.py | 421 | 4.34375 | 4 | # ask user name
name = input("What is your name?: ")
#ask user age
age = input("What is your age?: ")
#ask user city
city = input("Where do you live in?: ")
#ask user what they enjoy?
love = input("What do you love to do?: ")
#create output
string = "Your name is {} and you are {} years old. You are from {} & ... | true |
cca31d36b2890feea13506a2d934a0fd68162c63 | xaviercallens/convex-optimization | /tools.py | 684 | 4.21875 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Some tools.
"""
__version__ = "0.1"
__author__ = "Nasser Benabderrazik"
def give_available_values(ls):
""" Give the available values in ls as: "value1 or value2 or value3 ...".
This is used for printing the available values for string variables in a
fun... | true |
c463cec2b899361c5b989619e50d81831be29989 | ml5803/Data-Structures-and-Algorithms | /Data Lecture/9-27-RecursionContinued.py | 1,846 | 4.375 | 4 | '''
start assumption with WHEN CALLING
'''
def count_up3(start,end):
if start == end:
print(start)
else:
count_up3(start,(start+end)//2)
count_up3((start+end)//2+1,end)
# when calling countdown on a smaller range
# it would print the numbers in that range in a decreasing order
def coun... | true |
5b0c8fc9f82e9e39c9ee7a1d6f9ee9687aea3281 | filmote/PythonLessons | /Week2_4.py | 956 | 4.125 | 4 | import turtle
def polygon(aTurtle, sides, length):
counter = 0
angle = 360 / sides
while counter < sides:
aTurtle.right(angle)
aTurtle.forward(length)
counter = counter + 1
# -------------------------------------------------
# set up our shapes
#
triangle = {
"name": "Triangle"... | true |
eb43e22f2e3e59fa6bf239b47ea852b4534cdf8e | FictionDk/python-repo | /tensor-note/tensor1.14/tensor_1_1.py | 1,540 | 4.1875 | 4 | # -*- coding: utf-8 -*-
import sys
import turtle
# 列表
def list_test():
a = [1,2,3,4,5,6,7]
b = ["张三","李四","王五"]
c = [1,3,4,"4","5",b]
print(a)
print(b)
# 列表名[起:止] -- 前闭后开区间
print(c[0:2])
# 列表名[起:止:步长] -- 步长有方向
print(a[4:1:-2])
print(a[6::-2])
# 从倒数第二个开始
print(a[-2::-2])
... | false |
3dbfe7a30074d70668da454332320e22e1747026 | bebee4java/pytest | /test/org/py/test/functiontest.py | 1,705 | 4.15625 | 4 | #!/usr/bin/python3
def changeint(a):
a = 10
b = 2
changeint(b)
print(b) # 结果是2
# 可写函数说明
def changeme(mylist):
"修改传入的列表"
mylist.append([1, 2, 3, 4])
print("函数内取值: ", mylist)
return
# 调用changeme函数
mylist = [10, 20, 30]
changeme(mylist)
print("函数外取值: ", mylist)
# 可写函数说明
def printme(str):
... | false |
e97520c28a8f47624740a39aec5aa01fa8857db7 | JaydeepUniverse/python | /projects/gameBranchesAndFunctions.py | 2,974 | 4.21875 | 4 | from sys import exit
def start():
print """
Welcome to my small, easy and fun game.
There is a door to your right and left.
Which one would you take ? Type right or left.
"""
next = raw_input("> ")
if next == "left":
bear_room()
elif next == "right":
evil_room()
else... | true |
c95ff9f7a74cf4d9973f1e0f006a42840348539c | sminix/spongebob-meme | /spongebob.py | 876 | 4.15625 | 4 | '''
Take input string and output it in the format of sarcastic spongebob meme
Sam Minix
6/23/20
'''
import random
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def spongebob(text):
newText = '' #initialize new text
choice = [True, False] #initialize choices
for i in range(le... | true |
51d992a4447fd815d2241e74f33dd95da622ec1c | detcitty/100DaysOfCode | /challenges/kaggle/python-course/ex4.py | 715 | 4.21875 | 4 | def multi_word_search(doc_list, keywords):
"""
Takes list of documents (each document is a string) and a list of keywords.
Returns a dictionary where each key is a keyword, and the value is a list of indices
(from doc_list) of the documents containing that keyword
>>> doc_list = ["The Learn Pytho... | true |
be0696e5dbdc94185fd09ec087f83d7787b2492c | detcitty/100DaysOfCode | /python/unfinshed/findTheVowels.py | 559 | 4.3125 | 4 | # https://www.codewars.com/kata/5680781b6b7c2be860000036/train/python
'''
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
So given a string "super", we should return a list of [2, 4].
Some examples:
Mmmm => []
Super => [2,4... | true |
48bf51edf36127d6023eb16353cea66bd56e4159 | detcitty/100DaysOfCode | /python/unfinshed/tribonacci_sequence.py | 2,370 | 4.53125 | 5 | # https://www.codewars.com/kata/556deca17c58da83c00002db/train/python
'''
Well met with Fibonacci bigger brother, AKA Tribonacci.
As the name may already reveal, it works basically like a Fibonacci,
but summing the last 3 (instead of 2) numbers of the sequence to generate the next.
And, worse part of it, regrettabl... | true |
27f2a03e8e37e000028b5e8a556dfa15156198a8 | Programmer0000/python-studying | /mypython/first.py | 576 | 4.3125 | 4 | '''
第一部分,代码的输入输出以及算式运算
'''
# name = input("please input your name ")
# print("your name is", name)
# please input your name tomy
# your name is tomy
print('a', 'b', 'c') # 输出三个字母,分隔符默认为空格' ',结束符默认为换行符'\n'
print('a', 'b', 'c', sep=',') # 将字母之间的分隔符改为','号
print('a', 'b', 'c', end=';') # 将换行符改为';'
print('a', 'b', 'c')
... | false |
55cfcefef97312fa2cd309f8cdc071128ed4f478 | yewei600/Python | /Crack the code interview/Minesweeper.py | 846 | 4.21875 | 4 | '''
algorithm to place the bombs
placing bombs: card shuffling algorithm?
how to count number of boms neighboring a cell?
when click on a blank cell, algorithm to expand other blank cells
'''
import random
class board:
dim=7
numBombs=3
bombList=[None]*numBombs
def __init__(self):
print "let's ... | true |
9b9b89a566210fb165d1967f137a237f3817fa7e | yewei600/Python | /Crack the code interview/bit manipulation/pairwiseSwap.py | 449 | 4.1875 | 4 | def pairwiseSwap(num):
#swap odd and even bits in an integer with as few instructions as possible
tmp=0
num=bin(num)
num=num[2:]
num=list(num)
if len(num)%2:
num.insert(0,'0')
print("before swapping: "),
print num
for i in range(0,len(num),2):
tmp=num[i]
num[... | true |
3651d8f220a37e768a3ddd677a607c89035bed6f | yuxy000/PythonSyntax | /json/desc.py | 1,305 | 4.1875 | 4 | """
JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于ECMAScript的一个子集。
Python3 中可以使用 json 模块来对 JSON 数据进行编解码,它包含了两个函数:
json.dumps(): 对数据进行编码。
json.loads(): 对数据进行解码。
在json的编解码过程中,python 的原始类型与json类型会相互转换,具体的转化对照如下:
Python 编码为 JSON 类型转换对应表:
Python JSON
dict object
list, tuple array
str ... | false |
ee09a52cebcbbd5889a0f2a227672ac42e1c9cc3 | DerryPlaysXd/learn-python-basics | /Python Files/01-variables.py | 568 | 4.40625 | 4 | """
Welcome to the first course of the Learn-Python-Basics project!
Here you will learn how to create a new variable, print the variable out and do some basic math!
"""
# First of all let's create a variable:
aVar = 3
# We can print aVar out with the following line:
print(aVar)
# We can also do some calculations us... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.