blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
a788778604536cd38c6f74e26c982157cd874fb0 | newbieeashish/LeetCode_Algo | /1st_100_questions/SelfDividingNumber.py | 1,010 | 4.21875 | 4 | '''
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0,
and 128 % 8 == 0.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of ... | true |
86e19e215343fe545217ee67a4ea91ca28d2720c | newbieeashish/LeetCode_Algo | /1st_100_questions/CountLargestGroup.py | 889 | 4.34375 | 4 | '''
Given an integer n. Each number from 1 to n is grouped according to the sum of
its digits.
Return how many groups have the largest size.
Example 1:
Input: n = 13
Output: 4
Explanation: There are 9 groups in total, they are grouped according sum of its
digits of numbers from 1 to 13:
[1,10], [2,11]... | true |
ee428ee38ebe0ee081d7c0c3ebd982d6fa2c7649 | newbieeashish/LeetCode_Algo | /1st_100_questions/SubtractProductAndSumOfDigit.py | 656 | 4.21875 | 4 | '''
Given an integer number n, return the difference between the product of its
digits and the sum of its digits.
Example 1:
Input: n = 234
Output: 15
Explanation:
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15
Example 2:
Input: n = 4421
Output: 21
Expla... | true |
f1a7ee2726ef7de780efc31ba89d0e4e785036ee | newbieeashish/LeetCode_Algo | /1st_100_questions/ReverseWordsInSring3.py | 378 | 4.21875 | 4 | '''
Given a string, you need to reverse the order of characters in each word
within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
'''
def ReverseWords(s):
return ' '.join([w[::-1] for w in s.split... | true |
0305df4441a66096b9af78d25eff6892e76fdad1 | newbieeashish/LeetCode_Algo | /1st_100_questions/MinAbsoluteDiff.py | 976 | 4.375 | 4 | '''
Given an array of distinct integers arr, find all pairs of elements with the
minimum absolute difference of any two elements.
Return a list of pairs in ascending order(with respect to pairs),
each pair [a, b] follows
a, b are from arr
a < b
b - a equals to the minimum absolute difference of any two el... | true |
d15a64e9e07b8d528a42553c1a10ec070707b7ce | rob-kistner/modern-python | /orig_py_files/input.py | 218 | 4.28125 | 4 | """ ------------------------------
USER INPUT
------------------------------ """
# to get user input, just use the input() command...
answer = input("What's your favorite color? ")
print(f"you said {answer}")
| true |
fdd2452fb771381589ba1aba38a9614c38eb0e60 | olamiwhat/Algos-solution | /Python/shipping_cost.py | 1,798 | 4.34375 | 4 | #This program calculates the cheapest Shipping Method
#and Cost to ship a package at Sal's shipping
weight = int(input("Please, enter the weight of your package: "))
#define premium shipping cost as a variable
premium_shipping = 125.00
#Function to calculate cost of ground shipping
def ground_shipping (weight):
flat... | true |
9410bcb027d9e094a401b37f04d02058109e6ae8 | eduards-v/python_fundamentals | /newtons_square_root_problem.py | 573 | 4.125 | 4 | import math
x = 60 # a number to be square rooted
current = 1 # starting a guess of a square root value from 1
# function that returns a value based on a current guess
def z_next(z):
return z - ((z*z - x) / (2 * z)) # Newton's formula for calculating square root of a number
while current != z_next(current):
c... | true |
14dada3e093e658d0125a68a3521358f1d7d1a0d | kapis20/IoTInternships | /GPS/GPS_four_bytes.py | 1,494 | 4.125 | 4 | from decimal import Decimal
"""
Works similarly to the three byte encoder in that it will only work if the point
is located within that GPS coordinate square of 53, -1. Note that this is a far
larger area than could be transmitted by the three byte version. The encoder
strips the gps coordinates (Ex. 53.342, -1.445 -> ... | true |
7a66249816da377c1e4b76a361dcce543496ae65 | RashmiVin/my-python-scripts | /Quiz.py | 995 | 4.34375 | 4 | #what would the code print:
def thing():
print('Hello')
print('There')
#what would the code print:
def func(x):
print(x)
func(10)
func(20)
#what would the code print:
def stuff():
print('Hello')
return
print('World')
stuff()
#what would the code print:
def greet(lang):
if lang == 'es':
... | true |
9cb4a5716496f51d2fe167c7431e4e12e3647bff | money1won/Read-Write | /Read_Write EX_1.py | 591 | 4.375 | 4 | # Brief showing of how a file reads, writes, and appends
file = open("test.txt","w")
file.write("Hello World")
file.write("This is our new text file")
file.write("New line")
file.write("This is our new text file")
file.close
# Reads the entire file
# file = open("test.txt", "r")
# print(file.read())
... | true |
c2e1286123bab6e5e179d7f815ee62c763bf37fb | Jidnyesh/pypass | /pypass.py | 1,237 | 4.3125 | 4 | """
This is a module to generate random password of different length for your project
download this or clone and then from pypass import randompasswordgenerator
"""
import random
#String module used to get all the upper and lower alphabet in ascii
import string
#Declaring strings used in password
special_... | true |
5c67c7ebcf9390eb22bd0a7d951ee3e8ceb0ba42 | 61a-su15-website/61a-su15-website.github.io | /slides/09.py | 961 | 4.125 | 4 | def sum(lst):
"""Add all the numbers in lst. Use iteration.
>>> sum([1, 3, 3, 7])
14
>>> sum([])
0
"""
"*** YOUR CODE HERE ***"
total = 0
for elem in lst:
total += elem
return total
def count(d, v):
"""Return the number of times v occurs as
a value in dictionary... | true |
46abc1d446933a99fdab6df2a4c6b6b51495b625 | jorgecontreras/algorithms | /binary_search_first_last_index.py | 2,936 | 4.34375 | 4 |
# Given a sorted array that may have duplicate values,
# use binary search to find the first and last indexes of a given value.
# For example, if you have the array [0, 1, 2, 2, 3, 3, 3, 4, 5, 6]
# and the given value is 3, the answer will be [4, 6]
# (because the value 3 occurs first at index 4 and last at index 6... | true |
a67ff64f4cf8dfc80b5fae725f50e9bbbd9f3c86 | shahp7575/coding-with-friends | /Parth/LeetCode/Easy/rotate_array.py | 889 | 4.15625 | 4 | """
Runtime: 104 ms
Memory: 33 MB
"""
from typing import List
class Solution:
"""
Problem Statement:
Given an array, rotate the array to the right by k steps, where k is non-negative.
Input: nums = [1,2,3,4,5,6,7], k = 3
Output: [5,6,7,1,2,3,4]
Explanation:
rotate 1 steps to the right: [7... | true |
78a3034cbd3d459797a10a91cd52cd244a12cc05 | jinjuleekr/Python | /problem143.py | 466 | 4.21875 | 4 | #Roof
#Problem143
#Running the roof until the input is either even or odd
while True:
num_str = input("Enter the number : ")
if num_str.isnumeric():
num = int(num_str)
if num==0:
print("It's 0")
continue
elif num%2==1:
print("odd number")
... | true |
279bb6837788f7a7cb77797940c35e9317891fbc | nagask/leetcode-1 | /310 Minimum Height Trees/sol2.py | 1,631 | 4.125 | 4 | """
Better approach (but similar).
A tree can have at most 2 nodes that minimize the height of the tree.
We keep an array of every node, with a set of edges representing the neighbours nodes.
We also keep a list of the current leaves, and we remove them from the tree, updating the leaf list.
We continue doing so until ... | true |
1d90053bbdce1a1c82312d77f0ee4f98e5fc3c2b | nagask/leetcode-1 | /25 Reverse Nodes in k-Group/sol2.py | 2,593 | 4.15625 | 4 | """
Reverse a linked list in groups of k nodes.
Before doing so, we traverse ahead of k nodes from the current point, to know wehre the next reverse will start.
The function `get_kth_ahead` returns the k-th node ahead of the current position (can be null) and a boolean indicating whether there are at list k nodes afte... | true |
5101c36f61e29a8015a67afacdb7c6927e0b3514 | SwagLag/Perceptrons | /deliverables/P3/Activation.py | 991 | 4.46875 | 4 | # Activation classes. The idea is as follows;
# The classes should have attributes, but should ultimately be callable to be used in the Perceptrons, in order
# to return an output.
# To this end, make sure that implemented classes have an activate() function that only takes a int or float input
# and outputs a int or ... | true |
01da994ca131afa3e8adcc1ff14e92ca5285f376 | tanmaysharma015/Tanmay-task-1 | /Task1_Tanmay.py | 657 | 4.3125 | 4 | matrix = []
interleaved_array = []
#input
no_of_arrays = int(input("Enter the number of arrays:")) #this will act as rows
length = int(input("Enter the length of a single array:")) #this will act as columns
print(" \n")
for i in range(no_of_arrays): # A for loop for row entries
a =[]
print("e... | true |
31f5fd00943b1cd8f750fec37958e190b6f2a041 | aanzolaavila/MITx-6.00.1x | /Final/problem3.py | 551 | 4.25 | 4 | import string
def sum_digits(s):
""" assumes s a string
Returns an int that is the sum of all of the digits in s.
If there are no digits in s it raises a ValueError exception. """
assert isinstance(s, str), 'not a string'
found = False
sum = 0
for i in s:
if i in string.di... | true |
1ef2a328b5d3d4de6ab9a68a3c45d75959155ac3 | alejandradean/digital_archiving | /filename_list_with_dirs.py | 801 | 4.3125 | 4 | import os
directory_path = input("Enter directory path: ")
# the below will create a file 'filenames.txt' in the same directory the script is saved in. Enter the full path in addition to the .txt filename to create the file elsewhere.
with open('filenames.txt', 'a') as file:
for root, dirs, files in os.walk... | true |
a28a5240fb888c7686624e6186a5b3f77c5b4825 | speed785/Python-Projects | /lab8.py | 743 | 4.1875 | 4 | #lab8 James Dumitru
#Using built in
number_1 = int(input("Enter a number: "))
number_2 = int(input("Enter a number: "))
number_3 = int(input("Enter a number: "))
number_4 = int(input("Enter a number: "))
number_5 = int(input("Enter a number: "))
number_6 = int(input("Enter a number: "))
num_list = []
num_list.append(n... | true |
e0f95acb97a5f921722dacdf2773808421c80bc5 | speed785/Python-Projects | /Temperature converter.py | 1,289 | 4.28125 | 4 | #Coded by : James Dumitru
# input #
y=int(input("Please Enter A Number "))
x=int(input("Please Enter A Second Number "))
# variables #
add=x+y
multi=x*y
div=x/y
sub=x-y
mod=x%y
# What is shown #
print("This is the addition for the two numbers=", add)
print("This is the multiplication for the two numbers=", multi)
... | true |
b779cabe46235f12afb6d08104c2fe05e94f0c23 | khaldi505/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/5-text_indentation.py | 574 | 4.1875 | 4 | #!/usr/bin/python3
""" function that add a text indentation. """
def text_indentation(text):
"""
text = str
"""
txt = ""
if not isinstance(text, str):
raise TypeError("text must be a string")
for y in range(len(text)):
if text[y] == " " and text[y - 1] in [".", "?",... | true |
57c2fd29fa65988bcc3a38013f48ecb3a5c8aa02 | mafudge/learn-python | /content/lessons/07/Now-You-Code/NYC4-Sentiment-v1.py | 2,824 | 4.34375 | 4 | '''
Now You Code 3: Sentiment 1.0
Let's write a basic sentiment analyzer in Python. Sentiment analysis is the
act of extracting mood from text. It has practical applications in analyzing
reactions in social media, product opinions, movie reviews and much more.
The 1.0 version of our sentiment analyzer will start with... | true |
ac594af8db3882620707a74c6600e667f8d2b784 | tayloradam1999/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/0-add_integer.py | 627 | 4.34375 | 4 | #!/usr/bin/python3
"""
add_integer - adds 2 integers
a - first integer for addition
b - second integer for addition
Return: sum of addition
"""
def add_integer(a, b=98):
"""This def adds two integers and returns the sum.
Float arguments are typecasted to ints before additon is performed.
Raises a TypeErr... | true |
a88ee84f46356c83315bd3c0ce2e81d0328a8733 | tayloradam1999/holbertonschool-higher_level_programming | /0x0A-python-inheritance/1-my_list.py | 416 | 4.34375 | 4 | #!/usr/bin/python3
"""
This module writes a class 'MyList' that inherits from 'list'
"""
class MyList(list):
"""Class that inherits from 'list'
includes a method that prints the list, but in ascending order"""
def print_sorted(self):
"""Prints the list in ascending order"""
sort_list = []... | true |
3277de75085d160a739f2ea059361152403de931 | tayloradam1999/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/4-print_square.py | 542 | 4.375 | 4 | #!/usr/bin/python3
"""This module defines a square-printing function.
size: Height and width of the square."""
def print_square(size):
"""Defines a square-printing function.
Raises a TypeError if:
Size is not an integer
Raises a ValueError if:
Size is < 0"""
if not isinstance(size, in... | true |
4afb5f6f85657bb8b2586792c1ffdb03cabba379 | fitzystrikesagain/fullstack-nanodegree | /sql_and_data_modeling/psycopg-practice.py | 1,382 | 4.34375 | 4 | """
Exercise 1
----------
Create a database in your Postgres server (using `createdb`)
In psycopg2 create a table and insert some records using methods for SQL string composition. Make sure to establish
a connection and close it at the end of interacting with your database. Inspect your table schema and data in psql.
(... | true |
4f170c0d111c2c5b2ffcdd62714c0e8613eadfe2 | mariettas/SmartNinja_Project_smartninja_python2_homework | /fizzbuzz.py | 320 | 4.21875 | 4 | print("Hello, welcome to the fizzbuzz game!")
choice = int(input("Please, enter a number between 1 and 100: "))
for x in range(1, choice + 1):
if x % 3 == 0 and x % 5 == 0:
print("fizzbuzz")
elif x % 3 == 0:
print("fizz")
elif x % 5 == 0:
print("buzz")
else:
print(x)
| true |
552dcfca3facace254db3e547a547f11271d2cc0 | Vadum-cmd/lab5_12 | /cats.py | 1,867 | 4.125 | 4 | """
Module which contains classes Cat and Animal.
"""
class Animal:
"""
Class for describing animal's properties.
"""
def __init__(self, phylum, clas):
"""
Initializes an object of class Animal and sets its properties.
>>> animal1 = Animal("chordata", "mammalia")
>>> ass... | true |
84360bc297d4b20494db6d8782ed980cb9f55b9f | asimMahat/Advanced-python | /lists.py | 1,365 | 4.21875 | 4 |
mylist = ['banana', 'apple','orange']
# print(mylist)
mylist2 = [5,'apple',True]
# print (mylist2)
item = mylist[-1]
# print (item)
for i in mylist:
print(i)
'''
if 'orange' in mylist:
print("yes")
else:
print("no")
'''
# print(len(mylist))
mylist.append("lemon")
print(mylist)
mylist.insert(1,'berry')... | true |
b9f9c0c94167c21e15632171149413eeeccc359a | Guessan/python01 | /Assignments/Answer_3.3.py | 971 | 4.34375 | 4 | #Assignment: Write a program to prompt for a score between 0.0 and 1.0.
#If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table:
#Score Grade
#>= 0.9 A
#>= 0.8 B
#>= 0.7 C
#>= 0.6 D
#< 0.6 F
#If the user enters a value out of range, print a suitable... | true |
eadb4a678a48bef0d15acb3e9e2abfb6929c8f2c | archimedessena/Grokkingalgo | /selectionsort.py | 1,626 | 4.3125 | 4 | # selection sort algorithm
def findSmallest(arr):
smallest = arr[0] #Stores the smallest value
smallest_index = 0 #Stores the index of the smallest value
for i in range(1, len(arr)):
if arr[i] < smallest:
smallest = arr[i]
smallest_index = i
return smallest_index
#Now you... | true |
9339fdaeb9f8271c05910ecc4b1ee7d0a71f7d30 | bekahbooGH/Stacks-Queues | /queue.py | 1,113 | 4.3125 | 4 | class MyQueue:
def __init__(self):
"""Initialize your data structure here."""
self.stack1 = Stack()
self.stack2 = Stack()
def push(self, x: int) -> None:
"""Push element x to the back of queue."""
while not self.stack2.empty():
self.stack1.push(self.stack2.pop(... | true |
cde4e88e4c072257ca7e7489888a9a370b34c47c | sumit-kushwah/oops-in-python | /files/Exercise Files/Ch 4/immutable_finished.py | 574 | 4.4375 | 4 | # Python Object Oriented Programming by Joe Marini course example
# Creating immutable data classes
from dataclasses import dataclass
@dataclass(frozen=True) # "The "frozen" parameter makes the class immutable
class ImmutableClass:
value1: str = "Value 1"
value2: int = 0
def somefunc(self, newval):
... | true |
fe480bc286b420be4109bbdbfa2ea9a2d7d97896 | sumit-kushwah/oops-in-python | /files/Exercise Files/Ch 4/datadefault_start.py | 471 | 4.3125 | 4 | # Python Object Oriented Programming by Joe Marini course example
# implementing default values in data classes
from dataclasses import dataclass, field
import random
def price_func():
return float(random.randrange(20, 40))
@dataclass
class Book:
# you can define default values when attributes are declared... | true |
a8c9d7355b63df85868b8c53198828b50d4098e8 | Richiewong07/Python-Exercises | /python-udemy/Assessments_and_Challenges/Statements/listcomprehension.py | 211 | 4.46875 | 4 | # Use List Comprehension to create a list of the first letters of every word in the string below:
st = 'Create a list of the first letters of every word in this string'
print([word[0] for word in st.split()])
| true |
ae16fb85dcd03542eb414a5ba6e1d707b9afc01f | Richiewong07/Python-Exercises | /python-assignments/python-part1/work_or_sleep_in.py | 396 | 4.21875 | 4 | # Prompt the user for a day of the week just like the previous problem.
# Except this time print "Go to work" if it's a work day and "Sleep in" if it's
# a weekend day.
input = int(input('What day is it? Enter (0-6): '))
def conv_day(day):
if day in range(1,6):
print('It is a weekday. Wake up and go to wo... | true |
56529869d13d6bc30f578675cc8bfb510f81a8c4 | Richiewong07/Python-Exercises | /python-assignments/functions/plot_function.py | 300 | 4.21875 | 4 | # 2. y = x + 1
# Write a function f(x) that returns x + 1 and plot it for x values of -3 to 3 in increments of 1.
import matplotlib.pyplot as plot
def f(x):
return x + 1
xs = list(range(-3,4))
ys = []
for x in xs:
ys.append(f(x))
plot.plot(xs, ys)
plot.axis([-3, 3, -2, 4])
plot.show()
| true |
f1531778b5f766b5512a34b1c6d373ee5da71c39 | Richiewong07/Python-Exercises | /callbox-assesment/exercise3.py | 854 | 4.625 | 5 | # Exerciseโ โ3:
# Writeโ โaโ โfunctionโ โthatโ โidentifiesโ โifโ โanโ โintegerโ โisโ โaโ โpowerโ โofโ โ2.โ โTheโ โfunctionโ โshouldโ โreturnโ โaโ โboolean. Explainโ โwhyโ โyourโ โfunctionโ โwillโ โworkโ โforโ โanyโ โintegerโ โinputsโ โthatโ โitโ โreceives.
# Examples:
# is_power_two(6)โ โโโ โfalse is_power_two(16)โ โ... | true |
57ec4253919ae789a437781b3c0d3bd92b073480 | Richiewong07/Python-Exercises | /python-assignments/list/matrix_addition.py | 654 | 4.1875 | 4 | # 9. Matrix Addition
# Given two two-dimensional lists of numbers of the size 2x2 two dimensional list is represented as an list of lists:
#
# [ [2, -2],
# [5, 3] ]
# Calculate the result of adding the two matrices. The number in each position in the resulting matrix should be the sum of the numbers in the correspond... | true |
10d0346dabc7e4135ab9981d49f0df762694b43d | abhishekkulkarni24/Machine-Learning | /Numpy/operations_on_mobile_phone_prices.py | 1,643 | 4.125 | 4 | '''
Perform the following operations on an array of mobile phones prices 6999, 7500, 11999,
27899, 14999, 9999.
a. Create a 1d-array of mobile phones prices
b. Convert this array to float type
c. Append a new mobile having price of 13999 Rs. to this array
d. Reverse this array of mobile phones prices
e. Apply GST of 1... | true |
17b641ee02371d924e4dc0020f65d9ba3ce5a23c | boswellgathu/py_learn | /12_strings/count_triplets.py | 338 | 4.1875 | 4 | # Write a Python method countTriplets that accepts a string as an input
# The method must return the number of triplets in the given string
# We'll say that a "triplet" in a string is a char appearing three times in a row
# The triplets may overlap
# for more info on this quiz, go to this url: http://www.programmr.... | true |
5eab2196af7a27cfffeadcdacbc4e5f94c3d70c6 | boswellgathu/py_learn | /8_flow_control/grade.py | 497 | 4.125 | 4 | # Write a function grader that when given a dict marks scored by a student in different subjects
# prepares a report for each grade as A,B,C and FAIL and the average grade
# example: given
# marks = {'kisw': 34, 'eng': 50}
# return
# {'kisw': 'FAIL', 'eng': 'C', 'average': 'D'}
# A = 100 - 70, B = 60 - 70, C = 50 - 60... | true |
ebc4b93409aaa4382720eb1c7eaa5ea50ab6b31d | dfi/Learning-edX-MITx-6.00.1x | /itertools.py | 608 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 20:10:18 2017
@author: sss
"""
# https://docs.python.org/3.5/library/itertools.html
import operator
def accumulate(iterable, func=operator.add):
'Return running totals'
# accumulate([1,2,3,4,5]) --> 1 3 6 10 15
# accumulate([1,2,3,... | true |
a65f814ce9f62bc8cff8642691e206d8fa8c6b96 | pabolusandeep1/python | /lab1/source code/password.py | 854 | 4.15625 | 4 | #validation cliteria for the passwords
import re# importing the pre-defined regular expressions
p = input("Input your password: ")
x = True
while x:# loop for checking the various cliteria
if (len(p)<6 or len(p)>16):#checking for the length
print('\n length out of range')
break
elif not re.sear... | true |
fad58160cbcd35d9a671c8bc1217cf151560fafd | jasonifier/tstp_challenges | /ch6/challenge2.py | 247 | 4.125 | 4 | #!/usr/bin/env python3
response_one = input("Enter a written communication method: ")
response_two = input("Enter the name of a friend: ")
sentences = "Yesterday I wrote a {}. I sent it to {}!".format(response_one,response_two)
print(sentences)
| true |
4a68ac695f956f6f9ee1326e59d21ce5554362ee | jasonifier/tstp_challenges | /ch4/challenge1.py | 289 | 4.15625 | 4 | #!/usr/bin/env python3
def squared(x):
"""
Returns x ** 2
:param x: int, float.
:return: int, float square of x.
"""
return x ** 2
print(squared(5))
print(type(squared(5)))
print(squared(16))
print(type(squared(16)))
print(squared(5.0))
print(type(squared(5.0)))
| true |
76c7b4ba9c6176b96c050884111c397d651c2cba | Epiloguer/ThinkPython | /Chapter 2/Ex_2_2_3/Ex_2_2_3.py | 612 | 4.15625 | 4 | # If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile),
# then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again,
# what time do I get home for breakfast?
import datetime
easy_pace = datetime.timedelta(minutes = 8, seconds = 15)
easy_miles = 2
tempo = datetime.timedelta(minutes ... | true |
8c5f65fa6ce581a28ed8d34c5a36fa0c186af33d | Epiloguer/ThinkPython | /Chapter 1/Ex_1_2_3/Ex_1_2_3.py | 643 | 4.15625 | 4 | # If you run a 10 kilometer race in 42 minutes 42 seconds, what is your average pace
# (time per mile in minutes and seconds)? What is your average speed in miles per hour?
kilometers = 10
km_mi_conversion = 1.6
miles = kilometers * km_mi_conversion
print(f'you ran {miles} miles')
minutes = 42
minutes_to_seconds = min... | true |
b62fa67f503814abbe41952067be6b9083e7b0b9 | ANUMKHAN07/assignment-1 | /assign3 q6.py | 203 | 4.21875 | 4 | d = {'A':1,'B':2,'C':3} #DUMMY INNITIALIZATION
key = input("Enter key to check:")
if key in d.keys():
print("Key is present and value of the key is:",d[key])
else:
print("Key isn't present!") | true |
5cecd539c025b0733629ff4c403d70e280f00284 | PallaviGandalwad/Python_Assignment_1 | /Assignment1_9.py | 213 | 4.1875 | 4 | print("Write a program which display first 10 even numbers on screen.")
print("\n")
def EvenNumber():
i=1
while i<=10:
print(i*2," ",end="");
i=i+1
#no=int(input("Enter Number"))
EvenNumber()
| true |
47715f1e3fe9c0cc7dbb898ff0082d053ea6fa51 | csyhhu/LeetCodePratice | /Codes/33/33.py | 1,324 | 4.15625 | 4 | def search(nums, target: int):
"""
[0,1,2,4,5,6,7] => [4,5,6,7,0,1,2]
Find target in nums
:param nums:
:param target:
:return:
"""
def binSearch(nums, start, end, target):
mid = (start + end) // 2
print(start, mid, end)
if start > end:
return -1
... | true |
c39b8d31be3c31cc2a914a2bd0ae5a380363b27b | zhanengeng/mysite | /็ฅ่ฏ็น/ๅญ็ฌฆไธฒๅๅธธ็จๆฐๆฎ็ปๆ/ๆฅไปใ่จ็ฎ.py | 638 | 4.3125 | 4 | '''ๅ
ฅๅใใๆฅไปใฏใใฎๅนดไฝๆฅ็ฎ'''
def leap_year(year):
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
def which_day(year,month,day):
days_of_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days_count = 0
if leap_year(year):
days_of_month[1... | true |
9de40eb8d5d6abd67ff90ff2195562822399567f | lucien-stavenhagen/JS-interview-research | /fizzbuzz.py | 902 | 4.21875 | 4 | #
# and just for the heck of it, here's the
# Python 3.x version of FizzBuzz, using a Python closure
#
# Here's the original problem statment:
# "Write a program that prints all
# the numbers from 1 to 100.
# For multiples of 3, instead of the number,
# print "Fizz", for multiples of 5 print "Buzz".
# For numbers which... | true |
d4e9e097d89d3db339d92adde12b682548adf8c8 | Dipesh1Thakur/Python-Basic-codes | /marksheetgrade.py | 329 | 4.125 | 4 | marks=int(input("Enter the marks :"))
if (marks>=90):
print("grade A")
elif (marks>=80) and (marks<90):
print("grade B")
elif marks>=70 and marks<80:
print("grade C")
elif marks>=60 and marks<70:
print("grade D")
elif marks>=50 and marks<40:
print("grade E")
else:
print("Your grade i... | true |
774075170cd50e0197b4c5a830515a9a5fac7211 | zungu/learnpython | /lpthw/ex14.py | 982 | 4.4375 | 4 | #!/usr/bin/python
from sys import argv
#defines two items to be inputted for argv
(script, user_name) = argv
prompt1 = 'give me an answer you ass > '
prompt2 = 'I\'ll murder ye grandmotha if ye don\'t tell me > '
prompt3 = 'Sorry please answer, I\'m just having a bad day > '
print "Hi %s, I'm the %s script." % (use... | true |
acca2584c588aab08753d32484a804b5e492d8e0 | zungu/learnpython | /lpthw/ex20.py | 1,249 | 4.28125 | 4 | #!/usr/bin/python
from sys import argv
script, input_file = argv
#defines the function, the j can be any letter
def print_all(j):
print j.read()
def rewind (j) :
j.seek(0)
# defines a function, with a variable inside of it. line_count is a variable cleverly named so that the user knows what it is doing. late... | true |
5dde55554b5745f3dc71a7bb201d20a3e0496239 | rehmanalira/Python-Practice-Problems | /Practice problem8 Jumble funny name.py | 908 | 4.21875 | 4 | """
It is a program which gives funny name
"""
from random import shuffle # for shffling
from random import sample # sampling shuffle
def function_shuffling(ele): # this is a function which is used to shuflle with this is used for shuflling
ele=list(ele) # store the valu of list in ele
shuffl... | true |
53df6c7f31947ba21c4a0e0bbed1840ed790e8d9 | Ivankipsit/TalentPy | /May week5/Project1.py | 1,917 | 4.25 | 4 | """
Create a python class ATM which has a parametrised constructor (card_no, acc_balance).
Create methods withdraw(amount) which should check if the amount is available on the
account if yes, then deduct the amount and print the message โAmount withdrawnโ, if the
amount is not available then print the message โOOPS! Un... | true |
d12f4c3636de41e75e9a4bf5e435166f00866b4e | minal444/PythonCheatSheet | /ArithmaticOperations.py | 770 | 4.125 | 4 | # Arithmetic Operations
print(10+20) # Addition
print(20 - 5) # Subtraction
print(10 * 2) # Multiplication
print(10 / 2) # Division
print(10 % 3) # Modulo
print(10 ** 2) # Exponential
# augmented assignment operator
x = 10
x = x + 3
x += 3 # augmented assignment operator
x -= 3 # augmented assignme... | true |
c7237ded5227b686fe4d6a005db6b52a7c5bf435 | chandthash/nppy | /Project Number System/quinary_to_octal.py | 1,525 | 4.71875 | 5 | def quinary_to_octal(quinary_number):
'''Convert quinary number to octal number
You can convert quinary number to octal, first by converting quinary number to decimal and obtained decimal number to quinary number
For an instance, lets take binary number be 123
Step 1: Convert t... | true |
e0da7a3dd1e796cf7349392dc1681663e36616ad | chandthash/nppy | /Minor Projects/multiples.py | 317 | 4.25 | 4 | def multiples(number):
'''Get multiplication of a given number'''
try:
for x in range(1, 11):
print('{} * {} = {}'.format(number, x, number * x))
except (ValueError, NameError):
print('Integer value was expected')
if __name__ == '__main__':
multiples(10)
| true |
dddc399fa7fc2190e838591ae38c24b3065afadd | purwar2804/python | /smallest_number.py | 660 | 4.15625 | 4 | """Write a python function find_smallest_number() which accepts a number n and returns the smallest number having n divisors.
Handle the possible errors in the code written inside the function."""
def factor(temp):
count=0
for i in range(1,temp+1):
if(temp%i==0):
count=count+1
ret... | true |
37e7b3c7ea73bc62be4d046ce93db984b269e2aa | brawler129/Data-Structures-and-Algorithms | /Python/Data Structures/Arrays/reverse_string.py | 805 | 4.40625 | 4 | import sys
def reverse_string(string):
"""
Reverse provided string
"""
# Check for invalid input
if string is None or type(string) is not str:
return 'Invalid Input'
length = len(string)
# Check for single character strings
if length < 2:
return string # Retur... | true |
3425852ccba1415b95e0feaf62916082d4a3f8b6 | itu-qsp/2019-summer | /session-8/homework_solutions/sort_algos.py | 2,501 | 4.125 | 4 | """A collection of sorting algorithms, based on:
* http://interactivepython.org/runestone/static/pythonds/SortSearch/TheSelectionSort.html
* http://interactivepython.org/runestone/static/pythonds/SortSearch/TheMergeSort.html
Use the resources above for illustrations and visualizations.
"""
def bubble_sort(data_l... | true |
3f859b0275a136b8b8078b7d0798c3496d57af06 | itu-qsp/2019-summer | /session-6/homework_solutions/A.py | 2,864 | 4.6875 | 5 | """
Create a Mad Libs program that reads in text files and lets the user add their own text anywhere
the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file.
For example, a text file may look like this, see file mad_libs.txt:
The ADJECTIVE panda walked to the NOUN and then VERB. A nearby NOUN was
unaffected... | true |
7cf44380af29bb10e89ef1ec62ba1b2ee96c0066 | fortiz303/python_code_for_devops | /join.py | 290 | 4.34375 | 4 | #Storing our input into a variable named input_join
input_join = input("Type a word, separate them by spaces: ")
#We will add a dash in between each character of our input
join_by_dash = "-"
#Using the join method to join our input. Printing result
print(join_by_dash.join(input_join))
| true |
81151f0a5de8a7edda840bb24e97288a99d29ab0 | MyreMylar/artillery_duel | /game/wind.py | 2,110 | 4.15625 | 4 | import random
class Wind:
def __init__(self, min_wind, max_wind):
self.min = min_wind
self.max = max_wind
self.min_change = -3
self.max_change = 3
self.time_accumulator = 0.0
# Set the initial value of the wind
self.current_value = random.randint(self.min,... | true |
ea2e97ed068f7dc534f6d1dd6318927d2ed01a4a | svfarande/Python-Bootcamp | /PyBootCamp/errors and exception.py | 957 | 4.125 | 4 | while True:
try: # any code which is likely to give error is inserted in try
number1 = float(input("Enter Dividend (number1) for division : "))
number2 = float(input("Enter Divisor (number2) for division : "))
result = number1 / number2
except ValueError: # it will run when ValueError ... | true |
9b6c4e8219809f7e2235bdedad400d80f6d0be98 | nage2285/day-3-2-exercise | /main.py | 1,027 | 4.34375 | 4 | # ๐จ Don't change the code below ๐
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
# ๐จ Don't change the code above ๐
#Write your code below this line ๐
#print(type(height))
#print(type(weight))
#BMI Calculator
BMI = round(weight/ (height * height))
if BMI <... | true |
61d5f409e19effec42600395ec8e9ce06f88b956 | UjjwalDhakal7/basicpython | /typecasting.py | 1,793 | 4.46875 | 4 | #Type Casting or Type Cohersion
# The process of converting one type of vaue to other type.
#Five types of data can be used in type casting
# int, float, bool, str, complex
#converting float to int type :
a = int(10.3243)
print(a)
#converting complex to int type cannot be done.
#converting bool to int :
... | true |
48741d9ccf235ca379a3b7ead7082637b33c450d | UjjwalDhakal7/basicpython | /booleantypes.py | 248 | 4.21875 | 4 | #boolean datatypes
#we use boolean datatypes to work with boolean values(True/False, yes/no) and logical expressions.
a = True
print(type(a))
a = 10
b=20
c = a<b
print(c)
print(type(c))
print(True + True)
print(False * True)
| true |
50ed06f5df2f648636a8237cca5ca3cd36732b2c | UjjwalDhakal7/basicpython | /intdatatypes.py | 1,181 | 4.40625 | 4 | #we learn about integer datatypes here:
#'int' can be used to represent short and long integer values in python 3
# python 2 has a concpet of 'long' vs 'int' for long and short int values.
#There are four ways to define a int value :
#decimal, binary, octal, hexadecimal forms
#decimal number system is the default... | true |
8709a8799021fed49bb620d7088c22bc086492dd | ewrwrnjwqr/python-coding-problems | /python-coding-problems/unival tree challenge easy.py | 1,921 | 4.25 | 4 | #coding problem #8
#A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value.
#Given the r to a binary tree, count the number of unival subtrees.
# the given tree looks like..
# 0
# / \
# 1 0
# / \
# 1 0
# / \
# 1 ... | true |
1f3b48d098480dd34dee90aaabe24822b6682e71 | ColeCrase/Week-5Assignment | /Page82 pt1.py | 228 | 4.125 | 4 | number = int(input("Enter the numeric grade: "))
if number > 100:
print("Error: grade must be between 100 and 0")
elif number < 0:
print("Error: grade must be between 100 and 0")
else:
print("The grade is", number)
| true |
8de67b2e8d4fb914a3b9f3e29a5a85d9cba30c0c | subho781/MCA-Python-Assignment | /Assignment 2 Q7.py | 337 | 4.1875 | 4 | #WAP to input 3 numbers and find the second smallest.
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
if(num1<=num2 and num1<=num3):
s2=num1
elif(num2<=num1 and num2<=num3):
s2=num2
else:
s2=num3
print('second smallest... | true |
bd2ef2d43a62650f68d140b1097e98b73a27f293 | Athenstan/Leetcode | /Easy/Edu.BFSzigzag.py | 888 | 4.15625 | 4 | class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
#first try at the problem
def traverse(root):
result = []
if root is None:
return result
# TODO: Write your code here
queue = deque()
queue.append(root)
toggle = True
while queue:
levelsize = ... | true |
d407f3540a1a4d7240fb572a3e1fa12e430cdced | rjimeno/PracticePython | /e6.py | 273 | 4.125 | 4 | #!/usr/bin/env python3
print("Give me a string and I will check if it is a palindrome: ")
s = input("Type here: ")
for i in range(0, int(len(s)/2)):
l = len(s)
if s[i] != s[l-1-i]:
print("Not a palindrome.")
exit(1)
print("A palindrome!")
exit(0) | true |
f72b45ba5408c8ab5afbe1d88e96c10bb157b920 | rjimeno/PracticePython | /e3.py | 1,479 | 4.15625 | 4 | #!/usr/bin/env python3
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
default_limit = 5
for x in a:
if x < default_limit:
print(x)
# Extras:
# 1.Instead of printing the elements one by one, make a new list that has all
# the elements less than 5 from this list in it and print out this new list.
def list_less... | true |
c6e36b6fb21454dbfb35fcf4862afeb97c3abbc5 | souzartn/Python2Share | /other/completed/Rock_Paper_Scissors.py | 1,296 | 4.34375 | 4 | ################################################################
# Challenge 02
# Game "Rock, Paper, Scissors"
# Uses: Basic Python - e.g. If, elif,input, print
################################################################
import os
clearScreen = lambda: os.system('cls')
def computeGame(u1, u2):
if u1 == u2... | true |
80e6a92937db9f5a34465ec78fff113e99b1e4a9 | neerajmaurya250/100-Days-of-Code | /Day-12/power.py | 417 | 4.125 | 4 | terms = int(input("How many terms? "))
result = list(map(lambda x: 2 ** x, range(terms)))
# display the result
print("The total terms is:",terms)
for i in range(terms):
print("2 raised to power",i,"is",result[i])
# output:
# How many terms? 5
# The total terms is: 5
# 2 raised to power 0 is 1
# 2 raised t... | true |
a805c9af0f10ca75770fc88d7b33967e5af71cfc | everydaytimmy/code-war | /7kyu.py | 716 | 4.1875 | 4 | # In this kata, you are asked to square every digit of a number and concatenate them.
# For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1.
# Note: The function accepts an integer and returns an integer
def square_digits(num):
return int(''.join(str(int(i)**2) fo... | true |
c944e5314444364dfcffe437c49a16cd70062888 | rjrishav5/Codes | /Linkedlist/insert_doubly_linkedlist.py | 2,193 | 4.28125 | 4 | class Node:
def __init__(self,data):
self.data = data
self.next = None
self.prev = None
class doubly_linkedlist:
def __init__(self):
self.head = None
# insert node at the end of a doubly linkedlist
def at_end(self,data):
new_node = Node(data)
if self.head is... | true |
596d01a48433701abcdf0b13d338b6d176d3de90 | YOON81/PY4E-classes | /09_dictionaries/exercise_04.py | 973 | 4.25 | 4 | # Exercise 4: Add code to the above program to figure out who has the most messages
# in the file. After all the data has been read and the dictionary has been created,
# look through the dictionary using a maximum loop (see Chapter 5: Maximum and minimum
# loops) to find who has the most messages and print how many me... | true |
92514ac1daed990f7d22f402f23760511642d1c1 | YOON81/PY4E-classes | /04_functions/exercise_06.py | 759 | 4.15625 | 4 | # Exercise 6: Rewrite your pay computation with time-and-a-half for overtime and
# create a function called computepay which takes two parameters (hours and rate).
# ** ์ฒซ๋ฒ์งธ ์ง๋ฌธ์ ๋ฌธ์ ์
๋ ฅํ์ ๋ ์๋ฌ ๋ฉ์ธ์ง ๋จ๋ ๊ฑด ์์ง ํด๊ฒฐ ์๋จ **
# ** ๋ง์ง๋ง ํ๋ฆฐํธ๋ฌธ์ ์๋ฌ ๋ธ ! **
hours = input('Enter Hours: ')
rate = input('Enter Rate: ')
try:
hours = float... | true |
7f9d7da99a451c6e90b34331a02076cdbe4b2d3b | brad93hunt/Python | /github-python-exercises/programs/q12-l2-program.py | 482 | 4.125 | 4 | #!/usr/bin/env python
#
# Question 12 - Level 2
#
# Question:
# Write a program, which will find all such numbers between 1000 and 3000 (both included)
# such that each digit of the number is an even number.
# The numbers obtained should be printed in a comma-separated sequence on a single line.
def main():
# Prin... | true |
9bd97f882ac5185dd2f78b4f4ed83e3e7c930de6 | brad93hunt/Python | /github-python-exercises/programs/q13-l2-program.py | 595 | 4.21875 | 4 | #!/usr/bin/env python
# coding: utf-8
#
# Question 13 - Level 2
#
# Question:
#ย Write a program that accepts a sentence and calculate the number of letters and digits.
# Suppose the following input is supplied to the program:
# hello world! 123
# Then, the output should be:
# LETTERS 10
# DIGITS 3
def main():
user... | true |
2af9387667d6254a491cef429c85c32e75a3c2d8 | Artem123Q/Python-Base | /Shimanskiy_Artem/homework_5/homework5_2.py | 788 | 4.25 | 4 | '''
Task 5.2
Edit your previous task: put the results into a file.
Then create a new python script and import your previous program to the new script.
Write a program that reads the file and prints it three times.
Print the contents once by reading in the entire file, once by looping over the file object,
and once by ... | true |
9ecf2afb58c4c9a938b4d8a96f75a4858d5138bc | xinmu01/python-code-base | /Advanced_Topic/Iterator_example.py | 1,113 | 4.28125 | 4 | class Reverse:
"""Iterator for looping over a sequence backwards."""
def __init__(self, data):
self.data = data
self.index = len(data)
# After define the __iter__, the iter() and for in loop can be used.
def __iter__(self):
return self
#As long as define __next__, the next()... | true |
e5ea2965be23486032a8d31ee2bfc01cd8d59126 | cryptoaimdy/Python-strings | /src/string_indexing_and_slicing_and_length.py | 1,180 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[35]:
# string indexing and slicing
s = "crypto aimdy"
# printing a character in string using positive index number
print(s[5])
# printing a character in string using negative index number
print(s[-5])
# In[28]:
##String Slicing
#printing string upto 5 characters
print(... | true |
310c2e0bbde417cbf69ee2768a833c6c3cbdb51a | thonathan/Ch.04_Conditionals | /4.2_Grading_2.0.py | 787 | 4.25 | 4 | '''
GRADING 2.0
-------------------
Copy your Grading 1.0 program and modify it to also print out the letter grade depending on the numerical grade.
If they fail, tell them to "Transfer to Johnston!"
'''
grade= int(input("Please enter your grade: "))
exam= int(input("Please enter your exam score: "))
worth= int(input("... | true |
370cfa9c4c18e0345cd14d49f6bc5762886d3b84 | SHajjat/python | /binFunctionAndComplex.py | 359 | 4.1875 | 4 | # there is another data type called complex
complex =10 # its usually used in complicated equations its like imaginary number
# bin() changes to binary numbers
print(bin(10000)) # this will print 0b10011100010000
print(int("0b10011100010000",2)) # im telling it i have number to the base of 2 i wanna change to int
... | true |
ce2e9a4fce24333c40aab5c06c2b83d16c5ae9c0 | booherbg/ken | /ppt/magic/functions_examples.py | 2,601 | 4.125 | 4 | '''
Working with functions
'''
# one parameter, required
def person1(name):
print "My name is %s" % name
#one parameter, optional w/ default argument
def person2(name='ken'):
print "My name is %s" % name
#three parameters, two optional
def person3(name, city='cincinnati', work='library'):
pri... | true |
9c73b01299eeb325f8035f6c3307aab051fd804d | ShehrozeEhsan086/ICT | /Python_Basics/replace_find.py | 689 | 4.28125 | 4 | # replace() method
string = "she is beautiful and she is a good dancer"
print(string.replace(" ","_")) # replaces space with underscore
print(string.replace("is","was")) # replaces is with was
print(string.replace("is","was",1)) #replaces the first is with was
print(string.replace("is","was",2)) #replaces both is... | true |
508877d679b9c33911f6c9823045770931d7c0f0 | CallumRai/Radium-Tech | /radium/helpers/_truncate.py | 855 | 4.375 | 4 | import math
def _truncate(number, decimals=0):
"""
Truncates a number to a certain number of decimal places
Parameters
----------
number : numeric
Number to truncate
decimals : int
Decimal places to truncate to, must be non-negative
Returns
-------
ret : numeric
... | true |
6bbaf096406780be38dceedcf04602b1d48210d0 | AliSalman86/Learning-The-Complete-Python-Course | /10Oct2019/list_comprehension.py | 1,678 | 4.75 | 5 | # list comprehension is a python feature that allows us to create lists very
# succinctly but being very powerful.
# doubling a list of numbers without list comprehension:
numbers = [0, 1, 2, 3, 4, 5]
doubled_numbers = list()
# use for loop to iterate the numbers in the list and multiply it by 2
for number in numbers... | true |
a6ff0a523770dff757aecf156646ae5ad1ef9687 | AliSalman86/Learning-The-Complete-Python-Course | /07Oct2019/basic_while_exercise.py | 738 | 4.40625 | 4 | # you can input any letter but it will actually do something only if p entered to
# print hello or entered q to quit the program
user_input = input("Please input your choice p to start the prgram or q to terminate: ")
# Then, begin a while loop that runs for as long as the user doesn't type 'q', if q
# entered then ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.