blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
f5cbfbcda55a1174776c4a19e87239df817d9682 | parulsharma-121/CodingQuestions | /day_120_MaximumNumberOfBallons.py | 561 | 4.3125 | 4 | '''
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
You can use each character in text at most once. Return the maximum number of instances that can be formed.
Example 1:
Input: text = "nlaebolko"
Output: 1
'''
def maxNumberOfBalloons(text... | true |
e5aade93a300c070ec685b915f0cb5f9a376abe0 | kushalnaidu/titanic_survival_exploration | /accuracy.py | 2,597 | 4.15625 | 4 | #
# In this and the following exercises, you'll be adding train test splits to the data
# to see how it changes the performance of each classifier
#
# The code provided will load the Titanic dataset like you did in project 0, then train
# a decision tree (the method you used in your project) and a Bayesian classif... | true |
6fc1bd4ae3c8e7bceef5d26cb0a8ba1c7a05594c | kasragordini/Mercury | /Quera_Turtle_Rectancular.py | 704 | 4.125 | 4 | import math
import turtle
from turtle import left
a,b= input().split() #input a & b
a=int(a)
b=int(b)
wn = turtle.Screen() # for build a turtle window
line = turtle.Turtle() # for build a turtle line
line.hideturtle()
line.color("black")
line.pensize(2)
line.speed(5)
for i in range(2): # for the rectangular
lin... | true |
5b660e18fc07bd9446a9f00deaa8bed8e506a798 | munotsaurabh/LearnPython | /Enumerate/Enumerate.py | 337 | 4.375 | 4 | """
enumerate() function assigns a number to each element in the list
"""
friends = ["Virat", "Rohit", "Bhuvi", "Ashwin"]
enumerate_list = list(enumerate(friends))
enumerate_dict = dict(enumerate(friends, start=101)) # 'start' argument for assigning a number for each element in the list
print (enumerate_list)
print ... | true |
3dd425345fd7ae990335db772bc30253226ac534 | njerigathigi/Practice-Exercises-Python | /classes/question2.py | 761 | 4.125 | 4 | # Define a class called Songs, it will show the lyrics of a song.
# Its __init__() method should have two arguments:self and lyrics.lyrics
# is a list .Inside your class create a method called sing_me_a_song that
# prints each element of lyrics on his own line. Define a varible:
# happy_bday = Song(["May god bless ... | true |
c34ccbef4b954190413e3e62bededed3b16c3785 | njerigathigi/Practice-Exercises-Python | /functions/question7.py | 801 | 4.4375 | 4 | # Exercise Question 7: Assign a different name to function and call it
# through the new name
# Below is the function displayStudent(name, age). Assign a new name
# showStudent(name, age) to it and call through the new name
# def displayStudent(name, age):
# print(name, age)
# displayStudent("Emma", 26)
#
# y... | true |
c174c49e07cf0fe4d5a21c476e8693c5f5f74280 | njerigathigi/Practice-Exercises-Python | /Map/question4.py | 324 | 4.3125 | 4 | import math
# Write a Python program to create a list containing the power of said number in bases
# raised to the corresponding number in the index using Python map.
numbers = [1, 2, 3, 4, 5]
index = [i for i in range(len(numbers))]
print(numbers)
print(index)
powers = list(map(math.pow, numbers, index))
print(powe... | true |
067b8769558e92516720766e052b8b1f72dd0ea4 | ICS3U-Programming-JonathanK/Assign-02-Python | /volume_surface_tetrahedron.py | 668 | 4.65625 | 5 | #!/usr/bin/env python3
# Created by: Jonathan Kene
# Created on: May. 3, 2021
# This program asks the user for the edge length
# of the tetrahedron in m. It then
# calculates and displays the volume and
# surface area.
import math
def main():
# input
print("Today we will calculate the volume and")
print(... | true |
192b3c86f0b1339f8e198c803a8cb7874c82fc9a | mauney/DS-Unit-3-Sprint-2-SQL-and-Databases | /SC/demo_data.py | 1,429 | 4.34375 | 4 | import sqlite3
# conn = sqlite3.connect(':memory:')
conn = sqlite3.connect('demo_data.sqlite3')
curs = conn.cursor()
# Make table
create_table = """
CREATE TABLE demo
(
s TEXT,
x INTEGER,
y INTEGER
);
"""
curs.execute(create_table)
curs.close()
# Add data to table
def add_ro... | true |
5ba7f6dbdef4fc883307f2e2044dbc78413c5106 | manimaran-elumalai/FlowControls | /truefalse.py | 542 | 4.25 | 4 | day = "Saturday"
temperature = 30
raining = True
if (day == "Monday" and temperature > 27) or not raining:
print('Go Swimming')
else:
print("Learn Python")
print('**' * 12)
if 0:
print('True')
else:
print('False')
print('**' * 12)
name = input('Pls enter your name: ')
if name:
print("Hello, {}"... | true |
1853c88371d3890c644cf68d10ad497ceed3cda2 | grv1793/youtubevideos | /ytdvideo/common/adapters/utils/singleton.py | 2,280 | 4.375 | 4 | import functools
class Singleton:
"""Singleton can now be used as a decorator.
eg:
---- Regular Class ----
class ATS:
pass
obj1 = ATS()
obj2 = ATS()
obj1 is obj2
This evaluates to False
---- Singleton Class -----
@Singleton
class ATS:
pass
obj1 = AT... | true |
f277ddd6aee26280a9ac00b12c1d92a2cd71a5f1 | leagrove197/introduction-to-programming---lab | /tugas TA.py | 1,179 | 4.34375 | 4 | height = input("insert height here:") # in here we can type the height for the triangle, since the TA told us to input the height into 5, then we must type 5 here
height = int(height)
#No.1
for i in range(1,(height + 1)): #since the height is 5, then the range is from 1 to 6, so you will get 5 "*"
print("*" * i) #t... | true |
573959a070c5d9550af40403e8f6e5681995ce50 | Vika-Zil2020/python | /upplow.py | 279 | 4.1875 | 4 | inputed_text = input("enter the text")
def letters(inputed_text):
upper=0
lower=0
for i in inputed_text:
if i.isupper()==True:
upper+=1
else:
lower+=1
print("your upper letters are: "+ str(upper) + " " + "your lower letters are: " +str(lower))
letters(inputed_text) | true |
73bad9a924cd25b628e53dffe4aaa8680ff3a73e | tlee753/practice | /sphinx/test.py | 765 | 4.15625 | 4 | class Sorter():
"""
this is a class called Sorter
"""
def __init__(self, array):
self.array = array
def sort(self):
sortHelper(0, self.array)
""" this is a test comment"""
def sortHelper(i, array):
if (i == len(array) - 1):
return
sortHelpe... | true |
b5db6be2fba10cdfa5ac040f91a19fca1450deea | judas79/TKinter-git-theNewBoston | /Tkinter - 03 - Fitting Widgets in your Layout/Tkinter - 03 - Fitting Widgets in your Layout.py | 807 | 4.46875 | 4 | from tkinter import *
root = Tk() # creates a blank window named root
label1 = Label(root, text='one', fg='black', bg='white') # fg and bg colors work correctly with Label()
label1.pack(fill=BOTH, expand=True) # BOTH, dynamically increases X and Y o... | true |
5aeb6f7e86ac25045193a60523214d27a33b65f3 | cs-fullstack-2019-fall/python-loops-cw-LilPrice-Code | /index.py | 1,341 | 4.53125 | 5 | # Exercise 1:
#
# Print -20 to and including 50. Use any loop you want.
# x=range(-20, 51)
# for n in x:
# print(n)
#
# Exercise 2:
#
# Create a loop that prints even numbers from 0 to and including 20.Hint: You can find multiples of 2 with (whatever_number % 2 == 0)
# x = 0
# while x < 21:
# if x % 2==0:
# ... | true |
e635a4f0278528ea9f86ebe15b2c174d9e0fd65b | Hussein-A/Leetcode | /Medium/Python/75. Sort Colors.py | 1,433 | 4.21875 | 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 |
07372d0537704adde2e79beee86260f3acbb8a80 | muhammadAnas11/PIAIC-assignment | /table.py | 295 | 4.21875 | 4 | strt = int(input ("Enter the starting number : "))
end = int(input ("Enter the ending number : "))
for table_num in range(strt,end+1):
print("************************************")
for num in range(1,11):
print(str(table_num) + " x " + str(num) + " = " + str(table_num*num)) | true |
68e230d6698ccbb680ca24ca3cc3bff676811f88 | skyshock21/flipwords | /flipwords.py | 1,108 | 4.5 | 4 | #!/usr/bin/env python
#
# flipwords.py
# A script to read in a text file, reverse all the words,
# and output the reversed words
import sys,argparse
# Function Defs
def flipwords():
wordlist = args.file.read().split(' ') #read in file as list
newList=[] #initialize empty placeholde... | true |
6b5cec2e55d73ea0076bdbb9fc298f07a6c8ed79 | harryteasdal/College_Work | /Python_Practice/PythonBasics/DataStructures/Lists.py | 534 | 4.1875 | 4 | #a list is a data structure used for storing all data types
x = ['banannas','apples',2,3.141]
#to add to a list use ListName.append(what you want to add)
x.append('cheese')
#to insert a value use ListName.insert(Location,Value)
x.insert(2,'kiwi')
#to remove somthing use ListName.pop(location)
x.pop(2)
#to check the ... | true |
b6fdf1993a5c8c18429b0e1120159039386ef284 | thileepand/Python_Automation | /Documents/workspace_python/Python_Tutorial/controlstructure/homework_method.py | 944 | 4.15625 | 4 | """
Method exercise
Create a method, which takes a state and gross income as the arguments and returns the net income after deduction tax based on the state.
Assume federal tax: 10%
Assume state tax on your wish.
You don't have to do for all the states , just take 3-4 to solve the purpose of the exercise.
"""
def ca... | true |
5edc9cea1da95599a32cb2bbc719924acfbf278b | ZarkoHDS/Assignment-1-Driving-Simulation | /Driving Simulation.py | 706 | 4.21875 | 4 | initial_velocity=0
time=int(input("Please insert the amount of time spent on the road: "))
acc=int(input("Please insert the cars acceleration: "))
dist=int(input("please insert the cars destination: "))
dist=((initial_velocity*time)+(acc*time*time)/2)
velocity=initial_velocity+(acc*time)
speed=dist/time
if speed>60:... | true |
32ac6ddf823f64c7f1427ea1ab499d0eacdb82e1 | kiranganesh-s/python | /python day 7.py | 816 | 4.25 | 4 | Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> def function(a,b):
print('Addition of a,b is:',a+b)
print('Subtraction of a,b is:',a-b)
print('Multiplication of a,b is:',a*b)
print('Divi... | true |
12750d6504571364e01e72a6288ae17af8c20fb1 | anaruzz/holbertonschool-higher_level_programming | /0x0A-python-inheritance/10-square.py | 1,626 | 4.1875 | 4 | #!/usr/bin/python3
class BaseGeometry:
"""
class named BaseGeometry
"""
def area(self):
"""
raise an exception
"""
raise Exception('area() is not implemented')
def integer_validator(self, name, value):
"""
validates if a value of a name is integer and... | true |
79ccbe0ac4f338a50df9303d82b490a8bd44c217 | anaruzz/holbertonschool-higher_level_programming | /0x0B-python-input_output/3-write_file.py | 331 | 4.21875 | 4 | #!/usr/bin/python3
def write_file(filename="", text=""):
"""
function that writes a tring to a text file
and returns number of characters written
@filename: the name of the file
@text: string to be written
"""
with open(filename, mode="w", encoding='UTF-8') as f:
n = f.write(text)
... | true |
90d7c012452d691912cad7aa59d4412f469fb38f | KunalSinghP/Python-Beginner | /Sum and Factorial - Menu Driven#1.py | 1,474 | 4.4375 | 4 | #Menu driven program means you have two or more choices of performing different actions in one program like we have food choice in a hotel menu
def sum_num():
"""This function gives sum upto n numbers.
For example: Input:5 then Output=0+1+2+3+4+5=15""" #This is a docstring
... | true |
dbdbe39c6dc9ff7217663752cda50ae83d133084 | paulo-sk/introduction-python-programming | /2-intro/exemplos-capitulo/convert_numbers.py | 365 | 4.15625 | 4 | number_of_days = int(input("Enter numbers of days: "))
number_of_yers = number_of_days//365
number_of_months = (number_of_days % 365) // 30
number_of_weeks = (number_of_days % 365) % 30 / 7
remaining_number_of_days = number_of_days % 365 % 7
print(f"Yers: {number_of_yers}, Months: {number_of_months}, Weeks: {number_... | true |
90232432f5d98b6055fb6b94def4e0beadd395ef | swustlqsh/InterviewLqsh | /decorators/decorators1.py | 2,390 | 4.4375 | 4 | # -*- coding:utf-8 -*-
__author__ = 'qiusheng'
# email: qiushengli245@gmail.com
import random
# first things first
# before you can understand decorators, you must first understand.
# how functions work: functions return a value based on the given arguments
def foo(far):
return far + 1
print(foo(2) == 3)
print(ty... | true |
bf267a43e079da45c8407fb59a5d9949cd60c797 | AliRazani99/Pycharm_training | /if/ifs.py | 396 | 4.15625 | 4 | # Example file for working with conditional statement
def main():
x, y = 2, 8
if (x < y):
st = "x is less than y"
print(st)
# Example file for working with conditional statement
def main2():
x, y = 8, 8
if (x < y):
st = "x is less than y"
elif(x==y):
st = "x is greater... | true |
d573a77ede8646ecc3066d9abac037ffdd423bcf | Shasaravana/Array-Problems | /11.FindMax/Max.py | 961 | 4.15625 | 4 | # To find the max of dictionary values
Problem :
=========
To find the min of dictionary values
Input :
=======
Unsorted Array Elements
Output :
========
Maximum Element in an Unsorted Array
My Way of Solving the Problem (Algorithm) :
===========================================
1.Find the leng... | true |
b257183034a65838366965a58f34817b848bb0b2 | Programmer-Admin/binarysearch-editorials | /Subsequence Picking.py | 2,456 | 4.15625 | 4 | """
Subsequence Picking
Time complexity: O(n^2) I think, because we build a list of dictionary that have at most n elements.
Inspired by https://leetcode.com/problems/distinct-subsequences-ii/, modified to keep track of the count of subsequences of given length.
We want to minimize the cost of picking k subsequences... | true |
28710e58bf09fb32a0b356a489db33ca41ef45d6 | Maulik61/SDemo | /NestedIf_ForLoop.py | 245 | 4.125 | 4 | for temp in range(31,52):
if temp>30 and temp<=35:
print "Sunny Day"
elif temp>=35 and temp<=40:
print "Warm Day"
elif temp>=40 and temp<=50:
print "High Temperature"
else:
print "Invalid Input"
| true |
a3c369051e5525f9704ea2160640883c0df33957 | savardge/covnet | /covnet/geo.py | 2,495 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Manipulate geographical and cartesian coordinate systems.
"""
import numpy as np
def deg2cart(lon, lat, ref=None, earth_radius=6371.):
""" Geographical to cartesian coordinates, assuming spherical Earth.
The calculation is based on the approximate great-c... | true |
4c4ab0634b2f8aab1ca6bdda2092c7487a874886 | ballysingh818/pythontest | /Guess.py | 371 | 4.1875 | 4 | #!/usr/bin/env python3.8
import random
hidden = random.randint(1,10)
bool=True
while bool:
guess = int(input("enter your guess"))
if guess == hidden:
print("number guessed")
bool=False
elif guess < hidden:
print("guess is too low")
elif guess > hidden:
print("guess is to... | true |
2fe2dc55a8cc69d162a5899046187914628b9116 | SandeepDevrari/py_code | /py_tk/exampletkinterpack.py | 474 | 4.125 | 4 | ##this is an example of tkinter's pack() method in python3
##in tkinter, pack() method is one of geometry manager
import tkinter as tk
root=tk.Tk();
frame=tk.Frame(root, bg="red",width=200,height=200);
frame.pack();
frame1=tk.Frame(root,bg="skyblue",width=100,height=100);
frame1.pack(expand=1);
frame2=tk.Frame(root,bg=... | true |
112771213c3c3e89e7020b6090c9240e3e3f1fc9 | muon012/practiceProblems | /python/6-decorators.py | 2,550 | 4.5625 | 5 | # Property Decorator: Allows you to define a method but use it as an attribute. You can call the method by calling it
# as an attribute. Syntax is "@property";
# Setter Decorator: Allows you to set attributes using properties. Use the name of the property that you want to
# change followed by ".setter" and ... | true |
120e2f75d8795410a0c16024d908e0710da45cb0 | phil7j/Intro-Python-I | /src/13_file_io.py | 946 | 4.25 | 4 | """
Python makes performing file I/O simple. Take a look
at how to read and write to files here:
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
"""
# Open up the "foo.txt" file (which already exists) for reading
# Print all the contents of the file, then close the file
# YOUR CODE HERE... | true |
ff4dd19fc29f05333ad4a52fe5166edb0d7d64d1 | jx10ng/PythonX442.3 | /Quiz 5/sub_regex.py | 644 | 4.125 | 4 | """Question 2: Write a substitution command that will change names like file1, file2, etc.
to file01, file02, etc. but will not add a zero to names like file10 or file20."""
import re
def convert(x):
return (x.group('filename')+'0'+ x.group('num'))
def subs(string):
reg_pat = r'^(?P<filename>[a-zA-Z]+)(?P<num>... | true |
0bd4f597ace81e44fc31d63c0f65841e08ce1e0a | jx10ng/PythonX442.3 | /Written Assignment 6/map_comp.py | 401 | 4.28125 | 4 | """Question 3: Use the map function to add a constant to each element of a list.
Perform the same operation using a list comprehension. """
def main():
list1 = [1, 2, 3, 4]
num1 = 1
num2 = 2
map_list=map(lambda x: x + num1, list1) #use map
print(map_list)
comprehension_list = [item + num2 for item in list1... | true |
bfee37ead6d9cac1ebdbfc0e5272792229779dad | Disunito/hello-world | /python_work/Chap_six/fav_places.py | 593 | 4.6875 | 5 | #6-9 Make a dictionary called favorite_places.
#Think of three names to use as keys in the dictionary, and store one to
#three favorite places for each person. Loop through the dictionary, and print
#each person's name and their favorite places.
favorite_places = {
'god': ['haven', 'garden of eden', 'your mom'],
... | true |
9b1a27d9ee55a024ae474b73d22a7177bb3d2e31 | Disunito/hello-world | /python_work/Chap_four/animals.py | 677 | 4.625 | 5 | #4-2 Think of at least three different animals that have a common
#charactaristic. Store the names of these animals in a list, and then
#use a for loop to print out the name of each animal.
# -modify your program to print a statement about each animal,
# such as a dog would make a great pet.
# -Add a line at t... | true |
696c56a96f3cf04548b173f964ddc341b30d0f30 | Disunito/hello-world | /python_work/Chap_seven/mountian_poll.py | 704 | 4.15625 | 4 | # Empty dictionary for responses to poll
responses = {}
# Set flag to indicate that polling is active.
polling_active = True
while polling_active:
# Prompt for the person's name and response
name = input("\nWhat is your name? ")
response = input("Which mountian would you like to climb someday? ")
# Store the rep... | true |
4019758f7bbc3d69e47f7b5ac12ae097649cc776 | Disunito/hello-world | /python_work/Chap_four/pizza.py | 1,278 | 4.78125 | 5 |
#4-1 Think of at least three kinds of your favorite pizza. Store these
#pizza names in a list, and then use a for loop to print the name of
#each pizza
# -Modify your for loop to print a sentence using the name os the
# pizza instead of printing just the name of the pizza. For each
# pizza you should have one line of ... | true |
20bb7e744f18c0d3cb607f1828025e24f33af802 | Disunito/hello-world | /python_work/Chap_five/hello_admin.py | 1,092 | 4.25 | 4 | #5-8 Make a list of five or more usernames, including the name 'admin'.
#Imagine you are writting code that will print a greeting to each user after
#they log in to a website. Loop through the list, and print a greeting
#each other.
# -If the username 'admin', print a special gretting, such as Hello admin,
# would... | true |
3dd7269977992efa39111e741c584fcd79e137ff | mcleu/CodeFights | /DigitRoot.py | 856 | 4.28125 | 4 | # Digit root of some positive integer is defined as the sum of all of its digits.
# You are given an array of integers. Sort it in such a way that if a comes before b then
# the digit root of a is less than or equal to the digit root of b.
# If two numbers have the same digit root, the smaller one (in the regular sense... | true |
9969bc8041401d39e63f315782ed83f0f1908695 | EmanueleAMCappella/Learn_python_the_hard_way | /ex16.py | 758 | 4.1875 | 4 | from sys import argv
script, filename=argv
print "We're going to erase %r" %filename
print "If you don't want that hit CTRL-C(^C)"
print "If you do want that, hit RETURN"
raw_input("?")
print "Opening the file..."
target= open(filename, 'w')
print "Truncating the file. Goodbye!"
target.truncate()
... | true |
7b1e64be26439fbe3f660c47dc62bbc3dd6e154c | tati-/isip | /python-intro/introduction.py | 2,758 | 4.5 | 4 |
# coding: utf-8
# # Welcome to the wonderful world of Python!
# ## Basics
# Lets start of by outputing a string
# In[1]:
print('Hello World!')
# Now lets define a variable as an integer
# In[2]:
my_first_int = 10
type(my_first_int)
# And now a float
# In[3]:
my_first_float = 10.0
print(my_first_float)
#... | true |
128c6179b19dc6e5d155042b5f176efdc18ef912 | phil-obrien/PythonCodeWarsKata | /kata_7kyu_Isograms.py | 433 | 4.1875 | 4 | def is_isogram(string):
# Define a test_set as a SET of all the chars of an input string converted
# to lower case. Converting to set ensures no duplicate elements are present.
# After conversion if the lengths of string and SET are equal we know we are
# dealing with an isogram
test_set = set(st... | true |
b6e382aeb5e1b0531caa6747bedc20e4f3c3a748 | joeyrivas/ImpracticalPython | /Chapter4/challenge_three_rail_fence_cipher_encrypt.py | 1,910 | 4.34375 | 4 | """Encrypt a civil war 'rail fence' type cipher.
This is for a "3-rail" fence cipher for short messages.
Example text to encrypt: 'Buy more Maine potatoes'
Rail fence style: B O A P T
U M R M I E O A O S
Y E N T E
Read zigzag: \/\/\/\/\/\/\/\/\/\/
Enc... | true |
af45b70d8c101a4b95a0e6376ef14a0fd17a056a | ram83/epAis8_ramk | /assign8.py | 548 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 19:20:13 2020
@author: RAM
"""
def outerfunction():
''' this function is supposed to have a nested
function that checks whether the outerfunction has
a docstring size of more than 50 or not '''
x = len(outerfunction.__doc__)
def ... | true |
0aa841d634993bdccf68b79a35e7a9c061fae28a | SbasGM/Python-Exercises | /Solutions/E04.E03/Solution-E04.E03.py | 1,935 | 4.1875 | 4 |
# coding: utf-8
# # Solution: Exercise 4.E03
# In[5]:
import math
# In[6]:
# Initialization of variables
num1 = 100
num2 = 0.0
num3 = -100
num4 = 33
num5 = 16
num6 = 1000
# ### a)
# Calculate the square root of num1
# In[8]:
# Carry out the calculation
result = math.sqrt(num1)
# Display the result
print(r... | true |
fdcf96f3a9c4dbeb4d50194460cbda92698c0c7f | SbasGM/Python-Exercises | /Solutions/E03.E02/Solution-E03.E02.py | 329 | 4.25 | 4 |
# coding: utf-8
# # Solution: Exercise 3.E02
# In[1]:
# Request user input: User name
name = input("Please enter your name: ")
# Request user input: Country of residence
country = input("Please enter your country of residence: ")
# In[3]:
# Display the user input
print(name + " (" + country.upper() + ")")
# I... | true |
6f40267b4ee7d01a9765dac0fa52687bf870ddc9 | SbasGM/Python-Exercises | /Solutions/E06.E01/Solution-E06.E01.py | 487 | 4.21875 | 4 |
# coding: utf-8
# # Solution: Exercise 6.E01
# In[12]:
# Initialize a number
number = -10
# In[13]:
# Case 1: Check whether number is larger than 0
if(number > 0):
# Tell the user the number is positive
print("The number " + str(number) + " is positive")
# Case 2: Check whether number is smaller tha... | true |
1d8413a5b4a30e2fdca9a7cdf8d222d995d96627 | SbasGM/Python-Exercises | /Solutions/E08.S02/Solution-E08.S02.py | 1,029 | 4.25 | 4 |
# coding: utf-8
# # Solution: Exercise 8.S02
# In[20]:
# Request a number
numberStr = input("Please enter an integer: ")
# Convert the number into an integer
numberInt = int(numberStr)
# In[21]:
# Determine how many digits the number has
digits = len(numberStr)
# Initialize a result variable
result = 0
# In... | true |
2f30cba76a42325b36b6bb6785d43e27970c4db8 | SbasGM/Python-Exercises | /Solutions/E08.M04/Solution-E08.M04.py | 596 | 4.15625 | 4 |
# coding: utf-8
# # Solution: Exercise 8.M04
# In[15]:
# Request input from the user
number = input("Please enter an integer: ")
# Convert the input into an integer
number = int(number)
# In[16]:
# Set the counter equal to the number
counter = number
# Initialize the result
factorial = 1
# Initialize the WH... | true |
0bf72f4f7b74e02c7d6e4544b2342a133b2d310f | SbasGM/Python-Exercises | /Solutions/E06.M02/Solution-E06.M02.py | 987 | 4.25 | 4 |
# coding: utf-8
# # Solution: Exercise 6.M02
# In[10]:
# Request day of the week from user
day = input("Please enter the day of the week: ")
# In[11]:
# Request time of the day in 24h format
hour = input("Please enter the time in 24h format: ")
# In[12]:
# Convert the hour into an integer
hour = int(hour)
#... | true |
cac8441641cd46be1b4ab249613b5a50833e1712 | ZihengZZH/LeetCode | /py/Sqrt(x).py | 396 | 4.125 | 4 | '''
Implement int sqrt(int x).
Compute and return the square root of x.
Note that Newton's method is recommended.
'''
import random
class Solution(object):
def mySqrt(self, x):
r = x
while r*r > x:
r = (r+x/r)/2
return r
inputs = random.sample(range(10000),10)
solu = Solut... | true |
3819989ad29b4357c0a49b3061541b20c268af82 | ZihengZZH/LeetCode | /py/SortCharactersByFrequency.py | 1,407 | 4.21875 | 4 | '''
Given a string, sort it in decreasing order based on the frequency of characters.
Example 1:
Input: "tree"
Output: "eert"
Explanation:
'e' appears twice while 'r' and 't' both appear once.
So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.
Example 2:
Input: "cccaaa"
Output: "c... | true |
b91ee58dc21608f47136381bbf92c376d15cd022 | ZihengZZH/LeetCode | /py/PancakeSorting.py | 2,025 | 4.21875 | 4 | '''
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first k elements of A. We want to perform zero or more pancake flips (doing them one after another in succession) to sort the array A.
Return the k-values corresponding to a sequence of p... | true |
a7896d94daadb140e6d3a09d2e940af892feae70 | ZihengZZH/LeetCode | /py/ReverseString.py | 654 | 4.1875 | 4 | '''
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
NOTE: Try to avoid running-time-exceeded
'''
class Solution(object):
def reverseString(self,s):
res = ""
i = len(s)-1
while i >= 0:
res += s[i]
... | true |
e5d8c611f287fecc0c996810864248b297ff8ec4 | ZihengZZH/LeetCode | /py/SymmetricTree.py | 2,308 | 4.34375 | 4 | '''
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1
/ \
2 2
\ \
3 3
Note:
Bonus points if you cou... | true |
fdcabbc0cd1d5b98a9c0ec94d3ebde320cc45b1b | ZihengZZH/LeetCode | /py/BulbSwitcher.py | 2,198 | 4.125 | 4 | '''
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb. Find how... | true |
16163deb6574221989d47e9ecc80f811f3c5ca6e | annt20/chapter-3-programming-challenges-annt20 | /Quarter of the year.py | 502 | 4.3125 | 4 | value = int(input("Enter a number from 1 to 12: "))
if value > 12 or value < 1:
print('You have entered a wrong number!')
elif 1 <= value <= 3:
print('You have entered the month which is in the first quarter.')
elif 4 <= value <= 6:
print('You have entered the month which is in the second quarter.')
elif 7 ... | true |
aa75758812ef30d9ed04115d76aba8267faac3df | kavehahmadi60/Coding_practice | /next_permutation.py | 1,042 | 4.21875 | 4 | """
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place and use only constant extra memory.
Here a... | true |
626acedf566012cd046e38c4372537644344db58 | udayuk7/python | /while loop-4.py | 236 | 4.125 | 4 | #take 2 numbers from user and print numbers in backward in a given range
a=int(input('enter a value-'))
b=int(input('enter a value-'))
while(a>=b):
print(a,end=' ')
a-=1
while(b>=a):
print(b,end=' ')
b-=1
| true |
b4b18dcbcdeacebddf846503177f5d6d7e9cfdb1 | MitchA29/Problem_Solving_Problems | /problemsolving_problems_part2.py | 1,756 | 4.21875 | 4 |
# 1.
# I would create a user input and make a function to see if it is a happy or sad number. This function would continously break down the number by
# its squares until it reaches 1. If it doesn't it is a sad number.
def square_it (n):
squareSum = 0
while (n):
squareSum += (n % 10) * (n % 10)
... | true |
b1f058d8ff4c040d04c9a22fddacb5af6a1a61ae | colinbazzano/sorting-basics | /binary.py | 1,585 | 4.34375 | 4 | """
Assume arr is sorted, return True if target is in the array
"""
def binary_search(arr, target):
# set boundaries for low and high marks to search
low = 0
high = len(arr)
# While low and high do not overlap, check the mid point
while low <= high:
mid = (low + high) // 2
# If it is e... | true |
8194002681cc5629ebf1672d17619780295f06ea | kennycolsh/GMIT-Problem-Set | /Solution-5-Prime.py | 1,021 | 4.21875 | 4 | #Solution for problem 5
#Ref
#https://linuxconfig.org/function-to-check-for-a-prime-number-with-python
#this is the starting point--Solution 1
quit =0
def is_prime_number(x):
if x >= 2:
for y in range(2,x):
if not ( x % y ):
return "This Is NOT a Prime number"
... | true |
b328424d8a911e760dc1eaee220aedec91546f4b | wjohnsson/adventofcode | /2018/02/inventory_management.py | 1,946 | 4.3125 | 4 | def triplet_or_pair(items):
"""Checks if an item in a list has a triplet and/or a pair.
Returns a tuple containing two booleans."""
values = set(items)
similar_values_count = []
for x in values:
similar_values_count.append(items.count(x))
has_triplet = False
has_pair = False
if... | true |
afbd09124c1896a1f94c9b5010ec653a26328cda | adarshmaharjan/webpoint_assignment | /question_one.py | 1,367 | 4.21875 | 4 | """
Write a program which takes array of integers, keep a total score based on the following:
Add 1 point for every even number in the array
Add 3 points for every odd number in the array, expect for the number "5"
Add 5 points every time the number "5" appears in the array
Note that... | true |
67bf8fded0550bc0faed74f2821217b77a08c7cc | yuliqing16/python_learn | /ex3.py | 459 | 4.15625 | 4 | print("I will now count ,u chickens:")
print("Hens", 25 + 30 / 6)
print("Roosters", 100 - 25 * 3 % 4)
print("Noe i will count the eggs:")
print(3+2+1-5+4%2-1.0/4.0+6)
print("Is it true that 3 + 2 < 5 - 7?")
print(3 + 2 < 5 - 7)
print("What is 3+2?", 3+2)
print("what is 5-7?",5-7)
print("Oh, that's why it's False.")
pri... | true |
9598060b9528f5752e7d76b8775826482e488790 | Darshana-Waasala/FYPBackend | /python/b_controlFlow.py | 996 | 4.15625 | 4 | number = 23
guess = int(input('enter a guess number: '))
running = True
# if statement
if guess == number:
print('you have successfully guessed the number')
elif guess < number:
print('the number is grater than {guess}'.format(guess=guess))
elif guess > number:
print('the number is lesser than {guess}'.for... | true |
4792bf1b27d0bdb3b8b61a9e42d389c572e504a2 | rishikeshpuri/Algorithms-and-Data-Structure | /tree/level order data in reverse order.py | 725 | 4.125 | 4 | class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def reverseLevelOrder(root):
queue = []
stack = []
queue.append(root)
while len(queue)>0:
root = queue.pop(0)
stack.append(root)
if root.right:
q... | true |
39d8f9e236dba9e1fe8397b54a104c2445ba3f37 | NicciTheNomad/DojoAssignments | /DojoAssignments/Python/multi.py | 1,118 | 4.3125 | 4 | # Multiples
# Part I - Write code that prints all the odd numbers from 1 to 1000. Use the for loop and don't use a list to do this exercise.
# def multi(low,high):
# y = []
# for x in range(low,high+1):
# y.append(x)
# print y
# multi(1,1000)
# Part II - Create another program that prints al... | true |
ea2906c54b4907151b3506f122924ebf2364a9c3 | nwthomas/data-structures-and-algorithms | /algorithms/search_algorithms/breadth_first_search/binary_search_tree.py | 2,605 | 4.375 | 4 | """
The BinarySearchTree class is used to instantiate a new Binary Search
Tree (as well as associated nodes).
Each one has a value as well as a reference to the next left and right points (if they exist).
"""
class BinarySearchTree:
def __init__(self, value, left=None, right=None):
self.value = value
... | true |
002ff46bbc7e52ac2464e9e425d5ee6bd03ec83f | nwthomas/data-structures-and-algorithms | /algorithms/search_algorithms/binary_search/binary_search.py | 852 | 4.125 | 4 | def binary_search(list, target):
# Short-circuit evaluation if the list length is 0
if len(list) == 0:
return -1
# Define starting placements for low and high selections
low = 0
high = len(list) - 1
# While loop runs until low is lower than (or equal to) high
while low <= high:
... | true |
0c562d0d7ab1a2a996d61576cbae142788059b50 | henryoliver/cracking-coding-interview-solutions | /Arrays and Strings/checkPermutation.py | 2,672 | 4.21875 | 4 | def checkPermutation(strA='', strB=''):
'''
Solution 1 - Sort and compare
Complexity Analysis
O(n + m) time | O(1) space
Decide if one is a permutation of the other
string: strA - ASCII (128 characters)
string: strB - ASCII (128 characters)
return: True if first and second strings are... | true |
33b44f06debd4fd497d5e349ead9569aa5ac53a9 | willjkelly/MIT_courses | /Jamie/Lecture1/ps1b.py | 710 | 4.21875 | 4 | portion_down_payment = 0.25
current_savings = 0.00
r = 0.04
annual_salary = float(input("Enter your annual salary: "))
portion_saved = float(input("Enter the percent of your salary to save, as a decimal: "))
total_cost = float(input("Enter the cost of your dream home: "))
semi_annual_raise = float(input("Enter the se... | true |
c9aaa645a381ebf3ed6523aa9e18f73f8e57d8eb | prabhanshu/advance-python | /pythonic/most_common_word.py | 1,578 | 4.125 | 4 | """
Input:
paragraph = "Bob hit a ball, the hit BALL flew far after it was hit."
banned = ["hit"]
Output: "ball"
Explanation:
"hit" occurs 3 times, but it is a banned word.
"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph.
Note that words in the paragraph are not... | true |
8463c1aa707d46f3415a669a13a9aebc5f59a6f4 | DaZZware/Python-part-2-of-the-journey | /GuessingNumberVS.py | 1,221 | 4.125 | 4 | #Guessing number VS
import random
number = random.randint(1, 100)
print(" Welcome to 'Guess the Number' Vs the Computer!")
print("\n\n")
print("The Computer has selected number between 1 and 100.")
print("Try to guess it in as few attempts as possible. First to Guess Wins!! \n")
pNumber = int(input... | true |
61ed7b9e4f9491aca43941fbb3bd534e882ee004 | Pryangan/Python_Program | /Database with python/database.py | 2,555 | 4.25 | 4 | import sqlite3
while True:
print('***************************Menu********************************')
print('1. Create Database\n2. Create Table\n3. Insert Record into Table\n4. Select From Table\n5. Update Table\n6. Delete from Table')
choice = int(input('Enter Your Choice- '))
if choice is 1:
... | true |
135d416c2292a07d2524dece32dd12880bb861e4 | oyategbebose/python-datascience | /Day2.py | 1,544 | 4.375 | 4 | print('Hello ' + 'Welcome to pyhton class')#joining of two strings together
print('Hello' + ' ' + 'World') #with empty
#joining of variable and string with + and ,
Firstword = 'Simeon'
print('Welcome to python class ' + Firstword)
print('Welcome to python class', Firstword)
#joining of two variables with + a... | true |
dbcce937dfd4e0cf5bc2b8da79108dacf592688f | Surajit043/Python | /Python_Basic/ternary_operator.py | 398 | 4.3125 | 4 | '''
Ternary operator
value 1 if predicted else value 2
'''
number = int(input( ))
x = ('even' if number %2 == 0 else 'odd')
print (x)
# value 1 = 'odd' ,if number % 2 ==0 means that --->
# -----> if the input be devided by 2 and is reminder or modulas be 0 then the output print the value 1 .
# else 'odd' -----> ... | true |
07ddd604640d54dfc41c39c5b8cfb50fa4577e7b | Surajit043/Python | /Statistical_Mechanics/Q6 alternative.py | 1,067 | 4.1875 | 4 | # Plot distance as a function of time for a random walk together with the theoretical result
import numpy as np
import matplotlib.pyplot as plt
# We create 1000 realizations with 200 steps each
n_stories = 1000
t_max = 200
t = np.arange(t_max)
# Steps can be -1 or 1 (note that randint excludes the upper limit)
steps ... | true |
d03f39c27bfc9687b62d135be80f1752be537b4c | Kenjilam92/algorithm | /April/coinchange.py | 769 | 4.15625 | 4 | # Let's revisit Generate Coin Change!
# Change is inevitable (especially when breaking a twenty). Make generateCoinChange(cents). Accept a number of American cents, compute and represent that amount with smallest number of coins. Common American coins are pennies (1 cent), nickels (5 cents),dimes (10 cents), and quart... | true |
b1759d1a7ed265718c0ca379c4d7a964a2c18028 | livioribeiro/project-euler | /python/p001.py | 544 | 4.15625 | 4 | """
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
import functools
FACTORS = [0, 3, 5, 6, 9, 10, 12]
if __name__ == '__main__':
total = 0
# 990 is the last multipl... | true |
9b0002d2e2e6b3a693952a53dd220103256b7df1 | jsburckhardt/theartofdoing | /shipping_account.py | 1,697 | 4.1875 | 4 | # list price function
users = ['allenj','jsburckhardt','jsarmie4']
quantity_to_ship = 0
def display_price_details():
print("Current shipping prices are as follows:\n")
print("Shipping orders 0 to 100:\t\t\t$5.10 each")
print("Shipping orders 100 to 500:\t\t\t$5.00 each")
print("Shipping orders 500 to 1000:\t\t... | true |
7dba1bec950d28a41916e4538c274077190a8bc9 | jsburckhardt/theartofdoing | /gradesorter.py | 835 | 4.15625 | 4 | print("Welcome to the Grade Sorter App")
# Initialize list and ger user input
grades = []
grades.append(int(input("What is your first grade (0-100): ")))
grades.append(int(input("What is your second grade (0-100): ")))
grades.append(int(input("What is your third grade (0-100): ")))
grades.append(int(input("What is you... | true |
d721b758ecebe796326457ea02d9d1d020fb00b9 | jsburckhardt/theartofdoing | /27_even_odd_sorter.py | 1,103 | 4.25 | 4 | # Greeting
app = "Event Odd Number Sorter"
print(f"Welcome to the {app} app!")
running = True
while running:
comma_separated_numbers = (
input("\nEnter a string of numbers separated by a comma (,): ")
.lower()
.strip()
.split(",")
)
# odd and even holder
odd, even = [],... | true |
d364736808e39286a97f777eb092d3a1fd99d832 | bhavikjadav/Python_Crash_Course_Eric_Matthes_Chapter_9 | /9.6_Ice Cream Stand.py | 2,432 | 4.59375 | 5 | #!/usr/bin/env python
# coding: utf-8
# # 9-6. Ice Cream Stand: An ice cream stand is a specific kind of restaurant. Write a class called IceCreamStand that inherits from the Restaurant class you wrote in Exercise 9-1 (page 162) or Exercise 9-4 (page 167). Either version of the class will work; just pick the one you l... | true |
45becbdc525d25559d85a1951f6392efcc47fd8d | routdh2/100daysofcodingchallenge | /Day10/useful_py_cmds2.py | 683 | 4.34375 | 4 | '''Part 2 of useful python commands'''
if __name__=="__main__":
'''1. setattr() and getattr() method'''
class Employee:
pass
emp1=Employee()
emp1.name="Dhananjay"
emp1.age=23
print(emp1.name,emp1.age)
key1="salary"
val1=34000
#how to set this attribute to our emp object
s... | true |
8adc20b7f566ffe760578329f612809b5687218c | routdh2/100daysofcodingchallenge | /Day_12/generators.py | 456 | 4.28125 | 4 | '''Program to understand generators in Python'''
if __name__=="__main__":
def my_range(start,end):
while start<end:
# current=start
yield start #this command generates the generator
start+=1
for i in my_range(1,10):
print(i)
gen_ob = my_range(1,10)
pri... | true |
9bca38165ae1d2cfc27f61520d78e88d486bb33e | dev-abhi-abik/Python_Practice | /Programs/Array_Rotation/method_1.py | 647 | 4.3125 | 4 | # This method uses the temp array to rotate the array by 'd' elements towards left
# Time Complexity: O(n) n -> length of array
# Space Complexity: O(d) d -> elements to be rotated
def rotate_array_left(arr,d):
n = len(arr)
temp = list()
for i in range(0,d):
temp.append(arr[i])
i = 0
while d... | true |
db51228869e64677c021d5e4d4e9adaaeeae7b66 | Vanpaia/Python-Learning | /Euler Challenges/Problem 1.py | 307 | 4.1875 | 4 | """
Multiples of 3 and 5
Problem 1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
numbers = [i for i in range(1, 1000) if i%3 == 0 or i%5==0]
print sum(numbers) | true |
c58b19761720a29520148c85280e18a5c0d71ffb | codejoncode/python-data-structures-alogos | /searching/linearSearchMaxValue.py | 977 | 4.25 | 4 | """
Linear Search algorithm searching for the max value in the list.
Will go through the entire list. O(N) best worse and aveage.
pseduo code
# Create a variable called max_value_index
# Set max_value_index to the index of the first element of the search list
# For each element in the search list... | true |
1535569326745579b8be7b50df6ac0aca52e800d | smw11/CS112-Spring2012 | /hw03/prissybot.py | 2,291 | 4.28125 | 4 | #!/usr/bin/env python
print "Enter your name: "
name=raw_input()
print "Prissybot: Hello there, "+name+"."
name2=name+": "
text=raw_input(name2)
print "Prissybot: You mean, "+text+", sir!"
text2=raw_input(name2)
print "Prissybot: Well, I never have been so insulted in all my life."
text3=raw_input(name2)
print "Prissy... | true |
ce861691f901dbf4758170ce6b072b36a6cdf105 | GirishJoshi/interviewcake | /Arrays/merge_sorted (mine).py | 1,371 | 4.28125 | 4 | """
In order to win the prize for most cookies sold, my friend Alice and I are going to merge our
Girl Scout Cookies orders and enter as one unit.
Each order is represented by an "order id" (an integer).
We have our lists of orders sorted numerically already, in lists. Write a function to merge our
lists of orders ... | true |
7c3926f121b38072ff617aba3057108a4cb547ea | GirishJoshi/interviewcake | /Sorting, searching, logarithms/rotation_point.py | 2,194 | 4.28125 | 4 | """
I want to learn some big words so people think I'm smart.
I opened up a dictionary to a page in the middle and started flipping through,
looking for words I didn't know. I put each word I didn't know at increasing indices in
a huge list I created in memory. When I reached the end of the dictionary,
I started fr... | true |
79f2a2af579b537ea935dcb8efee67e5acf87289 | devInTheNorth/PySnippets | /collatz_sequence.py | 700 | 4.15625 | 4 |
def collatz(number):
''' returns a given number if it is equal to 1, half of
the number of it is even, (3 * number + 1) if the number is odd but not one '''
if number == 1:
print(number)
return number
if number % 2 == 0:
out = int(number/2)
if out != 1:
prin... | true |
431634650b117e9b46a364b939531823feae4e30 | siddharthkansara/PythonAssignment | /generator_range.py | 319 | 4.21875 | 4 | #generator range
a = (num for num in range(10)) # 'a' has become a generator object in this. this is generator comprehension
print(next(a),'First element') # this prints just the first element.
for num in a: # this loops through 'a'
print(num)
print(a) # this prints the address of memory object 'a'
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.