blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
fc5ea89086d69b46ba451b3ce24580786d165910 | shribadiger/pythonStudy | /ProgramWeight.py | 341 | 4.125 | 4 | #Program to convert the Weight in KG or in LBS
weight = int(input('WEIGHT : ')) # return value in string and converted to Integer
unit = input('L(BS) or K(G)')
if unit.upper() == "L":
converted = weight*0.45
print(f"You are {converted} Kilos")
else:
converted=weight / 0.45
print(f"You are {... | true |
462743e4b91495c1b6eca6df31e6e2b444ec1f2d | piotrmichna/python_egzamin_probny_1 | /exercise_01.py | 545 | 4.15625 | 4 | def shorten(txt):
"""Creates an shorten from eny text.
:param str: eny text
:rtype: str
:return: shortened
"""
sh_str = str(txt)
words = sh_str.split(' ')
sh_str = ""
for word in words:
sh_str += word[0]
sh_str = sh_str.upper()
return sh_str
if __name__ == '__main... | true |
8314022439b07bd21ff0ccfb83fa07d0624d0e8c | richardvecsey/python-basics | /033-harmonic_mean.py | 586 | 4.34375 | 4 | """
Get the harmonic mean of numbers
--------------------------------
Input: (list) numbers
Output: (float) harmonic mean of numbers
"""
from statistics import harmonic_mean
numbers = [20, 10, 5]
mean_1 = harmonic_mean(numbers)
print('original numbers: {}\nmean: {}'.format(numbers, mean_1))
n... | true |
3bc737194f3381cc76fdab0377bfd24ef432122d | richardvecsey/python-basics | /016-sum.py | 479 | 4.15625 | 4 | """
Return sum of iterable and start value
--------------------------------------
Input: value optional: start value
Return: sum of values
"""
numbers = [0, 1, 2, 3, 4, 5]
print('numbers: {}\n sum: {}'.format(numbers, sum(numbers)))
start_value = 10
print('numbers: {} + start value: {}\n sum: ... | true |
c9be82922f9afbfc29ef14fe5da4cd36d822a1d9 | richardvecsey/python-basics | /046-swapcase.py | 400 | 4.5 | 4 | """
Swap cases in a string
----------------------
Input: (string) any string
Output: (string) swapped string, upper cases become lower cases and
vice versa
"""
original_string = 'This is an "A" letter.'
modified_string = original_string.swapcase()
print('original st... | true |
2de30d34711d0f08e8877d2f1be40ddf31307e64 | richardvecsey/python-basics | /032-mean.py | 757 | 4.3125 | 4 | """
Get the arithmetic mean of numbers
----------------------------------
Input: (list) numbers
Output: (number) arithmetic mean of numbers
"""
from statistics import mean
numbers = [10, 5, 0, -5, -10]
mean_1 = mean(numbers)
print('original numbers: {}\nmean: {}'.format(numbers, mean_1))
number... | true |
60d6208ef1c30ab58ba1022c6154a8f1905d64d3 | richardvecsey/python-basics | /035-fmean.py | 668 | 4.375 | 4 | """
Get the arithmetic mean of numbers
----------------------------------
Input: (list) numbers
Output: (float) arithmetic mean of numbers
"""
# fmean() is faster, than mean() and always returns with float
# Python 3.8 is required
from statistics import fmean
numbers = [20, 5, 0, -5, -10]
mea... | true |
94be0f3423baca40dfd4817a41574d778c970987 | richardvecsey/python-basics | /044-lower.py | 376 | 4.53125 | 5 | """
Return lowercase version of a string
------------------------------------
Input: (string) any string
Output: (string) lowercase version of input string
"""
original_string = 'This is an "A" letter.'
modified_string = original_string.lower()
print(' Original string: {}\nLowercase versio... | true |
5e3e70ba04ab93172833d10c6b9ea21500e0d832 | vthavhiwa/myhackathon | /myhackathon/sorting.py | 1,171 | 4.28125 | 4 | def bubble_sort(items):
"""Return array of items, sorted in ascending order"""
count = 0
for item in range(len(items)-1):
if items[item] > items[item + 1]:
items[item],items[item + 1] = items[item + 1],items[item]
count += 1
if count == 0:
return items
else:
... | true |
0f1b32d34e7a31a1e9216e8d8a5695fcce0f13c8 | Geeky-har/Python-Files | /Practice_Set/capitalize.py | 415 | 4.25 | 4 | # the program is to capitalize the first letter of the word
# Ex: harsh negi -> Harsh Negi
import string
def change(name):
return string.capwords(name)
def change2(name): # alternative method
return name.title()
if __name__ == "__main__":
name = input("Write Your name: ")
# new_name = change(n... | true |
28fc8b4aa58e28f796ec5b27adf86b9ccc4c191f | vigneshwarand/SeleniumPythonProjectNew | /First_Selenium/PythonLoops.py | 435 | 4.1875 | 4 | if 5>3:
print("5 is greater than 3")
num = 0
if num > 0:
print("This is a positive num")
elif num == 0:
print("Num is zero")
else:
print("This is a negative num")
num = [1,2,3,4,5]
sum =0
for i in num:
print(i)
fruits = ["Apple","Oranges","Grapes"]
for val in fruits:
print(val)
else:
pr... | true |
c7c476f72825bc121061a9da328cb75fd5a0966b | JianxiangWang/python-journey | /leetcode/81_Search_in_Rotated_Sorted_Array_II.py | 1,354 | 4.1875 | 4 | # coding=utf-8
#
# Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
#
"""
The 81_Search_in_Rotated_Sorted_Array_II file.
Authors: Wang Jianxiang (wangjianxiang01@baidu.com)
"""
"""
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6] might become... | true |
e47500e0514c5243fb51023f83254d66770ad8ae | JianxiangWang/python-journey | /leetcode/206_Reverse_Linked_List.py | 1,073 | 4.125 | 4 | # coding=utf-8
#
# Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
#
"""
The 206_Reverse_Linked_List file.
Authors: Wang Jianxiang (wangjianxiang01@baidu.com)
"""
"""
Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Follow up:
A linked list can be reversed either... | true |
4033760f556a10bd30a5cb55851faa7fffe69958 | naellenhe/practice_code_challenge | /interviewcake/merge_sort.py | 825 | 4.28125 | 4 | def merge_lists(lst1, lst2):
"""Use merge to sort lists.
>>> list1 = [3, 4, 6]
>>> list2 = [1, 5]
>>> print merge_lists(list1, list2)
[1, 3, 4, 5, 6]
>>> list1 = [3, 4, 6, 10, 11, 12, 15, 20, 20]
>>> list2 = [1, 5, 8, 12, 14, 19, 20]
>>> print merge_lists... | true |
ae5e82ded1642f4a3cb9056812cccaf086527234 | Allam2003/Python-Activities- | /Al Python Source Code/Thinking 1/lvl2thinking - Copy.py | 320 | 4.3125 | 4 | temperature= int(input("Please enter the temperature C."))
if temperature>12:
print("The temperature is greater than average temperature C .")
elif temperatue==12:
print("The temperature is at the average temperature C.")
else:
print("The temperature is lower than average temperature C.")
| true |
4fa111e3b6806eafaa86a941a95956c0a6839d63 | KishanSewnath/Python | /Lessen/Les 4/Practice problems/4.2.py | 483 | 4.1875 | 4 | weather = 'It will be a sunny day today'
#print(weather.count('day'))
#print(weather.find('sunny')
print(weather.replace('sunny', 'cloudy'))
#write Python statements corresponding to these assignments:
# (a) To variable count, the number of occurrences of string 'day' in string forecast.
# (b) To variable weather... | true |
f1f7b1b1f1dd7337663436dde294bffaaed81802 | toyinfa2884/parsel_tongue | /ABDULFATAI_FOLDER/functions/exercise.py | 2,860 | 4.28125 | 4 |
# #write a python function to find the max of three numbers.
def max_of_three_numbers(number1, number2, number3):
number1 = int(input("Enter the first number"))
number2 = int(input("Enter the second number"))
number3 = int(input("Enter the third number"))
max_number = number1
if number2 > max_num... | true |
098f8274803e6123457f16800e031f32a50e72b6 | jhancock1229/PythonExercises | /Exercise3/exercise_3.py | 1,485 | 4.34375 | 4 | # Initial user input code
user_input = raw_input("Please enter a speed in miles/hour: ")
while True:
try:
user_input = float(user_input)
except ValueError:
user_input = (raw_input("MPH is a number, you dummy. Please enter an actual speed!: "))
continue
else:
break
user_input... | true |
505123556b075311907b83adf9cc2c3c5dc4b261 | Ayushd70/RetardedCodes | /python/kiloToMiles.py | 310 | 4.5 | 4 | # Program to convert Kilometers to Miles
# Taking kilometers input from the user
kilometers = float(input("Enter value in kilometers: "))
# conversion factor
convFac = 0.621371
# calculate miles
miles = kilometers * convFac
print("%0.2f kilometers is equal to %0.2f miles" % (kilometers, miles))
| true |
ddcb44925f0df6531fd92d5a9b590b4bfc835ae9 | Ayushd70/RetardedCodes | /python/mergeDic.py | 497 | 4.53125 | 5 | # Python program to merge two dictionary
# Method 1
# Using copy() and update()
dict_1 = {1: 'a', 2: 'b'}
dict_2 = {2: 'c', 4: 'd'}
dict_3 = dict_2.copy()
dict_3.update(dict_1)
print(dict_3)
# Method 2
# Using operator ** (Works only on Python 3.5 and above)
# dict_1 = {1: 'a', 2: 'b'}
# dict_2 = {2: 'c', 4: 'd'}
... | true |
635c92df3b6ff504c009dd644951a508e8037341 | ripfreeworld/Learn_Python_Workout | /lcy/exercise_3_pre.py | 615 | 4.5 | 4 | class MyClass:
"""A simple example class"""
# https://docs.python.org/3/tutorial/classes.html
i = 12345
def f(self):
return 'hello world'
sample = MyClass()
print(sample.f())
class Complex:
# When a class defines an __init__() method,
# class instantiation automatically invokes __in... | true |
1184a36dabac3bb8c05cd77785ce1a76a25a2346 | ripfreeworld/Learn_Python_Workout | /lxb/exercise2.py | 1,302 | 4.4375 | 4 | #!/usr/bin/env python3
# -*- coding:utf-8 -*-
'''
*re-implementing functionality*
The function takes a sequence of numbers, and returns the sum of those numbers. so if you were to invoke
sum([1,2,3]), the result would be 6.
The challenge here is to write a mysum function that does the same thing as the built-... | true |
f7faa97e02db4267cb4ce7a50b512d40f11eaa52 | marinamer/Code-Simplicity-Efficiency | /your-code/challenge-2.py | 1,654 | 4.21875 | 4 | """
The code below generates a given number of random strings that consists of numbers and
lower case English letters. You can also define the range of the variable lengths of
the strings being generated.
The code is functional but has a lot of room for improvement. Use what you have learned
about simple and efficien... | true |
cb23c30a12edd93d15dde6153fdcf2ca62c942b4 | Sausageexpert/MrWiFiPy | /countTheString.py | 427 | 4.125 | 4 | whatIWasGoingToSay = input("No Quotations \"Whatever I Want\" Pls ")
characterCount = 0
wordCount = 1
for i in whatIWasGoingToSay:
characterCount = characterCount + 1
if(i == ' '):
wordCount = wordCount + 1
print("Number Of Words You Were Going To Say 100% Accuracy")
print(wordCount)
prin... | true |
6151218dc35b978e212be65cf2b00ef1e238773a | kanik9/Plotly-and-Dash | /Bar Plot/bar_chart.py | 2,430 | 4.125 | 4 | # Bar Chart :
"""
A bar chart presents Categorical data with rectangular bars with heights (or lengths) proportional to the values that
they represent
* Using Bar Charts, we can visualize categorical data
* Typically the x-axis is the categories and the y-axis is the count(number of occurrences) in each category
*... | true |
d3bdb92d2507bb04b8f42c0758457f775fd79835 | iampsr8/Spectrum_intrn | /Spectrum_PythonDev/prgm9.py | 242 | 4.1875 | 4 | # nth smallest integer in the array
a=[]
x=int(input('Enter number of elements in array: '))
print('Enter elements in the array: ')
for i in range(x):
a.append(int(input()))
a.sort()
n=int(input('Enter integer n: '))
print(a[n-1]) | true |
0efd56aafc1c50ef62a5f830f72c268928233ac7 | EdwardCamilleri/Python-exercises | /Project4.py | 1,361 | 4.375 | 4 | # taking user input for their name and their room measurements
name = input("What is your name? ")
Length = float(input("What is the length of the room?: "))
Width = float(input("What is the width of the room?: "))
# calculating the area from the measurements and displaying it to the user
Area = Length * Width
... | true |
5592c8d2ad9005d62dddb737d02bcacba113854c | pavoli/checkIO | /home/house_password.py | 1,537 | 4.125 | 4 | # -*- coding: utf-8 -*-
__author__ = 'p.olifer'
"""
Input: A password as a string (Unicode for python 2.7).
Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean.
In the results you will see the converted results.
"""
#str = 'A1213pokl'
#str = 'bAse730onE'
... | true |
6d92dc6ffd87e186b1979cd126ee7624cc827b12 | RachelAJ/movie-picker | /movie_picker.py | 2,465 | 4.28125 | 4 | # Imported random module to populate a random movie from the lists when program runs and genre is chosen.
import random
# Added help function for instructions on how to retrieve a movie suggestion
def help():
print("Hey there, looking for a movie to watch? Follow these instructions to get some great suggestions!... | true |
c5e6d36234e1a8f418035921ca9cc0d0a509beef | IntroGM/2017 | /teaching_material/docs/build/html/_static/ball.py | 482 | 4.21875 | 4 | z = 1.8 # Starting elevation
Vz = 15 # Initial vertical velocity
nt = 6 # In how many steps we do the calculation
tottime = 3 # Total time (s) to calculate
# The total time and the number of time steps
# together implicitly set the size of the time step, dt.
dt = tottime / nt
print ("Size... | true |
18997d069c235c13224e8a3c35fb968ffbf0fdcc | calvinsettachatgul/cara | /algorithms/create_phone.py | 777 | 4.3125 | 4 | # https://www.codewars.com/kata/create-phone-number/train/python
'''
Write a function that accepts an array of 10 integers (between 0 and 9),
that returns a string of those numbers in the form of a phone number.
Example:
create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890"
The returned f... | true |
b560fcb5ccd40d73e62f94e10381ec2512e927a7 | cs-richardson/mario-mando210 | /Mario Less.py | 659 | 4.28125 | 4 | '''
This program prints out a half-pyramid of a given height from the user
Miki Ando
'''
#get the height of the half-pyramid from the user
height = input("Height: ")
#If the values are not a digit or is not in the range between 0 and 23,
#the program asks the user to re-enter the height
while not(height.isdigit()) or... | true |
14d2a3fc2ee8c1198ec58c228012bc748a4e53dc | anu1236/327983_Python-L1-Assignments | /Program20.py | 918 | 4.34375 | 4 | """Write a program to generate a Fibonacci series of numbers.
Starting numbers are 0 and 1, new number in the series is generated by adding previous two numbers in the series.
Example : 0, 1, 1, 2, 3, 5, 8,13,21,.....
a) Number of elements printed in the series should be N numbers, Where N is any +ve integer.
b)... | true |
21ae544f6c493c34ae6d95395a5ee1cc5d7763d9 | blizzarj2671/CTI110 | /P1HW1_BlizzardJacob.py | 697 | 4.5 | 4 | # This program calculates gross pay.
def main():
# Get the number of hours worked.
hours = int(input("How many hours did you work?"))
# Get the hourly pay rate.
pay_rate = float(input("Enter your hourly pay rate:"))
#Calculate the gross pay.
gross_pay = hours + pay_rate
#Disp... | true |
f4434efc3548ff30383969490bb380cbc422ff19 | Diogogrosario/FEUP-FPRO | /RE05/sumNumbers.py | 282 | 4.34375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 23 21:34:31 2018
@author: diogo
"""
def sum_numbers(n):
"""
returns the sum of all positive integers up to and including n
"""
sum=0
for i in range(n+1):
sum = sum + i
return sum | true |
3699d238f394b27bdf3bc9b11a64ef3ba147e231 | smmvalan/Python-Learning | /initial_file/swap.py | 781 | 4.25 | 4 | # To display the swapping numbers
'''
num1 = input('Enter First Number: ')
num2 = input('Enter Second Number: ')
print("Value of num1 before swapping: ", num1)
print("Value of num2 before swapping: ", num2)
# swapping two numbers using temporary variable
temp = num1
num1 = num2
num2 = temp
print("Value of num1 after s... | true |
3205da52a54ce26105e52ca6458eb79b7bff02cd | sacheenanand/Python | /geek2.py | 223 | 4.21875 | 4 | __author__ = 'sanand'
# Given starting and end points, write a Python program to print all even numbers in that given range.
string, end = 2, 15
for num in range(2, 15):
if num % 2 == 0:
print(num, end = " ")
| true |
97d39b0a56c7603ad807de597aa08afaec16d8d7 | sacheenanand/Python | /geeks4.py | 349 | 4.15625 | 4 | __author__ = 'sanand'
# Using for loop : Iterate each element in the list
# using for loop and check if num % 2 != 0. If the condition satisfies, then only print the number.
list1 = [2, 3, 7, 9, 10, 11, 14]
for num in list1:
if num % 2 != 0:
print(num, end = ' ')
only_odd = [num for num in list1 if num... | true |
a1d0050f85aefd5c9b75ed0bff7f3ee910c64e63 | blackbat13/Algorithms-Python | /numerical/monte_carlo_pi_plot.py | 1,095 | 4.34375 | 4 | import random
import matplotlib.pyplot as plt
def monte_carlo_pi(points_count: int) -> float:
"""Computes the estimated value of PI using a Monte Carlo method.
Args:
points_count (int): number of points to draw
Returns:
float: the estimated value of PI, using a Monte Carlo approach.
... | true |
e390b914f9270c89b339ec56b767a061fd7f1b33 | blackbat13/Algorithms-Python | /numerical/monte_carlo_pi.py | 804 | 4.28125 | 4 | import random
def monte_carlo_pi(points_count: int) -> float:
"""Computes the estimated value of PI using a Monte Carlo method.
Args:
points_count (int): number of points to draw
Returns:
float: the estimated value of PI, using a Monte Carlo approach.
"""
num_points_in_circle = ... | true |
cf41ba500f5558c226855bc8de1017f2e3f144d4 | wael20-meet/meet2018y1lab1 | /MEETinTurtle.py | 1,521 | 4.1875 | 4 |
import turtle
# Everything that comes after the # is a
# comment.
# It is a note to the person reading the code.
# The computer ignores it.
# Write your code below here...
turtle.penup() #Pick up the pen so it doesn’t
#draw
turtle.goto(-200,-100) #Move the turtle to the
#position (-200, -100)
#... | true |
ad7d2a0f51c83c6decf043284d6dee6f9aa391b9 | Reeftor/python-project-lvl1 | /brain_games/games/brain_progression.py | 995 | 4.125 | 4 | # -*- coding:utf-8 -*-
"""Brain_progression game logic."""
from random import randint
GAME_DESCR = 'What number is missing in the progression?'
def generate_progression():
"""Generate arithmetic progression for brain_progression game.
Returns:
progression and missing number.
"""
num = rand... | true |
2c8cb900412a0fb8aaf8d4c6051148bd20b9e88f | hunterfuchs/HFBNTest | /Fuchs_int.py | 1,663 | 4.125 | 4 |
def main():
#Describes the program
print('Enter two integers and I will tell you the relationship they satisfy.')
#User imput
firstInteger = int(input('Enter first integer: '))
secondInteger = int(input('Enter second integer: '))
#EQUAL
if firstInteger == secondInteger:
... | true |
782377d87d1d4ed49d1d152de6ffaa516e33aee1 | yinghuan007/LeetCode | /009_palindrome number/palindrome number.py | 1,104 | 4.40625 | 4 |
'''Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example ... | true |
ef54f7e902b2d908b309004051c940f561da95ea | hu6360567/ProjectEuler | /problem14.py | 1,333 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Longest Collatz sequence
Problem 14
The following iterative sequence is defined for the set of positive integers:
n ---> n/2 (n is even)
n ---> 3n+1 (n is ood)
Using the rule above and starting with 13, we generate the following sequence:
13 -> ... | true |
ba9e52a056609f5b36b810f6525522c85daa436a | hu6360567/ProjectEuler | /problem2.py | 695 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Even Fibonacci numbers
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whos... | true |
46e0ad4e7dfa87ca1c91a7e0185b8fd67e929cc9 | aniaskudlarska/mathelp | /subsets.py | 282 | 4.1875 | 4 | from itertools import *
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
x = powerset([1,2,3])
for item in x:
print(item) | true |
989a81fc5cfe6c839d23a46643b17f666c7f4277 | matinict/Python | /GuessingGameOne.py | 1,129 | 4.40625 | 4 | ###Guessing Game One Solutions
## Generate a random number between 1 and 9 (including 1 and 9).
## Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.
## (Hint: remember to use the user input lessons from the very first exercise)
## Extras:
## Keep the game going... | true |
a8f3e6c61e876c5afa3f25b152072ca4fed0e0ce | matinict/Python | /palindromeFunc.py | 418 | 4.625 | 5 | ##Ask the user for a string and print out whether this string is a palindrome or not.
##(A palindrome is a string that reads the same forwards and backwards.)
def palindromeTest(word):
rvs=word[::-1]
if word ==rvs:
print("This Word is Palindrome")
else:
print("This Word is not Palindrome")
##>>> palindromeTe... | true |
2a9524f955198b22cd4557d6dd1df055695f7509 | DeathSlayer0675/C.S.E | /Notes/HelloWorld.py | 1,255 | 4.34375 | 4 | print("Hello World")
# This is a comment. This has no effect on the code
# but this does allow me to do things. I can:
# 1. Make notes to myself
# 2. Comment pieces of code that does not work
# 3. Make my code easier to read
print("Look at what happens here. Is there any space?")
print()
print()
print("There should b... | true |
dee36eb4e95b831cacc6b897e1b4354641dd56f6 | AGagliano/HW05 | /HW05_ex00_logics.py | 2,028 | 4.4375 | 4 | #!/usr/bin/env python
# HW05_ex00_logics.py
##############################################################################
def even_odd():
""" Print even or odd:
Takes one integer from user
accepts only non-word numerals
must validate
Determines if even or odd
Prints... | true |
ffd5505149126bada1126caa8aa49833f5d654f3 | Cbkhare/Abstract_Data_Types | /adt_tree_binary_tree.py | 1,290 | 4.1875 | 4 | from Abstract_Data_Types.adt_tree import Tree
class BinaryTree(Tree):
"""Abstract base class for Binary Tree"""
# ----------- Abstract Methods ----------------------
def left(self, node):
"""Return the Position representing the left child Else None"""
raise NotImplementedError('Must be im... | true |
333d736ead70f14a5c08b97793efe190c9d5571a | xb4dc0d3/Daily-Interview-Pro | /squareroot.py | 931 | 4.21875 | 4 | '''
Hi, here's your problem today. This problem was recently asked by Google:
Given a positive integer, find the square root of the integer without using any built in square root \
or power functions (math.sqrt or the ** operator).
Give accuracy up to 3 decimal points.
'''
import sys
sys.setrecursionlimit(1500)
... | true |
6773700e7f28cfa09e9a7ed8f129f8d5872c277f | xb4dc0d3/Daily-Interview-Pro | /transpose_matrix.py | 543 | 4.15625 | 4 | '''
Hi, here's your problem today. This problem was recently asked by Twitter:
Given a matrix, transpose it. Transposing a matrix means the rows are now the column and vice-versa.
Here's an example:
'''
def transpose(mat):
column = len(mat[0])
row = len(mat)
result = [[0 for i in range(row)] for j in ran... | true |
344138de4970d66488e0e9e91a37adcb2a6a7ccb | xb4dc0d3/Daily-Interview-Pro | /majority_element.py | 545 | 4.125 | 4 | '''
Hi, here's your problem today. This problem was recently asked by AirBNB:
A majority element is an element that appears more than half the time.
Given a list with a majority element, find the majority element.
Here's an example and some starting code.
'''
def majority_element(nums):
data = {}
nums.sort(... | true |
262d6722f4c158d0a41b22433792cdc35651d156 | TMAC135/Pracrice | /maximum_depth_of_binary_tree.py | 695 | 4.21875 | 4 | # coding=utf-8
"""
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Example
Given a binary tree as follow:
1
/ \
2 3
/ \
4 5
The maximum depth is 3.
"""
"""
Definition of TreeNode:
"""
class ... | true |
74cdb90a83267b35a61a8627ee5c4dc7b32f407b | TMAC135/Pracrice | /convert_binary_search_tree_to_doubly_linked_list.py | 2,307 | 4.15625 | 4 | """
Convert a binary search tree to doubly linked list with in-order traversal.
Example:
Given a binary search tree:
4
/ \
2 5
/ \
1 3
return 1<->2<->3<->4<->5
"""
"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
this.val = val
this.left, this.right = None, None... | true |
9592517e14a3ae7007e44d12b0ad000b31fd8b5a | DenOn79/PythonIntroOnline | /Lesson_05/rhombus_with_diagonal.py | 748 | 4.21875 | 4 |
height = int(input('Input the height of rhombus. (Please, make it even): '))
while height % 2 == 0:
height = int(input('The number is not even. Input the height of rhombus. (Please, make it even): '))
else:
width = height
for i in range(height):
for j in range(width):
if i == height//2 \
... | true |
6231531b341a8e4ad5b43c9b0b7026e87b7cc561 | AkshayShenvi/DailyCodingChallengeSolution | /DCC27-3-2019.py | 878 | 4.21875 | 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 i... | true |
b3a1b3614815836b5453c1467c00f9c43b7b790e | RobertZSun/19S-SSW567-ZheSun | /Triangle.py | 2,198 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jan 14 13:44:00 2016
Updated Jan 21, 2018
The primary goal of this file is to demonstrate a simple python program to classify triangles
the results come as expected.
@author: zhe sun
"""
import math
def classifyTriangle(a, b, c):
""" This function classify_triangle(a, b... | true |
f720a02793e76f572216fd1af6ffae5ee97cf284 | peaches12/Python_m | /GuessNumber.py | 560 | 4.1875 | 4 | # Guess a number from 1 to 10
import random # the computer will generate random number from 1 to 10
numPC = random.randint(1,10)
print("numPC: " + str(numPC))
print("Do you want to guess a number from 1 to 10?")
print("Enter Yes/No: ")
num = int(input("Enter a number from 1 to 10: "))
print("your number: " + str(nu... | true |
51db5651d6bf853e30e84f72eee0570089adc5fb | peaches12/Python_m | /String Two First_Last Char.py | 602 | 4.21875 | 4 | # the program will concatente the first two and the last two characters of
# the input string
word = input("Enter a string here: ")
word1=word[0:2]
word2=word[len(word)-2:]
print()
print("new string: " + (word1+word2))
print('-------------------------------')
choice= input("continue? yes/no: ")
while choice.upper() ... | true |
9833005b48b67e664f7015a357ce50be6b7fa132 | peaches12/Python_m | /List_RemoveDuplicates.py | 399 | 4.125 | 4 | #the program will remove duplicates from the list
mylist = [1,1,2,2,3,4,4,5,5,6,7,7]
print('the initial list:' + str(mylist))
m = 0
while m < len(mylist):
if mylist[m] == mylist[m + 1]:
mylist.remove(mylist[m])
m = m+1
print('the final list: ' + str(mylist))
#turn the list into a tupl... | true |
52c38f8b5574c2b7b6e2e50181ab82bfac514118 | s-harding/spotify_puzzles | /spotify_puzzle_1.py | 270 | 4.15625 | 4 |
# coding: utf-8
def reverse_bin(x):
bin(x)
str_x = str(bin(x))
reverse_x = str_x[::-1]
ans_bin = reverse_x[:len(reverse_x)-2]
return int(ans_bin,2)
x = input("Please enter an integer:")
print("The binary reverse of {} is {}".format(x, reverse_bin(int(x))))
| true |
bd7e199baec031afb4ede2ae31f7df5ee76980b9 | emt2017/CS5590PythonSpring2018 | /Lab1Python/Question2.py | 1,457 | 4.21875 | 4 | '''Question 2'''
'''Write a Python function that accepts a sentence of words from user and display the following: '''
#a) Middle word
#b) Longest word in the sentence
#c) Reverse all the words in sentence
'''Import Libraries'''
import string
import sys
'''Function'''
def midLongReverse(string):
#get/sto... | true |
574b1f5f2299727960808bdd451bbe420c4eefdf | monish7108/PythonProg2 | /listingthepath.py | 1,221 | 4.25 | 4 | """This program takes a path of directory as input and gives list of all the
all the files, sub-folders, files under sub-folders and so on.
==============================================================
"""
import os
file = []
dir = []
def listing(path1, pathlist1):
for items in pathlist1:
if os.path... | true |
5c2240e374a1dafa9e9c2558a3336515bb993365 | monish7108/PythonProg2 | /fibonacciNumChecking.py | 1,384 | 4.28125 | 4 | """This programs check every number from command line
and tells whether number is in fibbonacci series or not.
Math: Instead of producing loop and checking the number there is a mathematical formula.
If (5*x*x)+4 or (5*x*x)-4 or both are perfect squares,
then the number is in fibona... | true |
0d7e30054d26670e94d498499a80a3641fb7f1cb | 01-Jacky/PracticeProblems | /Python/c/wepay/power_number.py | 1,560 | 4.4375 | 4 | """
A PowerNumber is defined as a number greater than zero that can be expressed as X^Y, where X and Y are integers greater than one.
Create a function takes in an integer i and returns the (zero-indexed) ith power number
Write a function that returns the nth power number, where a power number is a number that can be ... | true |
7592ee3a564ea148e7d25eb8e49cab827be82e18 | bhavsarp456-pnb/bhavsarp456 | /RockPaperScissor.py | 2,049 | 4.40625 | 4 | #user imports random function from which computer can playe random moves
from random import randint
#initialising the variables
player_wins = 0
computer_wins = 0
winning_score = 3
#for checking both variables reaches to winning score
while player_wins < winning_score and computer_wins < winning_score:
print... | true |
ff6c1782715b564a73d73cd6241f55e534a696db | savimanner/100-coding-challenges | /4.py | 384 | 4.1875 | 4 | #Question: Write a program which accepts a sequence of comma-separated numbers
# from console and generate a list and a tuple which contains every number.
# Suppose the following input is supplied to the program: 34,67,55,33,12,98 Then,
# the output should be: ['34', '67', '55', '33', '12', '98'] ('34', '67', '55', '... | true |
314e8981ac2dd67610ba1b4e87f5937ca5fedd9b | Ziiv-git/Coursera-Python-3- | /g.py | 525 | 4.34375 | 4 | #A palindrome is a phrase that, if reversed, would read the exact same.
#Write code that checks if p_phrase is a palindrome by reversing it and then
#checking if the reversed version is equal to the original. Assign the reversed
#version of p_phrase to the variable r_phrase so that we can check your work.
#Save & RunLo... | true |
6e622f756dc1f5c20421027a5596d1be9e0ad725 | vitorpio/pybible-cli | /pybible/classes/verse.py | 803 | 4.375 | 4 | class Verse:
"""A class used to represent a verse from the bible."""
def __init__(self, text: str, number: int):
"""
Initialize a `Verse` object.
:Parameters:
- `text`: sting containing the text of the verse.
- `number`: integer with the number of the verse.
... | true |
b19b715743c1bb852976da58db38ef681fb7d3f8 | alexshmmy/Python_Algorithms | /014.findWord2dArray.py | 1,732 | 4.1875 | 4 | # given a 2D array and a word, build a boolean function that checks if the word is in the
# array horizontally or vertically
# import packages
import numpy as np
# basic function
def findWord2DArray(array, word) :
'''gets an array and a word and checks if the word exists in the array'''
# define the length of th... | true |
d8837f7ea61778b43fbeef91a58b0c60cd1c05bb | alexshmmy/Python_Algorithms | /010.bubleSort.py | 511 | 4.21875 | 4 | # bublesort: a basic sorting algorithm in python
# input: a list of integers
# output: sorted list of integers
# time complexity: O(n^2)
# space complexity: O(1)
def bubbleSort(alist) :
'''implementation of bubblesort algorithm'''
# compute the length of the list
L = len(alist)
for i in range(0, L) :
for j in r... | true |
dd8ca8ece32b5a6a1fa629d46e9a65b57863a708 | Akshay-Kanawade/Image_Augmentation_Tool | /tools/crop.py | 1,755 | 4.15625 | 4 | # import library
import cv2
def Read(image_path):
"""
This function basically used to read the image.It read images in form of numpy array.
:param image_path: source image
:return: ndarray
"""
# use cv2.imread() to read an images.
# syntax : cv2.imread(filename, flag=None)
return cv2.... | true |
6256c71a3dff63febd45da9de76d78bf8918b889 | Akshay-Kanawade/Image_Augmentation_Tool | /tools/sharpen_image.py | 1,614 | 4.125 | 4 | # import library
import cv2
import numpy as np
def Read(image_path):
"""
This function basically used to read the image.It read images in form of numpy array.
:param image_path: source image
:return: ndarray
"""
# use cv2.imread() to read an images.
# syntax : cv2.imread(filename, flag=No... | true |
dc350bc67db84c61a33f07e7ae300d1165ed4f57 | PJHutson/prg105 | /4.3.py | 598 | 4.5 | 4 | # Nested loops to find the average rainfall
rainfall = 0
years = int(input("Please enter the number of years")) # convert years to integer
for year in range(1, years + 1): # set loops for the years
for month in range(1, 13): # set inner loops for months
rainfallpermonth = int(input... | true |
a760dabf47455f175cbd9b7926aa770b034d0631 | HaymanLiron/46_python_exercises | /q10.py | 321 | 4.15625 | 4 | def overlapping(a,b):
# checks if lists a and b have at least one common element
# uses nested if-loops to satisfy the requirements of the question
# even though it's not very efficient
for elem_a in a:
for elem_b in b:
if elem_a == elem_b:
return True
return Fals... | true |
2c766ebe972eead997f38b841a7f3c366c6dc436 | ehiaig/learn_python | /pyramid.py | 806 | 4.3125 | 4 | """
Exercise 1: Create a pyramid like below
*
***
*****
***
*
"""
for line in [1,2,3,2,1]:
#print("line {}".format(line))
for space in range(3-line):
print(" ", end="")
for stars in range(2*line-1):
print("*", end="")
print("")
#OR
line = 1
counter = 1
while line>0:
... | true |
fac2bd77f6c0000807e48cc1f40f354f03cc844d | ehiaig/learn_python | /second.py | 567 | 4.40625 | 4 | #For loops are for lists and ranges
my_num = [3,5,7,6,100]
for num in my_num:
print (num+3)
#Another
range(8)
#Yet another
for num in range(5):
print(num)
#For
for num in range(1,5):
print(num)
#Again
for num in range(1,10, 2):
print(num)
#Yet
for i in range(2):
for j in range(3):
print(... | true |
54e01a7410d972f4020650d10b277bdfbfba270c | im-jonhatan/hackerRankPython | /strings/stringSplitandJoin.py | 318 | 4.28125 | 4 | # Task
# You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen.
# Input Format
# The first line contains a string consisting of space separated words.
# Output Format
# Print the formatted string as explained above.
def split_and_join(line):
return line.replace(" ", "-") | true |
6224ac2e25db55ba7434d290e892e9e4c66c3d28 | im-jonhatan/hackerRankPython | /closuresandDecorators/standardizeMobileNumberUsingDecorators.py | 999 | 4.25 | 4 | # Let's dive into decorators! You are given N mobile numbers. Sort them in ascending order then print them in the standard format shown below:
# +91 xxxxx xxxxx
# The given mobile numbers may have +91, 91 or 0 written before the actual 10 digit number. Alternatively, there may not be any prefix at all.
# Input Format
... | true |
c825c5457a29022d3a323154fdc1befbd7bec4e8 | im-jonhatan/hackerRankPython | /sets/introductionToSets.py | 723 | 4.125 | 4 | # Task
# Now, let's use our knowledge of sets and help Mickey.
# Ms. Gabriel Williams is a botany professor at District College. One day, she asked her student Mickey to compute the average of all the plants with distinct heights in her greenhouse.
# Formula used:
# average = sum of distinct heights / total number of ... | true |
90f691f13aae8688dc5fb01385463810b7b578c1 | ppapuli/Portfolio | /ThinkPythonExamples/tp1.2.py | 787 | 4.40625 | 4 | ''' How many seconds are there in 42 minutes and 42 seconds? '''
#function to convert any hours and minutes to seconds
def time_in_seconds(hours = 0, minutes = 0, seconds = 0):
if hours + minutes + seconds == 0:
hours = float(input("How many hours? "))
minutes = float(input("How many minutes?... | true |
7c3b76bf725e9f336fb1c5780aa455eccc177ab6 | ppapuli/Portfolio | /ThinkPythonExamples/tp9.4.py | 293 | 4.21875 | 4 | fin = open('words.txt')
# prints true if all the letters in the word only contains letters used in the string
def uses_only(word, string):
for letter in word:
if letter not in string:
return False
return True
print(uses_only("hello face", " acefhlo "))
| true |
4fba239b1aff979e45f4971332d8a4b5d92e66cc | ppapuli/Portfolio | /ThinkPythonExamples/tp5.3.py | 454 | 4.4375 | 4 | # Function that checks whether three side lengths are capable of forming a triangle
def is_triangle(s1,s2,s3):
if s1 > s2+s3 or s2 > s1+s3 or s3 > s1+s2:
print("No")
else: print("Yes")
# Prompt user for the lengths of the triangle
sideA = int(input("What is your first length? \n"))
sideB = int(... | true |
b91fc6ebc5acebc7021d1507bdb646ee3e101c7a | nsm112/Passwordgenerator | /main.py | 2,756 | 4.21875 | 4 | # Using this symbol I can leave comments that do not effect the code.
# Below this comment I will explain the various lines of code and their function within this file
# The import function is used to import modules from python to create specific functions for later use
# I will use both the array and random funct... | true |
cce70fe0af76b0b59901051765f5bf84308c8549 | Yang-Le-321/Magic-8-Ball | /Magic.py | 1,044 | 4.21875 | 4 | import random
#Get user input
name = input("What is your name? ")
question = input("What would you like to ask? ")
answer = ""
#Generate random answer
random_number = random.randint(1,10)
if random_number == 1:
answer = "Yes - definitely."
elif random_number == 2:
answer = "It is decidedly so"
elif random_number ... | true |
1198d9cd67e56de696ce9485c61d20e7b606aa9d | Saurabh2105/PythonHackerRank | /RegularExpressions/FibonacciProblem.py | 772 | 4.375 | 4 | '''
Let's learn some new Python concepts! You have to generate a list of the first fibonacci numbers, being the first number.
Then, apply the map function and a lambda expression to cube each fibonacci number and print the list.
'''
cube = lambda x: x*x*x# complete the lambda function
def fibonacci(n):
lst=li... | true |
0e7c36c49bed0cdbf31aaf1e9b16d932848b6997 | psmithxoxo43/pod3_repo | /Dario/temperature.py | 983 | 4.34375 | 4 | #converting farenheit 100 to celsius and saving it to the variable celsius_100
celsius_100 = ((100 - 32) * 5/9)
#printing celsius_100
print(celsius_100)
#converting 0 degrees farenheit to celsius and saving to variable celsius_0
celsius_0 = ((0 - 32) * 5/9)
#printing celsius_0
print(celsius_0)
#converting and printing ... | true |
8a6e022c172e210c2411002aa59f6934fabf707b | psmithxoxo43/pod3_repo | /Paola/first_python_challenge.py | 1,561 | 4.34375 | 4 | print('1: Describe what is happening below by adding comments before each line')
# Assigning the word books to the box_1 variable
box_1 = 'books'
# Assigning the word clothes to the box_2 variable
box_2 = 'clothes'
# Assigning the word plants to the box_3 variable
box_3 = 'plants'
# Assigning the phrase kitchen stu... | true |
0ae30646a67cef2671d1a954bacaa1ee284fb91b | hamburgcodingschool/L2CX-January_new | /lesson 2/p3-revisions_3.py | 323 | 4.34375 | 4 | # CONDITIONAL OPERATORS == != > >= < <=
# result of the op is always a boolean (True/False)
age = 5
test = age >= 18
print(test)
# IF STATEMENT
if age >= 18:
print("You are old!")
print("Well not really... maybe")
else:
print("You are definitly youngn for a human")
print("THE END!... | true |
f199348a57fcde48d49c9c1dd4306759ce52e831 | jc239964/lookIGitIt | /ex15.py | 788 | 4.25 | 4 | # use argv to get the script's name and user input
from sys import argv
script, filename = argv
# defines variable 'txt' with the open function and
# the filename which user inputs via argv
txt = open(filename)
# prints the name of the file, then uses the read function to
# print it to the command line
print "Here... | true |
0375a5c92e2475fd2dc2043a99cd15083cd53478 | ZL4746/Basic-Python-Programming-Skill | /First_Part/07_Deal.py | 2,111 | 4.125 | 4 | def ReturnView(Prize,Guess):
# a function to return the View
if (Prize == Guess):
if (Guess == 3):
View = 1
else:
View = Guess + 1
else:
if (Guess == 3 and Prize == 2) or (Guess == 2 and Prize ==3):
... | true |
d7e70522a7912d96c6b89203265e1dd24c7b67d5 | Amagash/Udacity_Python | /CS101/rounding numbers.py | 1,131 | 4.34375 | 4 | # Given a variable, x, that stores the
# value of any decimal number, write Python
# code that prints out the nearest whole
# number to x.
# If x is exactly half way between two
# whole numbers, round up, so
# 3.5 rounds to 4 and 2.5 rounds to 3.
# You may assume x is not negative.
# Hint: The str function can convert... | true |
18c74b300a64d67319f90ebc1ee08ea1880c62bd | AbdullahiAbdulkabir/QuadraticEquation | /calcnoofdays.py | 626 | 4.125 | 4 | #Joshua Odubiro
#olayemisamuel55@gmail.com
#08162583688
#python to calculate number of days between two dates
from datetime import date
def op():
year=int(input("input the start year in integer format"))
month=int(input("input the start month in integer format"))
day=int(input("input the start d... | true |
ef6a68902dc913298c6d3b7dbb21df988da5dd11 | gillespilon/sql | /food.py | 2,342 | 4.21875 | 4 | #! /usr/bin/env python3
"""
Example of an sqlite3 db
- Create a dataframe
- Save as a table in a database
"""
from sqlalchemy import create_engine
import datasense as ds
import pandas as pd
import sqlite3
def main():
# engine = create_engine('sqlite://', echo=False)
connection = sqlite3.connect('groceries.... | true |
a0f011bed9d76b2dd839ee86cb409b7d236964c6 | mohito1999/Miniprojects | /Projects/ATBS/col1.py | 683 | 4.28125 | 4 | from sys import exit
def collatz(number):
if number % 2 == 0:
result = number // 2
elif number % 2 == 1:
result = number * 3 + 1
while number != 1:
number = result
print(number) #the very first return statement executed will end the function tha... | true |
fdc0930e953b6cde9c3ce7f9125b44f72da9f9d2 | ResearchInMotion/TestProject | /Maximum.py | 357 | 4.15625 | 4 | print("Enter the first number")
firstNumber=int(input())
print("Enter the second number")
secondNumber=int(input())
def maximum(Number1 , Number2):
if(Number1>Number2):
print("Number one is greater")
elif(Number1<Number2):
print("Number two is greater")
else:
print("both are same")... | true |
c5ac7b56e4c831d835080749c5ef09ab706069f5 | ResearchInMotion/TestProject | /mutiple.py | 452 | 4.21875 | 4 | print("please enter a number : ")
number = input()
number2=int(number)
if(number2%7==0):
print("numbr is divisble by 7")
if(number2%14==0):
print("number is divisble by 14")
else:
print("number is divisble by 3 , but not with 7 ")
#if number2 % 7 is 0:
#print("number is divisble by 7"... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.