blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
b37520ed33b2fef924c8ea17c96d34799b78cc37 | TimKillingsworth/Codio-Assignments | /src/dictionaries/person_with_school.py | 306 | 4.34375 | 4 | #Create dictionary with person information. Assign the dictionary to the variable person
person={'name':'Lisa', 'age':29}
#Print out the contents of person
print(person)
#Add the school which Lisa attends
person['school'] = 'SNHU'
#Print out the contents of person after adding the school
print(person) | true |
47f7f996f21d85e5b7613aa14c1a6d2752faaa82 | zaidjubapu/pythonjourney | /h5fileio.py | 1,969 | 4.15625 | 4 | # file io basic
'''f = open("zaid.txt","rt")
content=f.read(10) # it will read only first 10 character of file
print(content)
content=f.read(10) # it will read next 10 character of the file
print(content
f.close()
# must close the file in every program'''
'''f = open("zaid.txt","rt")
content=f.read() # it will read a... | true |
014987c11429d51e6d1462e3a6d0b7fb97b11822 | zaidjubapu/pythonjourney | /enumeratefunction.py | 592 | 4.59375 | 5 | '''enumerate functions: use for to easy the method of for loop the with enumerate method
we can find out index of the list
ex:
list=["a","b","c"]
for index,i in enumerate(list):
print(index,i)
'''
''' if ___name function :
print("and the name is ",__name__)# it will give main if it is written before
if __name__ =... | true |
50e523c196fc0df4be3ce6acab607f623119f4e1 | zaidjubapu/pythonjourney | /h23abstractbaseclassmethod.py | 634 | 4.21875 | 4 | # from abc import ABCMeta,abstractmethod
# class shape(metaclass=ABCMeta):
# or
from abc import ABC,abstractmethod
class shape(ABC):
@abstractmethod
def printarea(self):
return 0
class Rectangle(shape):
type= "Rectangle"
sides=4
def __init__(self):
self.length=6
self.b=7
... | true |
22773f2a2796ae9a493020885a6e3a987047e7f8 | Pegasus-01/hackerrank-python-works | /02-division in python.py | 454 | 4.125 | 4 | ##Task
##The provided code stub reads two integers, a and b, from STDIN.
##Add logic to print two lines. The first line should contain the result of integer division, a// b.
##The second line should contain the result of float division, a/ b.
##No rounding or formatting is necessary.
if __name__ == '__mai... | true |
5a4c0c930ea92260b88f0282297db9c9e5bffe3f | BarunBlog/Python-Files | /Learn Python3 the Hard Way by Zed Shaw/13_Function&Files_ex20.py | 1,236 | 4.21875 | 4 | from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
def rewind(f):
f.seek(0)
'''
fp.seek(offset, from_what)
where fp is the file pointer you're working with; offset means how many positions you will move; from_what defines your point of reference:
0: means your reference point is... | true |
b6fefcbd7ae15032f11a372c583c5b9d7b3199d9 | BarunBlog/Python-Files | /02 String operation.py | 993 | 4.21875 | 4 | str1 = "Barun "
str2 = "Hello "+"World"
print(str1+" "+str2)
'''
To insert characters that are illegal in a string, use an escape character.
An escape character is a backslash \ followed by the character you want to insert.
'''
str3 = 'I don\'t think so'
print(str3)
print('Source:D \Barun\Python files\first project.... | true |
6c727ec6706b42ea057f264ff97d6f39b7481338 | AnkitAvi11/100-Days-of-Code | /Day 11 to 20/MoveAllnegative.py | 798 | 4.59375 | 5 | """
python program to move all the negative elements to one side of the array
-------------------------------------------------------------------------
In this, the sequence of the array does not matter.
Time complexity : O(n)
space complexity : O(1)
"""
# function to move negatives to the right of the array
def... | true |
9f076e1b7465ff2d509b27296a2b963dd392a7f9 | kishoreramesh84/python-75-hackathon | /filepy2.py | 523 | 4.28125 | 4 | print("Reading operation from a file")
f2=open("newfile2.txt","w")
f2.write(" Hi! there\n")
f2.write("My python demo file\n")
f2.write("Thank u")
f2.close()
f3=open("newfile2.txt","r+")
print("Method 1:")
for l in f3: #Method 1 reading file using loops
print(l,end=" ")
f3.seek(0) #seek is used to place a pointer to... | true |
5bbce3aaa6c5a5d38b2a2848ce856322107a8c91 | mirsadm82/pyneng-examples-exercises-en | /exercises/06_control_structures/answer_task_6_2a.py | 1,788 | 4.34375 | 4 | # -*- coding: utf-8 -*-
"""
Task 6.2a
Make a copy of the code from the task 6.2.
Add verification of the entered IP address.
An IP address is considered correct if it:
- consists of 4 numbers (not letters or other symbols)
- numbers are separated by a dot
- every number in the range from 0 to 255
If the ... | true |
86fc4bc0e652ee494db883f657e918b2b056cf3e | mirsadm82/pyneng-examples-exercises-en | /exercises/04_data_structures/task_4_8.py | 1,107 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Task 4.8
Convert the IP address in the ip variable to binary and print output in columns
to stdout:
- the first line must be decimal values
- the second line is binary values
The output should be ordered in the same way as in the example output below:
- in columns
- column width 10 charact... | true |
b3cfe1ba6b28715f0f2bccff2599412d406fd342 | n001ce/python-control-flow-lab | /exercise-5.py | 670 | 4.40625 | 4 | # exercise-05 Fibonacci sequence for first 50 terms
# Write the code that:
# 1. Calculates and prints the first 50 terms of the fibonacci sequence.
# 2. Print each term and number as follows:
# term: 0 / number: 0
# term: 1 / number: 1
# term: 2 / number: 1
# term: 3 / number: 2
# term: 4 / nu... | true |
8d980ed029b0dc74e4dc6aa0e7785d6af0f95fa7 | NiharikaSinghRazdan/PracticeGit_Python | /Code_Practice/list_exercise.py | 512 | 4.21875 | 4 | # Convert string into list
mystring="This is the new change"
mylist = []
for letter in mystring:
mylist.append(letter)
print(mylist)
# Change string into list with different convert format and in one line
mystring1="Hi There"
mylist1 =[letter for letter in mystring1]
print(mylist1)
# Check other usage of this new... | true |
bc76d2ae44f894254a3e24c0b53c61db5039f4ff | NiharikaSinghRazdan/PracticeGit_Python | /Code_Practice/arbitary_list.py | 1,556 | 4.1875 | 4 | #retrun the list where the passed arguments are even
def myfunc(*args):
mylist=[]
for item in args:
if item%2==0:
mylist.append(item)
else:
continue
print(mylist)
print(myfunc(-2,4,3,5,7,8,10))
# return a string where every even letter is in uppercase and every odd l... | true |
37b1dce3bcbe2da05065e677491797983588c285 | dankolbman/NumericalAnalysis | /Homeworks/HW1/Problem1.py | 520 | 4.21875 | 4 | import math
a = 25.0
print("Squaring a square-root:")
while ( math.sqrt(a)**2 == a ):
print('sqrt(a)^2 = ' + str(a) + ' = ' + str(math.sqrt(a)**2))
a *= 10
# There was a rounding error
print('sqrt(a)^2 = ' + str(a) + ' != ' + str(math.sqrt(a)**2))
# Determine the exponent of the float
expo = math.floor(math.log10(a... | true |
bfc1710b45ac38465e6f545968f2e00cd535d2dc | Tarun-Rao00/Python-CodeWithHarry | /Chapter 4/03_list_methods.py | 522 | 4.21875 | 4 | l1 = [1, 8, 7, 2, 21, 15]
print(l1)
l1.sort() # sorts the list
print("Sorted: ", l1)
l1.reverse() #reverses the list
print("Reversed: ",l1)
l1.reverse()
print("Reversed 2: ",l1)
l1.append(45) # adds to the end of the list
print ("Append", l1)
l2 = [1,5, 4, 10]
l1.append(l2) # l2 (list) will be added
print("Append 2"... | true |
0ab24f03f7919f96e74301d06dd9af5a377ff987 | Tarun-Rao00/Python-CodeWithHarry | /Chapter 2/02_operators.py | 548 | 4.125 | 4 | a = 34
b = 4
# Arithimatic Operator
print("the value of 3+4 is ", 3+4)
print("the value of 3-4 is ", 3-4)
print("the value of 3*4 is ", 3*4)
print("the value of 3/4 is ", 3/4)
# Assignment Operators
a = 34
a += 2
print(a)
# Comparision Operators
b = (7>14)
c = (7<14)
d = (7==14)
e = (7>=14)
print(b)
print(c)
print(d... | true |
d31f727127690b2a4584755c941cd19c7452d9e4 | Tarun-Rao00/Python-CodeWithHarry | /Chapter 6/11_pr_06.py | 221 | 4.15625 | 4 | text = input("Enter your text: ")
text1 = text.capitalize()
num1 = text1.find("Harry")
num2 = text1.find("harry")
if (num1==-1 and num2==-1):
print("Not talking about Harry")
else:
print("Talking about Harry") | true |
406ad197c1a6b2ee7529aaa7c6ea5a86e10114de | carrenolg/python-code | /Chapter12/optimize/main.py | 896 | 4.25 | 4 | from time import time, sleep
from timeit import timeit, repeat
# main
def main():
"""
# measure timing
# example 1
t1 = time()
num = 5
num *= 2
print(time() - t1)
# example 2
t1 = time()
sleep(1.0)
print(time() - t1)
# using timeit
print(timeit('num = 5; num *= 2'... | true |
c5333727d54b5cb7edff94608ffb009a29e6b5f4 | nikita5119/python-experiments | /cw1/robot.py | 1,125 | 4.625 | 5 | # A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following:
# UP 5
# DOWN 3
# LEFT 3
# RIGHT 2
# The numbers after the direction are steps. Please write a program to compute the distance ... | true |
6e468bf7c8d0d37233ee7577645e1d8712b83474 | TameImp/compound_interest_app | /test_calc.py | 929 | 4.125 | 4 | '''
this programme test the compound interest calculator
'''
from calc import monthly_compounding
def test_tautology():
assert 3 == 3
#test that investing no money generates no returns
def test_zeros():
#initialise some user inputs
initial = 0
monthly = 0
years = 0
annual_rate = 0
#calcu... | true |
e0ee6d13b199a167c7cf72672876ff5d4b6e1b99 | LuisPereda/Learning_Python | /Chapter03/excercise1.py | 420 | 4.1875 | 4 | # This program parses a url
url = "http://www.flyingbear.co/our-story.html#:~:text=Flying%20Bear%20is%20a%20NYC,best%20rate%20in%20the%20city."
url_list = url.split("/") # Parsing begins at character (/)
domain_name = url_list[2] # Dictates at which character number parsing begins
print (domain_name.replace("www.",... | true |
9a915e306d84c786fd2290dc3180535c5773cafb | schase15/cs-module-project-iterative-sorting | /src/searching/searching.py | 1,967 | 4.375 | 4 | # Linear and Binary Search assignment
def linear_search(arr, target):
# Go through each value starting at the front
# Check to see if it is equal to the target
# Return index value if it is
# Return -1 if not found in the array`
for i in range(len(arr)):
if arr[i] == target:
... | true |
996da01a75f050ffcdb755c5c5f2b16fb1ec8f1c | Shmuco/PY4E | /PY4E/ex_05_02/ex_05_02.py | 839 | 4.15625 | 4 | ##### 5.2 Write a program that repeatedly prompts a user for integer numbers until
#the user enters 'done'. Once 'done' is entered, print out the largest and
#smallest of the numbers. If the user enters anything other than a valid number
#catch it with a try/except and put out an appropriate message and ignore the
#num... | true |
48f85e68fcdd06ca468437c536ac7e27fd20ef77 | endreujhelyi/zerda-exam-python | /first.py | 431 | 4.28125 | 4 | # Create a function that takes a list as a parameter,
# and returns a new list with every second element from the original list.
# It should raise an error if the parameter is not a list.
# Example: with the input [1, 2, 3, 4, 5] it should return [2, 4].
def even_elements(input_list):
if type(input_list) == list:
... | true |
40eb347ec2a99811529a9af3aa536a16618d0ad3 | DoranLyong/CSE-python-tutorial | /Coding-Test/CodeUp/Python/036_number.py | 345 | 4.375 | 4 | """
[ref] https://codeup.kr/problem.php?id=1036
Question:
1. take one English letter
2. print it out as the decimal value of the ASCII code table.
"""
letter = input()
print(ord(letter))
"""
Program to find the ASCII value of a character:
https://beginnersbook.com/2019/03/python-program-to-find-ascii-... | true |
58dce475f4c94e14c6d58a4ee3c1836e34c82f21 | DoranLyong/CSE-python-tutorial | /Coding-Test/CodeUp/Python/037_number.py | 319 | 4.125 | 4 | """
[ref] https://codeup.kr/problem.php?id=1037
Question:
1. take one decimal ineger
2. print it out in ASCII characters
"""
num = int(input())
print(chr(num))
"""
Program to find the ASCII value of a character:
https://beginnersbook.com/2019/03/python-program-to-find-ascii-value-of-a-character/
""" | true |
3442780fcf656417aa119190f13137e61db8d005 | jamessandy/Pycon-Ng-Refactoring- | /refcator.py | 527 | 4.21875 | 4 | #Example 1
num1 = 4
num2 = 4
result = num1 + num2
print(result)
#Example 2
num1 = int(input('enter the firExamst number:'))
num2 = int(input('enter the second number:'))
result = num1 + num2
print('your answer is:', result)
#Example 3
num1 = int(input('Enter number 1:'))
num2 = int(input('Enter number 2:'))
result =... | true |
e130159211e4dc6092a9943fa6a1c9422d058f68 | mclark116/techdegree-project | /guessing_game2.py | 2,321 | 4.125 | 4 | import random
history = []
def welcome():
print(
"""
____________________________________
Welcome to the Number Guessing Game!
____________________________________
""")
def start_game():
another = "y"
solution = random.randint(1,10)
value = "Oh no! That's not a valid value. Pl... | true |
cf7554340e039e9c317243a1aae5e5f9e52810f9 | IraPara08/raspberrypi | /meghapalindrom.py | 412 | 4.3125 | 4 | #Ask user for word
wordinput = input("Please Type In A Word: ")
#Define reverse palindrome
reverseword = ''
#For loop
for x in range(len(wordinput)-1, -1, -1):
reverseword = reverseword + wordinput[x]
#Print reverse word
print(reverseword)
#Compare
if wordinput == reverseword:
print("This is a palindrome!")... | true |
fed78ccbb8a565e936cacbac817485c26ab84383 | domlockett/pythoncourse2018 | /day03/exercise03_dl.py | 458 | 4.28125 | 4 | ## Write a function that counts how many vowels are in a word
## Raise a TypeError with an informative message if 'word' is passed as an integer
## When done, run the test file in the terminal and see your results.
def count_vowels(word):
vowels=('a','e','i','o','u')
count= 0
for i in word:
if type(... | true |
2074006981e41d2e7f0db760986ea31f6173d181 | ladas74/pyneng-ver2 | /exercises/06_control_structures/task_6_2a.py | 1,282 | 4.40625 | 4 | # -*- coding: utf-8 -*-
"""
Task 6.2a
Make a copy of the code from the task 6.2.
Add verification of the entered IP address.
An IP address is considered correct if it:
- consists of 4 numbers (not letters or other symbols)
- numbers are separated by a dot
- every number in the range from 0 to 255
If the ... | true |
27cc3bbaffff82dfb22f83be1bcbd163ff4c77f1 | ladas74/pyneng-ver2 | /exercises/05_basic_scripts/task_5_1.py | 1,340 | 4.3125 | 4 | # -*- coding: utf-8 -*-
"""
Task 5.1
The task contains a dictionary with information about different devices.
In the task you need: ask the user to enter the device name (r1, r2 or sw1).
Print information about the corresponding device to standard output
(information will be in the form of a dictionary).
An example ... | true |
70e15b366634efea90e939c6c169181510818fdb | Sushantghorpade72/100-days-of-coding-with-python | /Day-03/Day3.4_PizzaOrderCalculator.py | 881 | 4.15625 | 4 | '''
Project Name: Pizza Order
Author: Sushant
Tasks:
1. Ask customer for size of pizza
2. Do they want to add pepperoni?
3. Do they want extra cheese?
Given data:
Small piza: $15
Medium pizza: $20
Large pizza: $ 25
Pepperoni for Small Pizza: +$2
Pepperoni for medium & large pizza: +$3
Extra cheese ... | true |
9b4a03cec322c2c28438a0c1df52d36f1dfce769 | Long0Amateur/Self-learnPython | /Chapter 5 Miscellaneous/swapping.py | 297 | 4.21875 | 4 | # A program swaps the values of 3 variables
# x gets value of y, y gets value of z, and z gets value of x
x = 1
y = 2
z = 3
hold = x
x = y
y = hold
hold = y
y = z
z = hold
hold = z
z = x
z = hold
print('Value of x =',x)
print('Value of y =',y)
print('Value of z =',z)
| true |
edfd81e4cbd96b77f1666534f7532b0886f8ec4e | himashugit/python_dsa | /func_with_Arg_returnvalues.py | 617 | 4.15625 | 4 | '''
def addition(a,b):
result = a+b
return result # this value we're sending back to main func to print
def main():
a = eval(input("Enter your number: "))
b = eval(input("Enter your 2ndnumber: "))
result = addition(a,b) # calling addition func & argument value and storing in result
print(f... | true |
c9361ac9212e8bd0441b05a26940729dd6915861 | itsMagondu/python-snippets | /fib.py | 921 | 4.21875 | 4 | #This checks if a certain number num is a number in the fibbonacci sequence.
#It loops till the number is the sequence is either greater or equal to the number in the sequence.
#Thus we validate if the number is in the fibonacci sequence.
import sys
tot = sys.stdin.readline().strip()
try:
tot = int(tot)
except V... | true |
5ebb8cf419dd497c64b1d7ac3b22980f0c33b790 | sberk97/PythonCourse | /Week 2 - Mini Project Guess number game.py | 2,289 | 4.21875 | 4 | # template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
import random
import simplegui
# helper function to start and restart the game
def new_game():
# initialize global variables used in your code here
global s... | true |
5c4362ae8eea49bd105ae1f0ffced5d62aba12ed | ArnoldKevinDesouza/258327_Daily_Commits | /Dict_Unsolved02.py | 209 | 4.5 | 4 | # Write a Python program to convert a list into a nested dictionary of keys
list = [1, 2, 3, 4]
dictionary = current = {}
for name in list:
current[name] = {}
current = current[name]
print(dictionary) | true |
3963dccc95056b06715cf81c7a8eab7091c682a5 | ArnoldKevinDesouza/258327_Daily_Commits | /If_Else_Unsolved04.py | 314 | 4.15625 | 4 | # Write a program to get next day of a given date
from datetime import date, timedelta
import calendar
year=int(input("Year:"))
month=int(input("\nMonth:"))
day=int(input("\nDay:"))
try:
date = date(year, month, day)
except:
print("\nPlease Enter a Valid Date\n")
date += timedelta(days=1)
print(date) | true |
dd652b879fd1162d85c7e3454f8b724e577f5e7e | Einsamax/Dice-Roller-V2 | /main.py | 2,447 | 4.375 | 4 | from time import sleep
import random
#Introduce user to the program
if __name__ == "__main__": #This does a good thing
print ("*" * 32)
print("Welcome to the Dice Roller!".center(32))
print ("*" * 32)
print()
sleep(1)
def roll_dice(diceamnt, diceint): #Defines function roll_dice
... | true |
c6aadc50833356e4ce23f7f2a898634ff3efd4a7 | dsimonjones/MIT6.00.1x---Introduction-to-Computer-Science-and-Programming-using-Python | /Week2- Simple Programs/Lecture4- Functions/Function isIn (Chap 4.1.1).py | 611 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
@author: ali_shehzad
"""
"""
Finger exercise 11: Write a function isIn that accepts two strings as
arguments and returns True if either string occurs anywhere in the other,
and False otherwise. Hint: you might want to use the built-in str
operation in.
"""
def isIn(str1, str2... | true |
3bc103df43f3b4e607efa104b1e3a5a62caa1469 | LaurenShepheard/VsCode | /Learningpython.py | 1,227 | 4.375 | 4 | for i in range(2):
print("hello world")
# I just learnt how to comment by putting the hash key at the start of a line. Also if I put a backslash after a command you can put the command on the next line.
print\
("""This is a long code,
it spreads over multiple lines,
because of the triple quotaions and b... | true |
20b609e21199215965d79601920124905c16ef2d | katesem/data-structures | /hash_table.py | 884 | 4.25 | 4 | '''
In Python, the Dictionary data types represent the implementation of hash tables. The Keys in the dictionary satisfy the following requirements.
The keys of the dictionary are hashable i.e. the are generated by hashing function which generates unique result for each unique value supplied to the hash function.
The o... | true |
02aa151e60891f3c43b27a1091a35e4d75fe5f7d | mshalvagal/cmc_epfl2018 | /Lab0/Python/1_Import.py | 1,610 | 4.375 | 4 | """This script introduces you to the useage of Imports in Python.
One of the most powerful tool of any programming langauge is to be able to resuse code.
Python allows this by setting up modules. One can import existing libraries using the import function."""
### IMPORTS ###
from __future__ import print_function # ... | true |
42f37b58b8e3b4583208ea054d30bef34040a6ed | inshaal/cbse_cs-ch2 | /lastquest_funcoverload_Q18_ncert.py | 1,152 | 4.1875 | 4 | """FUNCTION OVERLOADING IS NOT POSSIBLE IN PYTHON"""
"""However, if it was possible, the following code would work."""
def volume(a): #For volume of cube
vol=a**3
print vol, "is volume of cube"
def volume(a,b,c): #volume of cuboid |b-height
vol=a*b*c
print vol, "is volume of cuboid"
def volume(... | true |
579a2fbc1f237e1207be37752963d17f2011b629 | edenizk/python_ex | /ifstatement.py | 866 | 4.15625 | 4 | def main():
phone_balance = 10
bank_balance = 50
if phone_balance < 10:
phone_balance += 10
bank_balance -= 10
print(phone_balance)
print(bank_balance)
number = 145
if number % 2 == 0:
print("Number " + str(number) + " is even.")
else:
print("Number "... | true |
1fb7b06f3ed69f53268c4b1f6fc0a39702f8274c | mishra-atul5001/Python-Exercises | /Search.py | 574 | 4.15625 | 4 | Stringy = '''
Suyash: Why are you wearing your pajamas?
Atul: [chuckles] These aren't pajamas! It's a warm-up suit.
Suyash: What are you warming up for Bro..!!?
Atul: Stuff.
Suyash: What sort of stuff?
Atul: Super-cool stuff you wouldn't understand.
Suyash: Like sleeping?
Atul: THEY ARE NOT PAJAMAS!
'''
print(Stringy)
... | true |
cc8e5d5db27730063c43f01ef610dcea40ec77df | lacra-oloeriu/learn-python | /ex15.py | 552 | 4.125 | 4 | from sys import argv# That is a pakege from argv
script, filename = argv#This is define the pakege
txt= open(filename)#that line told at computer ...open the file
print(f"Here's your file {filename}:")#print the text...and in {the name of file to open in extension txt}
print ( txt.read())
print("Type the filename ... | true |
af1191998cf3f8d5916e22b8b55da7766bead003 | huynhirene/ICTPRG-Python | /q1.py | 241 | 4.28125 | 4 | # Write a program that counts from 0 to 25, outputting each number on a new line.
num = 0
while num <= 26:
print(num)
num = num + 1
if num == 26:
break
# OR
for numbers in range(0,26):
print(numbers) | true |
113cddca4472e40432caf9672fdc4ce22f25fb86 | fjctp/find_prime_numbers | /python/libs/mylib.py | 542 | 4.15625 | 4 |
def is_prime(value, know_primes=[]):
'''
Given a list of prime numbers, check if a number is a prime number
'''
if (max(know_primes)**2) > value:
for prime in know_primes:
if (value % prime) == 0:
return False
return True
else:
raise ValueError('List of known primes is too short for the given value'... | true |
44cc5b20276024979f97fb31cd221b90ba78e351 | Mahdee14/Python | /2.Kaggle-Functions and Help.py | 2,989 | 4.40625 | 4 | def maximum_difference(a, b, c) : #def stands for define
"""Returns the value with the maximum difference among diff1, diff2 and diff3"""
diff1 = abs(a - b)
diff2 = abs(b - c)
diff3 = abs(a - c)
return min(diff1, diff2, diff3)
#If we don't include the 'return' keyword in a function that requires... | true |
d990ed78e1ecc5dd47c002e438d23400c72badba | mochadwi/mit-600sc | /unit_1/lec_4/ps1c.py | 1,368 | 4.1875 | 4 | # receive Input
initialBalance = float(raw_input("Enter your balance: "))
interestRate = float(raw_input("Enter your annual interest: "))
balance = initialBalance
monthlyInterestRate = interestRate / 12
lowerBoundPay = balance / 12
upperBoundPay = (balance * (1 + monthlyInterestRate) ** 12) / 12
while True:
balan... | true |
fbaf789fbe6bfaede28d2b2d3a6a1673e229f57b | bledidalipaj/codefights | /challenges/python/holidaybreak.py | 2,240 | 4.375 | 4 | """
My kids very fond of winter breaks, and are curious about the length of their holidays including all the weekends.
Each year the last day of study is usually December 22nd, and the first school day is January 2nd (which means that
the break lasts from December 23rd to January 1st). With additional weekends at the... | true |
0bad5a8a7ee86e45043ef0ddf38406a9ee4d1032 | pmayd/python-complete | /code/exercises/solutions/words_solution.py | 1,411 | 4.34375 | 4 | """Documentation strings, or docstrings, are standard ways of documenting modules, functions, methods, and classes"""
from collections import Counter
def words_occur():
"""words_occur() - count the occurrences of words in a file."""
# Prompt user for the name of the file to use.
file_nam... | true |
95b308d6bdb204928c6b014c8339c2cc8693b7d7 | pmayd/python-complete | /code/exercises/most_repeating_word.py | 870 | 4.3125 | 4 | import doctest
def most_repeating_word(words: list) -> str:
"""
Write a function, most_repeating_word, that takes a sequence of strings as input. The function should return the string that contains the greatest number of repeated letters. In other words:
for each word, find the letter that appears the mo... | true |
111c536fba28296ec4f2a93ab466360e57d839d6 | paul0920/leetcode | /question_leetcode/215_5.py | 1,471 | 4.25 | 4 | # Bucket sort algorithm
# Average time complexity: O(n)
# Best case: O(n)
# Worst case: O(n^2)
# Space complexity: O(nk), k: bucket count
# Bucket sort is mainly useful when input is uniformly distributed over a range
# Choose the bucket size & count, and put items in the corresponding bucket
nums = [3, 2, 1, 5,... | true |
d94c3e993bd855c950dfe809dba92957b40c4a20 | JimiofEden/PyMeth | /Week 1/TEST_roots_FalsePosition.py | 470 | 4.25 | 4 | import roots_FalsePosition
import numpy
'''
Adam Hollock 2/8/2013
This will calculate the roots of a given function in between two given
points via the False Position method.
'''
def f(x): return x**3+2*x**2-5*x-6
results = roots_FalsePosition.falsePosition(f,-3.8,-2.8,0.05)
print results
results = roots_FalsePositi... | true |
e579fadc31160475af8f2a8d42a20844575c95fa | mitalshivam1789/python | /oopfile4.py | 940 | 4.21875 | 4 | class A:
classvar1= "I am a class variable in class A."
def __init__(self):
self.var1 = "I am in class A's constructor."
self.classvar1 = "Instance variable of class A"
self.special = "Special"
class B(A):
classvar1="I am in class B"
classvar2 = "I am variable of class ... | true |
4ecd4d3a20e875b9c0b5019531e8858f4722b632 | victorbianchi/Toolbox-WordFrequency | /frequency.py | 1,789 | 4.5 | 4 | """ Analyzes the word frequencies in a book downloaded from
Project Gutenberg """
import string
def get_word_list(file_name):
""" Reads the specified project Gutenberg book. Header comments,
punctuation, and whitespace are stripped away. The function
returns a list of the words used in the book as a li... | true |
d2de097ee33f0060830681df81f87f600f5da69c | Scott-Dixon-Dev-Team-Organization/cs-guided-project-linked-lists | /src/demonstration_3.py | 804 | 4.1875 | 4 | """
Given a non-empty, singly linked list with a reference to the head node, return a middle node of linked list. If there are two middle nodes, return the second middle node.
Example 1:
Input: [1,2,3,4,5]
Output: Node 3 from this list
The returned node has value 3.
Note that we returned a `ListNode` object `ans`, su... | true |
00ead084fe729599aeedba61cc88fc277e7726ad | menezesluiz/MITx_-_edX | /week1/exercise/exercise-for.py | 442 | 4.34375 | 4 | """
Exercise: for
Finger Exercises due Aug 5, 2020 20:30 -03
Completed
Bookmark this page
Exercise: for exercise 1
5.0/5.0 points (graded)
ESTIMATED TIME TO COMPLETE: 5 minutes
In this problem you'll be given a chance to practice writing some for loops.
1. Convert the following code into code that uses a for loop.
... | true |
36e8464800601f9fc4553aacc2f48369940393df | menezesluiz/MITx_-_edX | /week1/exercise/exercise04.py | 2,056 | 4.40625 | 4 | """
Exercise 4
Finger Exercises due Aug 5, 2020 20:30 -03
Completed
Bookmark this page
Exercise 4
5/5 points (graded)
ESTIMATED TIME TO COMPLETE: 8 minutes
Below are some short Python programs. For each program, answer the associated
question.
Try to answer the questions without running the code. Check your answers,... | true |
8d6d347432112c3884102402bf0c269bcbd2ab89 | Preet2fun/Cisco_Devnet | /Python_OOP/encapsulation_privateMethod.py | 1,073 | 4.4375 | 4 | """
Encapsulation = Abstraction + data hiding
encapsulation means we are only going to show required part and rest will keep as private
"""
class Data:
__speed = 0 #private variable
__name = ''
def __init__(self):
self.a = 123
self._b = 456 # protected
self.__c ... | true |
cd9c959a5bc604f523799d07470931d281d79698 | paulc1600/Python-Problem-Solving | /H11_staircase.py | 1,391 | 4.53125 | 5 | #!/bin/python3
# ---------------------------------------------------------------------#
# Source: HackerRank
# Purpose: Consider a staircase of size n:
# #
# ##
# ###
#
####
#
# Observe that its base and height are both equal to n, and
# ... | true |
2cc6154799ccae67f873423a981c6688dc9fb2b5 | paulc1600/Python-Problem-Solving | /H22_migratoryBirds_final.py | 1,740 | 4.375 | 4 | #!/bin/python3
# ---------------------------------------------------------------------#
# Source: HackerRank
# Purpose: You have been asked to help study the population of birds
# migrating across the continent. Each type of bird you are
# interested in will be identified by an integer value. Each... | true |
e955679387cd90ad3e5dfbbff7f941478063823d | Hajaraabibi/s2t1 | /main.py | 1,395 | 4.1875 | 4 | myName = input("What is your name? ")
print("Hi " + myName + ", you have chosen to book a horse riding lesson, press enter to continue")
input("")
print("please answer the following 2 questions to ensure that you will be prepared on the day of your lesson.")
input("")
QuestionOne = None
while QuestionOne not in... | true |
0d0892bf443e39c3c5ef078f2cb846370b7852e9 | JakobLybarger/Graph-Pathfinding-Algorithms | /dijkstras.py | 1,297 | 4.15625 | 4 | import math
import heapq
def dijkstras(graph, start):
distances = {} # Dictionary to keep track of the shortest distance to each vertex in the graph
# The distance to each vertex is not known so we will just assume each vertex is infinitely far away
for vertex in graph:
distances[vertex] = math.... | true |
026526ddd9c38e990d966a0e3259edcb2c438807 | arlionn/readit | /readit/utilities/filelist.py | 1,003 | 4.21875 | 4 | import glob
from itertools import chain
def filelist(root: str, recursive: bool = True) -> [str]:
"""
Defines a function used to retrieve all of the file paths matching a
directory string expression.
:param root: The root directory/file to begin looking for files that will be read.
:param recursive... | true |
0d012a23dfd3e68024f560287226171040c2ca67 | EthanReeceBarrett/CP1404Practicals | /prac_03/password_check.py | 941 | 4.4375 | 4 | """Password check Program
checks user input length and and print * password if valid, BUT with functions"""
minimum_length = 3
def main():
password = get_password(minimum_length)
convert_password(password)
def convert_password(password):
"""converts password input to an equal length "*" output"""
fo... | true |
262d7b72a9b8c8715c1169b9385dd1017cb2632b | EthanReeceBarrett/CP1404Practicals | /prac_06/programming_language.py | 800 | 4.25 | 4 | """Intermediate Exercise 1, making a simple class."""
class ProgrammingLanguage:
"""class to store the information of a programing language."""
def __init__(self, field="", typing="", reflection="", year=""):
"""initialise a programming language instance."""
self.field = field
self.ty... | true |
8aa1cf81834abd2a7cb368ffdb9510ae7f0039e4 | nobleoxford/Simulation1 | /testbubblesort.py | 1,315 | 4.46875 | 4 | # Python program for implementation of Bubble Sort
def bubbleSort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the el... | true |
b29b3de7434393fca62ea01898df1015e7a8871f | iamkarantalwar/tkinter | /GUI Sixth/canvas.py | 1,080 | 4.21875 | 4 | #tkinter program to make screen a the center of window
from tkinter import *
class Main:
def __init__(self):
self.tk = Tk()
#these are the window height and width
height = self.tk.winfo_screenheight()
width = self.tk.winfo_screenwidth()
#we find out the center co or... | true |
5765384a784ac51407757564c0cbafa06cedb83b | divyaprabha123/programming | /arrays/set matrix zeroes.py | 1,059 | 4.125 | 4 | '''Set Matrix Zeroes
1. Time complexity O(m * n)
2. Inplace
'''
def setZeroes(matrix):
"""
Do not return anything, modify matrix in-place instead.
"""
#go through all the rows alone then
is_col = False
nrows = len(matrix)
ncols = len(matrix[0])
... | true |
9a3b9864abada3b264eeed335f6977e61b934cd2 | willzhang100/learn-python-the-hard-way | /ex32.py | 572 | 4.25 | 4 | the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
#first for loop goes through a list
for number in the_count:
print "This is count %d" % number
#same
for fruit in fruits:
print "A fruit of type: %s" % fruit
#mixed list use %r
for i ... | true |
d6c2b9f271797e580226702c6ec843e00eea3508 | SMinTexas/work_or_sleep | /work_or_sleep_in.py | 428 | 4.34375 | 4 | #The user will enter a number between 0 and 6 inclusive and given
#this number, will make a decision as to whether to sleep in or
#go to work depending on the day of the week. Day = 0 - 4 go to work
#Day = 5-6 sleep in
day = int(input('Day (0-6)? '))
if day >= 5 and day < 7:
print('Sleep in')
elif day >= 0 and d... | true |
d0db003c65b5b4bb5d08db8d23f49b29d15a2d9b | mariaKozlovtseva/Algorithms | /monotonic_check.py | 798 | 4.3125 | 4 | def monotonic(arr, if_true_false=False):
"""
Check whether array is monotonic or not
:param arr: array of different numbers
:return: string "Monotonic" / "Not monotonic" or if True / False
"""
decreasing = False
increasing = False
idx = 0
while not increasing and idx < len(arr)-1:
... | true |
41c3f5039e71c2ea562a61ddb37987b3e80ad0fc | grgoswami/Python_202011 | /source/reg17.py | 465 | 4.28125 | 4 |
def Fibonacci0(num):
"""
The following is called the docstring of the function.
Parameters
----------
num : int
The number of elements from the Fibonacci sequence.
Returns
-------
None. It prints the numbers.
"""
a = 1
print(a)
b = 1
print(b)
for i in r... | true |
8a0fcd96d2e7a22e2ef1d45af7dd914f4492d856 | vamsikrishnar161137/DSP-Laboratory-Programs | /arrayoperations.py | 1,774 | 4.28125 | 4 | #SOME OF THE ARRAY OPERATIONS
import numpy as np
a=np.array([(1,4,2,6,5),(2,5,6,7,9)])#defining the array.
print '1.The predifined first array is::',a
b=np.size(a)#finding size of a array.
print '2.Size of the array is::',b
c=np.shape(a)#finding shape of an array
print '3.Shape of the array is::',c
d=np.ndim(a)
print '... | true |
bc16a054e3eee1730211763fe3d0b71be4d41019 | shevdan/programming-group-209 | /D_bug_generate_grid.py | 2,259 | 4.375 | 4 | """
This module contains functions that implements generation of the game grid.
Function level_of_dif determines the range (which is the representation
of the level of difficulty which that will be increased thorough the test)
from which the numbers will be taken.
Function generate_grid generates grid, with a one spe... | true |
3da0639a03ae3f87446ad57a859b97af60384bc4 | blafuente/SelfTaughtProgram_PartFour | /list_comprehension.py | 2,397 | 4.65625 | 5 | # List Comprehensions
# Allows you to create lists based on criteria applied to existing lists.
# You can create a list comprehension with one line of code that examins every character in the original string
# Selects digigts from a string and puts them in a list.
# Or selects the right-most digit from the list.... | true |
d2f172a112ec5a30ab4daff10f08c5c4c5bc95a1 | AAKASH707/PYTHON | /binary search tree from given postorder traversal.py | 2,332 | 4.21875 | 4 | # Python program to construct binary search tree from given postorder traversal
# importing sys module
import sys
# class for creating tree nodes
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# initializing MIN and MAX
MIN = -sys.maxsize - 1
M... | true |
a079327ad1c4c1fcc01c22dc9e1e8f335f119958 | AAKASH707/PYTHON | /Print Square Number Pattern.py | 234 | 4.25 | 4 | # Python Program to Print Square Number Pattern
side = int(input("Please Enter any Side of a Square : "))
print("Square Number Pattern")
for i in range(side):
for i in range(side):
print('1', end = ' ')
print()
| true |
5b90a261a667a86387e49463f49a8855b477174c | AAKASH707/PYTHON | /Count Words in a String using Dictionary Example.py | 639 | 4.34375 | 4 | # Python Program to Count words in a String using Dictionary
string = input("Please enter any String : ")
words = []
words = string.split()
frequency = [words.count(i) for i in words]
myDict = dict(zip(words, frequency))
print("Dictionary Items : ", myDict)
*******************************************************... | true |
5d464a64a9d8ef963da82b64fba52c598bc2b56c | josh-folsom/exercises-in-python | /file_io_ex2.py | 402 | 4.4375 | 4 | # Exercise 2 Write a program that prompts the user to enter a file name, then
# prompts the user to enter the contents of the file, and then saves the
# content to the file.
file_name = input("Enter name of file you would like to write: ")
def writer(file_name):
file_handle = open(file_name, 'w')
file_handle.... | true |
f36220a4caae8212e34ff5070b9a203f4b5814f8 | josh-folsom/exercises-in-python | /python_object_ex_1.py | 2,486 | 4.375 | 4 | # Write code to:
# 1 Instantiate an instance object of Person with name of 'Sonny', email of
# 'sonny@hotmail.com', and phone of '483-485-4948', store it in the variable sonny.
# 2 Instantiate another person with the name of 'Jordan', email of 'jordan@aol.com',
# and phone of '495-586-3456', store it in the variable '... | true |
26f2d3651294e73420ff40ed603baf1ac2abb269 | Rohitjoshiii/bank1 | /read example.py | 439 | 4.21875 | 4 | # STEP1-OPEN THE FILE
file=open("abc.txt","r")
#STEP2-READ THE FILE
#result=file.read(2) # read(2) means ir reads teo characters only
#result=file.readline() #readline() it print one line only
#result=file.readlines() #readlines() print all lines into list
line=file.readlines() # for loop ... | true |
db3c248cd270dad58a6386c4c9b6dc67e6ae4fab | AK-1121/code_extraction | /python/python_20317.py | 208 | 4.1875 | 4 | # Why mutable not working when expression is changed in python ?
y += [1,3] # Means append to y list [1,3], object stays same
y = y+[1,3] # Means create new list equals y + [1,3] and write link to it in y
| true |
6f2581f4fafe6f3511327d5365f045ba579a46b1 | CdavisL-coder/automateTheBoringStuff | /plusOne.py | 372 | 4.21875 | 4 | #adds one to a number
#if number % 3 or 4 = 0, double number
#this function takes in a parameter
def plus_one(num):
num = num + 1
#if parameter is divided by 2 and equal zero, the number is doubled
if num % 2 == 0:
num2 = (num + 1) * 2
print(num2)
#else print the number
else:
... | true |
17e5dcdb6b83c5023ea428db1e93cc494d6fe405 | Parashar7/Introduction_to_Python | /Celsius_to_farenheight.py | 217 | 4.25 | 4 | print("This isa program to convert temprature in celcius to farenheight")
temp_cel=float(input("Enter the temprature in Celsius:"))
temp_faren= (temp_cel*1.8) +32
print("Temprature in Farenheight is:", temp_faren)
| true |
ebefd9d3d3d7139e0e40489bb4f3a022ee790c19 | vatasescu-predi-andrei/lab2-Python | /Lab 2 Task 2.3.py | 215 | 4.28125 | 4 | #task2.3
from math import sqrt
a=float(input("Enter the length of side a:"))
b=float(input("Enter the length of side b:"))
h= sqrt(a**2 + b**2)
newh=round(h, 2)
print("The length of the hypotenuse is", newh)
| true |
f235e7b36ac48915e7e0750af1fb6621a971f227 | yadavpratik/python-programs | /for_loops_programs.py | 1,901 | 4.28125 | 4 | # normal number print with for and range function
'''n=int(input("enter the number : "))
print("normal number print with for and range function")
for i in range(n):
print(i)
# =============================================================================================================================
# pr... | true |
a1ee1c5cfa1a83dfa4c2ca2dc2ec204b201ed1f2 | NatalieBeee/PythonWithMaggie | /algorithms/printing_patterns.py | 1,218 | 4.28125 | 4 | '''
#rows
for i in range(0,5):
#columns
for j in range(0,i+1):
print ('*', end ='')
print ('\r')
'''
# half_pyramid() is a function that takes in the number of rows
def half_pyramid(num_r):
#for each row -vertical
for i in range(0,num_r):
#for each column -horizontal
for j ... | true |
754cd0a9c3159b2eb91350df0f5d2907c543a6ad | sbishop7/DojoAssignments | /Python/pythonAssignments/funWithFunctions.py | 639 | 4.21875 | 4 | #Odd/Even
def odd_even():
for count in range(1,2001):
if count % 2 == 1:
print "Number is ", count, ". This is an odd number."
else:
print "Number is ", count, ". This is an even number."
#Multiply
def multiply(arr, x):
newList = []
for i in arr:
newList.... | true |
9535c83847a12174fc9d6002e19f70c163876af5 | LdeWaardt/Codecademy | /Python/1_Python_Syntax/09_Two_Types_of_Division.py | 1,640 | 4.59375 | 5 | # In Python 2, when we divide two integers, we get an integer as a result. When the quotient is a whole number, this works fine
# However, if the numbers do not divide evenly, the result of the division is truncated into an integer. In other words, the quotient is rounded down to a whole number. This can be surprisin... | true |
ea14d5de2d43b1f19eb612dea929a612ebfed717 | Ottermad/PythonNextSteps | /myMagic8BallHello.py | 819 | 4.15625 | 4 | # My Magic 8 Ball
import random
# put answers in a tuple
answers = (
"Go for it"
"No way, Jose!"
"I'm not sure. Ask me again."
"Fear of the unkown is what imprisons us."
"It would be madness to do that."
"Only you can save mankind!"
"Makes no difference to me, do or don't - whatever"
... | true |
9f4a1f9c1e212efe17186287746b7b4004ac037a | Col-R/python_fundamentals | /fundamentals/Cole_Robinson_hello_world.py | 762 | 4.21875 | 4 | # 1. TASK: print "Hello World"
print('Hello World!')
# 2. print "Hello Noelle!" with the name in a variable
name = "Col-R"
print('Hello', name) # with a comma
print('Hello ' + name) # with a +
# # 3. print "Hello 42!" with the number in a variable
number = 24
print('Hello', number) # with a comma
print('Hello '+ str(nu... | true |
768d5acc06bf952cb396c18ceea1c6f558634f6f | Col-R/python_fundamentals | /fundamentals/strings.py | 1,874 | 4.4375 | 4 | #string literals
print('this is a sample string')
#concatenation - The print() function inserts a space between elements separated by a comma.
name = "Zen"
print("My name is", name)
#The second is by concatenating the contents into a new string, with the help of +.
name = "Zen"
print("My name is " + name)
number = 5
... | true |
7ddac6a6f3770cacd02645e29e1058d885e871f2 | dburr698/week1-assignments | /todo_list.py | 1,924 | 4.46875 | 4 | # Create a todo list app.
tasks = []
# Add Task:
# Ask the user for the 'title' and 'priority' of the task. Priority can be high, medium and low.
def add_task(tasks):
name = input("\nEnter the name of your task: ")
priority = input("\nEnter priority of task: ")
task = {"Task": name, "Priority": priority}... | true |
7d6aef42709ca67f79beed472b3b1049efd73513 | chriklev/INF3331 | /assignment6/_build/html/_sources/temperature_CO2_plotter.py.txt | 2,237 | 4.1875 | 4 | import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def plot_temperature(months, time_bounds=None, y_bounds=None):
"""Plots the temperatures of given months vs years
Args:
months (string): The month for witch temperature values to plot. Can
also be list of strings with ... | true |
End of preview. Expand in Data Studio
Dataset created from styal/filtered-python-edu with only English samples. Enlgish samples have been classified with papluca/xlm-roberta-base-language-detection with a minimum threshold score of 0.8.
- Downloads last month
- 17