blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
a585ac1434cfc382a3d1f1f30850b36b4a0c3e35 | Millennial-Polymath/alx-higher_level_programming | /0x06-python-classes/5-square.py | 1,435 | 4.375 | 4 | #!/usr/bin/python3
""" Module 5 contains: class square """
class Square:
"""
Square: defines a square
Attributes:
size: size of the square.
Method:
__init__: initialialises size attribute in each of class instances
"""
def __init__(self, size=0):
self.__siz... | true |
944d8d7851bb5f27d6fc1e6d5b4043cacbb4e16a | beyzend/learn-sympy | /chapter3.py | 329 | 4.34375 | 4 | days = ["sunday", "monday", "tuesday", "wednesday", "thursday",
"friday", "saturday"]
startDay = 0
whichDay = 0
startDay = int(input("What day is the start of your trip?\n"))
totalDays = int(input("How many days is you trip?\n"))
whichDay = startDay + totalDays
print("The day is: {}".format(days[whichDay % len(... | true |
e1730b223bc66de92afdb0f2f857a1b617a43df9 | vivekdubeyvkd/python-utilities | /writeToFile.py | 462 | 4.40625 | 4 |
# create a new empty file named abc.txt
f = open("abc.txt", "x")
# Open the file "abc.txt" and append the content to file, "a" will also create "abc.txt" file if this file does not exist
f = open("abc.txt", "a")
f.write("Now the file has one more line!")
# Open the file "abc.txt" and overwrite the content of entire... | true |
191ce4a91dde400ff43493eea3a1b1a4f9ea08c9 | HaminKo/MIS3640 | /OOP/OOP3/Time1.py | 1,646 | 4.375 | 4 | class Time:
"""
Represents the time of day.
attributes: hour, minute, second
"""
def __init__(self, hour=0, minute=0, second=0):
self.hour = hour
self.minute = minute
self.second = second
def print_time(self):
print('{:02d}:{:02d}:{:02d}'.format(self.hour, self... | true |
04c359f3e674466994f258820239885690299c21 | HaminKo/MIS3640 | /session10/binary_search.py | 1,143 | 4.1875 | 4 | import math
def binary_search(my_list, x):
'''
this function adopts bisection/binary search to find the index of a given
number in an ordered list
my_list: an ordered list of numbers from smallest to largest
x: a number
returns the index of x if x is in my_list, None if not.
'''
pass
... | true |
fb16eda74a1e4ab4b412c9b206273839e3c8049c | jdogg6ms/project_euler | /p009/p9.py | 885 | 4.1875 | 4 | #!/usr/bin/env python
# Project Euler Problem #9
"""
A Pythagorean triplet is a set of three natural numbers.
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.
"""
from math import sqrt
def test_triplet(a,b,c):
re... | true |
0f8bc6d325c0e7af4cae255b3815e10be59148cb | utk09/open-appacademy-io | /1_IntroToProgramming/6_Advanced_Problems/10_prime_factors.py | 1,096 | 4.1875 | 4 | """
Write a method prime_factors that takes in a number and returns an array containing all of the prime factors of the given number.
"""
def prime_factors(number):
final_list = []
prime_list_2 = pick_primes(number)
for each_value in prime_list_2:
if number % each_value == 0:
final_lis... | true |
6ea5413956361c5ce26f70079caefca87f352112 | utk09/open-appacademy-io | /1_IntroToProgramming/6_Advanced_Problems/14_sequence.py | 1,120 | 4.46875 | 4 | """
A number's summation is the sum of all positive numbers less than or equal to the number. For example: the summation of 3 is 6 because 1 + 2 + 3 = 6, the summation of 6 is 21 because 1 + 2 + 3 + 4 + 5 + 6 = 21. Write a method summation_sequence that takes in a two numbers: start and length. The method should return... | true |
88f52244e93514f9bab7cbfb527c1505f298925b | utk09/open-appacademy-io | /1_IntroToProgramming/2_Arrays/2_yell.py | 481 | 4.28125 | 4 | # Write a method yell(words) that takes in an array of words and returns a new array where every word from the original array has an exclamation point after it.
def yell(words):
add_exclam = []
for i in range(len(words)):
old_word = words[i]
new_word = old_word + "!"
add_exclam.append(... | true |
ac6ddb7a5ff88871ed728cc8c90c54852658ce30 | utk09/open-appacademy-io | /1_IntroToProgramming/2_Arrays/12_sum_elements.py | 586 | 4.15625 | 4 | """
Write a method sum_elements(arr1, arr2) that takes in two arrays. The method should return a new array containing the results of adding together corresponding elements of the original arrays. You can assume the arrays have the same length.
"""
def sum_elements(arr1, arr2):
new_array = []
i = 0
while i... | true |
086ed855f74612d9ef8e28b2978ae7ffe5bf62f4 | Mzomuhle-git/CapstoneProjects | /FinanceCalculators/finance_calculators.py | 2,602 | 4.25 | 4 | # This program is financial calculator for calculating an investment and home loan repayment amount
# r - is the interest rate
# P - is the amount that the user deposits / current value of the house
# t - is the number of years that the money is being invested for.
# A - is the total amount once the interest has been a... | true |
4cbc8fddcb32ba425cbcbb2ff96f580384c8ddbb | rushabhshah341/Algos | /leetcode38.py | 1,397 | 4.21875 | 4 | '''The count-and-say sequence is the sequence of integers with the first five terms as following:
1. 1
2. 11
3. 21
4. 1211
5. 111221
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
Given an integer n, generate the nth term of the co... | true |
ca9c82e87d639e70de2ce6b214706617fb8f6a71 | JeterG/Post-Programming-Practice | /CodingBat/Python/String_2/end_other.py | 458 | 4.125 | 4 | #Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: s.lower() returns the lowercase version of a string
def end_other(a, b):
lA=len(a)
lB=len(b)
if ... | true |
f8b9bd890548a5d2b5fd2b60e23f68053b282097 | duongtran734/Python_OOP_Practice_Projects | /ReverseString.py | 625 | 4.5625 | 5 | # Class that has method that can reverse a string
class ReverseString:
# take in a string
def __init__(self, str=""):
self._str = str
# return a reverse string
def reverse(self):
reverse_str = ""
for i in range(len(self._str) - 1, -1, -1):
reverse_str += self._str[i... | true |
bd12113e4ca9a48b588c74d151d21373cdc9cfa1 | pwittchen/learn-python-the-hard-way | /exercises/exercise45.py | 875 | 4.25 | 4 | # Exercise 45: You Make A Game
'''
It's a very simple example of a "text-based game",
where you can go to one room or another.
It uses classes, inheritance and composition.
Of course, it can be improved or extended in the future.
'''
class Game(object):
def __init__(self):
self.kitchen = Kitchen()
self.livi... | true |
4186b70a8f55396abe0bbd533fe61b7e8819f14e | mprior19xx/prior_mike_rps_game | /functions.py | 919 | 4.34375 | 4 | # EXPLORING FUNCTIONS AND WHAT THE DO / HOW THEY WORK
#
# EVERY DEFINITION NEEDS 2 BLANK LINES BEFORE AND AFTER
#
def greeting():
# say hello
print("hello from your first function!")
# this is how you call / invoke a function
greeting()
def greetings(msg="hello player", num1=0):
# creating another func... | true |
53fcbf43171cfb5a3c38e05ee1c1d77d6b89a171 | jhmalpern/AdventOfCode | /Puzzles/Day5/Day5Solution.py | 2,238 | 4.1875 | 4 | # Imports
import time
from re import search
# From https://www.geeksforgeeks.org/python-count-display-vowels-string/
# Counts and returns number of vowels in a string
##### Part 1 functions #####
def Check_Vow(string, vowels):
final = [each for each in string if each in vowels]
return(len(final))
def Check_r... | true |
e7f9f4f92b756426ec8dfd9aa75eda62ef6f25f8 | ngthnam/Python | /Python Basics/18_MultiDimensional_List.py | 761 | 4.53125 | 5 | x = [2,3,4,6,73,6,87,7] # one dimensional list
print(x[4]) # single [] bracket to refer the index
x = [2,3,[1,2,3,4],6,73,6,87,7] # two dimensional list
print(x[2][1]) # using double [] to refer the index of list
x = [[2,3,[8,7,6,5,4,3,2,1]],[1,2,3,4],6,73,6,87,7] # three dimensional list
print(x[0][2][2]) # using t... | true |
73c8e86223f7de441517c9206ae526ef5365c664 | JonathanFrederick/what-to-watch | /movie_rec.py | 2,223 | 4.28125 | 4 | """This is a program to recommend movies based on user preference"""
from movie_lib import *
import sys
def get_int(low, high, prompt):
"""Prompts the player for an integer within a range"""
while True:
try:
integer = int(input(prompt))
if integer < low or integer > high:
... | true |
eced2979f93a7fe022bab64f1520480b7882bf10 | bishnu12345/python-basic | /simpleCalcualtor.py | 1,770 | 4.3125 | 4 | # def displayMenu():
# print('0.Quit')
# print('1.Add two numbers')
# print('2.Subtract two numbers')
# print('3.Multiply two numbers')
# print('4.Divide two numbers')
def calculate(num1,num2,operator):
result = 0
if operator=='+':
result = num1 + num2
if operator ... | true |
789ca9376e8a07fc228c109b4dddaaf796b55173 | skishorekanna/PracticePython | /longest_common_string.py | 1,093 | 4.15625 | 4 | """
Implement a function to determine the longest common string between
two given strings str1 and str2
"""
def check_common_longest(str1, str2):
# Make the small string as str1
if not len(str1)< len(str2):
str1, str2 = str2, str1
left_index=0
right_index=0
match_list = []
while ( left_... | true |
8b8471130787bf0c603dd98b79ac77848d72eda4 | Andrew-Lindsay42/Week1Day1HW | /precourse_recap.py | 277 | 4.15625 | 4 | user_weather = input("Whats the weather going to do tomorrow? ")
weather = user_weather.lower()
if weather == "rain":
print("You are right! It is Scotland after all.")
elif weather == "snow":
print("Could well happen.")
else:
print("It's actually going to rain.") | true |
7a03a57714a7e1e7c4be0d714266f119ffbe2667 | pankaj-raturi/python-practice | /chapter3.py | 1,086 | 4.34375 | 4 | #!/usr/bin/env python3
separatorLength = 40
lname = 'Raturi'
name = 'Pankaj ' + lname
# Get length of the string
length = len(name)
# String Function
lower = name.lower()
print (lower)
# * is repetation operator for string
print ( '-' * separatorLength)
# Integer Object
age = 30
# Convert Integers to string obj... | true |
8a3ad8eac1b92fcd869d220e1d41e19c65bf44d3 | MegaOktavian/praxis-academy | /novice/01-05/latihan/unpickling-1.py | 758 | 4.1875 | 4 | import pickle
class Animal:
def __init__(self, number_of_paws, color):
self.number_of_paws = number_of_paws
self.color = color
class Sheep(Animal):
def __init__(self, color):
Animal.__init__(self, 4, color)
# Step 1: Let's create the sheep Mary
mary = Sheep("white")
# Step 2:... | true |
ab88ff7a1b5ebad88c6934741a0582603b9313ea | bmschick/DemoProject | /Unit_1.2/1.2.1/Temp_1.2.1.py | 1,482 | 4.15625 | 4 | '''1.2.1 Catch-A-Turtle'''
'''Abstracting with Modules & Functions'''
# 0.1 How does the college board create a “function”?
# 0.2 What is “return”
# 1
# Quiz:
'''Events'''
#
#
'''Click a Turtle'''
# 2 through 14 (Make sure you comment the code!!):
# 14 Did you have any bugs throughout this section of cod... | true |
77244a8edec8f482e61cfe7cb2da857d989206cb | jesse10930/Similarities | /mario.py | 830 | 4.3125 | 4 | #allows us to use user input
from cs50 import get_int
#main function for the code
def main():
#assigns the user input into the letter n
while True:
n = get_int("Enter an integer between 1 and 23: ")
if n == 0:
return
elif n >= 1 and n <= 23:
break
#iterates ... | true |
2c55104e100681e13599c5e033a4750fc3c453d6 | gorkemunuvar/Data-Structures | /algorithm_questions/3_find_the_missing_element.py | 1,569 | 4.125 | 4 | # Problem: Consider an array of non-negative integers. A second array is formed by shuffling
# the elements of the first array and deleting a random element. Given these two arrays,
# find which element is missing in the second array.
import collections
# O(N)
# But this way is not work correctly cause
# arrays can h... | true |
e02442b00cf41f9d3dd1933bee6b63122225e3b6 | johnehunt/python-datastructures | /trees/list_based_tree.py | 1,441 | 4.1875 | 4 | # Sample tree constructed using lists
test_tree = ['a', # root
['b', # left subtree
['d', [], []],
['e', [], []]],
['c', # right subtree
['f', [], []],
[]]
]
print('tree', test_tree)
print('left subtree = ', test_tree[1])... | true |
070be4d1e2e9ebcdbff2f227ec97da5a83c45282 | johnehunt/python-datastructures | /abstractdatatypes/queue.py | 1,055 | 4.15625 | 4 | class BasicQueue:
""" Queue ADT
A queue is an ordered collection of items where
the addition of new items happens at one end,
called the “rear,” and the removal of existing
items occurs at the other end, commonly called
the “front.” As an element enters the queue it
starts at the rear and ma... | true |
ad133e4c54b80abf48ff3028f7c00db37a622ec5 | benwardswards/ProjectEuler | /problem038PanDigitMultiple.py | 1,853 | 4.21875 | 4 | """Pandigital multiples Problem 38
Take the number 192 and multiply it by each of 1, 2, and 3:
192 × 1 = 192
192 × 2 = 384
192 × 3 = 576
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)
The same can be achieved by starting with... | true |
1362ec74ae0c72c10bf26c69151e8d6c8d64105c | hopesfall23/Fizzbuzz | /fizzbuzz.py | 530 | 4.125 | 4 |
#William's Fizzbuzz program
n = 100 #Hard coded upper line
# "fizz" Divisible by 3
# "buzz" #Divisible by 5
#"Fizzbuzz" Divisible by 3 and 5
c = 0 #Current number, Will hold the value in our while loop and be printed
for c in range(0,n): #Will run this loop from 0 to 100 then terminate
if c <= n:
... | true |
447850fd37249fc7e61e435c8823d86a73c42512 | sprajjwal/CS-2.1-Trees-Sorting | /Code/sorting_iterative.py | 2,700 | 4.25 | 4 | #!python
def is_sorted(items):
"""Return a boolean indicating whether given items are in sorted order.
Running time: O(n) because we iterate through the loop once
Memory usage: O(1) because we check in place"""
# Check that all adjacent items are in order, return early if so
if len(items) < 2:
... | true |
cf33043df637dff1470547b466ded6b71d4cd434 | nightphoenix13/PythonClassProjects | /FinalExamQuestion31.py | 1,412 | 4.125 | 4 | def main():
month = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"]
highs = [0] * 12
lows = [0] * 12
for temps in range(len(month)):
highs[temps] = int(input("Enter the highest temperature for " +
... | true |
f6076d80cbf22a0af11337a6a329fe64df60477e | Allaye/Data-Structure-and-Algorithms | /Linked List/reverse_linked_list.py | 615 | 4.3125 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
from linked_list import LinkedList
L = LinkedList(10)
def reverse(L):
'''
reverse a linked list nodes, this reverse implementation made use of linked list implemented before
'''
lenght = L.length()
if(lenght == 0):
raise IndexError('The lis... | true |
edfba19244397e3c444e910b9650de1a855633b3 | Allaye/Data-Structure-and-Algorithms | /Stacks/balancedParen.py | 2,399 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
from Stack import Stack # personal implementation of stack using python list
# In[12]:
def check_balance(string, opening='('):
'''
a function to check if parenthesis used in a statement is balanced
this solution used a custom implementation of a stack u... | true |
cfcf85b40806e49c8cfaf1a51b78b1aa5c96ca18 | bislara/MOS-Simulator | /Initial work/input_type.py | 728 | 4.25 | 4 | name = raw_input("What's your name? ")
print("Nice to meet you " + name + "!")
age = raw_input("Your age? ")
print("So, you are already " + str(age) + " years old, " + name + "!")
#The input of the user will be interpreted. If the user e.g. puts in an integer value, the input function returns this integer value. If th... | true |
36906e07dd7a95969fcfbfb24bc566af77d6c290 | w0nko/hello_world | /parameters_and_arguments.py | 301 | 4.3125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 18:20:48 2017
@author: wonko
"""
def power(base, exponent): # Add your parameters here!
result = base ** exponent
print ("%d to the power of %d is %d.") % (base, exponent, result)
power(37, 4) # Add your arguments here! | true |
cc157edc908e4cb99ada1f2f4b880fa939d635cb | alojea/PythonDataStructures | /Tuples.py | 1,105 | 4.5 | 4 | #!/usr/bin/python
import isCharacterInsideTuple
import convertTupleIntoList
import addValueInsideTuple
alphabetTuple = ('a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
stringTuple = ""
for valueTuple in alphabetTuple:
stringTuple = ... | true |
c50d0f924ae516d9d6bab320cb1bb71cfc35d7a6 | nishantvyas/python | /unique_sorted.py | 1,603 | 4.15625 | 4 | """
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
Suppose the following input is supplied to the program:
hello world and practice makes perfect and hello world again
Then, the output should be:
a... | true |
589f077eb0b0080801f5dc3e7b4da8e3a4d1bf35 | applicationsbypaul/Module7 | /fun_with_collections/basic_list.py | 837 | 4.46875 | 4 | """
Program: basic_list.py
Author: Paul Ford
Last date modified: 06/21/2020
Purpose: uses inner functions to be able to
get a list of numbers from a user
"""
def make_list():
"""
creates a list and checks for valid data.
:return: returns a list of 3 integers
"""
a_list = []
for index ... | true |
726acce695d62e6d438f2abd93b1685daab8f95a | applicationsbypaul/Module7 | /Module8/more_fun_with_collections/dict_membership.py | 502 | 4.15625 | 4 | """
Program: dict_membership.py
Author: Paul Ford
Last date modified: 06/22/2020
Purpose: using dictionaries for the first time
"""
def in_dict(dictionary, data):
"""
accept a set and return a boolean value
stating if the element is in the dictionary
:param dictionary: The given dictionary to search
... | true |
8510a11490351504b7bf1707f5ba14318fae7240 | applicationsbypaul/Module7 | /Module8/more_fun_with_collections/dictionary_update.py | 1,563 | 4.28125 | 4 | """
Program: dictionary_update.py
Author: Paul Ford
Last date modified: 06/22/2020
Purpose: using dictionaries to gather
store and recall info
"""
def get_test_scores():
"""
Gathers test scores for a user and stores them
into a dictionary.
:return: scores_dict a dictionary of scores
"""
... | true |
97d812a9b932e9ae3d7db1726be2089627985347 | PikeyG25/Python-class | /forloops.py | 658 | 4.15625 | 4 | ##word=input("Enter a word")
##print("\nHere's each letter in your word:")
##for letter in word:
## print(letter)
## print(len(word))
##message = input("Enter a message: ")
##new_message = ""
##VOWELS = "aeiouy"
##
##for letter in message:
## if letter.lower() not in VOWELS:
## new_message+=letter
## ... | true |
6700dca221f6a0923ef9b5dbbf1ec56ab69b0671 | Reetishchand/Leetcode-Problems | /00328_OddEvenLinkedList_Medium.py | 1,368 | 4.21875 | 4 | '''Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.
You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.
Example 1:
Input: 1->2->3->4->5->N... | true |
56bb70f89a3b2e9fa203c1ee8d4f6f47ec71daf8 | Reetishchand/Leetcode-Problems | /00922_SortArrayByParityII_Easy.py | 924 | 4.125 | 4 | '''Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
Return any answer array that satisfies this condition.
Example 1:
Input: nums = [4,2,5,7]
Output: [4,5,2,7]
Explanat... | true |
5231912489a4f9b6686e4ffab24f4d4bc13f3a46 | Reetishchand/Leetcode-Problems | /00165_CompareVersionNumbers_Medium.py | 2,374 | 4.1875 | 4 | '''Given two version numbers, version1 and version2, compare them.
Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision ... | true |
8937e4cc7b216ba837dcbf3a326b2a75fb325cd0 | Reetishchand/Leetcode-Problems | /00690_EmployeeImportance_Easy.py | 1,800 | 4.1875 | 4 | '''You are given a data structure of employee information, which includes the employee's unique id, their importance value and their direct subordinates' id.
For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. They have importance value 15, 10 and 5, respectively. Then emplo... | true |
c0a23174b8c9d3021942781c960a21d2ad0699b5 | Reetishchand/Leetcode-Problems | /02402_Searcha2DMatrixII_Medium.py | 1,388 | 4.25 | 4 | '''Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties:
Integers in each row are sorted in ascending from left to right.
Integers in each column are sorted in ascending from top to bottom.
Example 1:
Input: matrix = [[1,4,7,11,15],[2,5,8,12... | true |
99202f99cbf5b47e4f294c8e0da826f993ac5d3b | Reetishchand/Leetcode-Problems | /00537_ComplexNumberMultiplication_Medium.py | 1,240 | 4.15625 | 4 | '''Given two strings representing two complex numbers.
You need to return a string representing their multiplication. Note i2 = -1 according to the definition.
Example 1:
Input: "1+1i", "1+1i"
Output: "0+2i"
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
Example 2:
In... | true |
68198c760cdb09b8e882088013830389b0b4d19d | Reetishchand/Leetcode-Problems | /00346_MovingAveragefromDataStream_Easy.py | 1,289 | 4.3125 | 4 | '''Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
Implement the MovingAverage class:
MovingAverage(int size) Initializes the object with the size of the window size.
double next(int val) Returns the moving average of the last size values of the stream.
... | true |
68f0b89631b89d1098932cd021cf579348d71004 | jaipal24/DataStructures | /Linked List/Detect_Loop_in_LinkedList.py | 1,388 | 4.25 | 4 | # Given a linked list, check if the linked list has loop or not.
#node class
class Node:
def __init__(self, data):
self.data = data
self.next = None
# linked list class
class LinkedList:
def __init__(self):
self.head = None
def push(self, data):
new_node = ... | true |
87f6078f3f99bd3c33f617e2b7b33143fed70369 | BonnieBo/Python | /第二章/2.18.py | 412 | 4.125 | 4 | # 计算时间
import time
currentTime = time.time()
print(currentTime)
totalSeconds = int(currentTime)
currentSeconds = totalSeconds % 60
totalMinutes = totalSeconds // 60
currentMinute = totalMinutes % 60
totalHours = totalMinutes // 60
currentHours = totalHours % 24
print("Current time is", currentHours, ":", currentMi... | true |
7b5b3ff7995758cb199808977015ea635a879309 | Farazi-Ahmed/python | /lab-version2-6.py | 288 | 4.125 | 4 | # Question 8 Draw the flowchart of a program that takes a number from user and prints the divisors of that number and then how many divisors there were.
a=int(input("Number? "))
c=1
d=0
while c<=a:
if a%c==0:
d+=1
print(c)
c+=1
print("Divisors in total: "+str(d)) | true |
03074b61771fa4e751fd84c97aac21e3a918fa35 | Farazi-Ahmed/python | /problem-solved-9.py | 326 | 4.4375 | 4 | # Question 9 : Draw flowchart of a program to find the largest among three different numbers entered by user.
x=int(input("Value of x: "))
y=int(input("Value of y: "))
z=int(input("Value of z: "))
if x>y and x>z:
print(x)
elif y>z and y>x:
print(y)
else:
print(z)
MaxValue = max(x,y,z)
print(Max... | true |
28f739f2ac311a56f42af138f8c3432a4e0620e9 | Farazi-Ahmed/python | /problem-solved-7.py | 303 | 4.375 | 4 | # Question 7: Write a flowchart that reads the values for the three sides x, y, and z of a triangle, and then calculates its area.
x=int(input("Value of x: "))
y=int(input("Value of y: "))
z=int(input("Value of z: "))
s = (x + y + z) / 2
area = ((s * (s-x)*(s-y)*(s-z)) ** 0.5)
print(area) | true |
519d04e843b4966f58d0d2ffc1e4a4596ef1ea09 | manand2/python_examples | /comprehension.py | 2,044 | 4.40625 | 4 | # list comprehension
nums = [1,2,3,4,5,6,7,8,9,10]
# I want 'n' for each 'n' in nums
my_list = []
for n in nums:
my_list.append(n)
print my_list
#list comprehension instead of for loop
my_list = [n for n in nums]
print my_list
# more complicated example
# I want 'n*n' for each 'n' in nums
my_list = [n*n for n i... | true |
37498e70f1550bd468c29f5b649075ce4254978d | chrishaining/python_stats_with_numpy | /arrays.py | 384 | 4.15625 | 4 | import numpy as np
#create an array
array = np.array([1, 2, 3, 4, 5, 6])
print(array)
#find the items that meet a boolean criterion (expect 4, 5, 6)
over_fives = array[array > 3]
print(over_fives)
#for each item in the array, checks whether that item meets a boolean criterion (expect an array of True/False, in this ... | true |
c0585d2d162e48dd8553ccfc823c3e363a2b28c0 | samson027/HacktoberFest_2021 | /Python/Bubble Sort.py | 416 | 4.125 | 4 | def bubblesort(array):
for i in range(len(array)):
for j in range(len(array) - 1):
nextIndex = j + 1
if array[j] > array[nextIndex]:
smallernum = array[nextIndex]
largernum = array[j]
array[nextIndex] = largernum
array[j... | true |
148418a17af55f181ecea8ffd5140ba367d7dc2d | youngdukk/python_stack | /python_activities/oop_activities/bike.py | 974 | 4.25 | 4 | class Bike(object):
def __init__(self, price, max_speed):
self.price = price
self.max_speed = max_speed
self.miles = 0
def displayInfo(self):
print("Bike's Price: ${}".format(self.price))
print("Bike's Maximum Speed: {} mph".format(self.max_speed))
print("Total ... | true |
52d35b2a21c30e5f35b1193b123f0b59a795fa17 | prefrontal/leetcode | /answers-python/0021-MergeSortedLists.py | 1,695 | 4.21875 | 4 | # LeetCode 21 - Merge Sorted Lists
#
# Merge two sorted linked lists and return it as a new sorted list. The new list should be
# made by splicing together the nodes of the first two lists.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def mergeTwoLists(l1: ... | true |
b1ff4822be75f8fffb11b8c2af5c64029a27a874 | prefrontal/leetcode | /answers-python/0023-MergeKSortedLists.py | 2,349 | 4.125 | 4 | # LeetCode 23 - Merge k sorted lists
#
# Given an array of linked-lists lists, each linked list is sorted in ascending order.
# Merge all the linked-lists into one sort linked-list and return it.
#
# Constraints:
# k == lists.length
# 0 <= k <= 10^4
# 0 <= lists[i].length <= 500
# -10^4 <= lists[i][j] <= 10^4
# lists[i... | true |
9348abc87c6ec5318606464dac6e792960a0bc0f | NNHSComputerScience/cp1ForLoopsStringsTuples | /notes/ch4_for_loops_&_sequences_starter.py | 1,795 | 4.78125 | 5 | # For Loops and Sequences Notes
# for_loops_&_sequences_starter.py
# SEQUENCE =
# For example: range(5) is an ordered list of numbers: 0,1,2,3,4
# ELEMENT =
# So far we have used range() to make sequences.
# Another type of sequence is a _________,
# which is a specific order of letters in a sequen... | true |
f0499de132924504b7d808d467e88af636eb5d27 | KindaExists/daily-programmer | /easy/3/3-easy.py | 1,057 | 4.21875 | 4 |
"""
[easy] challenge #3
Source / Reddit Post - https://www.reddit.com/r/dailyprogrammer/comments/pkw2m/2112012_challenge_3_easy/
"""
# This can most likely be done in less than 2 lines
# However still haven't figured a way to stop asking "shift" input
def encrypt(string, shift):
return ''.join([chr((((ord(char... | true |
d84ec922db8eeb84c633c868b5c440b5de7f9445 | gaogep/LeetCode | /剑指offer/28.二叉树的镜像.py | 1,116 | 4.125 | 4 | # 请完成一个函数,输入一棵二叉树,改函数输出它的镜像
class treeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
root = treeNode(1)
root.left = treeNode(2)
root.right = treeNode(3)
root.left.left = treeNode(4)
root.right.right = treeNode(5)
def showM... | true |
1e18b7a08b74e804774882603eabc30829622571 | pchandraprakash/python_practice | /mit_pyt_ex_1.5_user_input.py | 686 | 4.1875 | 4 | """
In this exercise, we will ask the user for his/her first and last name, and
date of birth, and print them out formatted.
Output:
Enter your first name: Chuck
Enter your last name: Norris
Enter your date of birth:
Month? March
Day? 10
Year? 1940
Chuck Norris was born on March 10, 1940.
"""
def userin... | true |
1e10d7f86e975ef682821785ebe59bc5e499d219 | J-pcy/Jffery_Leetcode_Python | /Medium/418_SentenceScreenFitting.py | 2,233 | 4.28125 | 4 | """
Given a rows x cols screen and a sentence represented by a list of non-empty words, find how many times the given sentence can be fitted on the screen.
Note:
A word cannot be split into two lines.
The order of words in the sentence must remain unchanged.
Two consecutive words in a line must be separated by a sing... | true |
c75df56aed95a3e74e0436c54ea4e22e669c395f | J-pcy/Jffery_Leetcode_Python | /Medium/75_SortColors.py | 2,518 | 4.25 | 4 | """
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the l... | true |
2d8491624e72ef82b1a1b7179dbc13bbbacb8ebb | juan-g-bonilla/Data-Structures-Project | /problem_2.py | 1,293 | 4.125 | 4 | import os
def find_files(suffix, path):
"""
Find all files beneath path with file name suffix.
Note that a path may contain further subdirectories
and those subdirectories may also contain further subdirectories.
There are no limit to the depth of the subdirectories can be.
Args:
suffi... | true |
31b93a072533214b5f1e592442d6072e1a83c01c | texrer/Python | /CIS007/Lab2/BMICalc.py | 658 | 4.40625 | 4 | #Richard Rogers
#Python Programming CIS 007
#Lab 2
#Question 4
#Body mass index (BMI) is a measure of health based on weight.
#It can be calculated by taking your weight in kilograms and dividing it by the square of your height in meters.
#Write a program that prompts the user to enter a weight in pounds and height i... | true |
ffbff41905680bde74a7d42f06d0aa90f55fca25 | yingwei1025/credit-card-checksum-validate | /credit.py | 1,333 | 4.125 | 4 | def main():
card = card_input()
check = checksum(card)
validate(card, check)
def card_input():
while True:
card_number = input("Card Number: ")
if card_number.isnumeric():
break
return card_number
def checksum(card_number):
even_sum = 0
odd_sum = 0
card_n... | true |
66f0ccab7057084061766ca23e21d790e829922b | irmowan/LeetCode | /Python/Binary-Tree-Maximum-Path-Sum.py | 1,307 | 4.15625 | 4 | # Time: O(n)
# Space: O(n)
# Given a binary tree, find the maximum path sum.
#
# For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path does not need to go through the root.
#
# For example:
# Given the below binary tree... | true |
9fe261707283f616194ebe30757a6381d500d534 | irmowan/LeetCode | /Python/Palindrome-Number.py | 1,065 | 4.125 | 4 | # Time: O(n)
# Space: O(1)
#
# Determine whether an integer is a palindrome. Do this without extra space.
#
# click to show spoilers.
#
# Some hints:
# Could negative integers be palindromes? (ie, -1)
#
# If you are thinking of converting the integer to string, note the restriction of using extra space.
#
# You could a... | true |
5f8c9db073643da16d88ef03512b4ca6e97d28ca | LinuxUser255/Python_Penetration_Testing | /Python_Review/dmv.py | 308 | 4.125 | 4 | #!/usr/bin/env python3
#If-else using user defined input:
print("""Legal driving age.
""")
age = int(input("What is your age? "))
if age < 16:
print("No.")
else:
if age in range(16, 67):
print("Yes, you are eligible.")
if age > 66:
print("Yes, but with special requirements.")
| true |
6361f4914c5a1570c9113a55222c139a9844efb2 | mihirbhaskar/save-the-pandas-intpython | /filterNearby.py | 973 | 4.125 | 4 | """
File: filterNearby
Description: Function to filter the dataframe with matches within a certain distance
Next steps:
- This function can be generalised, but for now assuming data is in a DF with lat/long columns named
'latitude' and 'longitude'
"""
import pandas as pd
from geopy.distance import distance
d... | true |
2096aed0b726883d89aae8c3d886ae5ef3b11518 | simplex06/HackerRankSolutions | /Lists.py | 1,683 | 4.3125 | 4 | # HackerRank - "Lists" Solution
#Consider a list (list = []). You can perform the following commands:
#
#insert i e: Insert integer at position .
#print: Print the list.
#remove e: Delete the first occurrence of integer .
#append e: Insert integer at the end of the list.
#sort: Sort the list.
#pop: Pop the last elem... | true |
492689343e28be7cdbb2d807514881925534a010 | SynTentional/CS-1.2 | /Coursework/Frequency-Counting/Frequency-Counter-Starter-Code/HashTable.py | 2,156 | 4.3125 | 4 | from LinkedList import LinkedList
class HashTable:
def __init__(self, size):
self.size = size
self.arr = self.create_arr(size)
# 1️⃣ TODO: Complete the create_arr method.
# Each element of the hash table (arr) is a linked list.
# This method creates an array (list) of a given size and populates eac... | true |
7f7c20e3c655b59fb28d90a5b7fec803d3b65170 | MrSmilez2/z25 | /lesson3/4.py | 272 | 4.125 | 4 | items = []
max_element = None
while True:
number = input('> ')
if not number:
break
number = float(number)
items.append(number)
if not max_element or number >= max_element:
max_element = number
print(items)
print('MAX', max_element)
| true |
a2ab21a48d07c3fe753681babeb8cfeea023038c | floryken/Ch.05_Looping | /5.2_Roshambo.py | 1,632 | 4.8125 | 5 | '''
ROSHAMBO PROGRAM
----------------
Create a program that randomly prints 1, 2, or 3.
Expand the program so it randomly prints rock, paper, or scissors using if statements. Don't select from a list.
Add to the program so it first asks the user their choice as well as if they want to quit.
(It will be easier if you h... | true |
f95a79a3a2d6c1718efb817cba7c8cb7072ce57f | goateater/SoloLearn-Notes | /SL-Python/Data Types/Dictionaries.py | 2,870 | 4.71875 | 5 | # Dictionaries
# Dictionaries are data structures used to map arbitrary keys to values.
# Lists can be thought of as dictionaries with integer keys within a certain range.
# Dictionaries can be indexed in the same way as lists, using square brackets containing keys.
# Each element in a dictionary is represented by a k... | true |
333d2fae7916937db479ee1778ed237c59e6e57d | goateater/SoloLearn-Notes | /SL-Python/Opening Files/writing_files.py | 2,703 | 4.5625 | 5 | # Writing Files
# To write to files you use the write method, which writes a string to the file.
# For Example:
file = open("newfile.txt", "w")
file.write("This has been written to a file")
file.close()
file = open("newfile.txt", "r")
print(file.read())
file.close()
print()
# When a file is opened in write mode, th... | true |
cb63ddf5d873dc45e0f46f0c048b06cf17864c53 | virenparmar/TechPyWeek | /core_python/Function/factorial using recursion.py | 499 | 4.28125 | 4 | # Python program to find the factorial of a number using recursion
def recur_factorial(n):
"""Function to return the factorial of a number using recursion"""
if n==1:
return n
else:
return n*recur_factorial(n-1)
#take input from the user
num=int(input("Enter a number="))
#check is the number is negative
if... | true |
830bf963c902c0382c08fca73c71d2fa2f7d1522 | virenparmar/TechPyWeek | /core_python/fibonacci sequence.py | 479 | 4.40625 | 4 | #Python program to display the fibonacci sequence up to n-th term where n is provided
#take in input from the user
num=int(input("How many term?"))
no1=0
no2=1
count=2
# check if the number of terms is valid
if num<=0:
print("please enter a positive integer")
elif num == 1:
print("fibonacci sequence")
print(no1... | true |
4ae8ad04f48d102055e470f4ca953940a8ca1f25 | virenparmar/TechPyWeek | /core_python/Function/anonymous(lambda) function.py | 299 | 4.46875 | 4 | #Python Program to display the power of 2 using anonymous function
#take number of terms from user
terms=int(input("How many terms?"))
#use anonymous function
result=list(map(lambda x:2 ** x, range(terms)))
#display the result
for i in range(terms):
print "2 raised to power",i,"is",result[i] | true |
01ab8ec47c8154a5d90d5ee4bd207f143a0051b3 | virenparmar/TechPyWeek | /core_python/Function/display calandar.py | 242 | 4.40625 | 4 | # Python Program to display calender of given month of the year
#import module
import calendar
#assk of month and year
yy=int(input("Enter the year="))
mm=int(input("Enter the month="))
#display the calender
print(calendar.month(yy,mm)) | true |
17af5750832fde25c0a10ec49865f478fae390d9 | jonathansantilli/SMSSpamFilter | /spamdetector/file_helper.py | 973 | 4.1875 | 4 | from os import path
class FileHelper:
def exist_path(self, path_to_check:str) -> bool:
"""
Verify if a path exist on the machine, returns a True in case it exist, otherwise False
:param path_to_check:
:return: boolean
"""
return path.exists(path_to_check)
def re... | true |
cf5b64089024a35ddd119fc90ae09cc8e404129e | mani-barathi/Python_MiniProjects | /Beginner_Projects/Number_guessing_game/game.py | 926 | 4.25 | 4 | from random import randint
def generateRandomNumber():
no = randint(1,21)
return no
print('Number Guessing Game!')
print("1. Computer will generate a number from 1 to 20")
print("2. You have to guess it with in 3 guess")
choice = input("Do you want to play?(yes/no): ")
if choice.lower() == 'yes':
while True:
nu... | true |
fc67206793cd483acdbb305f621ab33b8ad63083 | rsp-esl/python_examples_learning | /example_set-1/script_ex-1_27.py | 1,088 | 4.25 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
# Author: Rawat S. (Dept. of Electrical & Computer Engineering, KMUTNB)
# Date: 2017-11-17
##############################################################################
from __future__... | true |
ffc5c4eb524cd11e8e452e0e75c50b6ac0933e2b | rsp-esl/python_examples_learning | /example_set-3/script_ex-3_6.py | 2,966 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
# Author: Rawat S. (Dept. of Electrical & Computer Engineering, KMUTNB)
# Date: 2017-11-17
##############################################################################
from __future__... | true |
091be1a39775ef12d7eacc6b90c2ab563fddb340 | rsp-esl/python_examples_learning | /example_set-1/script_ex-1_34.py | 1,238 | 4.4375 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
# Author: Rawat S. (Dept. of Electrical & Computer Engineering, KMUTNB)
# Date: 2017-11-17
##############################################################################
from __future__... | true |
7f2111375c9fde24f8e238a901f59fd2b338c4b1 | theymightbepotatoesafter/School-Work | /CIS 210/p11_quiz_christian_carter.py | 2,320 | 4.3125 | 4 | '''
Prior programming experience quiz.
CIS 210 Project 1-1 Hello-Quiz Solution
Author: Christian Carter
Credits: N/A
Add docstrings to Python functions that implement quiz 1 pseudocode.
(See p11_cricket.py for examples of functions with docstrings.)
'''
def q1(onTime, absent):
'''
(bool, bool) -> string
... | true |
c42d57a4c634bae031e0dc1085cf88e95f1464d3 | tartlet/CS303E | /DaysInMonth.py | 1,512 | 4.40625 | 4 | # File: DaysInMonth.py
# Student: Jingsi Zhou
# UT EID: jz24729
# Course Name: CS303E
# Unique Number: 50695
#
# Date Created: 09/25/2020
# Date Last Modified: 09/25/2020
# Description of Program: User inputs a month and year in integer form and program
# outputs how many days the month has for any given year. Intende... | true |
6275743572e4abdd7c0a00d5852bb8b58cb4bd8f | anirudhn18/msba-python | /Lab5/Lab5_Ex1.py | 988 | 4.3125 | 4 |
class Point:
""" Represents a point in 2D space """
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def __str__(self):
return '({},{})'.format(self.x,self.y)
class Rectangle:
"""Represents a rectangle. attributes: width, height, corner."""
# def __init__... | true |
a72254ff8fee355dd7d06d31f9a3e30457704777 | tdhawale/Python_Practise | /Swap.py | 1,871 | 4.59375 | 5 | # One method to swap variable is using another variabl
print("--------------------------------------------------------")
print("Using the conventional method for swap")
a = 5
b = 6
print("The value of a before swap is :", a)
print("The value of b before swap is :", b)
temp = a
a = b
b = temp
print("The value of a after... | true |
2fae6de3cc45cae76936c8253f9951cfad720848 | tinadotmoardots/learning | /python/RPSv3.py | 1,223 | 4.375 | 4 | # This is a version of rock, paper, scissors that you can plan against a computer opponent
import random
player_wins = 0
computer_wins = 0
print("Rock...")
print("Paper...")
print("Scissors...")
while player_wins < 2 and computer_wins < 2:
print(f"Player Score: {player_wins} Computer Score: {computer_wins}")
play... | true |
fe065712a5b6500d9b9a8dc88ce1b7910a3990a6 | Jacob-Bankston/DigitalCrafts-Assignments | /Week1/Week1-Tuesday-Assignments/add-two-numbers.py | 876 | 4.34375 | 4 | #Defining a function to add two numbers together from user input
def add_numbers(input_1, input_2):
total = input_1 + input_2
return print(f"Your two numbers added together are: {total}")
#Seeking user input for the add_numbers function
while 1:
try: #Checking for integer input on the first number's input
... | true |
bff9e6911ee84b2424d298daa4ded0fd29e417f7 | acrane1995/projects | /Module 1/absolute beginners.py | 2,855 | 4.15625 | 4 | #my_num = 123
#num_intro = "My number is " + str(my_num)
#print(num_intro)
#total_cost = 3 + 45
#print(total_cost)
#45 was represented as a string and therefore could not be executed
#school_num = 123
#print("the street number of Central School is " + str(school_num))
#school_num is an int and needed to be converted... | true |
b36975217050a1e3a8af54e7e7a4d1d0e7ae3e1a | divyansh1235/Beta-Algo | /python/tree/PostorderTraversal.py | 2,087 | 4.375 | 4 | #POSTORDER BINARY TREE TRAVERSAL
# In this algorithm we print the value of the nodes present in the binary tree in postorder
# fashion.
# Here we first traverse the left subtree and then traverse the right subtree and finally we
# print the root
# The sequence is as follows -
# Left->Right->Root
class node (): ... | true |
41c9233b4165f4da13629a007e24dfbc248cff9d | jasonluocesc/CS_E3190 | /P4/shortest_cycle/solution.py | 1,791 | 4.34375 | 4 | # coding: utf-8
def get_length_of_shortest_cycle(g):
"""Find the length of the shortest cycle in the graph if a cycle exists.
To run doctests:
python -m doctest -v solution.py
>>> from networkx import Graph
>>> get_length_of_shortest_cycle(Graph({1: [2, 3], 2: [], 3: []}))
>>> get_length_o... | true |
aca7b1cf5d55a62b67f6156c9b633b7bc811e1ab | hansrajdeshpande18/geeksforgeeksorg-repo | /printreverse.py | 206 | 4.28125 | 4 | #Print first and last name in reverse order with a space between them
firstname = (input("Enter your first name:"))
lastname = (input("Enter your last name:"))
print("Hello " +lastname + " " +firstname) | true |
839102579223d22c81a0f54a816f585f7c70262e | skrall3119/prg105 | /MyProject/Practice 9.1.py | 2,704 | 4.5625 | 5 | import pickle
def add(dic): # adds a new entry to the dictionary
name = input('Enter the name you wish to add: ')
email = input('Enter the email you wish to associate with this name: ')
dic[name] = email
print(dictionary)
def remove(dic): # removes the entry of the dictionary
na... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.