blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
d6d13883deaedf3f3db0d95dda7a77fda53d5712 | CRaNkXD/PyMoneyOrga | /PyMoneyOrga/PyMoneyOrga/domain/account.py | 2,184 | 4.3125 | 4 | from dataclasses import dataclass
import datetime
@dataclass
class Transaction(object):
"""
Data class for transactions made from and to an account. Used in Account class.
"""
amount: int
new_balance: int
description: str
time_stamp: datetime.datetime
account_id: int = None # foreign... | true |
47c8166a0ae2e8c9ef5d2b38fefe83d2983e18d4 | as0113-dev/Python-Data-Structure | /mergeSort.py | 1,078 | 4.1875 | 4 | def mergeSort(array):
#base case
if len(array) <= 1:
return array
#midpoint of "array"
mid = len(array)//2
#split array in half
leftSplit = array[:mid]
rightSplit = array[mid:]
#recursively call the splitting of array
leftSplit = mergeSort(leftSplit)
rightSplit = mergeS... | true |
2b93732d35dbee22032b49dc9968e6f07ad8ee89 | stavernatalia95/Lesson-5.2-Assignment | /Exercise #1.py | 781 | 4.34375 | 4 | # Assume you have the list xs = [12, 10, 32, 3, 66, 17, 42, 99, 20]
xs = [12, 10, 32, 3, 66, 17, 42, 99, 20]
# Write a loop that prints each of the numbers on a new line
for i in xs:
print(i)
# Write a loop that prints each number and its square on a new line.
for i in xs:
print(i,i**2)
# Wr... | true |
c2beb9e3beeb12a3e91f5189ea70fde4e4a07c87 | SHETU-GUHA/1st | /1st chapter.py | 1,128 | 4.375 | 4 | print('Hellow World!')
print ('What is your name?')
myName = input()
print ('it is good to meet you ' + myName)
print('The length of our name is :')
print (len(myName))
print ('what is your age?')
myAge = input ()
print ('You will be ' + str (int(myAge)+1) + 'in a year.')
#1. operator (*, -, / , +) values ... | true |
f204312c8a2bd68d75b89db21b8334c3d7d9191d | Anurag-12/learning-python | /Coroutines_Example/main.py | 2,464 | 4.3125 | 4 | '''
Both generator and coroutine operate over the data; the main differences are:
Generators produce data
Coroutines consume data
Coroutines are mostly used in cases of time-consuming programs, such as tasks related to machine learning or deep learning algorithms or in cases
where the program has to re... | true |
d181bf517a3d745068e1e2de3af4d91abaf18b6b | Anurag-12/learning-python | /seek-tell-file/main.py | 861 | 4.4375 | 4 | #This code will change the current file position to 5, and print the rest of the line.
# Note: not all file objects are seekable.
f = open("myfile.txt", "r")
f.seek(5)
print( f.readline() )
f.close()
f = open("myfile.txt")
f.seek(11)
print(f.tell())
print(f.readline())
# print(f.tell())
print(f.readlin... | true |
5111dee03f6cdcc8dc76ffe3409b809fefaf4ffd | vijaypalmanit/daily_coding_problem | /daily_coding_problem_2.py | 649 | 4.125 | 4 | # This problem was asked by Uber.
# Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
# For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our... | true |
c4051d5b29c21c23b545cee418d14da0e11b29a0 | shaunakchitare/PythonLearnings | /function_programs.py | 2,152 | 4.40625 | 4 | #-------------------------------------------------------------------------------
#Exercise 1 - Creat a function that accepts 3 ardument and return their sum
print('\nExercise 1')
def add_numbers(x,y,z):
total = x + y + z
return total
total = add_numbers(5,1,9)
print(total)
#------------------------------------... | true |
1cd0a2fc2283355d1398aafb3fea2e57a50b5312 | kovokilla/python | /namedTuple.py | 684 | 4.375 | 4 | # Import the 'namedtuple' function from the 'collections' module
from collections import namedtuple
# Set the tuple
#tuple je v podstate object
individual = namedtuple("Nazov_identifikacia", "name age height")
user = individual(name="Homer", age=37, height=178)
user2 = individual(name="Peter", age=33, height=175)
# Pri... | true |
0161d8a35ce81625815121d56e93b56162a62b95 | sabirul-islam/Python-Practice | /ANISUL ISLAM/list.py | 1,125 | 4.34375 | 4 | subjects = ['javascript', 'python', 'php', 'java', 'flutter', 'kotlin']
print(subjects)
print(subjects[1])
print(subjects[2:]) # print from 2 number index
print(subjects[-1])
print('python' in subjects) # check is this subject in here?(case sensitive)
print('golang' not in subjects) # it returns true
print(subjects + [... | true |
a2ebbe7a95c56145f67b5e46208e3bbced0c44d2 | Bokomoko/classes-and-operations-in-data-model-python | /main.py | 744 | 4.375 | 4 | class Polynomial:
# method to initialize the object with some values
def __init__(self, *coefs):
self.coefs = coefs
# function to represent the object (print)
# similar to __str__ but for debuging purposes
# it will be used if no __str__ method
def __repr__(self):
return 'Polynomial(*{!r})'.forma... | true |
3ca81cce7fcf16010bd88b5fc94d932dd5834db0 | rodrigodata/learning | /pyhton/arithmetic_operations/arithmetic_operations.py | 434 | 4.1875 | 4 | # add
print(10 + 3) # 13
# subtract
print(10 - 4) # 6
#float
print(2.22 * 3) # 6.66
# multiplication
print(2 * 8) # 16
# division
print(10 / 3) # 3.3333333333333335
print(10 // 3) # 3 => Returns an integer from division
# modules
print(10 % 3) # 1 Returns the remaining
# exponation
print(10 ** 3) # 1000
####
#i... | true |
3c9c29480c72a6e8082cd18297d94773ab531e4f | gedo147/Python | /ConvertClassToDictionary/BinaryTree.py | 719 | 4.1875 | 4 |
class BinaryTree:
def __init__(self,value=None, left=None, right=None):
self.value = value
self.left = left
self.right = right
tree = BinaryTree(10,left=BinaryTree(7,left=3, right=8), right=BinaryTree(15,left=11,right=17))
print(tree.__dict__)
print("So as we can see only ... | true |
70ded69c41a75a06894364a029d28f77f54cad9c | ariannasg/python3-training | /standard_library/json_ops.py | 1,356 | 4.1875 | 4 | #!usr/bin/env python3
# working with JSON data
import json
import urllib.request
# use urllib to retrieve some sample JSON data
req = urllib.request.urlopen("http://httpbin.org/json")
data = req.read().decode('utf-8')
print(data)
# use the JSON module to parse the returned data
obj = json.loads(data)
# when the data... | true |
9835578b347135a0a3be9da82c7f1538b64843d1 | ariannasg/python3-training | /advanced/lambdas.py | 1,336 | 4.8125 | 5 | #!usr/bin/env python3
# lambdas are simple and small anonymous functions that are used in situations
# where defining a whole separate function would unnecessarily increase the
# complexity of the code and reduce readability.
# Lambdas can be used as in-place functions when using built-ins conversion
# functions like... | true |
45287696df3e49cbf7899d074edcdc0ae31e35a4 | ariannasg/python3-training | /standard_library/random_sequence.py | 1,788 | 4.8125 | 5 | #!usr/bin/env python3
import random
import string
# A common use case for random number generation is to use the generated
# random number along with a sequence of other values.
# So for example, you might want to select a random element from a list or
# a set of other elements.
# Use the choice function to randomly ... | true |
4e1dec27165ae11de26af08675f180aaaba8f2d9 | ariannasg/python3-training | /standard_library/urls_parsing.py | 1,349 | 4.15625 | 4 | #!usr/bin/env python3
# Using the URL parsing functions to deconstruct and parse URLs
import urllib.parse
sample_url = "https://example.com:8080/test.html?val1=1&val2=Hello+World"
# parse a URL with urlparse()
result = urllib.parse.urlparse(sample_url)
print(result)
print('scheme:', result.scheme)
print('hostname:', ... | true |
bec0dc0a1418dc6eaddb447325395115ed8dddb4 | ariannasg/python3-training | /standard_library/string_search.py | 897 | 4.46875 | 4 | #!usr/bin/env python3
# Use standard library functions to search strings for content
sample_str = "The quick brown fox jumps over the lazy dog"
# startsWith and endsWith functions
print(sample_str.startswith("The"))
print(sample_str.startswith("the"))
print(sample_str.endswith("dog"))
# the find function starts sea... | true |
e5acc44ad8a023261a1818cce025e33ea782e299 | vijonly/100_Days_of_Code | /Day2/tip_calculator.py | 357 | 4.1875 | 4 | # Tip Calculator project
print("Welcome to the tip calculator.")
bill = float(input("What was the total bill? $"))
partition = int(input("How many people to split the bill? "))
tip_percentage = int(input("What percentage tip would you like to give? 10, 12, or 15? "))
print(f"Each person should pay: ${(bill / partition... | true |
b3c75e95a54ef8a1ddaf19b83b4595a94df35cd7 | vijonly/100_Days_of_Code | /Day15/coffee_machine.py | 2,702 | 4.25 | 4 | # Coffee Machine Program
MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
... | true |
5db1788519d32d194b83d998344193c9cc8044d9 | vijonly/100_Days_of_Code | /Day8/area_calc.py | 654 | 4.3125 | 4 | # Area Calc
"""
You are painting a wall.
The instructions on the paint can says that 1 can of paint can cover 5 square meters of wall.
Given a random height and width of wall,
calculate how many cans of paint you'll need to buy.
Formula to caclculate number of cans:
(wall_height x wall_width) / coverage per can
"""
... | true |
591489c8f26efdd66c23665fce80a3d5ea3096dd | malmhaug/Py_AbsBegin | /Ch4E2_egasseM/main.py | 353 | 4.34375 | 4 | # Project Name: Ch4E2_egasseM
# Name: Jim-Kristian Malmhaug
# Date: 11 Des 2015
# Description: This program take an input message from the user and prints it backwards
message = str(input("Hey! Please enter a message: "))
print("\nThe message is backwards:\n")
for letter_nr in range(len(message), 0, -1):
print(... | true |
ab6a519ff67fba192d60c3fc45b4833034676a9a | malmhaug/Py_AbsBegin | /Ch3E4_GuessMyNumber_V1.02/main.py | 2,503 | 4.21875 | 4 | # Project Name: Ch3E4_GuessMyNumber_V1.02
# Name: Jim-Kristian Malmhaug
# Date: 25 Oct 2015
# Description: This program is a modified version of the
# Guess My Number program from the book, with computer versus player
# Guess My Number - Computer guesser
#
# The user picks a random number between 1 and 100
# The comp... | true |
cefb4ec8bf58af1859c49337d9cd7ca70df5ef77 | pohrebniak/Python-base-Online-March | /pogrebnyak_yuriy/03/Task_3_2_Custom map.py | 1,779 | 4.34375 | 4 | '''
Implement custom_map function, which will behave like the original Python map() function.
Add docstring.
'''
def custom_map(func, *args):
"""
Custom_map function, which will behave like the original Python map() function.
:param arg1: func, function name to which custom_map passes each element of giv... | true |
4674b82a4afad64d74fe1973eb1c83566b3c6aab | pohrebniak/Python-base-Online-March | /kirill_kravchenko/02/task_2.3.py | 1,580 | 4.25 | 4 | # Given an array, find the int that appears an odd number of times. There will always be only one integer that appears an odd number of times.
#
# Examples:
#
# list: [1, 2, 3, 1, 3, 2, 1]
# output: 1
str = [1, 2, 3, 1, 3, 2, 1]
# ======
# 1 variant
# ======
equiv = 0
for i in str:
for j in str:
if i ... | true |
d03e936eb276d78f90572ad39a31e14ff76a32e5 | MuskanKhandelwal/Coding-problem-prep | /Operator overloading.py | 456 | 4.125 | 4 | class Student:
def __init__(self,x,y):
self.x=x
self.y=y
def __add__(self, other):
ans1=self.x+other.x
ans2=self.y+other.y
return ans1,ans2
S1=Student(10,20)
S2=Student(5,6)
S3=S1+S2 #This will give error as we are trying to add 2 objects, so we will override ad... | true |
4c92cfc6d9f3709ab208e4fec1d2bc1970cccea2 | agladman/python-exercises | /small-exercises/readtime.py | 1,087 | 4.15625 | 4 | #!/usr/bin/env python3
"""
Calculates reading time based on average pace of 130 words per minute.
"""
import sys, time
def mpace(p):
if type(p) == int and p > 0:
return p
else:
match p:
case "slow":
return 100
case "average":
return 130... | true |
25dce67e505a17f3c7b71eb4a397539c956fa72d | agladman/python-exercises | /small-exercises/alphabetbob.py | 406 | 4.34375 | 4 | #!/usr/bin/env Python3
"""
Write a program that asks the user for their name, and then prints out
their name with the first letter replaced by each letter of the alphabet
in turn, e.g. for 'Bob' it prints 'Aob', 'Bob', 'Cob', 'Dob' etc.
"""
alpha = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.split()
name =... | true |
827baf8718a70c90c62f702f817824a47d6ac068 | dtom90/Algorithms | /Arrays/nearly-sorted-algorithm.py | 1,490 | 4.125 | 4 | """
Nearly Sorted Algorithm
https://practice.geeksforgeeks.org/problems/nearly-sorted-algorithm/0
Given an array of n elements, where each element is at most k away from its target position.
The task is to print array in sorted form.
Input:
First line consists of T test cases.
First line of every test case consists o... | true |
0a67103e7ad9ba72106c840ed1dfcd7e07c2869c | dtom90/Algorithms | /Encoding/url-shortener.py | 2,067 | 4.5 | 4 | """
https://practice.geeksforgeeks.org/problems/design-a-tiny-url-or-url-shortener/0
Design a system that takes big URLs like “http://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from-1-to-n/”
and converts them into a short 6 character URL.
It is given that URLs are stored in database and every URL has an asso... | true |
834de094ea09b3e3a66ea6b7222a8ad905f9d790 | nurawat/learning_python | /list_range_introduction.py | 641 | 4.15625 | 4 | ##
# Basic Learner type
#
##
# ip_address = input("Please Enter IP address : ")
# print(ip_address.count("."))
ip_address = ["127.0.0.1", "192.168.0.1", "192.168.1.1"]
for single_IP in ip_address:
print("IP given is {}".format(single_IP))
### List
even = [2, 4, 6, 8]
odd = [1, 3, 5, 7]
numbers = even + odd
l_num... | true |
34b4df534b19bc416dffdb4f35a63681d9c6fa16 | anant-creator/Other_sources | /Area_perimeter_of_Triangle.py | 404 | 4.125 | 4 | ''' Area and perimeter of a right angle triangle '''
base = int(input("Enter the base of triangle:- "))
height = int(input("Enter the height of triangle:- "))
print("If you want to know the area then use '0' as hypotenuse")
hypotenuse = int(input("Enter the hypotenuse:- "))
area = base * height / 2
perimeter = base +... | true |
66a5d533a37ba0df7d85bba6df765a903e5679d3 | KakE-TURTL3/PythonPractice | /Login System/loginSystem.py | 1,509 | 4.15625 | 4 | import time
#Introduces user to program they are using
print("Welcome to *insert name here*")
#Asks the user to either register or log in
opt = int(input ("To continue you must login or register. Please pick an option.\n1)Log In\n2)Register\n"))
#Defines login function
def login():
accountName = input(... | true |
704eeb3197f4bfd65121dcb7bed54dc5113014b5 | simrit1/scrabble-word-score-calculator | /scrabble_word_score.py | 1,837 | 4.25 | 4 | '''
Habitica Challenge October 2019
Challenge Description
In the game Scrabble each letter has a value. One completed word gives you a score.
Write a program that takes a word as an imput and outputs the calculated scrabble score.
Values and Letters:
1 - A, E, I, O, U, L, N, R, S, T
2 - D, G
3 - B, C, M, ... | true |
08f9a8c7e174acc88b18811e4b2b6ee2b6bc0c4f | Liquid-sun/MIT-6.00.1x | /week-4/fruits.py | 1,665 | 4.21875 | 4 |
"""
Code Grader: Python Loves Fruits
(10 points possible)
Python is an MIT student who loves fruits. He carries different types of fruits (represented by capital letters)
daily from his house to the MIT campus to eat on the way. But the way he eats fruits is unique.
After each fruit he eats (except the last one wh... | true |
d43a9d3ba885470d292cb3d377913f7257862571 | Liquid-sun/MIT-6.00.1x | /week-1-2/payments3.py | 731 | 4.125 | 4 | #!/usr/bin/env python
balance = 320000
annualInterestRate = 0.2
monthlyInterestRate = annualInterestRate / 12.0
min_pay = balance / 12
max_pay = (balance * (1 + monthlyInterestRate)**12) / 12.0
ans = (min_pay + max_pay) / 2
while(balance <= 0):
print('pay: ', ans)
for month in range(1, 13):
balance -= a... | true |
2dfc365283d74732559002389ca6b526ec4d0891 | Liquid-sun/MIT-6.00.1x | /quiz/flatten.py | 616 | 4.46875 | 4 | #!/usr/bin/env python
"""
Problem 6
(15 points possible)
Write a function to flatten a list. The list contains other lists, strings, or ints.
For example, [[1,'a',['cat'],2],[[[3]],'dog'],4,5] is flattened into [1,'a','cat',2,3,'dog',4,5]
"""
def flatten(aList):
'''
aList: a list
Returns a copy of a... | true |
96f5e490d0d0e216bc13b8ac4b6fced2a3888e86 | Liquid-sun/MIT-6.00.1x | /week-6/queue.py | 1,694 | 4.46875 | 4 | #!/usr/bin/env python
"""
For this exercise, you will be coding your very first class, a Queue class.
Queues are a fundamental computer science data structure. A queue is basically
like a line at Disneyland - you can add elements to a queue, and they maintain
a specific order.
When you want to get something off the en... | true |
d34b5d4f791efb03822cd6841ba5f7636cf635f1 | prajaktasangore/coding-challenge-2015 | /PythogorousTriplets.py | 787 | 4.3125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Prajakta Sangore
# Date: 30th September 2015
# Problem: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
# a2 + b2 = c2
# For example, 32 + 42 = 9 + 16 = 25 = 52.
# There exists exactly one Pythagorean triplet for which a + b... | true |
c8a6d7caef5c558d448908ba2f764f4adbfab1d8 | chunkify/Course_Materials | /CMPT 830_Bioinformatics_and_Computational_Biology/Assignment_1/Solution/Exercise 2.py | 2,098 | 4.21875 | 4 | #!/usr/bin/env python3
# This script will open the file "Glycoprotein.fasta" and read each line of the
# file within a for-loop. That means that each iteration through the for-loop
# will be performed with a new (the next) line of the input file. The
# number of characters in each line is printed.
# Open the file
#f... | true |
d3db0e57da66e3105e022c17ee7567a2358b9541 | chriscross00/cci | /data_structures/linked_lists.py | 2,176 | 4.15625 | 4 | # https://www.codefellows.org/blog/implementing-a-singly-linked-list-in-python/
# READ THIS https://www.greenteapress.com/thinkpython/thinkCSpy/html/chap17
# .html
# creating the class Node
class Node:
def __init__(self, data, next=None):
self.data = data
self.next = next
def get_data(self)... | true |
13300283d829e0a97591566f852896cbf30e2a00 | BlackTimber-Labs/DemoPullRequest | /Python/tripur1.py | 303 | 4.15625 | 4 | # to find sum
# of elements in given array
def _sum(arr):
sum=0
for i in arr:
sum = sum + i
return(sum)
# driver function
arr=[]
# input values to list
arr = [12, 3, 4, 15]
# calculating length of array
n = len(arr)
ans = _sum(arr)
# display sum
print ('Sum of the array is ', ans)
| true |
ae33b423103085042b0b0084035f20108689778e | fizzahwaseem/Assignments | /31_gcd.py | 394 | 4.21875 | 4 | #Python program to compute the greatest common divisor (GCD) of two positive integers.
print('To find GCD enter ')
num1 = int(input('number 1 : '))
num2 = int(input('number 2 : '))
if num1 > num2:
greater = num1
else:
greater = num2
for i in range(1, greater+1):
if((num1 % i == 0) and (num2 % i == 0... | true |
bd671af590ae1ec9251afc96487aa2e1f95db6cb | fizzahwaseem/Assignments | /20_time_to_seconds.py | 224 | 4.28125 | 4 | #Python program to convert all units of time into seconds.
hour = int(input("Enter time in hours: "))
minute = int(input("Enter time in minutes: "))
t = (hour * 60 * 60) + (minute * 60)
print("Total time in seconds is: ", t) | true |
26a3b257f2a1797e32773e653195450f68e83729 | AnneOkk/Alien_Game | /bullet.py | 1,561 | 4.125 | 4 | import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
"""A class to manage bullets fired from the ship"""
def __init__(self, ai_game):
"""Create a bullet object at the ship's current position."""
super().__init__()
self.screen = ai_game.screen
self.settings = ai_... | true |
343cd7567341f94b32b70ac9b1089734aa79aaaf | trev3rd/gogo | /guess1.py | 1,622 | 4.46875 | 4 | import random
guessesTaken = 0 #this represents how many times the user has tried guessing the right number starting from zero
number = random.randint(1, 10)
print(number) #this shows the random number the computer picked good for seeing if code works properly
print(' I am thinking of a number between 1 and 10.')
... | true |
0b5ce13bcb253816f93f40949150a0fc47b2dddd | faliona6/PythonWork | /letter.py | 404 | 4.125 | 4 |
word = input("What is the magical word?")
def Dictionary(word):
dictionary = {}
a = 0
for letter in word:
if letter in dictionary:
dictionary[letter] = dictionary[letter] + 1
else:
dictionary[letter] = 1
return dictionary
dictionary = Dictionary(word)
for let, ... | true |
1b536c7de215a6511df46e606f059fef64529533 | j33mk/PythonSandboxProdVersion | /pythonsandbox/sandbox/newpython/dopamine.py | 872 | 4.1875 | 4 | #i was thinking how can i link my dopamine with programming, get back to programming and learn datascience, machine learning, and make myself expert in everything that i come across
# what is stopping me? What are the things that are stopping me
# this is the question that i am searching the answer
print('dopamine re... | true |
eff5e1ac079573feb1d0cf78aacd4f2088e8c845 | turalss/Python | /day_2_a.py | 1,299 | 4.40625 | 4 | # Write a string that returns just the letter ‘r’ from ‘Hello World’
# For example, ‘Hello World’[0] returns ‘H’.You should write one line of code. Don’t assign a variable name to the string.
hello_world = 'Hello World'
print(hello_world[8])
# 2. String slicing to grab the word ‘ink’ from the word ‘thinker’
# S=’hel... | true |
8c4f0158e801cb77e85555ac6283c78f44c99ce9 | AISWARYAK99/Python | /tuples.py | 952 | 4.65625 | 5 | #tuples
#they are not mutable
my_tuple=()
my_tuple1=tuple()
print(my_tuple)
print(my_tuple1)
my_tuple=my_tuple+(1,2,3)
print(my_tuple)
my_tuple2=(1,2,3)
my_tupple4=tuple(('Python','Java','Php',1))
print(my_tuple2)
print(my_tupple4)
my_tuple5='example', #add comma if we want tuple with single elements
pri... | true |
b3fd5e9b71657eeb1333aa465f429d511ba27a2f | AISWARYAK99/Python | /start1.py | 1,685 | 4.28125 | 4 | #python beginning
'''
There are 6 data types in python.
1.Numeric(not mutable)
2.List(mutable)
3.Tuples
4.Dictionary
5.Set
6.String
'''
print('hello users welcome to the basics')
a=int(input('Enter num a:'))#input is read as a string so converting it to int.
b=int(input('Enter num s:'))#type conversion of s... | true |
eadc78f6241176af767fed72ac5fbf14b5440c4f | Ivasuissa/python1 | /isEven.py | 246 | 4.1875 | 4 |
def is_even(n):
if (n % 1) == 0:
if (n % 2) == 0:
print("True")
return True
else:
print("False")
return False
else:
print(f"{n} is not an integer")
is_even(-4) | true |
eb0146449cf4c1038ba3107983fbed12bb9db675 | mdmcconville/Solutions | /validPalindrome.py | 683 | 4.15625 | 4 | import string
"""
This determines whether a given string is a palindrome regardless of case,
punctuation, or whitespace.
"""
class Solution:
"""
Precondition: s is a string
Postcondition: returns a boolean
"""
def isPalindrome(self, s):
# Case: string is empty
if not s:
... | true |
9c86124bc1733189f8edab9712a4d79e3e074345 | mlesigues/Python | /everyday challenge/day_19.py | 1,916 | 4.125 | 4 | #Task: Vertical Order Traversal of a Binary Tree from Leetcode
#src:https://www.geeksforgeeks.org/print-binary-tree-vertical-order-set-2/
#src:https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/discuss/253965/Python-8-lines-array-and-hashmap-solutions
# Definition for a binary tree node.
# class T... | true |
551824b92a522ebbaa8d8efb5b2a790953662133 | mlesigues/Python | /everyday challenge/day_13.py | 1,713 | 4.125 | 4 | #TASK: Given a full name, your task is to capitalize the name appropriately.
#input: s is the full name
# Complete the solve function below.
def solve(s):
#s[0] = s.capitalize()
#cap = s.capitalize()
# for i in len(range(s)):
# if s[i] == " ":
# s[i+1] = s.capitalize()
# for i in ra... | true |
ece505a202ad37c9ca990f3b84f121cc076f5a02 | amrishparmar/countdown-solver | /countdown.py | 2,941 | 4.25 | 4 | import argparse
import sys
def load_words(filename):
"""Load all words (9 letters or less) from dictionary into memory
:param filename: A string, the filename to load
:return: A set, all relevant words in the file
"""
valid_words = set()
with open(filename, 'r') as word_file:
for... | true |
c77766a42c2ad2c69e0dbb57ae284d8aa04f5a64 | robinyms78/My-Portfolio | /Exercises/Python/Learning Python_5th Edition/Chapter 4_Introducing Python Object Types/Examples/Dictionaries/Nesting Revisited/Example1/Example1/Example1.py | 375 | 4.46875 | 4 | rec = {"name": {"first": "Bob", "last": "Smith"}, "jobs": ["dev","mgr"], "age": 40.5}
# "name" is a nested dictionary
print(rec["name"])
# Index the nested dictionary
print(rec["name"]["last"])
# "jobs" is a nested list
print(rec["jobs"])
# Index the nested list
print(rec["jobs"][-1])
# Expand Bob's job descripti... | true |
461fdf8ec3a0c44f068c802e51eff664a205dc27 | dineshkumarkummara/my-basic-programs-in-java-and-python | /folders/python/instagram/45while_else.py | 295 | 4.53125 | 5 | #In Python, you can add the "else" block after a "while" loop.
# It will be executed after the loop is over.
x=3
while x<=5: #change the condition to check different outputs
print(x)
x+=1
#if the condition is false then else statement will be executed
else:
print("done")
| true |
131fea2d621c3a61c365d6794793cd4ba30ba951 | dineshkumarkummara/my-basic-programs-in-java-and-python | /folders/python/others/fun2.py | 605 | 4.4375 | 4 | def fun(*args):
for i in args:
print(i)
args=1,2,3,4,5,6
fun(*args)
#or
print("----------")
fun(7,8,9)
#You can't provide a default for args, for example func(*args=[1,2,3]) will raise a syntax error (won't evencompile).
# You can't provide these by name when calling the function, for example func(*args=... | true |
d3ec9f8db3eceae68a3392d8de84c8acd9155de2 | muskanmahajan486/communication-error-checksum | /parity/index.py | 409 | 4.40625 | 4 | # Python3 code to get parity.
# Function to get parity of number n.
# It returns 1 if n has odd parity,
# and returns 0 if n has even parity
def getParity( n ):
parity = 0
while n:
parity = ~parity
n = n & (n - 1)
return parity
# Driver program to test getParity(... | true |
706f75c1b7da25049bdc240b0620b8303fcc8e72 | rahulcode22/Data-structures | /Arrays/BubbleSort.py | 583 | 4.4375 | 4 | '''
Bubble sort is a example of sorting algorithm . In this method we at first compare the data element in the first position with the second position and arrange them in desired order.Then we compare the data element with with third data element and arrange them in desired order. The same process continuous until the ... | true |
709312e9a2f50148b6393f5adc5bb9c59d722fb8 | rahulcode22/Data-structures | /Two Pointers/RemoveElements.py | 660 | 4.1875 | 4 | '''
Given an array and a value, remove all the instances of that value in the array.
Also return the number of elements left in the array after the operation.
It does not matter what is left beyond the expected length.
Example:
If array A is [4, 1, 1, 2, 1, 3]
and value elem is 1,
then new length is 3, and A is now [4... | true |
387179e6134508a1d71e818542318548d568258b | rahulcode22/Data-structures | /Math/FizzBuzz.py | 670 | 4.125 | 4 | '''
Given a positive integer N, print all the integers from 1 to N. But for multiples of 3 print “Fizz” instead of the number and for the multiples of 5 print “Buzz”. Also for number which are multiple of 3 and 5, prints “FizzBuzz”.
'''
class Solution:
# @param A : integer
# @return a list of strings
def fi... | true |
f675a20b4fb1b4acd7b8ca903097b07a666909f2 | rahulcode22/Data-structures | /Tree/level-order-traversal.py | 952 | 4.125 | 4 | class Node:
def __init__(self,key):
self.val = key
self.left = None
self.right = None
def printLevelOrder(root):
h = height(root)
for i in range(1,h+1):
printGivenOrder(root,i)
def printGivenOrder(root,level):
if root is None:
return
if level == 1:
p... | true |
ba2d6b6297ea813c6fbfd92782aada21cb368555 | rahulcode22/Data-structures | /Doublylinkedlist/DLL_insertion.py | 1,145 | 4.28125 | 4 | #Insertion at front
def insertafter(head,data):
new_node=node(data)
new_node.next=head
new_node.prev=None
if head is not None:
head.prev=new_node
head=new_node
#Add a node after a given node
def insertafter(prev_node,data):
if prev_node is None:
return
#Allo... | true |
d3123c6a569f57767865a6972bde32d3b858d348 | SamanehGhafouri/Data-Structures-and-Algorithms-in-python | /Experiments/find_largest_element.py | 676 | 4.3125 | 4 | # ######### Find the largest element in array ########
def largest_element(arr):
if len(arr) == 0:
return None
max_num = arr[0]
for i in range(len(arr)):
print(i, arr[i])
if arr[i] > max_num:
max_num = arr[i]
return max_num
ar = [90, 69, 23, 120, 180]
print(largest... | true |
5692a8e56f59808656816b733166021af8f5d3c1 | SamanehGhafouri/Data-Structures-and-Algorithms-in-python | /Sorting/bubble_sort.py | 682 | 4.3125 | 4 | # Bubble sort: takes an unsorted list and sort it in ascending order
# lowest value at the beginning by comparing 2 elements at a time
# this operation continues till all the elements are sorted
# we have to find the breaking point
# Time Complexity: best case: O(n)
# average and worst case: O(n^2)
de... | true |
e35fd14187b0b277064bfc4d2019079376ba4781 | SamanehGhafouri/Data-Structures-and-Algorithms-in-python | /Recursion/reverse_str.py | 516 | 4.15625 | 4 | # C-4.16 reverse a string
def reverse_str(string):
if len(string) == 0:
return '' # we cut the first character and put it in
# the back of the string each time
else: ... | true |
7a37455274916403acdee17331216be6d7cc0810 | SachinKtn1126/python_practice | /11_better_calculator.py | 905 | 4.40625 | 4 | # Title: Creating a better calculator
# Author: Sachin Kotian
# Created date (DD-MM-YYYY): 07-12-2018
# Last modified date (DD-MM-YYYY): 07-12-2018
#
# ABOUT:
# This code is to create a better calculator using if else statement and user input.
# Inpu... | true |
ab0ca448a75ff4094c8c7cfe7f112647a22ec37d | SachinKtn1126/python_practice | /10_if_statements_comparisons.py | 1,217 | 4.15625 | 4 | # Title: If statement in python
# Author: Sachin Kotian
# Created date (DD-MM-YYYY): 07-12-2018
# Last modified date (DD-MM-YYYY): 07-12-2018
#
# ABOUT:
# This code is to try and test the working of if statement
# Defining boolean variables
is_male ... | true |
71111a542b32a7815b1dd9c7f55ea93d3e75c2b0 | green-fox-academy/criollo01 | /week-02/day-05/palindrome_maker.py | 299 | 4.3125 | 4 | #Create a function named create palindrome following your current language's style guide.
# It should take a string, create a palindrome from it and then return it.
word = str(input("Write a word! "))
def palin_maker(word):
new_word = word + word[::-1]
print(new_word)
palin_maker(word)
| true |
601f2398b30c816fb76ee389a8a93995b98d2fa5 | green-fox-academy/criollo01 | /week-02/day-02/reverse.py | 306 | 4.5625 | 5 | # - Create a variable named `aj`
# with the following content: `[3, 4, 5, 6, 7]`
# - Reverse the order of the elements in `aj`
# - Print the elements of the reversed `aj`
aj = [3, 4, 5, 6, 7]
# ---solution 1---
for i in reversed(aj):
print(i)
#
# ---solution 2--- (nicer)
print(list(reversed(aj))) | true |
d00d45e57e5f130d3356cefa7bc7b50d63a185fe | saikrishna96111/StLab | /triangle.py | 516 | 4.1875 | 4 | print("enter three sides of a Triangle in the range (0 to 10)")
a=int(input("Enter the value of a "))
b=int(input("Enter the value of b "))
c=int(input("Enter the value of c "))
if a>10 or b>10 or c>10:
printf("invalid input values are exceeding the range")
if (a<(b+c))and(b<(a+c))and(c<(a+b)):
if a==b==... | true |
abc28cc6001d0f1c626995ec69eda14235636446 | brybalicious/LearnPython | /brybalicious/ex15.py | 2,707 | 4.4375 | 4 | # -*- coding: utf-8 -*-
# This line imports the argv module from the sys package
# which makes the argv actions available in this script
# Interestingly, if you run a script without importing argv, yet you type
# in args when you run the script in shell (!= python interpreter), it
# still runs and just igno... | true |
25bc4acccf3f18d73ef6b5a3fa6ea39dd4ba329e | ABradwell/Portfolio | /Language Competency/Python/Basic_Abilities/Arrays, Lists, and Selection sort/Occurances in List.py | 1,226 | 4.3125 | 4 | '''
Count the number of an element
occurrences in a list
• Create a function that takes a list and an integer v, and
returns the number of occurrences of v is in the list. Add
the variable NP as to count number of times the loop
runs (and display a message).
• The main program should generate a list, call the
function,... | true |
d75e6cfdd1f826e8cbd9c8c8ca744f38b4c4e8fd | ABradwell/Portfolio | /Language Competency/Python/Basic_Abilities/Matricies/Matrix Trandformation.py | 876 | 4.125 | 4 | ##– Exercise 1: Matrix transposed
##– Exercise 2: Sum of an array
##– Exercise 3: Multiplication with arrays
#Exercise One
#November 6th, 2018
'''
for example use... 1 2 3,
4 5 6
'''
def transform(A):
AT = []
collums = len(A)
rows = len(A[0])
i = 0
for i in ra... | true |
1d0ba82cfb5a76e6b7efd43a3b1266cf658dbca5 | JennifferLockwood/python_learning | /python_crash_course/chapter_9/9-13_orderedDict_rewrite.py | 860 | 4.1875 | 4 | from collections import OrderedDict
glossary = OrderedDict()
glossary['string'] = 'simply a series of characters.'
glossary['list'] = 'is a collection of items in a particular order.'
glossary['append'] = 'is a method that adds an item to the list.'
glossary['tuple'] = 'is an immutable list.'
glossary['dictionary'] ... | true |
9082625477c61bdd518483945261039e3868c49d | JennifferLockwood/python_learning | /python_crash_course/chapter_10/10-8_cats_and_dogs.py | 610 | 4.28125 | 4 | def reading_files(filename):
"""Count the approximate number of words in a file."""
try:
with open(filename) as file_object:
lines = file_object.readlines()
except FileNotFoundError:
msg = "\nSorry, the file " + filename + " does not exist."
print(msg)
else:
#... | true |
f9a57cf4fbffe700b4f0c15111c0e78479f0a263 | Jinsaeng/CS-Python | /al4995_hw3_q1.py | 382 | 4.21875 | 4 | weight = float(input("Please enter your weight in kilograms:"));
height = float(input("Please enter your height in meters:"));
BMI = weight / (height ** 2)
if (BMI < 18.5):
status = ("Underweight")
elif (BMI < 24.9 ):
status = ("Normal")
elif (BMI <29.9):
status = "Overweight"
else:
stat... | true |
d1c7ab2c0a3a608ff42596a52315fced6f632d00 | Jinsaeng/CS-Python | /al4995_hw2_q1b.py | 383 | 4.21875 | 4 | weight = float(input("Please enter your weight in pounds:"));
height = float(input("Please enter your height in inches:"));
BMI = (weight*0.453592) / ((height*0.0254) ** 2)
#conversion using the note in the hw, pounds to kilo and inches to meters
#the example BMI is close to the one produced by the program but ... | true |
233187ddede43970dd98411b388c2f2c863fd215 | mihirkelkar/languageprojects | /python/double_ended_queue/doubly_linked_list.py | 899 | 4.15625 | 4 | """
Implementation of a doubly linked list parent class
"""
class Node(object):
def __init__(self, value):
self.next = None
self.prev = None
self.value = value
class DoublyLinked(object):
def __init__(self):
self.head = None
self.tail = None
def addNode(self, value):
if self.head == Non... | true |
851d77deec23c2cf86d338bc831ec253065f056b | mihirkelkar/languageprojects | /python/palindrome.py | 280 | 4.25 | 4 | def check_palindrome(string):
if len(string) > 1:
if string[0] == string[-1]:
check_palindrome(string[1:][:-1])
else:
print "Not a palindrome"
else:
print "Palindrome"
text = raw_input("Please enter your text string")
check_palindrome(text.lower().replace(" ",""))
| true |
bfe427c331a3d1982b2aa13cf45707e063356568 | mwpnava/Python-Code | /My_own_Python_package/guesser_game/numberGuesserGame.py | 2,373 | 4.28125 | 4 | from random import randrange
from .GuesserGame import Guesser
class GuessMyNumber(Guesser):
""" GuessMyNumber class for calculating the result of arithmetic operations applied to an unknow number
given by the player
Attributes:
numberinMind represents the number a player has in mind at the end o... | true |
4e97f7e8c80fedb802649a3e1c51c60800a15bee | mwpnava/Python-Code | /missingValue3.py | 453 | 4.25 | 4 | '''
Consider an array of non-negative integers.
A second array is formed by shuffling the elements of the first array and
deleting a random element. Given these two arrays, find which element is missing in the second array.
Approach 3
'''
def missingValue(arr1,arr2):
arr1.sort()
arr2.sort()
for n1,n2 in... | true |
8362df19e83ad9aa361557272d9abed226133853 | vzqz2186/DAnA_Scripts | /Arrays.Lists/vazquez_hw021218_v1.00.py | 2,015 | 4.15625 | 4 | """
Program: Arrays/List
Author: Daniel Vazquez
Date: 02/10/2018
Assignment: Create array/list with 20 possible elements. Fill with 10
random integers 1 <= n <= 100. Write a function to insert value
in middle of list.
Due Date:
Objective: Write a function to insert value in... | true |
b7757a06f89cacb51cb96eba0c685b4cf31a9b4a | jdobner/grok-code | /find_smallest_sub2.py | 1,537 | 4.21875 | 4 | def find_substring(str, pattern):
""" Given a string and a pattern, find the smallest substring in
the given string which has all the characters of the given pattern.
:param str:
:param pattern:
:return: str
>>> find_substring("aabdec", 'abc')
'abdec'
>>> find_substring("abdbca", 'abc')
'bca'
>>> f... | true |
02c484b6cb30a7187b1b67585dfb0158747db857 | jamestonkin/file_storage | /car_storage.py | 1,195 | 4.34375 | 4 | class Car_storage:
""" This adds functionality and stores car list makes and models"""
def __init__(self):
self.car_makes = list()
self.car_models = list()
def read_car_makes(self):
""" Reads car makes from car-makes.txt file """
with open('car-makes.txt', 'r') as makes:
... | true |
febdf1ea7d39be0fd144488b75c2f145d07a5677 | iumentum666/PythonCrashCourse | /Kapittel 10 - 11/word_count.py | 894 | 4.46875 | 4 |
# This is a test of files that are not found. If the file is not present,
# This will throw an error. We need to handle that error.
# In the previous file, we had an error. Here we will create the file
# In this version we will work with several files
# So the bulk of the code is put in a function
def count_words(fi... | true |
a8fa29813cb4291a39db8d93c46ff0c9c8d5bded | acpfog/python | /6.00.1x_scripts/Week 8/Final Exam/problem3.py | 966 | 4.46875 | 4 | #
# dict_invert takes in a dictionary with immutable values and returns the inverse of the dictionary.
# The inverse of a dictionary d is another dictionary whose keys are the unique dictionary values in d.
# The value for a key in the inverse dictionary is a sorted list of all keys in d that have the same value in d.
... | true |
ccb58e3365e0bbfc25781cee9c118715a0493513 | acpfog/python | /6.00.1x_scripts/Week 2/do_polysum.py | 979 | 4.3125 | 4 | # A regular polygon has 'n' number of sides. Each side has length 's'.
# * The area of regular polygon is: (0.25*n*s^2)/tan(pi/n)
# * The perimeter of a polygon is: length of the boundary of the polygon
# Write a function called 'polysum' that takes 2 arguments, 'n' and 's'.
# This function should sum the area and squa... | true |
a7699c41987cbf101e478a6a1623e5bf83221997 | paw39/Python---coding-problems | /Problem13.py | 1,257 | 4.34375 | 4 | # 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 encoded as "4A3B2C1D2A".
#
# Implement run-length encoding and d... | true |
f40e03b6e5812149476681db8ddc24fd22e2063b | HS4MORVEL/Lintcode-solution-in-Python | /004_ugly_number_II.py | 1,009 | 4.25 | 4 | '''
Ugly number is a number that only have factors 2, 3 and 5.
Design an algorithm to find the nth ugly number.
The first 10 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12...
Notice
Note that 1 is typically treated as an ugly number.
Example
If n=9, return 10.
Challenge
O(n log n) or O(n) time.
'''
from heapq imp... | true |
33fab8dd21256c3f107d68652af5e6cc9216809a | athina-rm/extra_labs | /extralabs_basic/extralabs_basic.py | 343 | 4.15625 | 4 | #Write a Python program display a list of the dates for the 2nd Saturday of every month for a
#given year.
from datetime import datetime
year=int(input("enter the year:"))
for j in range(1,13):
for i in range (8,15):
dates =datetime(year,j,i)
if dates.strftime("%w")=="6":
print(dates.s... | true |
a6737f8bc4d71bb4d48b3b62c8145626a578007e | athina-rm/extra_labs | /extralabs_basic/module5.py | 273 | 4.375 | 4 | # Find
#Find all occurrences of “USA” in given string ignoring the case
string=input("Enter the string : ")
count=0
count=string.lower().count('usa')
if count==0:
print('"USA" is not found in the entered string')
else:
print(f'"USA" is found {count} times')
| true |
b1020a0e36baa29b31dd14c9f476c80fe095ef95 | rob0ak/Hang_Man_Game | /app.py | 2,728 | 4.125 | 4 | import random
def set_up_game(word, list_of_letters, blank_list):
for letter in word:
list_of_letters += letter
blank_list += "-"
def find_letters(word_list, blank_list, guess, list_of_guesses):
count = 0
# Checks the users guess to see if its within the word_list
for let... | true |
5c708d99765f36579409eca6fa9d389b0f83b16e | Albertpython/pythonhome | /home14.py | 328 | 4.375 | 4 | '''Write a Python program to find the
length of a tuple'''
# tup = ("black", "bmw", "red", "ferrary")
# res = 0
# for x in tup:
# res += 1
# continue
# print(res)
'''Write a Python program to convert a tuple to a string'''
# name = ('A', 'L', 'B', 'E', 'R', 'T')
# print(name[0]+name[1]+name[2]+name[3]+name[4]+nam... | true |
db53054877bc9e03ad2feba2efba6c0792857c32 | panovitch/code-101 | /1_shapes _and_color.py | 1,510 | 4.15625 | 4 | """
Here we introduce the concepts of statements and basic types: strings and integers.
WE talk about how a program is a list of senteses exuted from top to bottom, and
that some commands can result in a change of state, and some commands are just actions to execute.
We also explain what comments are :D
"""
# here we... | true |
2b4f5355db301ea1a0c2892d384a48dec3c3ecae | Ratheshprabakar/Python-Programs | /maxmin.py | 260 | 4.15625 | 4 | print("Enter the three numbers")
a=int(input("Enter the 1st Number"))
b=int(input("Enter the 2nd Number\n"))
c=int(input("Enter the 3rd Number"))
print("The maximum among three numbers",max(a,b,c))
print("The Minimum among three numbers",min(a,b,c))
| true |
4879b0be7e47945416bfe1764495968ae896726c | Ratheshprabakar/Python-Programs | /concatenate and count the no. of characters in a string.py | 318 | 4.3125 | 4 | #Concatnation of two strings
#To find the number of characters in the concatenated string
first_string=input("Enter the 1st string")
second_string=input("Enter the 2nd string")
two_string=first_string+second_string
print(two_string)
c=0
for k in two_string:
c+=1
print("No. of charcters in string is",c)
| true |
e54a34636c36321cb03605dfc39b69f1fab40f89 | Ratheshprabakar/Python-Programs | /Multiplication table.py | 241 | 4.28125 | 4 | #To display the multiplication table
x=int(input("Enter the table no. you want to get"))
y=int(input("Enter the table limit of table"))
print("The Multiplication table of",x,"is:")
i=1
while i<=y:
print(i,"*",x,"=",x*i)
i+=1
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.