blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
36a3e44f366e2bcf8bbab61ce3cee2f551acd80b | itsfarooqui/Python-Programs | /Program15.py | 275 | 4.125 | 4 | #15. Write a method to find number of even number and odd numbers in an array.
arr = [8, 4, 3, 6, 9, 2]
i = 0
for i in range(0, len(arr)):
if arr[i]%2 == 0:
print("Even Number: ", arr[i])
else:
print("Odd Number: ", arr[i])
i = i +1 | true |
960bc02fa729a588f9220769365fd4194fc7e0a3 | thinkphp/rabin-miller | /rabin-miller.py | 2,613 | 4.21875 | 4 | # Miller-Rabin Probabilistic Primality Test.
#
# It's a primality test, an algorithm which determines whether a given number is prime.
#
# Theory
#
# 1. Fermat's little theorem states that if p is a prime and 1<=a<p then a^p-1 = 1(mod p)
#
# 2. If p is a prime x^2 = 1(mod p) or(x-1)(x+1) = 0 (mod p), then x = 1 (mod ... | true |
15b439cc89bae13fbfd7a981ce68aa5c23ecaf0f | randcyp/FIT2085 | /Practical 1/Exercise 1 - task_1.py | 1,633 | 4.21875 | 4 | # Non-assessed practical
"""
This module demonstrates a way to interface basic list
operations.
"""
__author__ = "Chia Yong Peng"
from typing import List, TypeVar
T = TypeVar('T')
list_of_items = []
def print_menu() -> None:
"""
Prints the menu.
"""
menu_items = ["append", "reverse", "print", "pop... | true |
583f9a7bf7f1aa39295f404f8ad42ba4c529abb3 | Frindge/Esercizi-Workbook | /Exercises Workbook Capit. 2/Exercise 040 - Sound Levels.py | 845 | 4.4375 | 4 | # Exercise 40: Sound Levels
# Jackhammer 130 dB
# Gas Lawnmower 106 dB
# Alarm Clock 70 dB
# Quiet Room 40 dB
Sound=float(input("Enter a number to define a sound level in decibels: "))
if Sound > 130:
Sound="The sound level is louder than a Jackhammer"
elif Sound == 130:
Sound="The sound level is Jackhammer"... | true |
93153b09c6c76b9e8b7daf4643d507e2a4bbacde | Frindge/Esercizi-Workbook | /Exercises Workbook Capit. 2/Exercise 051 - Roots of a Quadratic Function.py | 547 | 4.1875 | 4 | # Exercise 51: Roots of a Quadratic Function
import math
a=float(input("Enter the value a: "))
b=float(input("Enter the value b: "))
c=float(input("Enter the value c: "))
discriminant = (b**2) - (4 * a * c)
print(discriminant)
if discriminant < 0:
print("has no real roots")
elif discriminant == 0:
result =... | true |
22c14c12f08fcc25ab970493f8ef05cb5b73982b | Frindge/Esercizi-Workbook | /Exercises Workbook Capit. 2/Exercise 035 - Even or Odd.py | 208 | 4.125 | 4 | # Exercise 35: Even or Odd?
number=int(input("Enter a valid integer number: "))
number1=number % 2
if number1 == 0:
number1="the number is even."
else:
number1="the number is odd: "
print(number1)
| true |
b971b310ae02ec049a32d1bebca9ea41a6ac5fb1 | taoyuc3/SERIUS_NUS | /5.28.py | 1,699 | 4.125 | 4 | # https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
# Load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.data.csv", delimiter=",")... | true |
9d44df3ad84744af06d02d53553f0049c382f2d2 | Nana-Antwi/UVM-CS-21 | /distance.py | 799 | 4.125 | 4 | #Nana Antwi
#cs 21
#assignment 4
#distance.py
#write a program that calculates distance
#distance is equal to speed muliple by time
#variables
speed = 0.0
time = 0.0
distance = 0.0
var_cons = 1.0
#user input variable
speed = float(input('Enter speed: ')) #user prompts
#condition loop statements
wh... | true |
0c2bc2ff035678d3f8d947124c05d6293a0c7da0 | rynoV/andrew_ng-ml | /mongo-lin-reg/src/computeCost.py | 790 | 4.3125 | 4 | import numpy as np
def computeCost(X, y, theta):
"""
Compute cost for linear regression with multiple variables.
Computes the cost of using theta as the parameter for linear regression to fit the data points in X and y.
Parameters
----------
X : array_like
The dataset of sh... | true |
7a2aba24cf92a368bdeef9eae3951420627c2830 | nazomeku/miscellaneous | /fizzbuzz.py | 489 | 4.375 | 4 | def fizzbuzz(x):
"""Take integer and check if it is divisable by:
3: return 'fizz',
5: return 'buzz',
3 and 5: return 'fizzbuzz',
otherwise: return input as string.
Args:
x: The integer for which the condition is checked.
Returns:
Corresponding string value.
"""
if x ... | true |
cc79f38420b39113f7d988a6171bdf3fd6f27e2d | UmmadisettyRamsai/ramsai | /labprogramme2.py | 1,140 | 4.46875 | 4 |
# basic operations on single array
#A PYTHON PROGRAM TO PERFORM UNIARY OPERATIONS
import numpy as np
a = np.array([1, 2, 5, 3])
# add 2 to every element
print ("Adding 2 to every element:", a+2)
# subtract 3 from each element
print ("Subtracting 3 from each element:", a-3)
# multiply each element b... | true |
ab7ef4dd24c0e21a857cd1a8c28c9fdb36739169 | Psycadelik/sifu | /general/is_integer_palindrome.py | 486 | 4.15625 | 4 | """
Check Whether a Number is Palindrome or Not
Time complexity : O(log 10(n)).
We divided the input by 10 for every iteration,
so the time complexity is O(log10(n))
Space complexity : O(1)
"""
def is_palindrome(num):
original_num = num
reversed_num = 0
while (num != 0):
num, rem = divmod(num, ... | true |
1f3533dc0dd324766f4e7d39681dbdf434ad0d4d | MPeteva/HackBulgariaProgramming101 | /Week0/1-PythonSimpleProblemsSet/T11_CountSubstrings.py | 330 | 4.25 | 4 | def count_substrings(haystack, needle):
count_of_occurrences = haystack.count(needle)
return count_of_occurrences
def main():
String = input("Input a string: ")
Word = input("Input a word to count occurrences of it in string: ")
print (count_substrings(String, Word))
if __name__ == '__main__':
... | true |
15836a7c158c46605a536ab7b889119eed45fe7b | SaudiWebDev2020/Sumiyah_Fallatah | /Weekly_Challenges/python/week5/wee5day3.py | 2,632 | 4.3125 | 4 | # Create a queue using 2 stacks. A hint: stack1 will hold the contents of the actual queue, stack2 will be used in the enQueueing
# Efficiency is not the goal!
# Efficiency is not the goal!
# Efficiency is not the goal!
# The goal is to practice using one data structure to implement another one, in our case Queue from ... | true |
c059e02dfe1f9c556b82de12ee26cd89a810db93 | ton4phy/hello-world | /Python/55. Logic.py | 253 | 4.28125 | 4 | # Exercise
# Implement the flip_flop function, which accepts a string as input and, if that string is 'flip',
# returns the string 'flop'. Otherwise, the function should return 'flip'.
def flip_flop(arg):
return 'flop' if arg == 'flip' else 'flip'
| true |
ca71548c786da72de4c83531cdba7a5d8e6f3519 | ton4phy/hello-world | /Python/57. Cycles.py | 379 | 4.3125 | 4 | # Exercise
# Modify the print_numbers function so that it prints the numbers in reverse order. To do this,
# go from the top to the bottom. That is,
# the counter should be initialized with the maximum value,
# and in the body of the loop it should be reduced to the lower limit.
def print_numbers(n):
while n > 0:... | true |
af32739412f82b395268bf8a13e89b42184a8bb8 | ton4phy/hello-world | /Python/59. Cycles.py | 817 | 4.125 | 4 | # Exercise
# Implement the is_arguments_for_substr_correct predicate function, which takes three arguments:
# the string
# index from which to start extraction
# extractable substring length
# The function returns False if at least one of the conditions is true:
# Negative length of the extracted substring
# Negative... | true |
bd152a5e10c36bfc628bcd88b405966b3741c0c2 | Chriskoka/Kokanour_Story | /Tutorials/mathFunctions.py | 557 | 4.28125 | 4 | """
Math Functions
"""
#Variables
a = 3
b = -6
c = 9
#Addition & Subtraction
print(a+b)
print(a-b)
#Multiplication & Division
print(a * b)
print(a / b)
#exponents
print(a ** b) # Notice ** means to the power of
print(b ** a)
#Square Root & Cube Root
print(c ** (1/3))
print(c ** (1/2))
#Modulus (% symbol is us... | true |
20ffa4780a571b56cd17304dde237f4a4fb7eed5 | Chriskoka/Kokanour_Story | /Tutorials/addSix.py | 233 | 4.3125 | 4 | """
This program will take the input of the user and return that number plus 6 in a print statement
"""
numb = int(input ('Choose an integer from 1 to 10. Input: '))
print ('The number ' + str(numb) + ' plus six = ' + str(numb + 6)) | true |
0838e7bca4295999e847c41b218bd1b5b928e6c1 | josandotavalo/OSSU | /001-Python-for-Everyone/Exercise-9.5.py | 814 | 4.15625 | 4 | # Exercise 5: Write a program to read through the mail box data and when you find line that starts
# with “From”, you will split the line into words using the split function. We are interested in who
# sent the message, which is the second word on the From line.
# You will parse the From line and print out the second... | true |
ce6840467ee5ec0a8cb7748bd7441527b6fad2da | mohit-singh4180/python | /string operations/StringLogical operation.py | 645 | 4.3125 | 4 | stra=''
strb='Singh'
print(repr(stra and strb))
print(repr(stra or strb))
stra='Mohit'
print(repr(stra and strb))
print(repr(strb and stra))
print(repr(stra or strb))
print(repr(not stra))
stra=''
print(repr(not stra))
# A Python program to demonstrate the
# working of the string template
from string import Tem... | true |
ea291fcdc704b8133b4b0ef66f3883c251776399 | gonegitdone/MITx-6.00.2x | /Week 5 - Knapsack and optimization/L9_Problem_2.py | 1,897 | 4.15625 | 4 | # ==============L9 Problem 2 =================
'''
L9 PROBLEM 2 (10 points possible)
Consider our representation of permutations of students in a line from Problem 1. In this case, we will consider a
line of three students, Alice, Bob, and Carol (denoted A, B, and C). Using the Graph class created in the lecture,
we c... | true |
a05b26542169a4cb883d87c62baee613856ece9d | CallieCoder/TechDegree_Project-1 | /01_GuessGame.py | 938 | 4.125 | 4 | CORRECT_GUESS = 34
attempts = [1]
print("Hello, welcome to the Guessing Game! \nThe current high score is 250 points.")
while True:
try:
guess = int(input("Guess a number from 1 - 100: "))
except ValueError:
print("Invalid entry. Please enter numbers as integers only.")
else:
if guess < 1 or guess > 100:
... | true |
28b749e2ea944bcd4e56112453fd2b9836da0cca | amrfekryy/daysBetweenDates | /daysBetweenDates.py | 1,800 | 4.375 | 4 | # Given your birthday and the current date, calculate your age
# in days. Compensate for leap days. Assume that the birthday
# and current date are correct dates (and no time travel).
# Simply put, if you were born 1 Jan 2012 and todays date is
# 2 Jan 2012 you are 1 day old.
def isLeapYear(year):
"""returns T... | true |
b1545d03a2ae61fa8c7858f14183f60ff9ff4493 | joshp123/Project-Euler | /4.py | 460 | 4.21875 | 4 | def isPalindrome(string):
if string == string[::-1]:
return 1 # string reversed = string
else:
return 0 # not a palindrome
palindromes = []
for num1 in xrange(999, 100, -1):
for num2 in xrange(999, 100, -1):
product = num1 * num2
if isPalindrome(str(product)) == 1:
... | true |
e805d017fb69438e5cf968288dfd77488a00246f | zjuKeLiu/PythonLearning | /GUI.py | 1,306 | 4.21875 | 4 | import tkinter
import tkinter.messagebox
def main():
flag = True
#change the words on label
def change_label_text():
nonlocal flag
flag = not flag
color, msg = ('red', 'Hello, world!')\
if flag else ('blue', 'Goodbye, world')
label.conflg(text = msg, fg = color)... | true |
1603adb378d36caaba42ea862482e4810f3591b2 | igusia/python-algorithms | /binary_search.py | 452 | 4.125 | 4 | import random
#searching for an item inside a search structure
def binary_search(search, item):
low = 0
high = len(search)-1
while low <= high:
mid = (low + high)//2 #if odd -> returns a lower number
guess = search[mid]
if guess < item:
low = mid+1 #it's not mid, so we d... | true |
cd70df45ab8f7635e3e4d4ae38fed02e8bab4e51 | oluyalireuben/python_workout | /session_one.py | 1,398 | 4.25 | 4 | # getting started
print("Hello, World!")
# syntax
if 5 > 2:
print("Five is greater than two")
# Variables
x = 23
y = 45
print(x + y)
a = "python "
b = "is "
c = "awesome"
print(a + b + c)
u = "I like "
j = "Codding "
k = "with python language"
print(u + j + k)
# python numbers and strings
h = "Welcome to eMobi... | true |
090435b9cf27a02233288045250d90f4181f4b9b | Maciejklos71/PythonLearn | /Practice_python/palidrom.py | 635 | 4.4375 | 4 | #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 palidrom(string):
string = string.lower().replace(" ","")
for i in range(0,len(string)):
if string[i]==string[-i-1]:
if i ==... | true |
692d14e3fea32a798eb19731e5d2b214fa40dcdc | robado/automate-the-boring-stuff-with-python | /2. Flow Control/5. If, Else, and Elif Statements.py | 1,216 | 4.1875 | 4 | # if statement
name = 'Alice'
if name == 'Alice':
print('Hi Alice')
print('Done')
# Hi Alice
# Done
# if name is other than Alice than the output will beDone
# else statement
password = 'swordfish'
if password == 'swordfish':
print('Access granted.')
else:
print('Wrong password.')
# If password is swordfis... | true |
dd109d0231382f4680d93159ac106fe0f9d2e0b0 | scarletgrant/python-programming1 | /p9p1_cumulative_numbers.py | 593 | 4.375 | 4 | '''
PROGRAM
Write a program that prompts the user for a positive integer and uses a
while loop to calculate the sum of the integers up to and including that number.
PSEUDO-CODE
Set and initialize number to zero
Set and initialize total to zero
Prompt user for first positive integer
While number => 0:
total += numb... | true |
340b1481b39b4ed272b3bd09ad648f933570e7de | scarletgrant/python-programming1 | /p8p3_multiplication_table_simple.py | 415 | 4.3125 | 4 | '''
PROGRAM p8p3
Write a program that uses a while loop to generate a simple multiplication
table from 0 to 20.
PSEUDO-CODE
initialize i to zero
prompt user for number j that set the table size
while i <= 20:
print(i, " ", i*j)
increment i+=1
print a new line with print()
'''
i = 0
j = int(input("Please... | true |
3bfb8410e8a4e2b498ed3387833a74ed905088e3 | scarletgrant/python-programming1 | /p10p1_square_root_exhaustive_enumeration.py | 1,305 | 4.25 | 4 | '''
PROGRAM
Write a program that prompts the user for an integer and performs exhaustive
enumeration to find the integer square root of the number. By “exhaustive enumeration”,
we mean that we start at 0 and succcessively go through the integers, checking whether
the square of the integer is equal to the number entered... | true |
707e0ea61e1f821b44b7225c5e287a6645a04815 | LucaDev13/hashing_tool | /hashing/hash_text.py | 1,252 | 4.1875 | 4 | from algoritms import sha1_encryption, sha224_encryption, sha256_encryption, sha512_encryption, md5_encryption, \
sha3_224_encryption
print("This program works with hashlib library. It support the following algorithms: \n"
"sha1, sha224, sha256, sha512, md5, sha3_224\n")
print("In order to use this program ... | true |
47208a23d4ea29f0ad4cf605d0ded3aa4c4ca495 | tripaak/python | /Practice_Files/cube_finder.py | 638 | 4.1875 | 4 | # Execercise
# Define a Function that takes a number
# return a dictionary containing cubes of number from 1 to n
# example
# cube_finder(3)
# {1:1, 2:8, 3:27}
####### First approach
# def cube_finder(input_number):
# dNumb = {}
# for j in range(1,input_number + 1):
# vCube = 1
# for i in... | true |
e8f93243c5fdb8b236abf3defd638a338884ca14 | vibhor-shri/Python-Basics | /controlflow/Loops.py | 400 | 4.34375 | 4 | separator = "============================"
print("Loops in python")
print("There are 2 types of loops in python, for loops and while loop")
print(separator)
print()
print()
print("A for loop, is used to iterate over an iterable. An iterable is an object which returns one of it's elements "
"at a time")
cities =... | true |
3817df8619e45824b2a425b5e2768bd6d8989b40 | curtisjm/python | /personal/basics/functions.py | 1,210 | 4.46875 | 4 | # declare a function
def my_function():
print("Hello from a function")
# call a function
my_function()
# arbitrary arguments
# if you do not know how many arguments that will be passed into your function,
# add a * before the parameter name in the function definition
# this way the function will receive a tuple of ... | true |
7de2665bd9b5d91fab286fd7b09c4172d85363ad | curtisjm/python | /personal/basics/inheritance.py | 1,890 | 4.5625 | 5 | # create a parent class
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
x = Person("John", "Doe")
x.printname()
# to create a class that inherits the functionality from another class,
# send the parent cla... | true |
f0c27da11efe0dfda2bc81b296bedfdc64303b2b | chettayyuvanika/Questions | /Easy/Pascals_Triangle_Problem.py | 1,236 | 4.28125 | 4 | # Problem Name is Pascals Triangle PLEASE DO NOT REMOVE THIS LINE.
"""
/*
** The below pattern of numbers are called Pascals Triangle.
**
** Pascals Triangle exhibits the following behaviour:
**
** The first and last numbers of each row in the triangle are 1
** Each number in the triangle is the sum of t... | true |
0311c673ba64df27b3acf07c4ade56ebbc823a87 | chettayyuvanika/Questions | /Medium/Best_Average_grade_Problem.py | 1,820 | 4.1875 | 4 | # Problem Name is &&& Best Average Grade &&& PLEASE DO NOT REMOVE THIS LINE.
"""
Instructions:
Given a list of student test scores, find the best average grade. Each student may have more than one test score in the list.
Complete the bestAverageGrade function in the editor below. It has one parameter, scores, ... | true |
ec304864d363af08d7245df034c786523674b85d | kornel45/basic_algorithms | /quick_sort.py | 533 | 4.15625 | 4 | #!/usr/bin/python
import random
def quick_sort(lst):
"""Quick sort algorithm implementation"""
if len(lst) < 2:
return lst
pivot = lst[random.randint(0, len(lst) - 1)]
left_list = []
right_list = []
for val in lst:
if val < pivot:
left_list.append(val)
elif ... | true |
a7faa8c5043ecf8405c113f3ef1b7e21bc690dc9 | TarSen99/python3 | /lab7_3.py | 1,163 | 4.3125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def UI_input_string() -> str:
'''Function input string'''
checkString = input("Enter some string ")
return checkString
def UI_print_result(result: bool):
'''Print result'''
if result:
print("String is correct")
else:
print("String is NOT correct")
... | true |
875bb31378cf1de15998763dc39d985c906bd6d3 | TarSen99/python3 | /lab8_2.py | 758 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
def set_size() -> int:
'''inputs size'''
size = int(input("Enter size of list "))
return size
def print_sorted(currList: list):
'''print sorted list'''
print(currList)
def generate_list(size: int) -> list:
'''generate list'''
cu... | true |
a51cbcf803b13929c0737ba36c30c2a189ec650b | TarSen99/python3 | /lab52.py | 552 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
print('Enter 2 dimensions of the door')
width = int(input())
height = int(input())
print('Enter 3 dimensions of the box')
a = int(input())
b = int(input())
c = int(input())
exist = False
if (width > a and height > b) or (width > b and height > a):
exist = True
el... | true |
9a1ddd72238f9b770e0e6754f82a6d1348ab757a | SakiFu/sea-c28-students | /Students/SakiFu/session03/pseudocode.py | 991 | 4.3125 | 4 |
#!/usr/bin/env python
This is the list of donors
donor_dict = {'Andy': [10, 20, 30, 20], 'Brian': [20, 40, 30],
'Daniel': [30, 40,10, 10, 30]}
prompt the user to choose from a menu of 2 actions: 'Send a Thank You' or 'Create a Report'.
If the user chose 'Send a Thank You'
Prompt for a Full Name.
... | true |
ad43d34ca563c60c7987d0a02de482407b558d99 | liberdamj/Cookbook | /python/ShapesProject/shape/circle.py | 948 | 4.1875 | 4 | # Circle Class
import math
class Circle:
# Radius is passed in when constructor called else default is 5
def __init__(self, radius=5):
self.radius = radius
self.circumference = (2 * (math.pi * self.radius))
self.diameter = (radius * 2)
self.area = (math.pi * (radius * radius))
... | true |
ff46a43fbb377a07fc38ecf781220c6cf1cad33d | klbinns/project-euler-solutions | /Solutions/Problem09.py | 546 | 4.25 | 4 | from math import floor
'''
Problem 9:
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
a**2 + b**2 = c**2
For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
'''
s = 1000
a = 3
... | true |
00069652dcb1d3adab681230ee43147a97f8b831 | nmasamba/learningPython | /23_list_comprehension.py | 819 | 4.5 | 4 |
"""
Author: Nyasha Masamba
Based on the lessons from Codecademy at https://www.codecademy.com/learn/python
This Python program is an example of Python's expressiveness. Less is more when it
comes to true Pythonic code, and list comprehensions prove that. A list comprehension
is an easy way of automatically creatin... | true |
2c0d1241ef7354776f28dbf02587b1c3ef705942 | nmasamba/learningPython | /22_iteration.py | 1,121 | 4.5 | 4 |
"""
Author: Nyasha Pride Masamba
Based on the lessons from Codecademy at https://www.codecademy.com/learn/python
This Python program shows a way to iterate over tuples, dictionaries and strings.
Python includes a special keyword: in. You can use in very intuitively, like below.
In the example, first we create and i... | true |
e88c2d3097b8f1eda62acb39223f4c5e2848a96b | nmasamba/learningPython | /14_anti_vowel.py | 849 | 4.25 | 4 |
"""
Author: Nyasha Pride Masamba
Based on the lessons from Codecademy at https://www.codecademy.com/learn/python
This Python program is an example of modularity, encapsulation and algorithmic thinking.
It is simply a function that takes a string text as input. It will then return that string
without any vowels. No... | true |
c1e5a23c822dc77349e3ffd91817d59e71dd62f8 | nmasamba/learningPython | /20_remove_duplicates.py | 589 | 4.25 | 4 |
"""
Author: Nyasha Pride Masamba
Based on the lessons from Codecademy at https://www.codecademy.com/learn/python
This Python program is an example of modularity, encapsulation and algorithmic thinking.
It is simply a function that takes in a list of integers. It will then remove elements
of the list that are the ... | true |
248a46e01c23a9a818ca88afc3e78b0f9e85269b | amitagrahari2512/PythonBasics | /Numpy_Array_ShallowAndDeepCopy.py | 1,376 | 4.21875 | 4 | from numpy import *
print("Copy of array")
arr1 = array([1,2,3,4,5])
arr2 = arr1
print(arr1)
print(arr2)
print("Both address is same")
print(id(arr1))
print(id(arr2))
print("------------------------------Shallow Copy------------------------------------------------")
print("So we can use view() method , so it will g... | true |
c388cc4fb91fd3b4e4d568f9b8dcfebdffc9319e | ryanhake/python_fundamentals | /02_basic_datatypes/2_strings/02_09_vowel.py | 533 | 4.3125 | 4 | '''
Write a script that prints the total number of vowels that are used in a user-inputted string.
CHALLENGE: Can you change the script so that it counts the occurrence of each individual vowel
in the string and print a count for each of them?
'''
def isvowel(c):
return (c == "a") or (c == "e") or (c... | true |
16d8884b52f368d613c1c75b7965f116678001ae | ryanhake/python_fundamentals | /10_testing/10_02_tdd.py | 1,171 | 4.375 | 4 | '''
Write a script that demonstrates TDD. Using pseudocode, plan out a couple simple functions. They could be
as simple as add and subtract or more complex such as functions that read and write to files.
Instead of writing out the functions, only provide the tests. Think about how the functions might
fail and write te... | true |
4c0960015e4ebfe69e5e06a30c0c0c0223f7979d | DesireeMcElroy/hacker_rank_challenges | /python_exercises.py | 2,383 | 4.21875 | 4 | # Python exercises
# If-Else
# Task
# Given an integer, , perform the following conditional actions:
# If is odd, print Weird
# If is even and in the inclusive range of to , print Not Weird
# If is even and in the inclusive range of to , print Weird
# If is even and greater than , print Not Weird
# Input Fo... | true |
f8cd504dd44ff54de0c85010baced9f3b202c051 | prathameshkurunkar7/common-algos-and-problems | /Math and Logic/Prime Number/Prime.py | 378 | 4.21875 | 4 | def isPrime(number):
if number == 1 or number == 0:
return False
limit = (number // 2) + 1
for i in range(2, limit):
if number % i == 0:
return False
return True
if __name__ == "__main__":
number = int(input("Enter a number: "))
print("Entered number is", ... | true |
5f3def601254e9e873f48b1ec47153f6d1abc00e | seige13/SSW-567 | /HW-01/hw_01_chris_boffa.py | 1,044 | 4.3125 | 4 | """
# equilateral triangles have all three sides with the same length
# isosceles triangles have two sides with the same length
# scalene triangles have three sides with different lengths
# right triangles have three sides with lengths, a, b, and c where a2 + b2 = c2
"""
def classify_triangle(side_a, side_b, side_c):... | true |
308e92c4dc6f53a773e2e8320463fdb7eb0925b4 | manpreet1994/topgear_python_level2 | /q5.py | 2,347 | 4.5625 | 5 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 12:16:54 2020
@author: manpreet
python assignment level 2
Level 2 assignment:
-------------------
program 1:
write a python program using regex or by any other method to check
if the credit card number given is valid or invalid. your python ... | true |
191d92772eb8464c5fa2a9e37298ae1911b2c2f2 | cnastoski/Data-Structures | /Hybrid Sort/HybridSort.py | 2,482 | 4.65625 | 5 | def merge_sort(unsorted, threshold, reverse):
"""
Splits a list in half until it cant anymore, then merges them back together in order
:param unsorted: the unsorted list
:param threshold: if the list size is at or below the threshold, switch to insertion sort
:param reverse: sorts the list in descen... | true |
a83cb5b5cab2973aa697cab221e20aaf3bea570e | ksemele/coffee_machine | /coffee_machine.py | 2,235 | 4.125 | 4 | class CoffeeMachine:
def __init__(self):
self.water = 400
self.milk = 540
self.beans = 120
self.cups = 9
self.money = 550
def status(self):
print("\nThe coffee machine has:")
print(str(self.water) + " of water")
print(str(self.milk) + " of milk")
print(str(self.beans) + " of coffee beans")
print(... | true |
2ca25165a87b7a7360d35e86b519469f9606da1f | Mahiuha/RSA-Factoring-Challenge | /factors | 1,887 | 4.34375 | 4 | #!/usr/bin/python3
"""
Factorize as many numbers as possible into a product of two smaller numbers.
Usage: factors <file>
where <file> is a file containing natural numbers to factor.
One number per line
You can assume that all lines will be valid natural numbers\
greater tha... | true |
1a7ef6b488b6ce7e7a592d8dbeac6625547ea0fc | rdasxy/programming-autograder | /problems/CS101/0035/solution.py | 350 | 4.21875 | 4 | # Prompt the use to "Enter some numbers: "
# The user should enter a few numbers, separated by spaces, all on one line
# Sort the resulting sequence, then print all the numbers but the first two and the last two,
# one to a line.
seq = raw_input("Enter some numbers: ")
seq = [int(s) for s in seq.split()]
seq.sort()
fo... | true |
f3213933c26dc79928dfb3be5323cec7977b2884 | dasdachs/smart | /08/python/to_lower.py | 384 | 4.28125 | 4 | #! /usr/bin/env python2
# -*- coding: utf-8 -*-
"""Return the input text in lower case."""
import argparse
parser = argparse.ArgumentParser(description='Transforms text to lower case.')
parser.add_argument('text', type=str, nargs="+", help='Text that will be transformed to lower case.')
args = parser.parse_args()
if... | true |
715df80224d4637c68ccf079bf8903df7c50206e | dasdachs/smart | /10/python/game.py | 867 | 4.125 | 4 | def main():
country_capital_dict = {"Slovenia": "Ljubljana", "Croatia": "Zagreb", "Austria": "Vienna"}
while True:
selected_country = country_capital_dict.keys()[0]
guess = raw_input("What is the capital of %s? " % selected_country)
check_guess(guess, selected_country, country_capital... | true |
f1337838af3d2dafe14302b84ac07870d7409029 | magnuskonrad98/max_int | /FORRIT/timaverkefni/27.08.19/prime_number.py | 341 | 4.15625 | 4 | n = int(input("Input a natural number: ")) # Do not change this line
# Fill in the missing code below
divisor = 2
while divisor < n:
if n % divisor == 0:
prime = False
break
else:
divisor += 1
else:
prime = True
# Do not changes the lines below
if prime:
print("Prime")
else:
... | true |
8fa2839f5c02e9c272f21e437caa8e2ab7f4f2c9 | TedYav/CodingChallenges | /Pramp/python/flatten_dict.py | 1,137 | 4.125 | 4 | """
Time Complexity: O(n) based on number of elements in dictionary
1. allocate empty dictionary to store result = {}
2. for each key in dictionary:
call add_to_output(key,value,result)
add_to_output(prefix,value,result)
- if value is dict:
for each key in dict, call add_... | true |
b600abf744c3dbb8abbaa694f1df0516847b1cab | lucianopereira86/Python-Examples | /examples/error_handling.py | 661 | 4.15625 | 4 | # Division by zero
x = 1
y = 0
try:
print(x/y)
except ZeroDivisionError as e:
print('You must NOT divide by zero!!!')
finally:
print('This is a ZeroDivisionError test')
# Wrong type for parsing
a = 'abc'
try:
print(int(a))
except ValueError as e:
print('Your string cannot to be parsed to int')
fina... | true |
b85fd57a82d8cd32671f1f7c6cfe05659d182cf0 | mydopico/HackerRank-Python | /Introduction/division.py | 539 | 4.1875 | 4 | # Task
# Read two integers and print two lines. The first line should contain integer division, aa//bb. The second line should contain float division, aa/bb.
# You don't need to perform any rounding or formatting operations.
# Input Format
# The first line contains the first integer, aa. The second line contains the ... | true |
57ba583649fdb78dfd5afdad714e2b9bd72ea363 | nini564413689/day-3-2-exercise | /main.py | 546 | 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 👇
BMI = round (weight / height ** 2,1)
if BMI < 18.5:
result = "You are underweight."
elif BMI < 25:
result ... | true |
9cd8f10f326504cf9a46d47048fcf3c25d2df827 | chaithra-yenikapati/python-code | /question_08.py | 1,356 | 4.21875 | 4 | __author__ = 'Chaithra'
notes = """
This is to make you familiar with linked list structures usage in python
see the listutils.py module for some helper functions
"""
from listutils import *
#Given sorted list with one sublist reversed,
#find the reversed sublist and correct it
#Ex: 1->2->5->4->6-... | true |
c18b622285056b2305b06fa34624e566826b2f19 | asbabiy/programming-2021-19fpl | /shapes/reuleaux_triangle.py | 1,435 | 4.1875 | 4 | """
Programming for linguists
Implementation of the class ReuleauxTriangle
"""
import math
from shapes.shape import Shape
class ReuleauxTriangle(Shape):
"""
A class for Reuleaux triangles
"""
def __init__(self, uid: int, width: int):
super().__init__(uid)
self.width = width
def... | true |
95058a6355a18b7a0ce81c9671e8e102ce194ac0 | bhanugudheniya/Python-Program-Directory | /CWH_Program_Practice_DIR/CH6_ConditionalExpression_PositiveIntegerCheck.py | 229 | 4.28125 | 4 | userInput = int(input("Enter Number: "))
if userInput > 0:
print(userInput, "is a positive integer")
elif userInput < 0:
print(userInput, "is a negative integer")
else:
print("Nor Positive and Nor Negative Integer, it's Zero") | true |
f4eb7877a49cca45074124096ace75dd5e89b72f | bhanugudheniya/Python-Program-Directory | /CWH_Program_Practice_DIR/CH5_DictionaryAndSets_DeclarationAndInitialization.py | 499 | 4.15625 | 4 | student = {
"name" : "bhanu",
"marks" : 99,
"subject" : "CS",
# "marks" : 98 # always print last updated value
}
print(student) # print whole dictionary
print(student["name"]) # print value of key "name"
print(len(student)) # print dictionary length
print(type(student)) # data types
# Access Dicti... | true |
a528a47e1d7c6c1c861e9128c43db7a6645ff453 | bhanugudheniya/Python-Program-Directory | /PythonHome/Input/UserInput_JTP.py | 705 | 4.25 | 4 | name = input("Enter name of student : ")
print("Student name is : ", name)
# 'name' is variable which store value are stored by user
# 'input()' is function which is helps to take user input and string are written in this which is as it is show on screen
# -------------------------------------------------------------... | true |
141b1eafcfbdbd8324b7f5004774ea9c3a2986e8 | gmaldona/Turtles | /runGame.py | 2,561 | 4.21875 | 4 | import turtle
import random
from tkinter import *
import time
### Class for each player object
class Player:
## Starting y coordinate
y = -250
## Initialing variables
def __init__(self, vMin, vMax, color):
self.player = turtle.Turtle()
self.player.showturtle()
self.pla... | true |
0aa3a7fddbe66a9fb10a00f251c5bc0519267e19 | Code-Law/Ex | /BYFassess.py | 2,097 | 4.15625 | 4 | def Student():
Student_num = int(input("please input your student number:"))
while Student_num < 4990 or Student_num > 5200:
Student_num = int(input("your student number is out of range, please input again!"))
while Student_num in Student_Numbers:
Student_num = int(input("this student number... | true |
43624ddb794cc122bf493cbb055169b042824d1b | michaelmnicholl/reimagined-train | /module_grade_program.py | 555 | 4.21875 | 4 | marks = [0,55,47,67]
lowest = marks[0]
mean = 0
if len(marks) < 3:
print("Fail")
print("Your score is below the threshold and you have failed the course")
exit()
for item in marks:
if item < lowest:
lowest = item
for item in marks:
mean = mean + item
mean = mean - lowest
mean ... | true |
1b5f0832809513821db10e2be39737d60209ea5f | braxtonphillips/SDEV140 | /PhillipsBraxtonM02_Ch3Ex12.py | 2,041 | 4.46875 | 4 | #Braxton Phillips
#SDEV 140
#M02 Chapter 3 Exercise 12
#This purpuse of this program is to calculate the amount a discount,
# if any, based on quantity of packages being purchased.
print('Hello, this progam will read user input to determine if a discount is applicable based on order quantity.')
packageQuantity ... | true |
4e31d151c7d8d2246a42e286263ae5af2cd87cb4 | nanihari/regular-expressions | /lower with __.py | 394 | 4.40625 | 4 | #program to find sequences of lowercase letters joined with a underscore.
import re
def lower_with__(text):
patterns="^[a-z]+_[a-z]+$"
if re.search(patterns,text):
return ("found match")
else:
return ("no match")
print(lower_with__("aab_hari"))
print(lower_with__("hari_krishna"))
p... | true |
e15765c217cc41d624aa18e1fb54d7490fde49ff | nanihari/regular-expressions | /replace_space_capital.py | 270 | 4.1875 | 4 | #program to insert spaces between words starting with capital letters.
import re
def replace_spaceC(text):
return re.sub(r"(\w)([A-Z])", r"\1 \2", text)
print(replace_spaceC("HariKrishna"))
print(replace_spaceC("AnAimInTheLifeIsTheOnlyFortuneWorthFinding"))
| true |
809214d38526ab39fa2026b0c05525ae34aaebde | nanihari/regular-expressions | /remove numbers.py | 278 | 4.375 | 4 | ##program to check for a number at the end of a string.
import re
def check_number(string):
search=re.compile(r".*[0-9]$")
if search.match(string):
return True
else:
return False
print(check_number("haari00"))
print(check_number("hari"))
| true |
50929ea4cbf1a0ca13d4a9054c577055e71bb196 | ar1ndamg/algo_practice | /3.sorting_algos.py | 1,533 | 4.5 | 4 | def insertion_sort(arr: list):
""" Takes an list and sorts it using insertion sort algorithm """
l = len(arr)
#print(f"length: {l}")
for i in range(1, l):
key = arr[i]
j = i-1
while j >= 0:
if key < arr[j]:
# slide the elements what are greater than th... | true |
0c6e89d23d913a1234d8bcd95de548b6a5bd6a62 | hariprasadraja/python-workspace | /MoshTutorial/basics.py | 2,268 | 4.28125 | 4 | import math
"""
Tutorial: https://www.youtube.com/watch?v=_uQrJ0TkZlc&t=7729s
"""
course = 'Python learning tutorial'
print(course[0:-3])
print("Another variable: ")
another = course[:]
print(another)
# works only on python > 3.6
# formated_string = (f'this is an another course')
# print(formated_string)
print(le... | true |
ba785abefc90c1d15878514b9d93be99c7383f4f | Ankush-Chander/euler-project | /9SpecialPythagoreanTriplet.py | 539 | 4.28125 | 4 | '''
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
'''
import sys
import os
if len(sys.argv) != 2:
print("Usage: python " + sys... | true |
1df7dca01c15594555d5b19f63c50049229a4b05 | rudrasingh21/Python---Using-Examples | /27. Dict - Given Key Exists in a Dictionary or Not.py | 247 | 4.125 | 4 | # Given Key Exist in a Dictionary or Not
d={'A':1,'B':2,'C':3}
k = input("Enter Key which you want to search:- ")
if k in d.keys():
print("Value is present and value for the Key is:- ", d[k])
else:
print("Key is not present")
| true |
6958f52980d417abfb01324cebe6f4b6cf452eb3 | rudrasingh21/Python---Using-Examples | /11.Count the Number of Digits in a Number.py | 271 | 4.125 | 4 | #Count the Number of Digits in a Number
'''
n=int(input("Enter number: "))
s = len(str(n))
print(s)
'''
n=int(input("Enter number: "))
count = 0
while(n>0):
count=count+1
n=n//10
print("The number of digits in the number are: ",count)
| true |
26ecc9df30d13fbeabe16387bfcf5dd79b3ee02d | rudrasingh21/Python---Using-Examples | /25. Dict - Add a Key-Value Pair to the Dictionary.py | 278 | 4.25 | 4 | #Add a Key-Value Pair to the Dictionary
n = int(input("Enter number of Element you want in Dictionary:- "))
d = {}
for i in range(1,n+1):
Key = input("Enter Key : ")
Value = input("Enter Value : ")
d.update({Key:Value})
print("Updated Dictonary is: ",d) | true |
d063654808224d54d7ee8c41d6019dab24b458ac | arjun-krishna1/leetcode-grind | /mergeIntervals.py | 2,766 | 4.34375 | 4 | '''
GIVEN
INPUT
intervals: intervals[i] = [start of i'th interval, end of i'th interval]
merge all overlapping intervals
OUTPUT
return an array of the non-overlapping intervals that cover all the intervals in the input
EXAMPLE
1:
intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]
already sorted
the end of intervals[0] i... | true |
826a3993e35aece4c19e88969dd44439fc86b969 | ericdasse28/graph-algorithms-implementation | /depth-first-search.py | 1,334 | 4.3125 | 4 | """
Python3 program to print DFS traversal
from a given graph
"""
from collections import defaultdict
# This class represents a directed graph using
# adjacency list representation
class Graph:
def __init__(self):
# Default dictionary to store graph
self.graph = defaultdict(list)
def add_ed... | true |
d86d291ac0a1a21683cd70d4a23bed601a90262a | DeveloperJoseph/PYTHON---DE---0---10000 | /Modulo 1/appBirthday.py | 705 | 4.25 | 4 | dictionary = {}
while True:
print("--- APP BIRTHDAY ---")
print(">>(1) Show birthdays")
print(">>(2) Add to Birthday list")
print(">>(3) Exit")
choice = int(input("Enter the choice: "))
if choice == 1:
if(len(dictionary.keys()))==0:
print("Nothing to show..")
else:
... | true |
29c5eaa6897dbbbb6d3cbfe9d868c5110992366b | DeveloperJoseph/PYTHON---DE---0---10000 | /Modulo 1/ejercicio24.py | 2,464 | 4.34375 | 4 | ## PYTHON JSON ##
# - JSON is a syntax for storing and exchanging data.
# - JSON is text, written with Javascript object notation.
# JSON IN PYTHON:
#Python has built-in package called json, which can be use
#to work with JSON data.
#Example:
# Import the json module:
import json
#Parse JSON - Convert from JSON t... | true |
39773f7d4aa077701cbb9b8bd826f63c5b6169a4 | DeveloperJoseph/PYTHON---DE---0---10000 | /Modulo 3 - File Handling/writeFiles.py | 1,040 | 4.65625 | 5 | # PYTHON FILE WRITE #
#Create a new File:
# To create a new file in Python, use the open() method, with one of the
# following parameter:
# "x" - Create - will create a file, returns an error if the file exist
# "a" - Append - will create a file if the specified file does not exist
#Example:
# Cre... | true |
429f9f55f17d32174ab5c856728622926b38c861 | juanmunoz00/python_classes | /ej_validate_user_input.py | 829 | 4.40625 | 4 | ##This code validates if the user's input is a number, it's type or it's a string
##So far no library's needed
##Method that performs the validation
def ValidateInput(user_input):
try:
# Verify input is an integer by direct casting
is_int = int(user_input)
print("Input is an integer: ", is_... | true |
626dc70789de6e61963051996357f3ba6aae42e6 | noisebridge/PythonClass | /instructors/course-2015/errors_and_introspection/project/primetester4.py | 1,242 | 4.46875 | 4 | """
For any given number, we only need to test the primes below it.
e.g. 9 -- we need only test 1,2,3,5,7
e.g. 8 -- we need only test 1,2,3,5,7
for example, the number 12 has factors 1,2,3,6,12.
We could find the six factor but we will find the two factor first.
The definition of a composite number is that it is co... | true |
9c81264446ef2fd968208b79fd0d696409bb5f83 | noisebridge/PythonClass | /instructors/lessons/higher_order_functions/examples/closure1.py | 1,509 | 4.15625 | 4 | """
This example intentionally doesn't work.
Go through this code and predict what will happen, then run
the code.
The below function fixes i in the parent scope, which means
that the function 'f' 'gets updates' as i progresses through
the loop.
Clearly we need to somehow fix i to be contained in the local
scope for... | true |
f412f50e278ad7ba058891a8e463625155bffdfb | noisebridge/PythonClass | /instructors/projects-2015/workshop_100515/quick_sort.py | 1,124 | 4.1875 | 4 | """ Quick Sort
Implement a simple quick sort in Python.
"""
# we'll use a random pivot.
import random
def my_sorter(mylist):
""" The atomic component of recursive quick sort
"""
# we are missing a base case
if len(mylist) == 1:
return mylist
# do we need this?
if len(mylist) == 0:
... | true |
9db3cd6f2fbadcfa1e558ac85e38bb1129f163b2 | noisebridge/PythonClass | /instructors/lessons/functions_and_gens/examples/example0.py | 618 | 4.1875 | 4 | #Return the absolute value of the number x. Floats as well as ints are accepted values.
abs(-100)
abs(-77.312304986)
abs(10)
#Return True if any element of the iterable is true. If the iterable is empty, return False.
any([0,1,2,3])
any([0, False, "", {}, []])
#enumerate() returns an iterator which yields a tuple tha... | true |
3d7581fb9378298bd491df6a5f54063a659ae965 | PhuocThienTran/Learning-Python-During-Lockdown | /30DaysOfPython/chapter6/strings.py | 720 | 4.125 | 4 | word = "Ishini"
def backward(word):
index = len(word) - 1
while index >= 0:
print(word[index])
index -= 1
backward(word)
fruit = "apple"
def count(fruit, count):
count = 0
for letter in fruit:
if letter == "p":
count = count + 1
print("Amount of p:", count)
coun... | true |
b1d766d3d8a6a7635f7c928e085844594e0eb329 | PhuocThienTran/Learning-Python-During-Lockdown | /30DaysOfPython/chapter5/iteration.py | 1,479 | 4.3125 | 4 | import math
n = 5
while n > 0:
print(n)
n =- 1
print("Launched!")
while True:
line = input('> ')
if line == 'done':
break #this means if input is "done" -> break the while loop
print(line)
print('Done!')
while True:
usr_line = input('> ')
if usr_line[0] == '#':
continue #... | true |
ad1894bc97e870b14a06d8dd46bcc6ff9875cdb5 | rakshithvasudev/Datacamp-Solutions | /Recommendation Engines in Pyspark/How ALS works/ex16.py | 606 | 4.28125 | 4 | """
Get RMSE
Now that you know how to build a model and generate predictions, and have an evaluator to tell us how well it predicts ratings, we can calculate the RMSE to see how well an ALS model performed. We'll use the evaluator that we built in the previous exercise to calculate and print the rmse.
Instructions
100... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.