blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
eb8ac907b35bacba795aae007f4d3adb03a77e23 | monicajoa/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/4-print_square.py | 703 | 4.5 | 4 | #!/usr/bin/python3
"""
This module hold a function that prints a square with the character #.
"""
def print_square(size):
"""
This function prints square by the size
Paramethers:
size: length of the square
Errors:
TypeError: size must be an integer
ValueError: size must be >= 0... | true |
63dac65210c83675bf6c7b07e055231e7434a8ec | enkefalos/PythonCourse | /hw1_question3.py | 1,184 | 4.28125 | 4 | def compare_subjects_within_student(subj1_all_students :dict,
subj2_all_students :dict):
"""
Compare the two subjects with their students and print out the "preferred"
subject for each student. Single-subject students shouldn't be printed.
Choice for the data structu... | true |
14f7a544807a575b1ee39c99bfbdad6c7efd90b1 | tyteotin/codewars | /6_kyu/is_triangle_number.py | 1,168 | 4.15625 | 4 | """
Description:
Description:
A triangle number is a number where n objects form an equilateral triangle (it's a bit hard to explain). For example,
6 is a triangle number because you can arrange 6 objects into an equilateral triangle:
1
2 3
4 5 6
8 is not a triangle number because 8 objects do not form an equila... | true |
d60efd85d0348706c2262820706a4234a775df1a | Sairahul-19/CSD-Excercise01 | /04_is_rotating_prime.py | 1,148 | 4.28125 | 4 | import unittest
question_04 = """
Rotating primes
Given an integer n, return whether every rotation of n is prime.
Example 1:
Input:
n = 199
Output:
True
Explanation:
199 is prime, 919 is prime, and 991 is prime.
Example 2:
Input:
n = 19
Output:
False
Explanation:
Although 19 is prime, 91 is not.
"""
# Implement t... | true |
dfd38f505944aeb4fee6fa57bda110fa84952084 | ajorve/pdxcodeguild | /json-reader/main.py | 1,131 | 4.5 | 4 | """
Objective
Write a simple program that reads in a file containing some JSON and prints out some of the data.
1. Create a new directory called json-reader
2. In your new directory, create a new file called main.py
The output to the screen when the program is run should be the following:
The Latitude/Longi... | true |
dbfe81b01a012a936086b78b5344682238e88ea5 | ajorve/pdxcodeguild | /puzzles/fizzbuzz.py | 1,145 | 4.375 | 4 | """
Here are the rules for the FizzBuzz problem:
Given the length of the output of numbers from 1 - n:
If a number is divisible by 3, append "Fizz" to a list.
If a number is divisible by 5, append "Buzz" to that same list.
If a number is divisible by both 3 and 5, append "FizzBuzz" to the list.
If a number meets none ... | true |
5733f941bb23cec0470a41d4bb6ab1f78d86bd73 | ajorve/pdxcodeguild | /warm-ups/pop_sim.py | 2,021 | 4.375 | 4 | """
Population Sim
In a small town the population is 1000 at the beginning of a year.
The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town.
How many years does the town need to see its population greater or equal to 1200 inhabitants?
Write a fun... | true |
8523f0d7a6dd5773e2b947e5302906f1f385187d | kevinwei666/python-projects | /hw1/solution1/Q4.py | 634 | 4.625 | 5 | """
Asks the user to input an integer. The program checks if the user entered an integer,
then checks to see if the integer is within 10 (10 is included) of 100 or 200.
If that is the case, prints ‘Yes’, else prints ‘No’.
Examples:
90 should print 'Yes'
209 should also print 'Yes'
189 should print 'No'
"""
#Get use... | true |
e095d54de54855fbf5c006b6fe47ee93e51fd5ba | DinakarBijili/Data-structures-and-Algorithms | /BINARY TREE/11.Top View of Binary Tree .py | 1,394 | 4.28125 | 4 | """
Top View of Binary Tree
Given below is a binary tree. The task is to print the top view of binary tree. Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. For the given below tree
1
/ \
2 3
/ \ / \
4 5 6 7
Top view will be: 4 2 1 ... | true |
7629f38b20e5dd43ceda19cceb9e68a7386adee0 | DinakarBijili/Data-structures-and-Algorithms | /SORTING AND SEARCHING/18.K-th element of two sorted Arrays.py | 1,027 | 4.25 | 4 | """
K-th element of two sorted Arrays
Given two sorted arrays arr1 and arr2 of size M and N respectively and an element K. The task is to find the element that would be at the k’th position of the final sorted array.
Example 1:
Input:
arr1[] = {2, 3, 6, 7, 9}
arr2[] = {1, 4, 8, 10}
k = 5
Output:
6
Explanation:
The... | true |
6d66d78b7774086fa047257b28fd2d3d83c7d7ca | DinakarBijili/Data-structures-and-Algorithms | /ARRAY/10.min_no._of_jumps_to_reach_end_of_arr.py | 1,639 | 4.1875 | 4 | """
Minimum number of jumps
Given an array of integers where each element represents the max number of steps that can be made forward from that element. Find the minimum number of jumps to reach the end of the array (starting from the first element). If an element is 0, then you cannot move through that element.
Exa... | true |
4bd049da90d733d69710804afaa9b5352667caf3 | DinakarBijili/Data-structures-and-Algorithms | /SORTING AND SEARCHING/7.Majority Element.py | 900 | 4.40625 | 4 | """
Majority Element
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so t... | true |
a6b70b95e2abd954adf5c0ef7884792630fc1e5e | DinakarBijili/Data-structures-and-Algorithms | /LINKED_LIST/Rotate Doubly linked list by N nodes.py | 2,692 | 4.1875 | 4 | """
Rotate Doubly linked list by N nodes
Given a doubly linked list, rotate the linked list counter-clockwise by N nodes. Here N is a given positive integer and is smaller than the count of nodes in linked list.
N = 2
Rotated List:
Examples:
Input : a b c d e N = 2
Output : c d e a b
Input : a b c ... | true |
6fc2e1d949f0bfaa8b60947c38faf8e435a41a73 | DinakarBijili/Data-structures-and-Algorithms | /BINARY TREE/1.Level order traversal.py | 1,352 | 4.125 | 4 | """
Level order traversal
Given a binary tree, find its level order traversal.
Level order traversal of a tree is breadth-first traversal for the tree.
Example 1:
Input:
1
/ \
3 2
Output:1 3 2
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:10 20 30 40 60 N N
"""
c... | true |
1c32e5e226de7d4f2d1e3711911554730b406f9a | DinakarBijili/Data-structures-and-Algorithms | /LINKED_LIST/Check if Linked List is Palindrome.py | 2,064 | 4.21875 | 4 | """
Check if Linked List is Palindrome
Given a singly linked list of size N of integers. The task is to check if the given linked list is palindrome or not.
Example 1:
Input:
N = 3
value[] = {1,2,1}
Output: 1
Explanation: The given linked list is
1 2 1 , which is a palindrome and
Hence, the output is 1.
Example 2:
... | true |
dcd5db7c301734d0b7406153043d6e89ece94997 | DinakarBijili/Data-structures-and-Algorithms | /LINKED_LIST/Reverse a Linked List in groups of given size.py | 2,665 | 4.3125 | 4 | """
Reverse a Linked List in groups of given size
Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list.
Example 1:
Input:
LinkedList: 1->2->2->4->5->6->7->8
K = 4
Output: 4 2 2 1 8 7 6 5
Explanation:
The first 4 elements 1,2,2,4 are reversed f... | true |
da2f6f83dca1a4776eba5777e39cb41676e29f2a | DinakarBijili/Data-structures-and-Algorithms | /ARRAY/4.Sort_arr-of_0s,1s,and,2s.without_using_any_sortMethod.py | 971 | 4.375 | 4 | # Sort an array of 0s, 1s and 2s
# Given an array of size N containing only 0s, 1s, and 2s; sort the array in ascending order.
# Example 1:
# Input:
# N = 5
# arr[]= {0 2 1 2 0}
# Output:
# 0 0 1 2 2
# Explanation:
# 0s 1s and 2s are segregated
# into ascending order.
# Example 2:
# Input:
# N = 3
# arr[] = {... | true |
11960b0f8caeafeda8c4cffcfa4d90bf087ad4bd | DinakarBijili/Data-structures-and-Algorithms | /BINARY TREE/5.Create a mirror tree from the given binary tree.py | 1,605 | 4.375 | 4 | """
Create a mirror tree from the given binary tree
Given a binary tree, the task is to create a new binary tree which is a mirror image of the given binary tree.
Examples:
Input:
5
/ \
3 6
/ \
2 4
Output:
Inorder of original tree: 2 3 4 5 6
Inorder of mirror tree: 6 5 4 3 2
Mirro... | true |
1665a5752794a64a0de7e505e172a814c9b32e8f | andrewsanc/pythonFunctionalProgramming | /exerciseLambda.py | 282 | 4.15625 | 4 | '''
Python Jupyter - Exercise: Lambda expressions.
'''
# Using Lambda, return squared numbers.
#%%
nums = [5,4,3]
print(list(map(lambda num: num**2, nums)))
# List sorting. Sort by the second element.
#%%
a = [(0,2), (4,3), (9,9), (10,-1)]
a.sort(key=lambda x: x[1])
print(a)
#%%
| true |
3a6fa89d2f42f9b264fc509e02c13c8222e8d76c | DandyCV/SoftServeITAcademy | /L07/L07_HW1_3.py | 321 | 4.15625 | 4 | def square(size):
"""Function returns tuple with float {[perimeter], [area], [diagonal]}
Argument - integer/float (side of square)"""
perimeter = 4 * size
area = size ** 2
diagonal = round((2 * area) ** 0.5, 2)
square_tuple = (perimeter, area, diagonal)
return square_tuple
print(square(3))... | true |
97d0ccc3d5c0bd1f9d84c1201695309d49c09fb9 | DandyCV/SoftServeITAcademy | /L07/L07_HW1_1.py | 473 | 4.5 | 4 | def arithmetic(value_1, value_2, operation):
"""Function makes mathematical operations with 2 numbers.
First and second arguments - int/float numbers
Third argument - string operator(+, -, *, /)"""
if operation == "+": return value_1 + value_2
if operation == "-": return value_1 - value_2
if ope... | true |
b7f773a51b49ad7512c4dee4a860c49d2e600ba7 | ramalho/modernoopy | /examples/tombola/ibingo.py | 814 | 4.34375 | 4 | """
Class ``IBingo`` is an iterable that yields items at random from
a collection of items, like to a bingo cage.
To create an ``IBingo`` instance, provide an iterable with the items::
>>> balls = set(range(3))
>>> cage = IBingo(balls)
The instance is iterable::
>>> results = [item for item in cage]
... | true |
53bd12eb151b9514575a8958560352ddb44bd941 | SLongofono/Python-Misc | /python2/properties.py | 1,250 | 4.125 | 4 | """
This demonstrates the use of object properties as a way to give the illusion of private members and
getters/setters per object oriented programming. Variables prefixed by underscore are a signal to other
programmers that they should be changing them directly, but there really isn't any enforcement. There are
still... | true |
3aa2076bc76d17d5cb2c903e5089f9dc6c913a13 | acemourya/D_S | /C_1/Chatper-01 DataScience Modules-stats-Example/Module-numpy-example.py | 1,100 | 4.15625 | 4 | #numpy: numerical python which provides function to manage multiple dimenssion array
#array : collection of similar type data or values
import numpy as np
#create array from given range
x = np.arange(1,10)
print(x)
y = x*2
print(y)
#show data type
print(type(x))
print(type(y))
#convert list to array
d = [11,22,4... | true |
b9b836dffee50eea89374a9978eeb48a86431187 | vladosed/PY_LABS_1 | /3-4/3-4.py | 730 | 4.3125 | 4 | #create random string with lower and upper case and with numbers
str_var = "asdjhJVYGHV42315gvghvHGV214HVhjjJK"
print(str_var)
#find first symbol of string
first_symbol = str_var[0]
print(first_symbol)
#find the last symbol of string
last_symbol = str_var[-1]
print(last_symbol)
#slice first 8 symbols
print(str_var[s... | true |
b5418dbfb626ef9a83a73a5de00da17e8e3822b5 | Kristjamar/Verklegt-namskei- | /Breki/Add_to_dict.py | 233 | 4.1875 | 4 | x = {}
def add_to_dict(x):
key = input("Key: ")
value = input("Value: ")
if key in x:
print("Error. Key already exists.")
return x
else:
x[key] = value
return x
add_to_dict(x)
print(x) | true |
df86c8f38f511f08aa08938abba0c79875727eb9 | green-fox-academy/hanzs_solo | /Foundation/week_02-week_04/PythonBasicsProject/week_02/expressions_and_control_flow/conditionals/odd_even.py | 234 | 4.46875 | 4 | # Write a program that reads a number from the standard input,
# then prints "Odd" if the number is odd, or "Even" if it is even.
number = int(input("enter an integer: "))
if number % 2 == 0:
print("Even")
else:
print("Odd")
| true |
39147e634f16988b71a0aee7d825d8e93def5359 | green-fox-academy/hanzs_solo | /Foundation/week_02-week_04/PythonBasicsProject/week_02/expressions_and_control_flow/user_input/average_of_input.py | 316 | 4.34375 | 4 | # Write a program that asks for 5 integers in a row,
# then it should print the sum and the average of these numbers like:
#
# Sum: 22, Average: 4.4
sum = 0
number_of_numbers = 5
for x in range(number_of_numbers):
sum += int(input("enter an integer: "))
print("sum:", sum, "average:", sum / number_of_numbers)
| true |
a314a1eef3981612f213986b9d261adaf2ff85ce | green-fox-academy/hanzs_solo | /Foundation/week_02-week_04/PythonBasicsProject/week_02/arrays/reverse_list.py | 327 | 4.46875 | 4 | # - Create a variable named `numbers`
# with the following content: `[3, 4, 5, 6, 7]`
# - Reverse the order of the elements of `numbers`
# - Print the elements of the reversed `numbers`
numbers = [3, 4, 5, 6, 7]
temp = []
for i in range(len(numbers)):
temp.append(numbers[len(numbers)-i-1])
numbers = temp
print(n... | true |
31170eab6926b9a475fe8fb1b7258571d762b96e | green-fox-academy/hanzs_solo | /Foundation/week_02-week_04/PythonBasicsProject/week_02/data_structures/list_introduction_1.py | 1,247 | 4.78125 | 5 | # # List introduction 1
#
# We are going to play with lists. Feel free to use the built-in methods where
# possible.
#
# - Create an empty list which will contain names (strings)
# - Print out the number of elements in the list
# - Add William to the list
# - Print out whether the list is empty or not
# - Add John to t... | true |
238f272124f13645a7e58e8de1aaee8d9a433967 | green-fox-academy/hanzs_solo | /Foundation/week_02-week_04/PythonBasicsProject/week_02/expressions_and_control_flow/loops/count_from_to.py | 634 | 4.28125 | 4 | # Create a program that asks for two numbers
# If the second number is not bigger than the first one it should print:
# "The second number should be bigger"
#
# If it is bigger it should count from the first number to the second by one
#
# example:
#
# first number: 3, second number: 6, should print:
#
# 3
# 4
# 5
a = ... | true |
27a458c5355a32cf2bc9eb53cef586a8120e9e36 | hr4official/python-basic | /td.py | 840 | 4.53125 | 5 | # nested list
#my_list = ["mouse", [8, 4, 6], ['a']]
#print(my_list[1])
# empty list
my_list1 = []
# list of integers
my_list2 = [1, 2, 3]
# list with mixed datatypes
my_list3 = [1, "Hello", 3.4]
#slice lists
my_list = ['p','r','o','g','r','a','m','i','z']
# elements 3rd to 5th
print(my_list[2:5])
... | true |
cff7d4a762f14e761f3c3c46c2e656f74cb19403 | sharikgrg/week3.Python-Theory | /exercises/exercise1.py | 745 | 4.375 | 4 | # Define the following variable
# name, last name, age, eye_colour, hair_colour
# Prompt user for input and reassign these
# Print them back to the user as conversation
# Eg: Hello Jack! Welcome, your age is 26, you eyes are green and your hair_colour are grey
name = input('What is your name?')
last_name = input('Wh... | true |
cda99da103298b6c26c29b9083038a732826be11 | sharikgrg/week3.Python-Theory | /102_data_types.py | 1,736 | 4.5 | 4 | # Numerical Data Types
# - Int, long, float, complex
# These are numerical data types which we can use numerical operators.
# Complex and long we don't use as much
# complex brings an imaginary type of number
# long - are integers of unlimited size
# Floats
# int - stmads for integers
# Whole numbers
my_int = 20
prin... | true |
5cba492f9034b07ca9bc7d266dca716ea684ba3c | sdhanendra/coding_practice | /DataStructures/linkedlist/linkedlist_classtest.py | 1,647 | 4.5 | 4 | # This program is to test the LinkedList class
from DataStructures.linkedlist.linkedlist_class import LinkedList
def main():
ll = LinkedList()
# Insert 10 nodes in linked list
print('linked list with 10 elements')
for i in range(10):
ll.insert_node_at_end(i)
ll.print_list()
# delete... | true |
f37a3a22ad3f2272e65ba5077308a6bfb5364429 | ItaloPerez2019/UnitTestSample | /mymath.py | 695 | 4.15625 | 4 | # make a list of integer values from 1 to 100.
# create a function to return max value from the list
# create a function that return min value from the list
# create a function that return averaga value from the list.
# create unit test cases to test all the above functions.
# [ dont use python built in min function, ... | true |
f289bd52b2eaf19d4e34ec72b37345af0f747d05 | AErenzo/Python_course_programs | /acronym.py | 640 | 4.21875 | 4 | phrase = input('Please enter a phrase: ')
# strip white spacing from the phrase
phrase = phrase.strip()
# change the phrase to upper case
phrase = phrase.upper()
# create new variable containing the phrase split into seperate items
words = phrase.split()
# create empty list for first letter of each it... | true |
f028bde75c24f7d2eec83ee24a638d0240b5628c | julianalvarezcaro/holbertonschool-higher_level_programming | /0x06-python-classes/6-square.py | 1,780 | 4.40625 | 4 | #!/usr/bin/python3
"""6-square module"""
class Square:
"""Square class"""
def __init__(self, size=0, position=(0, 0)):
"""Class constructor"""
self.size = size
self.position = position
def area(self):
"""Returns the area of the square"""
return self.__size * self._... | true |
d72f79ad097f5eace2fcb22d0471c0d3424290ac | elYaro/Codewars-Katas-Python | /8 kyu/Convert_number_to_reversed_array_of_digits.py | 320 | 4.21875 | 4 | '''
Convert number to reversed array of digits
Given a random number:
C#: long;
C++: unsigned long;
You have to return the digits of this number within an array in reverse order.
Example:
348597 => [7,9,5,8,4,3]
'''
def digitize(n):
nstr = str(n)
l=[int(nstr[i]) for i in range(len(nstr)-1,-1,-1)]
return l | true |
ae32fe698d8afb7b31a70999c9875af162c2dbe6 | elYaro/Codewars-Katas-Python | /8 kyu/Is_it_a_number.py | 582 | 4.28125 | 4 | '''
Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
isDigit("3")
isDigit(" 3 ")
isDigit("-3.23")
should return false:
isDigit("3-4")
isDigit(" 3 5")
isDigit("3 5")
isDigit("zero")
'''
def i... | true |
ba06a43362449d7f90a447537840c42b591b8adf | elYaro/Codewars-Katas-Python | /8 kyu/String_cleaning.py | 955 | 4.125 | 4 | '''
Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database.
At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. For example:
string_clean('! !... | true |
ca9334b0325fdbe0e9d4505dd4ab89649d0628f3 | elYaro/Codewars-Katas-Python | /8 kyu/Find_Multiples_of_a_Number.py | 708 | 4.59375 | 5 | '''
In this simple exercise, you will build a program that takes a value, integer, and returns a list of its multiples up to another value, limit.
If limit is a multiple of integer, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0.
The limit will a... | true |
79d418430029288067984d7573880866b3e43328 | elYaro/Codewars-Katas-Python | /7 kyu/KISS_Keep_It_Simple_Stupid.py | 1,093 | 4.34375 | 4 | '''
KISS stands for Keep It Simple Stupid. It is a design principle for keeping things simple rather than complex.
You are the boss of Joe.
Joe is submitting words to you to publish to a blog. He likes to complicate things.
Define a function that determines if Joe's work is simple or complex.
Input will be non emtpy st... | true |
c35fc57fec26636282eba11ea122628c8a07c0a3 | ericaschwa/code_challenges | /LexmaxReplace.py | 1,192 | 4.34375 | 4 | """
LexmaxReplace
By: Erica Schwartz (ericaschwa)
Solves problem as articulated here:
https://community.topcoder.com/stat?c=problem_statement&pm=14631&rd=16932
Problem Statement:
Alice has a string s of lowercase letters. The string is written on a wall.
Alice also has a set of cards. Each card contains a single let... | true |
a10242f6ed3268cad16740d2a072e5851cff7816 | Bhaney44/Intro_to_Python_Problems | /Problem_1_B.py | 1,975 | 4.28125 | 4 | #Part B: Saving, with a raise
#Write a program that asks the user to enter the following variables
#The starting annual salary
#The semi-annual raise
#The portion of the salary to be saved
#The total cost of the dream home
#Return the number of months to pay for the down payment.
starting_annual_salar... | true |
54d13bef355f59710b0b6f7a314d86a6daf8af68 | TroyJJeffery/troyjjeffery.github.io | /Computer Science/Data Structures/Week 4/CH5_EX3.py | 2,347 | 4.5 | 4 | """
Modify the recursive tree program using one or all of the following ideas:
Modify the thickness of the branches so that as the branchLen gets smaller, the line gets thinner.
Modify the color of the branches so that as the branchLen gets very short it is colored like a leaf.
Modify the angle used in turnin... | true |
1d2f84f2f3a4a22172a30392f5ac8a146555cd0d | lopezjronald/Python-Crash-Course | /part-1-basics/Ch_2/name_cases.py | 1,968 | 4.625 | 5 | """
2-3. Personal Message: Use a variable to represent a person’s name, and print a message to
that person. Your message should be simple, such as, “Hello Eric, would you like to learn some
Python today?”
2-4. Name Cases: Use a variable to represent a person’s name, and then print that person’s
name in lowercase, uppe... | true |
26d4c7b0708fab0a34f64a0446a488ca6aafc6b4 | baharaysel/python-study-from-giraffeAcademy | /tryexcept.py | 719 | 4.1875 | 4 |
try:
number = int(input("Enter a number: "))
print(number)
except:
print("Invalid Input")
# trying to catch different type of errors
try:
value = 10 / 0
number = int(input("Enter a number: "))
print(number)
except ZeroDivisionError:
print("Divide by zero")
except ValueError:
print("Invalid ... | true |
fc831d3a4869ab1084622ec1cdee10b43d11203d | Diamoon18/grafika | /burning_flower.py | 1,106 | 4.1875 | 4 | import turtle
from turtle import Turtle, Screen
ANGLE = 2
color = 'blue'
color1 = 'black'
color2 = 'red'
color3 = 'yellow'
def circles(t, size, small):
for i in range(10):
t.circle(size)
size=size-small
def circle_direction(t, size, repeat, small):
for i in range (repeat):
... | true |
5d0371c886729ffd8070088321fe21381c2d3487 | xiaowuc2/Code-in-Place-2021-Assignment-Solution | /Assignment-2/4. Random Numbers.py | 864 | 4.59375 | 5 | """
Write a program in the file random_numbers.py that prints 10 random integers (each random integer should have a value between 0 and 100, inclusive).
Your program should use a constant named NUM_RANDOM, which determines the number of random numbers to print (with a value of 10).
It should also use constants named ... | true |
cf695905d4d217da034247bf4bd9d5b4ab3b0c76 | xiaowuc2/Code-in-Place-2021-Assignment-Solution | /Assignment-3/2. Finding Forest Flames.py | 1,630 | 4.1875 | 4 | """
This program highlights fires in an image by identifying pixels
whose red intensity is more than INTENSITY_THRESHOLD times the
average of the red, green, and blue values at a pixel. Those
"sufficiently red" pixels are then highlighted in the image
and other pixels are turned grey, by setting the pixel red,
green, a... | true |
13b15323e2cca29ee326a58a7b7a74bf997f3ecd | Graey/pythoncharmers | /Die_Roller.py | 322 | 4.1875 | 4 | #Using Random Number Generator
import random
min_value = 1
max_value = 6
again = True
while again:
print(random.randint(min_value, max_value))
another_roll = input('Want to roll the dice again? ')
if another_roll == 'yes' or another_roll == 'y':
again = True
else:
again = Fals... | true |
09a05fdb4236cebffaa44ae9b71b734e6b0d82b2 | SMinTexas/multiply_a_list | /mult_list.py | 349 | 4.1875 | 4 | # Given a list of numbers, and a single factor (also a number), create a
# new list consisting of each of the numbers in the first list multiplied by
# the factor. Print this list.
mult_factor = 2
numbers = [2,4,6,8,10]
new_numbers = []
for number in numbers:
product = number * mult_factor
new_numbers.append... | true |
8a1bab3272fd58fe4999fe571fa7eb58f1cac9e4 | Souravvk18/Python-Project | /dice_roll.py | 1,204 | 5 | 5 | '''
The Dice Roll Simulation can be done by
choosing a random integer between 1 and 6 for which we can use the random module in the Python programming language.
The smallest value of a dice roll is 1 and the largest is 6, this logic can be used to simulate a dice roll.
This gives us the start and end values to use i... | true |
b836b5f8ee930033348291d83be460e57ef5fd0d | Souravvk18/Python-Project | /text_based.py | 861 | 4.34375 | 4 | '''
you will learn how to create a very basic text-based game with Python.
Here I will show you the basic idea of how you can create this game and then you can modify or
increase the size of this game with more situations and user inputs to suit you.
'''
name = str(input("Enter Your Name: "))
print(f"{name} you are... | true |
a4626ca589be214fc375c7c0fe005807cf4f9291 | rosekay/data_structures | /lists.py | 1,232 | 4.34375 | 4 | #list methods applied
list_a = [15, 13.56, 200.0, -34,-1]
list_b = ['a', 'b', 'g',"henry", 7]
def list_max_min(price):
#list comprehension
return [num for num in price if num == min(price) or num == max(price)]
def list_reverse(price):
#reverse the list
price.reverse()
return price
def list_count(price, num)... | true |
6983b9b8ad8737a418c59ed38256630d3ed7b598 | SbSharK/PYTHON | /PYTHON/whileelse.py | 246 | 4.1875 | 4 | num = int(input("Enter a no.: "))
if num<0:
print("Enter a positive number!")
else:
while num>0:
if num==6:
break
print(num)
num-=1
else:
print("Loop is not terminated with break") | true |
0ecddbc90aaf35f0fb28351b096deb152ebd0e44 | tuhiniris/Python-ShortCodes-Applications | /patterns1/hollow inverted right triangle star pattern.py | 374 | 4.1875 | 4 | '''
Pattern
Hollow inverted right triangle star pattern
Enter number of rows: 5
*****
* *
* *
**
*
'''
print('Hollow inverted right triangle star pattern: ')
rows=int(input('Enter number of rows: '))
for i in range(1,rows+1):
for j in range(i,rows+1):
if i==1 or i==j or j==rows:
print('*',end=' '... | true |
0215399d8173998139d327bfd73917982e9a4e7a | tuhiniris/Python-ShortCodes-Applications | /array/right rotate an array.py | 797 | 4.3125 | 4 | from array import *
arr=array("i",[])
n=int(input("Enter the length of the array: "))
for i in range(n):
x=int(input(f"Enter the elements into array at position {i}: "))
arr.append(x)
print("Origianl elements of the array: ",end=" ")
for i in range(n):
print(arr[i],end=" ")
print()
#Rotate the given array ... | true |
6a157dd21d9cdff8fbd373649f1a5dead92151ac | tuhiniris/Python-ShortCodes-Applications | /basic program/print the sum of negative numbers, positive even numbers and positive odd numbers in a given list.py | 779 | 4.125 | 4 | n= int(input("Enter the number of elements to be in the list: "))
even=[]
odd=[]
negative=[]
b=[]
for i in range(0,n):
a=int(input("Enter the element: "))
b.append(a)
print("Element in the list are: {}".format(b))
sum_negative = 0
sum_positive_even = 0
sum_positive_odd = 0
for j in b:
if j > 0:
if j%... | true |
987fdb176bd3aba61e03f288233d20db427e47df | tuhiniris/Python-ShortCodes-Applications | /array/print the number of elements of an array.py | 611 | 4.40625 | 4 | """
In this program, we need to count and print the number of elements present in the array.
Some elements present in the array can be found by calculating the length of the array.
"""
from array import *
arr=array("i",[])
n=int(input("Enter the length of the array: "))
for i in range(n):
x=int(input(f"Enter t... | true |
7139cde7a49d54db3883ae161d1acecf942489ed | tuhiniris/Python-ShortCodes-Applications | /list/Reversing a List.py | 1,808 | 5.03125 | 5 | print("-------------METHOD 1------------------")
"""
Using the reversed() built-in function.
In this method, we neither reverse a list in-place
(modify the original list), nor we create any copy of the list.
Instead, we get a reverse iterator which we use to cycle through the list.
"""
def reverse(list):
retur... | true |
584171438444fc7001b68698651b725933f58b26 | tuhiniris/Python-ShortCodes-Applications | /patterns2/program to print 0 or 1 square number pattern.py | 390 | 4.1875 | 4 | '''
Pattern
Square number pattern:
Enter number of rows: 5
Enter number of column: 5
11111
11111
11111
11111
11111
'''
print('Square number pattern: ')
number_rows=int(input('Enter number of rows: '))
number_columns=int(input('Enter number of columns:'))
for row in range(1,number_rows+1):
for column in ... | true |
7166cac047616cf383f96c4584f7cf8a756ede9e | tuhiniris/Python-ShortCodes-Applications | /patterns1/alphabet pattern_29.py | 327 | 4.25 | 4 | """
Example:
Enter number: 5
A B C D E
A B C D
A B C
A B
A
"""
print('Alphabet Pattern: ')
number_rows = int(input("Enter number of rows: "))
for row in range(1,number_rows+1):
print(" "*(row-1),end="")
for column in range(1,number_rows+2-row):
print(chr(64+column),end=" ")
... | true |
05245453d39856168dbc249ebf5de56d659b338c | tuhiniris/Python-ShortCodes-Applications | /number programs/determine whether a given number is a happy number.py | 1,573 | 4.25 | 4 | """
Happy number:
The happy number can be defined as
a number which will yield 1 when it is replaced by the sum of the square of its digits repeatedly.
If this process results in an endless cycle of numbers containing 4,then the number is called an unhappy number.
For example, 32 is a happy number as the process ... | true |
091a210b5cc80d42ce28a35b80b7186e808ae101 | tuhiniris/Python-ShortCodes-Applications | /strings/find the frequency of characters.py | 1,095 | 4.3125 | 4 | """
To accomplish this task, we will maintain an array called freq with same size of the length of the string. Freq will be used to maintain the count of each character present in the string. Now, iterate through the string to compare each character with rest of the string. Increment the count of corresponding element... | true |
a92e1513deea941b6d84b8c6bfdac8a5accb8715 | tuhiniris/Python-ShortCodes-Applications | /tuples/Access Tuple Item.py | 367 | 4.21875 | 4 | '''
To access tuple item need to refer it by it's the index number,
inside square brackets:
'''
a=[]
n=int(input('Enter size of tuple: '))
for i in range(n):
data=input('Enter elements of tuple: ')
a.append(data)
tuple_a=tuple(a)
print(f'Tuple elements: {tuple_a}')
for i in range(n):
print(f'\nElement... | true |
f3ff7b22352de6864f57eb3c9b52e4643215de8c | tuhiniris/Python-ShortCodes-Applications | /file handling/Read a File and Capitalize the First Letter of Every Word in the File.py | 346 | 4.28125 | 4 | '''
Problem Description:
-------------------
The program reads a file and capitalizes
the first letter of every word in the file.
'''
print(__doc__,end="")
print('-'*25)
fileName=input('Enter file name: ')
print('-'*35)
print(f'Contents of the file are : ')
with open(fileName,'r') as f:
for line in f:
... | true |
3fc0f4902507d2fab0a8d3b597ab87dd24981a13 | tuhiniris/Python-ShortCodes-Applications | /list/Find the Union of two Lists.py | 1,136 | 4.4375 | 4 | """
Problem Description
The program takes two lists and finds the unions of the two lists.
Problem Solution
1. Define a function which accepts two lists and returns the union of them.
2. Declare two empty lists and initialise to an empty list.
3. Consider a for loop to accept values for two lists.
4. Take the nu... | true |
5bffa97dee1d35e4f0901c7fa8ca8bb4b7d59d9e | tuhiniris/Python-ShortCodes-Applications | /basic program/test Collatz Conjecture for a Given Number.py | 897 | 4.5625 | 5 | # a Python program to test Collatz conjecture for a given number
"""The Collatz conjecture is a conjecture that a particular sequence always reaches 1.
The sequence is defined as
start with a number n.
The next number in the sequence is n/2 if n is even and 3n + 1 if n is odd.
Problem Solution
1. Create a f... | true |
47d85156bab21b683fd7b8314b2e5e5a4a9872cc | tuhiniris/Python-ShortCodes-Applications | /patterns1/alphabet pattern_3.py | 281 | 4.25 | 4 | """
Example:
Enter the number of rows: 5
A A A A A
B B B B
C C C
D D
E
"""
print('Alphabet Pattern: ')
number_rows=int(input('Enter number of rows: '))
for row in range(1,number_rows+1):
for column in range(1,number_rows+2-row):
print(chr(64+row),end=' ')
print() | true |
4961def023e1e2fb805239116cd8785ea4b09b74 | tuhiniris/Python-ShortCodes-Applications | /list/Put Even and Odd elements in a List into Two Different Lists.py | 826 | 4.46875 | 4 | """
Problem Description
The program takes a list and puts the even and odd elements in it into two separate lists.
Problem Solution
1. Take in the number of elements and store it in a variable.
2. Take in the elements of the list one by one.
3. Use a for loop to traverse through the elements of the list and an if... | true |
377813d90508ffa5402d90d7a288c078d9fa3786 | tuhiniris/Python-ShortCodes-Applications | /strings/replace the spaces of a string with a specific character.py | 208 | 4.15625 | 4 | string=input('Enter string here: ')
character='_'
#replace space with specific character
string=string.replace(' ',character)
print(f'String after replacing spaces with given character: \" {string} \" ') | true |
454c5b13b7079f428bd1b04b3a243a9c4c05bdcd | tuhiniris/Python-ShortCodes-Applications | /list/Ways to find length of list.py | 1,584 | 4.46875 | 4 | #naive method
print("----------METHOD 1--------------------------")
list=[]
n=int(input("Enter the size of the list: "))
for i in range(n):
data=int(input("Enter elements of the array: "))
list.append(data)
print(f"elements in the list: {list}",end=" ")
# for i in range(n):
# print(list[i],end=" ")
print()... | true |
7c9bef892156d20b357d5855820d8b7e79c316af | tuhiniris/Python-ShortCodes-Applications | /dictionary/Check if a Given Key Exists in a Dictionary or Not.py | 731 | 4.21875 | 4 | '''
Problem Description
The program takes a dictionary and checks if a
given key exists in a dictionary or not.
Problem Solution
1. Declare and initialize a dictionary to have some key-value pairs.
2. Take a key from the user and store it in a variable.
3. Using an if statement and the in operator,
check if... | true |
293e894a12b3f1064a46443f84cbfe4d0b70db6e | tuhiniris/Python-ShortCodes-Applications | /basic program/count set bits in a number.py | 724 | 4.21875 | 4 | """
The program finds the number of ones in the binary representation of a number.
Problem Solution
1. Create a function count_set_bits that takes a number n as argument.
2. The function works by performing bitwise AND of n with n – 1 and storing the result in n until n becomes 0.
3. Performing bitwise AND with n ... | true |
6d7a32d214efdcef903bd37f2030ea91df771a05 | tuhiniris/Python-ShortCodes-Applications | /number programs/check if a number is an Armstrong number.py | 414 | 4.375 | 4 | #Python Program to check if a number is an Armstrong number..
n = int(input("Enter the number: "))
a = list(map(int,str(n)))
print(f"the value of a in the program {a}")
b = list(map(lambda x:x**3,a))
print(f"the value of b in the program {b} and sum of elements in b is: {sum(b)}")
if sum(b)==n:
print(f"The numb... | true |
5f4083e687b65899f292802a57f3eb9b1b64ca5a | tuhiniris/Python-ShortCodes-Applications | /basic program/program takes an upper range and lower range and finds those numbers within the range which are divisible by 7 and multiple of 5.py | 295 | 4.125 | 4 | #program takes an upper range and lower range and finds those numbers within the range which are divisible by 7 and multiple of 5
lower = int(input("Enter the lower range: "))
upper = int(input("Enter the upper range: "))
for i in range(lower,upper+1):
if i%7 == 0 and i%5==0:
print(i)
| true |
7599d879058a9fca9866b3f68d93bcf2bda0001c | tuhiniris/Python-ShortCodes-Applications | /number programs/Swapping of two numbers without temperay variable.py | 1,492 | 4.15625 | 4 | ##Problem Description
##The program takes both the values from the user and swaps them
print("-------------------------------Method 1-----------------------")
a=int(input("Enter the First Number: "))
b=int(input("Enter the Second Number: "))
print("Before swapping First Number is {0} and Second Number is {1}" .f... | true |
ad835b40d50ac5db87b17903ac17f79c3fc820ef | tuhiniris/Python-ShortCodes-Applications | /matrix/find the transpose of a given matrix.py | 1,212 | 4.6875 | 5 | print('''
Note!
Transpose of a matrix can be found by interchanging rows with the column that is,
rows of the original matrix will become columns of the new matrix.
Similarly, columns in the original matrix will become rows in the new matrix.
If the dimension of the original matrix is 2 × 3 then,
the dimensio... | true |
ae96cee9c409b9af3ee4f2cca771093eb5fd32cd | tuhiniris/Python-ShortCodes-Applications | /list/Generate Random Numbers from 1 to 20 and Append Them to the List.py | 564 | 4.53125 | 5 | """
Problem Description
The program takes in the number of elements and generates random numbers from 1 to 20 and appends them to the list.
Problem Solution
1. Import the random module into the program.
2. Take the number of elements from the user.
3. Use a for loop, random.randint() is used to generate random ... | true |
4730566ea55fb752722cfb9257308de6de3ccc9c | tuhiniris/Python-ShortCodes-Applications | /recursion/Find if a Number is Prime or Not Prime Using Recursion.py | 539 | 4.25 | 4 | '''
Problem Description
-------------------
The program takes a number
and finds if the number is
prime or not using recursion.
'''
print(__doc__,end="")
print('-'*25)
def check(n, div = None):
if div is None:
div = n - 1
while div >= 2:
if n % div == 0:
print(f"Numbe... | true |
ef045cb0440d1fe1466a7fda39915e68db973872 | mwnickerson/python-crash-course | /chapter_9/cars_vers4.py | 930 | 4.1875 | 4 | # Cars version 4
# Chapter 9
# modifying an attributes vales through a method
class Car:
"""a simple attempt to simulate a car"""
def __init__(self, make, model, year):
"""Initialize attributes to describe a car"""
self.make = make
self.model = model
self.year = year
se... | true |
7e79127380cc86a94a1c4c5e836b8e00158481dc | mwnickerson/python-crash-course | /chapter_7/pizza_toppings.py | 321 | 4.28125 | 4 | # pizza toppings
# chapter 7 exercise 4
# a conditional loop that prompts user to enter toppings
prompt ="\nWhat topping would you like on your pizza?"
message = ""
while message != 'quit':
message = input(prompt)
topping = message
if message != 'quit':
print(f"I will add {topping} to your pizza!"... | true |
22bdf928b3a3d79e5dccd1361536f8fb7f0136f1 | mwnickerson/python-crash-course | /chapter_5/voting_vers2.py | 218 | 4.25 | 4 | # if and else statement
age = 17
if age >= 18:
print("You are able to vote!")
print("Have you registered to vote?")
else:
print("Sorry you are too young to vote.")
print("Please register to vote as you turn 18!")
| true |
7393500c1f9e8b7d3e3ceafce7f4e923d9111ae1 | hangnguyen81/HY-data-analysis-with-python | /part02-e13_diamond/diamond.py | 703 | 4.3125 | 4 | #!/usr/bin/env python3
'''
Create a function diamond that returns a two dimensional integer array where the 1s form a diamond shape.
Rest of the numbers are 0. The function should get a parameter that tells the length of a side of the diamond.
Do this using the eye and concatenate functions of NumPy and array slicing... | true |
14f3fd6898259a53461de709e7dc409a28ba829f | hangnguyen81/HY-data-analysis-with-python | /part01-e07_areas_of_shapes/areas_of_shapes.py | 902 | 4.15625 | 4 | #!/usr/bin/env python3
import math
def main():
while 1:
chosen = input('Choose a shape (triangle, rectangle, circle):')
chosen = chosen.lower()
if chosen == '':
break
elif chosen == 'triangle':
b=int(input('Give base of the triangle:'))
h=int(in... | true |
f86510558d0e668d9fc15fd0a3ff277ac93ec656 | keerthisreedeep/LuminarPythonNOV | /Functionsandmodules/function pgm one.py | 1,125 | 4.46875 | 4 | #function
#functions are used to perform a specific task
print() # print msg int the console
input() # to read value through console
int() # type cast to int
# user defined function
# syntax
# def functionname(arg1,arg2,arg3,.................argn):
# function defnition
#-----------------------------------------... | true |
cb1e9921d2f54d3bc3e3cb8bf67ca3e2af019197 | mgeorgic/Python-Challenge | /PyBank/main.py | 2,471 | 4.25 | 4 | # Import os module to create file paths across operating systems
# Import csv module for reading CSV files
import csv
import os
# Set a path to collect the CSV data from the Resources folder
PyBankcsv = os.path.join('Resources', 'budget_data.csv')
# Open the CSV in reader mode using the path above PyBankiv
with open ... | true |
672c5c943f6b90605cf98d7ac4672316df20773a | vittal666/Python-Assignments | /Third Assignment/Question-9.py | 399 | 4.28125 | 4 | word = input("Enter a string : ")
lowerCaseCount = 0
upperCaseCount = 0
for char in word:
print(char)
if char.islower() :
lowerCaseCount = lowerCaseCount+1
if char.isupper() :
upperCaseCount = upperCaseCount+1
print("Number of Uppercase characters in the string is :", lowerCaseCou... | true |
d614fd1df5ad36a1237a29c998e72af51dec2c99 | ahmedbodi/ProgrammingHelp | /minmax.py | 322 | 4.125 | 4 | def minmax(numbers):
lowest = None
highest = None
for number in numbers:
if number < lowest or lowest is None:
lowest = number
if number > highest or highest is None:
highest = number
return lowest, highest
min, max = minmax([1,2,3,4,5,6,7,8,9,10])
print(min, max... | true |
fa050769df11502c362c3f7000dae14a0373a5c9 | jbenejam7/Ith-order-statistic | /insertionsort.py | 713 | 4.15625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jun 29 18:02:06 2021
@author: djwre
"""
import random
#Function for InsertionSort
def InsertionSort(A, n):
#traverse through 1 to len(arr)
for i in range(1, n):
key = A[i]
#move elements of arr [0..i-1], that are
#great... | true |
9a6829d0e2e6cd55e7b969674845a733a14d31d2 | rabi-siddique/LeetCode | /Lists/MergeKSortedLists.py | 1,581 | 4.4375 | 4 | '''
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
Example 1:
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: The linked-lists are:
[
1->4->5,
1->3->4,
2->6
]
m... | true |
55d2c65bb61b82e52e00c2f2f768399f17e78367 | evanmascitti/ecol-597-programming-for-ecologists | /Python/Homework_Day4_Mascitti_problem_2.py | 2,766 | 4.40625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Feb 1 21:16:35 2021
@author: evanm
"""
# assign raw data to variables
observed_group_1_data = [1, 4, 5, 3, 1, 5, 3, 7, 2, 2]
observed_group_2_data = [6, 7, 9, 3, 5, 7, 8, 10, 12]
combined_data = observed_group_1_data + observed_group_2_data
# define a func... | true |
373ecc01e393f54d7d67e3fcba648bc9bdae323f | Teresa-Rosemary/Text-Pre-Processing-in-Python | /individual_python_files/word_tokenize.py | 880 | 4.15625 | 4 | # coding: utf-8
import nltk
from nltk import word_tokenize
def word_tokenize(text):
"""
take string input and return list of words.
use nltk.word_tokenize() to split the words.
"""
word_list=[]
for sentences in nltk.sent_tokenize(text):
for words in nltk.word_tokenize(sentences):
... | true |
60154b97d18346acc13abb79f1026e4cf07f80e0 | scott-currie/data_structures_and_algorithms | /data_structures/binary_tree/binary_tree.py | 1,400 | 4.125 | 4 | from queue import Queue
class Node(object):
""""""
def __init__(self, val):
""""""
self.val = val
self.left = None
self.right = None
def __repr__(self):
""""""
return f'<Node object: val={ self.val }>'
def __str__(self):
""""""
return ... | true |
9964fcd07621271656f2ad95b8befd93f6546a54 | scott-currie/data_structures_and_algorithms | /data_structures/stack/stack.py | 1,756 | 4.15625 | 4 | from .node import Node
class Stack(object):
"""Class to implement stack functionality. It serves as a wrapper for
Node objects and implements push, pop, and peek functionality. It also
overrides __len__ to return a _size attribute that should be
updated by any method that adds or removes nodes from th... | true |
134ad277c30c6f24878f0e7d38c238f147196a64 | scott-currie/data_structures_and_algorithms | /challenges/array_binary_search/array_binary_search.py | 788 | 4.3125 | 4 | def binary_search(search_list, search_key):
"""Find the index of a value of a key in a sorted list using
a binary search algorithm. Returns the index of the value if
found. Otherwise, returns -1.
"""
left_idx, right_idx = 0, len(search_list) - 1
# while True:
while left_idx <= right_idx:
... | true |
16f21ae65b3d5e3aba3f44decb5a1a4c556c95a5 | scott-currie/data_structures_and_algorithms | /challenges/multi-bracket-validation/multi_bracket_validation.py | 900 | 4.25 | 4 | from stack import Stack
def multi_bracket_validation(input_str):
"""Parse a string to determine if the grouping sequences within it are
balanced.
param: input_str (str) string to parse
return: (boolean) True if input_str is balanced, else False
"""
if type(input_str) is not str:
raise... | true |
d46fc6f5940512ae2764ba93f4ad59d920ea16c4 | rentheroot/Learning-Pygame | /Following-Car-Game-Tutorial/Adding-Boundries.py | 2,062 | 4.25 | 4 | #learning to use pygame
#following this tutorial: https://pythonprogramming.net/displaying-images-pygame/?completed=/pygame-python-3-part-1-intro/
#imports
import pygame
#start pygame
pygame.init()
#store width and height vars
display_width = 800
display_height = 600
#init display
gameDisplay = pygame.display.set_m... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.