blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
e2a3b42c92a3bee0577c37c825cca6989e4fb694 | EmIErO/Programming-Puzzles | /corruption_checksum.py | 1,042 | 4.4375 | 4 | # Program converts txt file with data to a table (list of lists).
# It calculates the difference between the largest value and the smallest value for each row;
# then it calculates the sum of all of these differences.
def convert_data_to_table(file_name):
"""
Converts txt file with data to a table (list of lists) of ... | true |
f881c10bcc85560274ffbe2870ba498542b0165e | MerinGeorge1987/PES_PYTHON_Assignment_SET-1 | /ass1Q16.py | 918 | 4.1875 | 4 | #!/usr/bin/python
#Title: Assignment1---Question16
#Author:Merin
#Version:1
#DateTime:02/12/2018 5:30pm
#Summary:Write program to perform following:
# i) Check whether given number is prime or not.
# ii) Generate all the prime numbers between 1 to N where N is given number.
#i) Check whether... | true |
da69991eeb394b938db82b5bba25ff87e2240cf8 | MerinGeorge1987/PES_PYTHON_Assignment_SET-1 | /ass1Q10.py | 769 | 4.1875 | 4 | #!/usr/bin/python
#Title: Assignment1---Question10
#Author:Merin
#Version:1
#DateTime:02/12/2018 3:10pm
#Summary:Using assignment operators, perform following operations
# Addition, Substation, Multiplication, Division, Modulus, Exponent and Floor division operations
a=40
b=3
#Addition
res=a+b
p... | true |
1dad42d021d6502da9e9aaa70f073ff2d629bce8 | mindful-ai/oracle-june20 | /day_02/code/11_understanding_functions_and_modules/project_a_new.py | 508 | 4.28125 | 4 | # Project A
# Function based approach
# Program to determine if a number is prime or not
def checkprime(num):
for i in range(2, num):
if(num % i == 0):
return False
return True
# ------------------------------
print("Name: ", __name__)
if __name__ == "__main__":
... | true |
0b01166508e91c0412f783f80ddafb9a9e2f529c | jenlij/DC-Week2 | /py108.py | 1,462 | 4.15625 | 4 | # Reading and writing files!
# Reading a file.
# Use the built-in `open` function
hello_file = open('hello.txt')
file_contents = hello_file.read()
print file_contents
# What if it doesn't exit?
boo_error_file = open('no_file_here_buddy.txt')
# (Error will print out)
# Reading line by line
swift = open('swift.txt')... | true |
e525cba83c896a374ee7554def4c9829abd85ad4 | Indolent-Idiot/All-Assignments-of-Python-for-Everybody-bunch-of-courses- | /Assignment 8.4.py | 1,131 | 4.65625 | 5 | #8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and ... | true |
59667e5fb7abff4a718cd8c61c20dd392b52ebd1 | ahmadghabar/hangman-game | /hangman.py | 1,733 | 4.28125 | 4 | #I used random
import random
#I made list of words
listofwords = ["python", "turtle", "class", "bored" , "school"]
#This randomly picks one of the words out
secretword = random.choice(listofwords)
#my function
def get_guess():
# this is to make the dashes in the beginning and then be able to update them
dashes = "-... | true |
6cb903321858e364f88275f741520172c27bb2b2 | Pratik-Sanghani/Python-Tutorial | /Strings/stringindetail.py | 1,724 | 4.46875 | 4 | # A string is created by entering text between two single or double quotation marks.
# e.g. create a string with single and double quotes.
string1='python is fun!'
print(string1)
string2="I am programmer"
print(string2)
# python provides an easy way to avoid manually writing "\n" to escape newlines in a string.
# 'cus... | true |
e6f68a02dc5d9ccbc6207a038e8f2874706bb9d2 | shaneleblanc/kickstartcoding | /3.2-functions/activities/3_parameters.py | 2,850 | 4.15625 | 4 | # REMINDER: Only do one challenge at a time! Save and test after every one.
print('Challenge 1 -------------')
# Challenge 1:
# Write the code to "invoke" the function named challenge_1, providing a name.
def challenge_1(name=None):
print('Hello', name, '!')
challenge_1(name='Jack')
print('Challenge 2 --------... | true |
4d6e8c435b308a2a729175425acb252062e4c865 | Alexander-AJ-Berman/password_strength_detector | /main.py | 1,410 | 4.375 | 4 | #!/usr/bin/env python3
"""Strong Password Detector
This script allows the user to input a password and validate its strength. The criteria
for a strong password are as follows:
1. At least 7 characters long
2. Contains both uppercase and lowercase letters
3. Contains at least one digit (0-9)
4. Conta... | true |
ad1fe2b895f91daf1a374f67b7537d38987bc108 | dhimanmonika/PythonCode | /MISC/ArgsKwargs.py | 834 | 4.8125 | 5 | """The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function.
It is used to pass a non-keyworded, variable-length argument list."""
def testify(arg1, *argv):
print("first argument :", arg1)
for arg in argv:
print("Next argument through *arg... | true |
6e87b4af460b3ff05ac2b17091ec6838b677d308 | dhimanmonika/PythonCode | /Regex/FloatNumber.py | 1,136 | 4.34375 | 4 | """You are given a string .
Your task is to verify that is a floating point number.
In this task, a valid float number must satisfy all of the following requirements:
Number can start with +, - or . symbol.
You are given a string .
Your task is to verify that is a floating point number.
In this task, a valid float n... | true |
2da803123991c041b313d2b768498a081ca50a09 | ajaysharma12799/Learning-Python | /Control Flow/app2.py | 1,203 | 4.65625 | 5 | ####################################################
# Loops
"""
Note :- There are 3 Type of Loop
1. For Loop
2. Nested Loop
3. While Loop
Note :- There are Another Variant of Each Loop's With Else Statement Also.
"""
# 1. For Loop
for number in range(3): # By Default Start From 0 and Exclude Last Index
print... | true |
3759298271ba14be498fc9c68bc8bde2326f5e8b | ManasveeMittal/dropbox | /Python/Python_by_udacity/renaming_files.py | 772 | 4.3125 | 4 | #--------PSEUDO CODE________//
#define directory(s) name and path
#define selection criteria for files
#point to the directory(s)
#specify renaming criteria
#enclose file names into a list
#specify replacemnt criteria into a function
#loop over the file names
#execution the name changes
#again add the changes into a l... | true |
25f06472a39a3a3000f07a2e574d89336dec11a8 | ManasveeMittal/dropbox | /DataStructures/DataStructureAndAlgorithmicThinkingWithPython-master/chapter06trees/BSTToDLLWithDivideAndConquer.py | 2,507 | 4.125 | 4 | # Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
# E-Mail : info@careermonk.com
# Creation Date : 2014-01-10 06:15:46
# Last modification : 2008-10-31
# by : Narasimha Karumanchi
# Book Title : Data Structures And Algorithmic Thinking With Python
# Warranty ... | true |
c0225a37853adb520d9bd9487733599e3a2c3ed3 | ManasveeMittal/dropbox | /Python/python_algo_implement/picking_numbers.py | 1,761 | 4.15625 | 4 | '''
Given an array of integers, find and print the maximum number of integers you can select from the array such
that the absolute difference between any two of the chosen integers is <= 1.
Input Format
The first line contains a single integer, n, denoting the size of the array.
The second line contains space-separa... | true |
3bb73de814a44708f6b12cb5ce294c9545b04201 | dsoloha/py | /Lab04/sdrawkcab-dsoloha.py | 322 | 4.3125 | 4 | # Backwards-izer
# Dan Soloha
# 9/12/2019
word = input("Welcome to the Backwards-izer! Enter the word you would like to make backwards. Press \"enter\" at any time to exit. ")
while word != "":
reversed_word = list(reversed(word))
reversed_word = "".join(reversed_word)
word = input(f"{reversed_wo... | true |
1cbf888fa258e090228375c88eb20e504d1df0fe | akshatakulkarni98/ProblemSolving | /DataStructures/adhoc/employee_importance.py | 1,934 | 4.28125 | 4 | """
You are given a data structure of employee information, which includes the employee's unique id, their importance value and their direct subordinates' id.
For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3.
They have importance value 15, 10 and 5, respectively. Then emp... | true |
519a13c91aaa73900cd8ce09e618848e8d089fef | Hadiyaqoobi/NYUx | /evennumbers.py | 398 | 4.3125 | 4 | """
Description
Write a program that reads a positive integer n, and prints the first
n even numbers.
For example, one execution would look like this:
Please enter a positive integer: 3
2
4
6
"""
import math
print("Please enter a positive integer: ")
number = int(input())
for x in range (number + (n... | true |
c4daced112e6845e3a7a6ca529dfd8b06a4a2f2b | Hadiyaqoobi/NYUx | /maxabsinlst.py | 616 | 4.28125 | 4 | """
Implement function max_abs_val(lst), which returns the maximum absolute
value of the elements in list.
For example, given a list lst: [-19, -3, 20, -1, 0, -25], the function
should return 25.
The name of the method should be max_abs_val and the method should take one parameter which is the list of values to test.... | true |
39d6c64e73affacc14c0ec0f87f33c547d3f80ed | twitu/bot_programming | /movement_cost.py | 2,858 | 4.28125 | 4 | import random
import math
def linear_cost(scale=1):
"""
Manhattan distance, only linear movement is allowed
Args:
start (int, int): x and y coordinates of start point
end (int, int): x and y coordinates of end point
scale (int): scale of one step
Returns:
Ret... | true |
75e29eca8678e26edc74b1fb6046214a89d666ca | farhana13/python | /tup.py | 1,848 | 4.375 | 4 | #tuples are unmodified lists
x = ('john', 'sally', 'bob')
print ( x[2])
#constant syntax
y = (1, 9, 2)
print (y)
print (max(y))
for iter in y:
print (iter)
# unlike lists once you create a tuple, you cannt alter its contents-similar to a string.
x = [9,8,7]
x[2] = 6
print (x)
#things not to do with... | true |
926e88c0edd8d8d3a29f528fba82efc0fd1c838e | jambellops/redxpo | /mitx6.00/creditcode.py | 2,643 | 4.28125 | 4 | ##
## Title: Credit statement
## Author: James Bellagio
## Description: Calculation of Credit Statement assignment for edx mit 6.00 week 2
##
##
##
##
##
##
# def balance_unpaid(balance, payment):
# """ function of remaining balance after payment
# parameter: balance = initial balance
# parameter: pa... | true |
535d4cbb8a14c2b1d5b03d8cd2791a875b3b1c6b | Hacklad/Mygame | /quizgame.py | 1,093 | 4.1875 | 4 | print("Welcome to my computer quiz!")
playing = input("Do you want to play, Yes or No? ")
if playing.lower() != "yes":
quit()
print("Okay! Let's play :)")
score, scored = 0, 0
answer = input("What does CPU stand for? ")
scored += 1
if answer.lower() == "central processing unit":
print('Correct!')
score... | true |
a864a339df5ff230eca56cda8829395e77e28a37 | angela97lin/Sophomore-Year | /hw29-<Lin Angela>/hw29.py | 2,569 | 4.21875 | 4 | #Angela Lin
##pd 06
##HW29
##05=06=13
##Write a Python script that will read in a literary work of appreciable length and print its 30 most frequently occurring words.
##
##General guidelines:
##Place your files in a folder named “hw29-<Last First>”, then compress this folder into a ZIP archive. (no RAR!)
##Upload to... | true |
7a35a83576f488ce9f1f1e239b0d741b6f782ee5 | ofs8421/MachineLearning | /SimpleChat/SimpleChat.py | 2,182 | 4.125 | 4 | import re
prompts = {
"what": "What is a video game?",
"use": "What are video games used for?",
"companies": "what companies make video games?",
"long": "how long have video games been out?"
}
responses = {
"what": "A video game is an electronic game that involves interaction with a user interf... | true |
1490abf534ed1dd6c45ecbd2bac1d092c53c6690 | RaihanHeggi/pythonProgramChallenge_40 | /Second Challenge (Miles Per Hour Conversion App)/Miles Per Hour Conversion App.py | 303 | 4.125 | 4 | print("Welcome to the MPH and MPS Conversion App\n")
#getting MPH value
milesPerHour = float(input('What is your speed in miles per hour: '))
#conversion MPH to MPS and Print it
conversionToMPS = milesPerHour * 0.4474
print("Your speed in meter per second is "+str(round(conversionToMPS, 2)))
| true |
f80bb349a818334a93e74cbc13eb9966f1ab0acb | RaihanHeggi/pythonProgramChallenge_40 | /Fourth Challenge (Right Triangle Problem)/Right Triangle Solver.py | 642 | 4.3125 | 4 | import math
print("Welcome to the Right Triangle Solver App\n")
firstLeg = float(input("What is the first leg of the triangle: "))
secondLeg = float(input("What is the second leg of the triangle: "))
#calculate third leg with pythagorean theorem c^2 = a^2+b^2
thirdLeg = round(math.sqrt(firstLeg**2 + secondLeg*... | true |
d23932c4063ca81ce95f25d8fcf758948f33dbee | iproduct/intro-python | /01-sdp-intro/hello_python.py | 612 | 4.3125 | 4 |
def hello_python(name):
"""
simple function demo
using name as argument
"""
print(f'Hello, {name}!')
def conditional_print(number): # conditional print demo
if number > 2:
print(f"{number} is greater than two!")
elif number == 2:
print(f"{number} is equal to two!")
el... | true |
269ebcd1231bbfc25e64ec016931a8b35fba0715 | engrishmuffin/LPTHW | /ex15.py | 775 | 4.15625 | 4 | from sys import argv
# prompts user to name the file they would like opened.
script, filename = argv
# defines txt by opening the file(name) defined in the argv
txt = open(filename)
# prints the name of the file, and reads the opened txt.
print "Here's your file %r:" % filename
print txt.read()
# closes txt, which was ... | true |
ee63085a5fd07e4515d7271b8aad5a3238a085bc | Marist-CMPT120-FA19/Patrick-Sach-Lab-5 | /Sentence Statistics.py | 505 | 4.25 | 4 | def sentencestatistics ():
words = input("Please enter a sentance: ").lower() #Input a sentence
number = len(words) #Counts the length of the sentance
print("The number of characters in your sentance is: ", number)
count=len(words.split())#Splits the sentence and counts the words
print("The number o... | true |
de0442782a4904785f306d3059d1666e8428a4d6 | soumyaevan/PythonProgramming | /CSV/FindUser.py | 911 | 4.3125 | 4 | '''
find user For this exercise, you'll be working with a file called users. csv user's last name.
Implement the following function: Each row of data consists of two columns: a user's first name,
and a Takes in a first name and a last name and searches for a user with that first and last name in the file.
If the user i... | true |
c300973f6439df6f9027265f1558d78790b8cfbe | blafuente/self_taught_programmer_lesson | /loop.py | 2,057 | 4.5625 | 5 | # Loops
# There's two different kinds of loops
# - For loops
# - used for iterating: one by one through an iterable like a list or a string
# example:
name = "Brian"
for character in name:
print(character)
shows = ["GOT", "Narcos", "Vice"]
for show in shows:
print(show)
coms = ("A. Developemnt", "Friend... | true |
cb65f759b04a644983e34e0988ab7e84ba40a76a | kiriyan1989/Pythonlearn | /17 - expo fun.py | 469 | 4.3125 | 4 | #print(2**3) ## power (expo)
def raise_to_power (base_num, pow_num):
result = 1
for i in range (pow_num):
result = result * base_num
return result
print(raise_to_power(2, 4))
############# Same as above but without the loop#########
def raise_to_power_2 (base_num, pow_num): ... | true |
d67901e609311c9f6a2f190f9884adfa183f8429 | mdfaizan7/google-foobar | /solar_doomsday.py | 2,051 | 4.25 | 4 | # Solar Doomsday
# ==============
# Who would've guessed? Doomsday devices take a LOT of power.
# Commander Lambda wants to supplement the LAMBCHOP's quantum antimatter reactor core with solar arrays,
# and she's tasked you with setting up the solar panels.
# Due to the nature of the space station's outer paneling,... | true |
9d9022808b3c02c0da9a84804ca8746f9724ceb7 | Ze1598/Programming-challenges | /programming_challenges/anagram.py | 2,300 | 4.375 | 4 | #codeacademy challenge
#https://discuss.codecademy.com/t/challenge-anagram-detector/83127
string1 = input('Enter the first expression:') #string input 1
string2 = input('Enter the second expression:') #string input 2
#calculate factorial
def result_fact(x):
fact = 1
for x in range(x,0,-1):
fact *= x
... | true |
e252b4dd9558d7c010daa745f546fb7fefd8f411 | endrewu/Coursework | /INF3331/INF3331-Endre/week3/flexcircle.py | 1,148 | 4.15625 | 4 | #!/usr/bin/env python
from math import pi, sqrt
class FlexCircle(object):
def __init__(self, radius):
self.radius = radius
def set_radius(self, r):
if r < 0:
print "An error occured, a circle can not have a negative radius"
self.radius = 0
return
self._radius = r
self._area = pi*self.radius*self.r... | true |
c094d81e6696ed07fa7fa205d5ec234341983497 | wuxu1019/leetcode_sophia | /medium/math/test_866_Prime_Palindrome.py | 973 | 4.3125 | 4 | """
Find the smallest prime palindrome greater than or equal to N.
Recall that a number is prime if it's only divisors are 1 and itself, and it is greater than 1.
For example, 2,3,5,7,11 and 13 are primes.
Recall that a number is a palindrome if it reads the same from left to right as it does from right to left.
Fo... | true |
7dcac48ffa685cf54d1cba6c294fd826b40877fd | wuxu1019/leetcode_sophia | /medium/tree/test_114_Flatten_Binary_Tree_to_Linked_List.py | 1,354 | 4.28125 | 4 | """
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
click to show hints.
... | true |
0b48aef0261b71afc265826b3678885bc37ac1a3 | wuxu1019/leetcode_sophia | /easy/focus/479_Largest_Palindrome_Product.py | 887 | 4.125 | 4 | """
Find the largest palindrome made from the product of two n-digit numbers.
Since the result could be very large, you should return the largest palindrome mod 1337.
Example:
Input: 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
Note:
The range of n is [1,8].
"""
ass Solution(object):
def l... | true |
ddd52432f09dc65f5365b40d21ad3792c49db924 | wuxu1019/leetcode_sophia | /dailycoding_problem/encode_decode_string.py | 1,178 | 4.28125 | 4 | """
Good morning! Here's your coding interview problem for today.
This problem was asked by Amazon.
Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encode... | true |
cfd4ee6cfdc320df10f790871394c1e2fc5196d8 | wuxu1019/leetcode_sophia | /medium/dp/test_376_Wiggle_Subsequence.py | 2,097 | 4.125 | 4 | """
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a wiggle sequence.
For example, [1,7,4,9,2,... | true |
ba514039dc374ed5c25908eeba8070664d912c3f | guyhill/ellipses | /ellipses.py | 2,564 | 4.21875 | 4 | import math
import matplotlib.pyplot as plt
import sys
x=0
y=1
dt = 0.0001 # small time interval
# mode selection
if len(sys.argv) < 2:
mode = "3d"
else:
mode = sys.argv[1]
if mode == "3d":
pow = 3
max_orbits = 1
vmin = 5
vmax = 13
elif mode == "2d":
pow = 2
max_orbits = 5
vmin =... | true |
afbabf9a36378f280dd5e1136227d4e84ba9e62a | Arnaav-Singh/Beginner-code | /Upper case- lower case.py | 292 | 4.4375 | 4 | # To enter any character and print it's upper case and lower case
x = input("Enter the symbol to be checked: ")
if x >= 'A' and x <= 'Z':
print(x ," is an Uppercase character")
elif x >= 'a' and x <= 'z':
print(x , "is an lower case character")
else:
("Invalid Input")
| true |
a63a965abf66c2845ca93c5cddf2aa9fa927c1ba | Goodmanv4108/cti110 | /P4HW2_BasicMath_Goodman.py | 1,508 | 4.25 | 4 | #CTI-110
#P4HW2 - BasicMath
#Veronica Goodman
#3/12/2020
#
ans=True
while ans:
#Number One Choice
Number1 = int(input('Enter your first number: '))
#Number Two Choice
Number2 = int(input('Enter your second number: '))
#The sum of the two numbers added, multiplied, and subtration
add_... | true |
11febde5b888da054e2af1788fafe6f301ccc0f1 | adwaitmathkari/pythonSampleCodes | /nQueens_lc.py | 2,590 | 4.15625 | 4 |
from typing import List
class Solution:
"""
1) Start in the leftmost column
2) If all queens are placed
return true
3) Try all rows in the current column. Do following for every tried row.
a) If the queen can be placed safely in this row then mark this [row,
column] as p... | true |
0296a00b6c6c326eb7d83b4a3a15034726180c8d | Cvam27/PyLearn_final | /venv/Programs/functin_new.py | 362 | 4.125 | 4 | # function to add two numbers
def add_numbers(num1, num2):
return num1 + num2
# function to multiply two numbers
def multiply_numbers(num1, num2):
return num1 * num2
number1 = 5
number2 = 30
sum_result = add_numbers(number1, number2)
print("Sum is", sum_result)
product_result = multiply_numbers(number1, num... | true |
4954ee3cdefb1c9ee3e9cde7ce4391b2b7b7ad9a | naghashzade/my-python-journey | /day3-rollercoaster.py | 331 | 4.125 | 4 | print("Wellcome to the Rollercoaster.")
if int(input("Height in cm: ")) >= 120:
age = int(input("Age: "))
if age >= 18:
print("your ticket costs 7$")
elif age < 12:
print("your ticket costs 3$")
else:
print("your ticket costs 5$")
else:
print("you are not allowed to use rolle... | true |
2d0cd4ec7a29b666dd1911a35315b5452caaa7fe | stephsorandom/PythonJourney | /BasicFoundations/Operators/IfElseStatments.py | 1,432 | 4.21875 | 4 | If, Elif, Else Statements
~ Control Flow Syntax in Python use of colons, indentation and whitespace
• This is VERY important and sets Python apart from other programming languages.
if some_condition :
# execute some code
else :
# do something else
elif some_other_condit... | true |
4ab5c52abe748650d998199c83a049176ed51472 | saregos/ssw567homework2 | /TestTriangle.py | 2,426 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Updated Jan 21, 2018
The primary goal of this file is to demonstrate a simple unittest implementation
@author: jrr
@author: rk
"""
import unittest
from Triangle import classifyTriangle
# This code implements the unit test functionality
# https://docs.python.org/3/library/unittest.html ha... | true |
aeda4fb358498be512c17e84198fd9f28ec15155 | philipteu/Philpython | /The guessing game.py | 978 | 4.375 | 4 | #The Guessing Game
#Step-by-step to develop a program.
#The guessing game program will do the following:
#• The player only gets five turns.
#• The program tells the player after each guess if the number is higher or lower.
#• The program prints appropriate messages for when the player wins and loses.
i... | true |
35bdab241a0abbf63592bb2047d3a081cdd8dd2f | Penzragon/CipherFile | /file.py | 2,403 | 4.21875 | 4 | alphabet = "abcdefghijklmnopqrstuvwxyz"
symbol = "~`!@#$%^&*()_-+=;:'\",.? "
def vigenere(message, keyword):
"""This is a function for decrypting a message
Args:
message (string): message that going to be decrypted
keyword (string): a keyword for decrypting the message
Returns... | true |
7ae2df6791de10590a2bffb773fae99fd9ad2824 | caroling2015/excise_2018 | /test/learn/charpter 1/charpter 1.py | 551 | 4.1875 | 4 | # -*- encoding: utf-8 -*-
# 正则表达式 regular expression
import re
# Match literal string value literal
n = re.match('foo','foo')
if n is not None:
print n.group()
# Match regular expressions re1 or re2
bt = 'bat|bet|bit'
m = re.match(bt,'bat')
if m is not None:
print m.group()
l = re.match(bt,'he bit me')
if l ... | true |
1a21c454f2956a9ca01a8e9df52ec6eb058543da | lcodesignx/pythontools | /lists/names.py | 208 | 4.4375 | 4 | #!/usr/local/bin/python3
# Store a few names in a list then print each name
# by accessing each element in the list, one at a time
names = ['python', 'c++', 'c', 'java']
for name in names:
print(name)
| true |
1c382bc5797fd633b81fe46c8dee98141b4b631d | Yoann-CH/git-tutorial | /guessing.game.py | 1,096 | 4.375 | 4 | #! /usr/bin/python3
# The random package is needed to choose a random number
import random
#Define the game in a function
def guess_loop():
#This is the number the user will have to guess, chosen randomly in betw een 1 and 100
number_to_guess = random.randint (1, 100)
print("I have in mind a number in between 1 an... | true |
b61f2572a06fc16a9636e4f7318da88e8781f5b5 | MohammedSabith/PythonProgramming | /filescore.py | 582 | 4.21875 | 4 | '''Suppose that a text file contains an unspecified number of scores. Write a program
that reads the scores from the file and displays their total and average. Scores are
separated by blanks. Your program should prompt the user to enter a filename.'''
fname = input("Enter the filename : ")... | true |
7298ebdc56b9306a91f8051def636c9aeb5dc898 | dpappo/python-tutorial | /six.py | 1,166 | 4.28125 | 4 | "This is a docstring"
# how do objects, classes, and inheritance work in Python?
# here's a list of functions that are part of every number object
# print(dir(5))
# looking at one of the magic methods aka dunder aka double underscore
print(bool(0))
# classes are the blueprints for objects in python
print(type('a'))
... | true |
7d5b8ea1838103b8bf4c240badad88de7403bed0 | Psp29onetwo/python | /multipleof10.py | 240 | 4.34375 | 4 | multiple_of_ten = int(input("Enter the number and i will tell you that entered number is multiple of ten or not: "))
if (multiple_of_ten % 10) == 0:
print("Number is multiple of ten")
else:
print("Number is not multiple of ten") | true |
39e4603f2c6224a0c12838bd2809545b8825c43e | Psp29onetwo/python | /ch3/list.py | 413 | 4.46875 | 4 | bicycle = ['trek', 'cannondale', 'redline', 'specialized']
#List declartaion and initialization
print(bicycle) #Printing list
print(bicycle[0])#Pulling out the first element of list
print(bicycle[0].title())#printing very first element in list in form of title
'''Indexing the list'''
print(bicycle[-1])#returning... | true |
15f44b114a85890be057b7b467a3590cc18ef28f | BraysonWheeler/Python-Basics | /Functions.py | 821 | 4.15625 | 4 |
#def declares function dont need to declare anynumber
def activity(anynumber):
if (anynumber == 0):
print ("given number is 0")
elif (anynumber > 0):
print ("given number is pos")
else:
print("given numbe is negative")
number = int(input("Enter any number"))
activity(number)
activity(number*-2)
#... | true |
623be520ee39be247a5c1327fb1c0a74942d5c96 | shivang17/learnPythonTheHardWay | /ex18.py | 511 | 4.15625 | 4 | # this one is like the scripts with argv
def print_two(*args):
arg1,arg2 = args
print(f"arg1 : {arg1}, arg2: {arg2}")
# *args is not recommended, instead we can use the following method.
def print_two_again(arg1,arg2):
print(f"arg1: {arg1}, arg2: {arg2}")
# One argument function
def print_one(arg1):
... | true |
d74ad8e8b8c7e04b649401adbb4b2811d9596333 | RithvikKasarla/Udacity-Data-Structures-Algorithms-Nanodegree-Program | /Unscramble Computer Science Problems/Task4.py | 1,345 | 4.21875 | 4 | """
Read file into texts and calls.
It's ok if you don't understand how to read files.
"""
import csv
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
texts = list(reader)
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
calls = list(reader)
if __name__ == '__main__':
incomingtex... | true |
8bae74c76c436768df150474c61e3ce54ec1792e | danrneal/restaurant-menu-app | /models.py | 2,357 | 4.34375 | 4 | """Model objects used to model data for the db.
Attributes:
engine: A sqlalchemy Engine object with a connection to the sqlite db
Classes:
Base()
Restaurant()
MenuItem()
"""
from sqlalchemy import Column, ForeignKey, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_ba... | true |
bebdcd816eb674b3aed82fc98a145ea9858ded06 | namhla1986/pythonpractice | /translator_practice.py | 714 | 4.1875 | 4 | def translate(phrase):
translation = ""
for letter in phrase:
if letter.lower() in "aeiou":
if letter.isupper():
translation = translation + "G"
else:
translation = translation + "g"
else:
translation = translation + le... | true |
9c93949912fc77ad1833f767013569f4c4ddc4f6 | ilante/exercises_python_lpthw | /ex11.py | 325 | 4.15625 | 4 | #software
# 1 takes input
# 2 does something with it
# prints out something to show how it changed
print("How old are you?", end=" ")
age = input()
print("How tall are you?", end='')
height = input()
print('How much do you weigh?', end='')
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} hea... | true |
35ff67f966de50a59ebe73912169f829ef41b71c | adam-weiler/GA-Reinforcing-Exercises-Functions | /exercise.py | 284 | 4.1875 | 4 | def word_counter(string): #Counts how many words in a string.
if string:
return(len(string.split(' ')))
else:
return(0)
print(word_counter("Hello world")) # returns 2
print(word_counter("This is a sentence")) # returns 4
print(word_counter("")) # returns 0
| true |
c65c1051989e32dbee0e7b0ab6a784c654ba9f78 | yummychuit/TIL | /homework/submit/homework05.py | 260 | 4.28125 | 4 | # 1
for sth in my_list:
print(sth)
# 2
for index, num in enumerate(my_list):
print(index, num)
# 3
for key in my_dict:
print(key)
for value in my_dict.values():
print(value)
for key, value in my_dict.items():
print(key, value)
# 4
None | true |
ae79fa9452ac79299955911627f82bf38ad08032 | lenngro/codingchallenges | /RotateMatrix/RotateMatrix.py | 1,279 | 4.15625 | 4 | import numpy as np
class RotateMatrix(object):
def rotate90(self, matrix):
"""
To rotate a matrix by 90 degrees, transpose it first, then reverse each column.
:param matrix:
:return:
"""
tmatrix = self.transpose(matrix)
rmatrix = self.reverseColumns(tmatrix)... | true |
5d7c61e72a8cf91579e0598dab6aa4ed365ed3b4 | MattMacario/Poly-Programming-Team | /Detect_Cycle_In_Linked_List.py | 1,001 | 4.125 | 4 | # Matthew Macario Detecting a Cycle in a Linked Lists
# For reference:
#class Node(object):
# def __init__(self, data=None, next_node=None):
# self.data = data
# self.next = next_node
def has_cycle(head):
# Creates a list to store the data that has already been passed over
dataList... | true |
1211efb7146a21086cd036062ccd9ff04fbeebdd | Hardik12c/snake-water-gun-game | /game.py | 1,154 | 4.1875 | 4 | import random # importing random module
def game(c,y):
# checking condition when computer turn = your turn
if c==y:
return "tie"
#checking condition when computer chooses stone
elif c=="s":
if y=="p":
return "you win!"
else:
return "you loose!"
#chec... | true |
dfe21c343e5740ccdb60d083f0c3dc9046eae1fd | ShaamP/Grocery-program | /Cart.py | 1,647 | 4.28125 | 4 | #####################################
# COMPSCI 105 S2 C, 2015 #
# Assignment 1 Question 1 #
# #
# @author YOUR NAME and UPI #
# @version THE DATE #
#####################################
from Item import Item
class Cart:
# the constructor
... | true |
84d1e9eca4618180e1c2ed5b23e153695322f930 | alexmontolio/Philosophy | /wikipedia_game/tree_node.py | 1,469 | 4.28125 | 4 | """
The Node class for building trees
"""
class Node(object):
"""
The basic Node of a Tree data structue
Basic Usage:
>>> a = Node('first')
>>> b = Node('second')
>>> a.add_child(b)
"""
def __init__(self, name):
self.name = name
self.children = []
def add_child(sel... | true |
64b5b695e053404803633ce7673e414b37dafb25 | thiagotato/Programing-Python | /decorators.py | 865 | 4.21875 | 4 | import functools
def trace_function(f):
"""Add tracing before and after a function"""
@functools.wraps(f)
def new_f(*args):
"""The new function"""
print(
'Called {}({!r})'
.format(f, *args))
result = f(*args)
print('Returing', result)
r... | true |
80df817700d692076b0583fd641fbf57afd69483 | Tommy8109/Tkinter_template | /Tkinter template.py | 2,779 | 4.28125 | 4 | "This is a template for the basic, starting point for Tkinter programs"
from tkinter import *
from tkinter import ttk
class gui_template():
def __init__(self):
"This is the init method, it'll set up all the variables needed in the app"
self.__title = "Test ... | true |
53e768354e681a632924d599661e04d67790111a | austinthemassive/first-py | /lambda calculator.py | 840 | 4.34375 | 4 | #!/usr/bin/python
#This file is meant to demonstrate using functions. However since I've used functions before, I will attempt to use lamdas.
#add
add = lambda x,y: x+y
#subtract
subtract = lambda x,y: x-y
#multiply
multiply = lambda x,y: x*y
#divide
divide = lambda x,y: x/y
#while
while True:
try:
num1 = fl... | true |
cae804a30e3de12689b0d2d4f33a1d237431d6cc | SekalfNroc/03_list_less_than_ten | /__main__.py | 358 | 4.1875 | 4 | #!/usr/bin/env python
numbers = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
try:
divider = int(input("Enter a number: "))
except:
print("That's silly")
exit()
less_than = []
for number in numbers:
if number < divider:
less_than.append(str(number))
print("The numbers in the list less than %d are %s... | true |
093d43f6865f140f58654f6986a1ce3f5cd532dd | edwardjthompson/resilience_data | /keovonm/normalize.py | 1,397 | 4.15625 | 4 | import pandas as pd
import sys
import os
def normalize(filename, column_name):
'''
This method normalizes a column and places the normalized values
one column to the right of the original
:param filename: name of csv file
:param column_name: column that should be normalized
:r... | true |
6f6b3ba920bd014fb03effa672fb7df7acaf8933 | zhubw91/Leetcode | /Add_and_Search_Word.py | 1,684 | 4.15625 | 4 | class TrieNode(object):
def __init__(self):
self.children = {}
self.is_word = False
class WordDictionary(object):
def __init__(self):
"""
initialize your data structure here.
"""
self.root = TrieNode()
def addWord(self, word):
"""
Ad... | true |
fe15490ff1fc0d6f78069083d9dcbd28df2a0c56 | ronliang6/A01199458_1510 | /Lab01/my_circle.py | 765 | 4.53125 | 5 | """Calculate area and radius of a circle with given radius, and compares to circumference and area of circle with
double that radius"""
Pi = 3.14159
radius = 0
print("Please enter a number for a radius")
radius = float(input())
radius_doubled = radius * 2
circumference = 2 * Pi * radius
circumference_doubled_radius = ... | true |
67a6dec5b87cd0de6437d2c75c5970edc8e68eb9 | ronliang6/A01199458_1510 | /Lab07/exceptions.py | 2,111 | 4.5625 | 5 | import doctest
def heron(num: int):
"""
Return the square root of a given integer or -1 if that integer is not positive.
:param num: an integer.
:precondition: provide the function with a valid argument according to the PARAM statement above.
:postcondition: return an object according to the retu... | true |
05c8cd898bbe6e7a9bf754c4d7c45a373f6f9fbd | nia-ja/Sorting | /src/iterative_sorting/iterative_sorting.py | 1,052 | 4.1875 | 4 | # TO-DO: Complete the selection_sort() function below
def selection_sort( arr ):
# loop through n-1 elements
for i in range(0, len(arr) - 1):
smallest_index = i
# TO-DO: find next smallest element
# (hint, can do in 3 loc)
for e in range(i + 1, len(arr)):
if arr[e] ... | true |
e69de86af9107c4b4d72a132b5b809bb64de7199 | HoldenCaulfieldRye/python | /functional/functional.py | 2,216 | 4.1875 | 4 | # http://docs.python.org/2/howto/functional.html
################################################################################
# ITERATORS #
################################################################################
# important foundation fo... | true |
801e6955a7b89d863ac53f2fc3ea9ff21d241e83 | denamyte/Hyperskill_Python_06_Coffee_Machine | /Coffee Machine/task/previous/coffee_machine4.py | 1,434 | 4.1875 | 4 | from typing import List
buy_action, fill_action, take_action = 'buy', 'fill', 'take'
resources = [400, 540, 120, 9, 550]
coffee_costs = [[-250, 0, -16, -1, 4], # espresso
[-350, -75, -20, -1, 7], # latte
[-200, -100, -12, -1, 6]] # cappuccino
add_prompts = ['Write how many ml of wate... | true |
61b7ba4f2ecb877a19a0b20ad22ce13cc02ac7db | bvishal8510/Coding | /python programs/List insertion.py | 1,733 | 4.40625 | 4 | print "Enter 1. to insert element at beginning."
print "Enter 2. to insert element at end."
print "Enter 3. to insert element at desired position."
print "Enter 4. to delete element from beginning."
print "Enter 5. to delete last element."
print "Enter 6. to delete element from desired position."
print "Enter 7. ... | true |
b74ee930f04695da23898292ceceb21f3252979b | holmes1313/Leetcode | /746_Min_Cost_Climbing_Stairs.py | 1,437 | 4.21875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 8 15:13:03 2019
@author: z.chen7
"""
# un solved
# 746. Min Cost Climbing Stairs
"""
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to r... | true |
9c5c513abd1c40791bdc1972f326f2a6e5a6e888 | holmes1313/Leetcode | /518_Coin_Change_2.py | 1,288 | 4.15625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 10:57:29 2019
@author: z.chen7
"""
# 518. Coin Change 2
"""
You are given coins of different denominations and a total amount of money.
Write a function to compute the number of combinations that make up that amount.
You may assume that you have infinite number of e... | true |
8af5c04d70fc72c4f0046e8da167e8ef8af2628e | holmes1313/Leetcode | /array_and_strings/500_Keyboard_Row.py | 1,196 | 4.15625 | 4 | """
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.
In the American keyboard:
the first row consists of the characters "qwertyuiop",
the second row consists of the characters "asdfghjkl", and
the third row con... | true |
0bb1c537af47523a326c80b8776196b74b03fa11 | holmes1313/Leetcode | /array_and_strings/check_408_Valid_Word_Abbreviation.py | 1,621 | 4.40625 | 4 | """
lengths. The lengths should not have leading zeros.
For example, a string such as "substitution" could be abbreviated as (but not limited to):
"s10n" ("s ubstitutio n")
"sub4u4" ("sub stit u tion")
"12" ("substitution")
"su3i1u2on" ("su bst i t u ti on")
"substitution" (no substrings replaced)
The following are n... | true |
ec271a49ddd1d9d93989b0e1c913fb7c6fbeccf6 | liuhuipy/Algorithm-python | /array/flatten.py | 610 | 4.25 | 4 | # -*- coding:utf-8 -*-
"""
Implement Flatten Arrays.
Given an array that may contain nested arrays,
give a single resultant array.
function flatten(input){
}
Example:
Input: var input = [2, 1, [3, [4, 5], 6], 7, [8]];
flatten(input);
Output: [2, 1, 3, 4, 5, 6, 7, 8]
"""
def list_flatten(alist, res=None):
if res i... | true |
03cf9108fddb23e91a30d43ac9d985fb17fb4a88 | Navaneeth442000/PythonLab | /CO1/program03.py | 412 | 4.1875 | 4 | #List Comprehensions
list=[3,6,-2,0,-6,-2,5,1,9]
newlist=[x for x in list if x>0]
print(newlist)
N=int(input("Enter number of no:s "))
list=[]
for x in range(N):
x=int(input("Enter no: "))
list.append(x)
print(list)
squarelist=[x**2 for x in list]
print(squarelist)
word="umberella"
vowels="aeiou"
list=[x for x... | true |
5d2f4f8f8c2d6deadde1f35100cb56baf0158d80 | ximonsson/python-course | /week-5/main_input_from_file.py | 663 | 4.28125 | 4 | """
Description:
This script will read every line in 'sequence.txt' and factorize the value on it and then
print it out to console.
As an optional exercise try making the script take as a command line argument of the file
that it should read for input.
"""
from mathfuncs import fact
# Exercise: make t... | true |
c7a696d47b67e2e40a1e889ed646fb157c6dd0df | prathyushaV/pyalgorithm | /merge_sort.py | 1,753 | 4.28125 | 4 | from abstract import AbstractAlgorithm
class MergeSort(AbstractAlgorithm):
name = ""
o_notation = ""
def implement(self,array,start,stop):
"""
Merge sort implementation a
recursive one :)
"""
if start < stop:
splitter = (start+stop)/2
self.im... | true |
334faf370f8b54adde42f3e60c1f456e0b40ca19 | cnshuimu/classwork | /If statement.py | 1,331 | 4.125 | 4 | # Q34
try:
num = int(input("enter a number: "))
except ValueError:
print('Value must be an integer')
else:
if num % 2 == 0:
print("it is an even number")
elif num % 2 == 1:
print("it is an odd number")
# Q35
human_year = float(input("enter a human year: "))
if human_year <= 2 and human_... | true |
b77d47c301e45a7446d7e0785687194b4e6a47e3 | vvakrilov/python_basics | /03. Conditional Statements Advanced/02. Training/02. Summer Outfit.py | 902 | 4.40625 | 4 | outside_degrees = int(input())
part_of_the_day = input()
outfit = ""
shoes = ""
if part_of_the_day == "Morning" and 10 <= outside_degrees <= 18:
outfit = "Sweatshirt"
shoes = "Sneakers"
elif part_of_the_day == "Morning" and 18 < outside_degrees <= 24:
outfit = "Shirt"
shoes = "Moccasins"
elif part_of_th... | true |
7a5c7864f2e4be8b80c9fc1a8aeb90eade2c0715 | JEPHTAH-DAVIDS/Python-for-Everybody-Programming-for-Everybody- | /python-data-structures-assignment7.1.py | 478 | 4.59375 | 5 | ''' Write a program that prompts for a file name, then opens that file and reads through the file,
and print the contents of the file in upper case. Use the file, words.txt to produce to the output below. You
can download the sample data at https://www.py4e.com/code3/words.txt?PHPSESSID=88c95d597d36e3db919cbef32f4ce6... | true |
23362101fcf09380b72fe260028c7b42d078577d | AnkitMitraOfficial/yash_friend_python | /4.py | 312 | 4.28125 | 4 | # Task:
# To check a given number is prime
prime_number = int(input('Write down a number to find whether it is prime or not!: '))
def find_prime(n=prime_number):
if n % 2 == 0:
print(f'Number {n} is a prime number :)')
else:
print(f'Number {n} is not a prime number :(')
find_prime() | true |
49b9f5b36a059a7681d0a43bb464d33c9a64f1cd | noodlles/pathPlaner-A- | /student_code.py | 2,644 | 4.125 | 4 | import math
import copy
def shortest_path(M,start,goal):
print("shortest path called")
path_list=[]
solution_path=[]
knownNode=set()
#init
path1=path(M,start,goal)
path_list.append(path1)
while(not(len(path_list)==0)):
#get the minimum total_cost path
... | true |
2332b026ad042a60a61c60e5b6420f564721290d | alexbarsan944/Python | /Lab1/ex9.py | 620 | 4.25 | 4 | # 9 Write a functions that determine the most common letter in a string. For example if the string is "an apple is
# not a tomato", then the most common character is "a" (4 times). Only letters (A-Z or a-z) are to be considered.
# Casing should not be considered "A" and "a" represent the same character.
def most_commo... | true |
1c35777a6133fb51eabc3120b51bfdedbd2a3edc | naresh2136/oops | /threading.py | 2,315 | 4.34375 | 4 | run() − The run() method is the entry point for a thread.
start() − The start() method starts a thread by calling the run method.
join([time]) − The join() waits for threads to terminate.
isAlive() − The isAlive() method checks whether a thread is still executing.
getName() − The getName() method returns the name o... | true |
6e4e62a52b16a9452437d2efa8ad94d4f1a6fbd1 | antadlp/pythonHardWay | /ex5_studyDrill_03.py~ | 957 | 4.28125 | 4 | #Search online for all of the Python format characters
print "%d : Signed integer decimal"
print "%i : Signed integer decimal"
print "%o : Unsigned octal"
print "%u : Unsigned decimal"
print "%x : Unsigned hexadecimal (lowercase)"
print "%X : Unsigned hexadecimal (uppercase)"
print "%e : Floating point exponential for... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.