blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
7334abb4a4292b369af8ecbcb18980f127cbc558 | FluffyFu/UCSD_Algorithms_Course_1 | /week3_greedy_algorithms/5_collecting_signatures/covering_segments.py | 1,115 | 4.3125 | 4 | # Uses python3
import sys
from collections import namedtuple
Segment = namedtuple('Segment', 'start end')
def optimal_points(segments):
"""
Given a list of intervals (defined by integers). Find the minimum number of points,
such that each segment at least contains one point.
Args:
segments (... | true |
b85f45db7324fe4acbb6beb920cd38071e01da91 | FluffyFu/UCSD_Algorithms_Course_1 | /week2_algorithmic_warmup/8_last_digit_of_the_sum_of_squares_of_fibonacci_numbers/fibonacci_sum_squares.py | 972 | 4.28125 | 4 | # Uses python3
from sys import stdin
def fibonacci_sum_squares_naive(n):
if n <= 1:
return n
previous = 0
current = 1
sum = 1
for _ in range(n - 1):
previous, current = current, previous + current
sum += current * current
return sum % 10
def fibonacci_sum_squares(n... | true |
763c4122695531a8de231f3982bdfb070097cf87 | AkshayLavhagale/SW_567_HW_01 | /HW_01.py | 1,585 | 4.3125 | 4 | """ Name - Akshay Lavhagale
HW 01: Testing triangle classification
The function returns a string that specifies whether the triangle is scalene, isosceles, or equilateral,
and whether it is a right triangle as well. """
def classify_triangle(a, b, c):
# This function will tell us whether the triangle ... | true |
7c7d3f029730d3c2a2653c367c9dbc45fb9bcd41 | Mollocks/Day_at_the_py_shop | /Day1.py | 435 | 4.28125 | 4 | #!/usr/bin/env python3
#This is my first script :)
print("Hello World!")
x = "Passion fruit"
y = x.upper()
print(y)
#Anything I want
age = 49
txt = "My name is Hubert, and I am {}"
print(txt.format(age))
"""
This is Hubert and he is 49.
You can mix strings only using the .format function
"""
#https://www.w3school... | true |
9470642703b3ac4a62e94276dcd3eb529b38fe31 | Austin-Faulkner/Basic_General_Python_Practice | /OxfordComma.py | 1,442 | 4.34375 | 4 | # When writing out a list in English, one normally spearates
# the items with commas. In addition, the word "and" is normally
# included before the last item, unless the list only contains
# one item. Consider the following four lists:
# apples
# apples and oranges
# apples, oranges, and bananas
# apples, oran... | true |
7cea87bed8615753466b2cd60712e2c22ce34fb2 | nurur/ReplaceFirstCharacter-R.vs.Python | /repFirstCharacter.py | 613 | 4.53125 | 5 | # Python script to change the case (lower or upper) of the first letter of a string
# String
a='circulating'
print 'The string is:', a
print ''
#Method 1: splitting string into letters
print 'Changing the first letter by splitting the string into letters'
b=list(a)
b[0] = b[0].upper()
b=''.join(b)
print b
print ... | true |
bd5ac9ee6116ebe863436db0dcf969b525beec5e | noahjett/Algorithmic-Number-Theory | /Algorithmic Number Theory/Binary_Exponentiation.py | 2,450 | 4.15625 | 4 | # Author: Noah Jett
# Date: 10/1/2018
# CS 370: Algorithmic Number Theory - Prof. Shallue
# This program is an implementation of the binary exponentiation algorithm to solve a problem of form a**e % n in fewer steps
# I referenced our classroom discussion and the python wiki for the Math.log2 method
import math... | true |
f14c4696cc8e4f2db90416bd8e4216a7319c3860 | Quiver92/edX_Introduction-to-Python-Creating-Scalable-Robust-Interactive-Code | /Boolean_Operators/Task1.py | 761 | 4.375 | 4 | #Boolean Operators
#Boolean values (True, False)
# [ ] Use relational and/or arithmetic operators with the variables x and y to write:
# 3 expressions that evaluate to True (i.e. x >= y)
# 3 expressions that evaluate to False (i.e. x <= y)
x = 84
y = 17
print(x >= y)
print(x >= y and x >= y)
print(x >= y or x >= y)... | true |
837bebc2d9fbed6fe2ab8443f09a30bce9554478 | Quiver92/edX_Introduction-to-Python-Creating-Scalable-Robust-Interactive-Code | /File_System/Task_2.py | 908 | 4.40625 | 4 | import os.path
# [ ] Write a program that prompts the user for a file or directory name
# then prints a message verifying if it exists in the current working directory
dir_name = input("Please provide a file or directory name: ")
if(os.path.exists(dir_name)):
print("Path exists")
# Test to see if it's a file o... | true |
655bf45e09a32b1544b54c5c938b8f5430daf4e7 | grimesj7913/cti110 | /P3T1_AreaOfRectangles_JamesGrimes.py | 733 | 4.34375 | 4 | #A calculator for calculating two seperate areas of rectangles
#September 11th 2018
#CTI-110 P3T1 - Areas of Rectangles
#James Grimes
#
length1 = float(input("What is the length of the first rectangle?:"))
width1 = float(input("What is the width of the first rectangle?:" ))
area1 = float(length1 * width1)
len... | true |
78c7fb57d30e08b0c7f0808c3272769d6f2a2726 | elnieto/Python-Activities | /Coprime.py | 1,342 | 4.125 | 4 | #Elizabeth Nieto
#09/20/19
#Honor Statement: I have not given or received any unauthorized assistance \
#on this assignment.
#https://youtu.be/6rhgXRIZ6OA
#HW 1 Part 2
def coprime(a,b):
'takes two numbers and returns whether or not they are are coprime'
#check if the numbers are divisible by 2 or if b... | true |
07079cd63c24d88847a4b4c6a6749c8c2dca2abb | AbhijeetSah/BasicPython | /DemoHiererchialInheritance.py | 446 | 4.15625 | 4 | #hiererchial Inheritance
class Shape:
def setValue(self, s):
self.s=s
class Square(Shape):
def area(self):
return self.s*self.s
class Circle(Shape):
def area(self):
return 3.14*self.s*self.s
sq= Square()
s= int(input("Enter the side of square "))
sq.setValue(s)
print("Area of squa... | true |
7bf3778c0dd682739cec943e2f9550e01a517538 | itssamuelrowe/arpya | /session5/names_loop.py | 577 | 4.84375 | 5 | # 0 1 2 3
names = [
"Arpya Roy",
"Samuel Rowe",
"Sreem Chowdhary",
"Ayushmann Khurrana"
]
for name in names:
print(name)
"""
When you give a collection to a for loop, what Python does is create an iterator for the
collection. So what is an iterator? In the context of a for loop, a... | true |
3b32018a5f493a622d5aee4bd979813c15c7c86c | vanderzj/IT3038C | /Python/nameage.py | 819 | 4.15625 | 4 | import time
start_time = time.time()
#gets user's name and age
print('What is your name?')
myName = input()
print('Hello ' + myName + '. That is a good name. How old are you?')
myAge = input()
#Gives different responses based on the user's age.
if myAge < 13:
print("Learning young, that's good.")
elif myAge == 1... | true |
b598c4d34d7f60ad2a821efaed87e47d7ed16781 | vanderzj/IT3038C | /Python/TKinter_Practice/buttons.py | 1,002 | 4.53125 | 5 | # Imports tkinter, which is a built-in Python module used to make GUIs.
from tkinter import *
# Creates the window that the content of our script will sit in.
win = Tk()
# This function is being set up to give the button below functionality with the (command=) arguement.
# The Command function should be written as (c... | true |
1f030e2f733874480af9f92425566e9f593dfe34 | ledbagholberton/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/0-add_integer.py | 605 | 4.375 | 4 | #!/usr/bin/python3
def add_integer(a, b=98):
""" Function that summ two numbers integer or float.
Args:
a: First parameter (integer or float)
b: Second paramenter (integer of float)
Returns:
Summ of a & b
"""
if a is None or (type(a) is not int and type(a)... | true |
5b82dd7f7e00b9ed2a8ee39e194384eb32ccc3f0 | green-fox-academy/MartonG11 | /week-02/day-1/mile_to_km_converter.py | 273 | 4.4375 | 4 | # Write a program that asks for an integer that is a distance in kilometers,
# then it converts that value to miles and prints it
km = float(input('Put a kilometer to convert to miles: '))
factor = 0.621371192
miles = km * factor
print("The distance in miles is: ", miles) | true |
cc328013864be876f42b1b7c25117bc3ffcccb4a | green-fox-academy/MartonG11 | /week-02/day-2/swap_elements.py | 250 | 4.34375 | 4 | # - Create a variable named `abc`
# with the following content: `["first", "second", "third"]`
# - Swap the first and the third element of `abc`
abc = ["first", "second", "third"]
def swap(x):
x[0] , x[2] = x[2] , x[0]
print(x)
swap(abc) | true |
210519003481bc2545f6a2dfeab8c81ec67df223 | green-fox-academy/MartonG11 | /week-03/day-3/rainbow_box_function.py | 767 | 4.1875 | 4 | from tkinter import *
root = Tk()
canvas = Canvas(root, width='300', height='300')
canvas.pack()
# create a square drawing function that takes 2 parameters:
# the square size, and the fill color,
# and draws a square of that size and color to the center of the canvas.
# create a loop that fills the canvas with rainb... | true |
8b6d39bb03692cc8ff81dbfdd62d59ed51b3629f | green-fox-academy/MartonG11 | /week-03/day-3/center_box_function.py | 535 | 4.34375 | 4 | from tkinter import *
root = Tk()
canvas = Canvas(root, width='300', height='300')
canvas.pack()
# create a square drawing function that takes 1 parameter:
# the square size
# and draws a square of that size to the center of the canvas.
# draw 3 squares with that function.
size1 = 130
size2 = 100
size3 = 50
def dr... | true |
b500ce44e4652624e0b5f94e19da756ad190e217 | hkscy/algorithms | /Miscellaneous Algorithms/Palindrome Checker/palindrome.py | 2,216 | 4.25 | 4 | # Chris Hicks 2020
#
# Based on Microsoft Technical Interview question:
# "Given a string, write an algorithm that will determine if it is a palindrome"
# Input: string of characters, Output: True (palindrome) False (palindrome)
#
# What is a palindrome?
# - A sequence of characters which reads the same backward as ... | true |
f4891c92ba34699fe80a9d71f66a6ae13c39a75f | JosueOb/Taller1 | /Ejercicios/Ejercicio4-6.py | 1,577 | 4.15625 | 4 | from tkinter import *
root = Tk()
v = IntVar()
Label(root,
text="""Choose a programming language:""",
justify = LEFT,
padx = 20).pack()
Radiobutton(root,
text="Python",
padx = 20,
variable=v,
value=1).pack(anchor=W)
Radiobutton(root, text="Perl",
... | true |
bffba3eb19fd92bfed2563216c3d7478a8b92fed | LitianZhou/Intro_Python | /ass_4.py | 2,635 | 4.15625 | 4 | # Part 1
while True:
RATE = 1.03
while True:
print("--------------------------------------")
start_tuition = float(input("Please type in the starting tuition: "))
if start_tuition <= 25000 and start_tuition >= 5000:
break
else:
print("The starting tuition ... | true |
cd9812c4bce5cf9755e99f06cc75db716499f0e1 | edek437/LPHW | /uy2.py | 876 | 4.125 | 4 | # understanding yield part 2
from random import sample
def get_data():
"""Return 3 random ints beetween 0 and 9"""
return sample(range(10),3)
def consume():
"""Displays a running average across lists of integers sent to it"""
running_sum=0
data_items_seen=0
while True:
data=yield
... | true |
3cdbde7f1435ef0fc65ab69b325fed08e1136216 | cakmakok/pygorithms | /string_rotation.py | 209 | 4.15625 | 4 | def is_substring(word1, word2):
return (word2 in word1) or (word1 in word2)
def string_rotation(word1, word2):
return is_substring(word2*2,word1)
print(string_rotation("waterbottle","erbottlewat"))
| true |
df61bd0ca36e962e134772f6d7d50200c7a3a7aa | phuongnguyen-ucb/LearnPythonTheHardWay | /battleship.py | 2,320 | 4.34375 | 4 | from random import randint
board = []
# Create a 5x5 board by making a list of 5 "0" and repeat it 5 times:
for element in range(5):
board.append(["O"] * 5)
# To print each outer list of a big list. 1 outer list = 1 row:
def print_board(board):
for row in board:
print " ".join(row) # to concatenate a... | true |
ac4ecdf8ffd9532f0254c6d848ba74a886122ed8 | mvoecks/CSCI5448 | /OO Project 2/Source Code/Feline.py | 2,173 | 4.125 | 4 | import abc
from Animal import Animal
from roamBehaviorAbstract import climbTree
from roamBehaviorAbstract import randomAction
''' The roaming behavior for Felines can either be to climb a tree or to do a
random action. Therefore we create two roamBehaviorAbstract variables,
climbTree and randomAction that we ... | true |
83424e65bc9b7240d3ff929a22884e2ebef578d3 | asvkarthick/LearnPython | /GUI/tkinter/tkinter-label-02.py | 620 | 4.25 | 4 | #!/usr/bin/python3
# Author: Karthick Kumaran <asvkarthick@gmail.com>
# Simple GUI Program with just a window and a label
import tkinter as tk
from tkinter import ttk
# Create instance
win = tk.Tk()
# Set the title for the window
win.title("Python GUI with a label")
# Add a label
label = ttk.Label(win, text = "Labe... | true |
ee3acb288c29099d6336e9d5fd0b7a54f71573fe | asvkarthick/LearnPython | /02-function/function-05.py | 218 | 4.125 | 4 | #!/usr/bin/python
# Author: Karthick Kumaran <asvkarthick@gmail.com>
# Function with variable number of arguments
def print_args(*args):
if len(args):
for i in args:
print(i);
else:
print('No arguments passed')
print_args(1, 2, 3)
| true |
8fa01eb2322cd9c2d82e043aedd950a408c46901 | optionalg/challenges-leetcode-interesting | /degree-of-an-array/test.py | 2,851 | 4.15625 | 4 | #!/usr/bin/env python
##-------------------------------------------------------------------
## @copyright 2017 brain.dennyzhang.com
## Licensed under MIT
## https://www.dennyzhang.com/wp-content/mit_license.txt
##
## File: test.py
## Author : Denny <http://brain.dennyzhang.com/contact>
## Tags:
## Description:
## ... | true |
e24f2c5e5688efbfc9a8e1c041765efc22fa0cc0 | optionalg/challenges-leetcode-interesting | /reverse-words-in-a-string/test.py | 1,323 | 4.28125 | 4 | #!/usr/bin/env python
##-------------------------------------------------------------------
## @copyright 2017 brain.dennyzhang.com
## Licensed under MIT
## https://www.dennyzhang.com/wp-content/mit_license.txt
##
## File: test.py
## Author : Denny <http://brain.dennyzhang.com/contact>
## Tags:
## Description:
## ... | true |
37cc4a21931e88c5558809dfb756e01e01a92d10 | brianpeterson28/Princeton_Python_SWD | /bep_exercises/chapter1.2/contcompinterest/contcompinterest.py | 2,227 | 4.3125 | 4 | '''
Author: Brian Peterson | https://github.com/brianpeterson28
Creative Exercise 1.2.21 - Intro to Programming In Python
'''
import math
import decimal
print("Calculates Future Value @ Continuously Compounded Rate.")
def askForInterestRate():
while True:
try:
interestrate = float(input("Enter interest rate: ")... | true |
ad8dd825f3f56a5773b4d0bb79f27a3738c13533 | crishabhkumar/Python-Learning | /Assignments/Trailing Zeroes.py | 299 | 4.15625 | 4 | #find and return number of trailing 0s in n factorial
#without calculation n factorial
n = int(input("Please enter a number:"))
def trailingZeros2(n):
result = 0
power = 5
while(n >= power):
result += n // power
power *= 5
return result
print(trailingZeros2(n))
| true |
60f2c7a1930e69268bd41975cc3778e545ee9100 | sudhansom/python_sda | /python_fundamentals/10-functions/functions-exercise-01.py | 306 | 4.3125 | 4 | # write a function that returns the biggest of all the three given numbers
def max_of_three(a, b, c):
if a > b:
if a > c:
return a
else:
return c
else:
if b > c:
return b
else:
return c
print(max_of_three(3, 7, 3)) | true |
10f075ee5aff42884240b0a5070d649d3c71d972 | sudhansom/python_sda | /python_fundamentals/06-basic-string-operations/strings-exercise.py | 420 | 4.21875 | 4 | # assigning a string value to a string of length more than 10 letters
string = "hello"
reminder = len(string) % 2
print(reminder)
number_of_letters = 2
middle_index = int(len(string)/2)
start_index = middle_index - number_of_letters
end_index = middle_index + number_of_letters + reminder
result = string[start_index:end... | true |
8a21cc7dc1f16ae2715479dbc875d4c5e0696f6a | sudhansom/python_sda | /python_fundamentals/00-python-HomePractice/w3resource/conditions-statements-loops/problem43.py | 386 | 4.28125 | 4 | """
Write a Python program to create the multiplication table (from 1 to 10) of a number. Go to the editor
Expected Output:
Input a number: 6
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60
"""
user_input = int(input("Enter the number: ").strip())
for i in... | true |
8c8ba8bbd6230a3c045971542159acb1ef584596 | dlu270/A-First-Look-at-Iteration | /Problem 3-DL.py | 683 | 4.65625 | 5 | #Daniel Lu
#08/08/2020
#This program asks the user for the number of sides of a shape, the length of sides and the color. It then draws the shape and colors it.
import turtle
wn = turtle.Screen()
bob = turtle.Turtle()
sides = input ("What are the number of sides of the polygon?: ")
length = input ("What i... | true |
7ab66c17162421433ec712ebb1bbad0c0afbdd0b | Dianajarenga/PythonClass | /PythonClass/student.py | 1,075 | 4.59375 | 5 | class Student:
school="Akirachix"
#to create a class use a class keyword
#start the class name with a capital letter.if it has more than one letter capitalize each word
#do not include spaces
#many modules in a directory form a package
#when you save your code oin a .py file its called a module
#to import a class f... | true |
6096598f70d386090efba0a31f1be8a6a483a39e | johnashu/Various-Sorting-and-SEarching-Algorithms | /search/interpolation.py | 1,970 | 4.1875 | 4 | """
Interpolation search is an improved variant of binary search. This search algorithm works on the probing position of the required value. For this algorithm to work properly, the data collection should be in a sorted form and equally distributed.
Binary search has a huge advantage of time complexity over linear sea... | true |
11a2948ed09d97d32565e20dcb6ef0f7158a879f | zosopick/mawpy | /Chapters 1 to 5/Chapter 1/1-5 Turtle spiral.py | 498 | 4.28125 | 4 | '''
Excersise 1-5: Turtle spiral
Make a funciton to draw 60 squares, turning 5 degrees after each
square and making each successive square bigger. Start at a length
of 5 and increment 5 units every square.
'''
from turtle import *
shape('turtle')
speed(10)
length=5
def turtle_spiral():
length=5... | true |
2e432eac8fbcb96bdd568ac0ebb83f08761bc912 | zosopick/mawpy | /Chapters 1 to 5/Chapter 5/Exercise__5_1_A_spin_cycle/Exercise__5_1_A_spin_cycle.pyde | 771 | 4.1875 | 4 | '''
Exercise 5-1: A spin cycle
Create a circle of equilateral triangles in a processing sketch and
rotate them using the rotate() function
'''
t=0
def setup():
size(1000,1000)
rectMode(CORNERS) #This keeps the squares rotating around the center
#also, one can use CORNER or... | true |
bf73c880b2704f1ef37080e4bb18ef0777d6ff5a | vighneshdeepweb/Turtle-corona | /Turtle-Covid/covid.py | 676 | 4.125 | 4 | import turtle
#create a screen
screen = turtle.Screen()
#create a drawer for drawing
drawer = turtle.Turtle()
#Set the background color of the screen
screen.bgcolor("black")
#For set a Background,color,speed,pensize and color of the drawer
drawer.pencolor("darkgreen")
drawer.pensize(3)
drawer1 = 0
dr... | true |
d10975f40f51444b69afcee04b30a0347faf0da5 | veldc/basics | /labs/02_basic_datatypes/02_04_temp.py | 402 | 4.34375 | 4 | '''
Fahrenheit to Celsius:
Write the necessary code to read a degree in Fahrenheit from the console
then convert it to Celsius and print it to the console.
C = (F - 32) * (5 / 9)
Output should read like - "81.32 degrees fahrenheit = 27.4 degrees celsius"
'''
Farh = float(input("Enter degree Farh: "))
Celsius ... | true |
776fa8276987922284cac8b4a28c8e974242f0ee | veldc/basics | /labs/02_basic_datatypes/02_05_convert.py | 799 | 4.40625 | 4 | '''
Demonstrate how to:
1) Convert an int to a float
2) Convert a float to an int
3) Perform floor division using a float and an int.
4) Use two user inputted values to perform multiplication.
Take note of what information is lost when some conversions take place.
'''
# int to float
Num = 8
Div ... | true |
764e49079883e2419c2ed66de6d3b883f3074b10 | VanessaVanG/number_game | /racecar.py | 1,536 | 4.3125 | 4 | '''OK, let's combine everything we've done so far into one challenge!
First, create a class named RaceCar. In the __init__ for the class, take arguments for color and fuel_remaining. Be sure to set these as attributes on the instance.
Also, use setattr to take any other keyword arguments that come in.'''
class RaceC... | true |
30288a48048f82daf25da88ed697364d86d0fc4d | OliverTarrant17/CMEECourseWork | /Week2/Code/basic_io.py | 1,589 | 4.21875 | 4 | #! usr/bin/python
"""Author - Oliver Tarrant
This file gives the example code for opening a file for reading using python.
Then the code writes a new file called testout.txt which is the output of 1-100
and saves this file in Sandbox folder (see below). Finally the code gives an example of
storing objects for later u... | true |
e80b0d4d97c6cce390144e17307a65a7fb0cced1 | DroidFreak32/PythonLab | /p13.py | 2,590 | 4.75 | 5 | # p13.py
"""
Design a class named Account that contains:
* A private int data field named id for the account.
* A private float data field named balance for the account.
* A private float data field named annualInterestRate that stores the current interest rate.
* A constructor that creates an account with the specifie... | true |
650c23952ab2978697916954ed04761ed800330c | DroidFreak32/PythonLab | /p09.py | 592 | 4.1875 | 4 | # p09.py
'''
Consider two strings, String1 and String2 and display the merged_string as output. The merged_string should be the capital letters from both the strings in the order they appear. Sample Input: String1: I Like C String2: Mary Likes Python Merged_string should be ILCMLP
'''
String1=input("Enter string 1:")
... | true |
64e179dae3eada5e76890da5c412dacddab81a1e | TenckHitomi/turtle-racing | /racing_project.py | 2,391 | 4.3125 | 4 | import turtle
import time
import random
WIDTH, HEIGHT = 500, 500
COLORS = ['red', 'green', 'blue', 'orange', 'yellow', 'black', 'purple', 'pink', 'brown', 'cyan']
def get_number_of_racers():
"""Input number of turtles you want to show up on the screen"""
racers = 0
while True:
racers = input("Ent... | true |
f5c0aa56ad89771487550747ea9edaa2656c0e0a | carlshan/design-and-analysis-of-algorithms-part-1 | /coursework/week2/quicksort.py | 1,554 | 4.28125 | 4 |
def choose_pivot(array, length):
return array[0], 0
def swap(array, i, j):
temp = array[i]
array[i] = array[j]
array[j] = temp
def partition(array, low, high):
pivot = array[low]
i, j = low + 1, high - 1 # initializes i to be first position after pivot and j to be last index
while True... | true |
7c885c274f4103db153970a6ce1476cf415c790e | Mkaif-Agb/Python_3 | /zip.py | 398 | 4.46875 | 4 | first_name = ["Jack", "Tom", "Dwayne"]
last_name = ["Ryan","Holland", "Johnson"]
name = zip(first_name,last_name)
for a,b in name:
print(a,b)
def pallindrome():
while True:
string=input("Enter the string or number you want to check")
if string == string[::-1]:
print("It is a pallin... | true |
0af9c97699b04830aa12069d4258c5725f8f0c35 | sheriline/python | /D11/Activities/friend.py | 562 | 4.21875 | 4 | """
Elijah
Make a program that filters a list of strings and
returns a dictionary with your friends and
foes respectively.
If a name has exactly 4 letters in it, you can
be sure that it has to be a friend of yours!
Otherwise, you can be sure he's not...
Output = {
"Ryan":"friend", "Kieran":"foe",
"Jason":"foe",... | true |
030162330c0295f35315dd1d90a688b293a39759 | sheriline/python | /D1 D2/ifstatement.py | 731 | 4.3125 | 4 | #!/usr/bin/env python3.7
#example
# gender = input("Gender? ")
# if gender == "male" or gender == "Male":
# print("Your cat is male")
# else:
# print("Your cat is female")
# age = int(input("Age of your cat? "))
# if age < 5:
# print("Your cat is young.")
# else:
# print("Your cat is adult.")
#exerci... | true |
464ddc137e89538fd0a5cc63b58bfc837bdf06c5 | scotttct/tamuk | /Python/Python_Abs_Begin/Mod3_Conditionals/3_5_Math_3.py | 787 | 4.59375 | 5 | # Task 3
# PROJECT: IMPROVED MULTIPLYING CALCULATOR FUNCTION
# putting together conditionals, input casting and math
# update the multiply() function to multiply or divide
# single parameter is operator with arguments of * or / operator
# default operator is "*" (multiply)
# return the result of multiplication or divis... | true |
a8f769fc11e575144fed429fd57165f9b318ee36 | scotttct/tamuk | /Python/Python_Abs_Begin/Mod4_Nested/4_3-7_1-While_True.py | 1,132 | 4.1875 | 4 | # Task 1
# WHILE TRUE
# [ ] Program: Get a name forever ...or until done
# create variable, familar_name, and assign it an empty string ("")
# use while True:
# ask for user input for familar_name (common name friends/family use)
# keep asking until given a non-blank/non-space alphabetical name is received (Hint: Boole... | true |
a2d480068f763e0465022ea3ed208a4b4889ac4a | scotttct/tamuk | /Homework/Homework1.py | 1,702 | 4.53125 | 5 | # Write a program that prints the numbers from 1 to 100.
# But for multiples of three print “Fizz” instead of the number
# and for the multiples of five print “Buzz”.
# For numbers which are multiples of both three and five print “FizzBuzz”."
# for i in range(0, 101):
# print(i)
# print()
# for t in range(0, ... | true |
9f5ab86e2e150066f02dacc8d1c35defabc1115f | scotttct/tamuk | /Python/Python_Abs_Begin/Mod1/p1_2.py | 280 | 4.125 | 4 | # examples of printing strings with single and double quotes
# print('strings go in single')
# print("or double quotes")
# printing an Integer with python: No quotes in integers/numbers
print(299)
# printing a string made of Integer (number) characters with python
print("2017") | true |
ec67d5050211e27b595231fa5f5f3ae31011b821 | palaciosdiego/pythoniseasy | /src/fizzBuzzAssignment.py | 630 | 4.15625 | 4 | def isPrime(number):
# prime number is always greater than 1
if number > 1:
for i in range(2, number):
if (number % i) == 0:
return False
# break
else:
return True
# if the entered number is less than or equal to 1
# then it is not ... | true |
fbfd74756c1efd103b8958b594b2f876f9ed4876 | arefrazavi/spark_stack | /spark_sql/select_teenagers_sql.py | 1,769 | 4.15625 | 4 | from pyspark import SparkConf, SparkContext
from pyspark.sql import SparkSession, Row
def convert_to_sql_row(line):
row = line.split(',')
return Row(id=int(row[0]), name=str(row[1]), age=int(row[2]), friends_count=int(row[3]))
if __name__ == '__main__':
sc_conf = SparkConf().setMaster('local[*]').setA... | true |
b3defea1bcb2f421c1d0ba8b54faf7f4a659ea43 | EmersonPaul/MIT-OCW-Assignments | /Ps4/ps4a.py | 1,929 | 4.34375 | 4 | # Problem Set 4A
# Name: <your name here>
# Collaborators:
# Time Spent: x:xx
def get_permutations(sequence):
'''
Enumerate all permutations of a given string
sequence (string): an arbitrary string to permute. Assume that it is a
non-empty string.
You MUST use recursion for this par... | true |
ee37314201ebeace70e328eabf38777faedfd212 | dairof7/holbertonschool-higher_level_programming | /0x07-python-test_driven_development/5-text_indentation.py | 641 | 4.15625 | 4 | #!/usr/bin/python3
"""
Module text_indentation
module to ident a text
print a text
"""
def text_indentation(text):
"""this functions print a text
insert newline where find a ".", "?", ":"
"""
if type(text) != str or text is None:
raise TypeError("text must be a string")
sw = 0
for i in... | true |
bb3c1324e8def64fbfddcfcba51d48ce526b40ae | PriyanjaniCh/Python | /henderson_method.py | 2,980 | 4.3125 | 4 | #!/usr/bin/python3
# Purpose: To implement the Henderson method
# Execution: One argument for start number can be passed
#
# William F. Henderson III was a brilliant computer scientist who was taken from us all too soon. He had trouble falling asleep
# because there were too many thoughts running through his... | true |
f390a60a44262785efe169930db6f56cba694885 | hyperlearningai/introduction-to-python | /examples/my-first-project/myutils/collections/listutils.py | 982 | 4.15625 | 4 | #!/usr/bin/env python3
"""Collection of useful tools for working with list objects.
This module demonstrates the creation and usage of modules in Python.
The documentation standard for modules is to provide a docstring at the top
of the module script file. This docstring consists of a one-line summary
followed by a mo... | true |
b752e89398d424ec93433eb14083f898431ce8bd | mcp292/INF502 | /src/midterm/2a.py | 726 | 4.4375 | 4 | '''
Approach: I knew I had to run a for loop it range of the entered number to print
the asterisks. The hard part was converting user input to a list of integers.
I found out a good use for list comprehension, which made the code a one liner.
'''
nums = input("Enter 5 comma separated numbers between 1 and 20: ").spl... | true |
c7443de044ebc3149c37b398ee230d21ca784bee | johnnymango/IS211_Assignment1 | /assignment1_part1.py | 1,969 | 4.4375 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Assignment 1 - Part 1"""
def listDivide(numbers=[], divide=2):
""" The function returns the number of elements in the numbers list that
are divisible by divide.
Args:
numbers(list): a list of numbers
divide (int, default=2): the number by w... | true |
dc72e0c85760fb647f5ce64289303cbe915fdb04 | Anosike-CK/class_code | /Membership_Operartors.py | 1,389 | 4.625 | 5 | # MEMBERSHIP OPERATORS ARE USED TO CHECK FOR THE MEMBERSHIP OF A VARIABLE IN A SEQUENCE
a = 10
b = 20
num_list = [1, 2, 3, 4, 5 ]
if ( a in num_list ):
print ("Line 1 - a is available in the given num_list")
else:
print ("Line 1 - a is not available in the given num_list")
if ( b not in num_list ):
print ("... | true |
fd0012b59d8cda95b17f00aecef6093446defd34 | Anosike-CK/class_code | /first_thonny_practice.py | 330 | 4.25 | 4 | """website = "Apple.com"
#we re-write the program to change the value of website to programiz.com
website = "programiz.com"
print(website) """
"""#Assign multiple values to multiple variables
a,b,c = 5,3,5.2
print(a)
print(b)
print(c)"""
#Assign the same value to multiple variables
x = y = z = "hmm"
print(x)
print(y... | true |
90e061241a1de2eb2ec544b864782218ec8d6711 | Kllicks/DigitalCraftsPythonExercises | /OddNumbers.py | 356 | 4.375 | 4 | #using while loop, print out the odd numbers 1-10 inclusive, one on a line
#initiate variable
i = 1
#while loop to cycle through and print 1-10
while i <= 10:
#if statement to check if the number is also odd
#can't use and on outer while loop because it would end the program when 2 failed
if i % 2 !... | true |
5c250f4557d71212cde13a0002b7ebc8f39f4bc6 | yasar84/week1 | /lists.py | 2,166 | 4.5 | 4 | cars = ["toyota","lexus", "bmw", "merc" ]
print(cars)
# accessing the list
print("first element of cars list: " + cars[0])
print("second element of cars list: " + cars[1])
print("third element of cars list: " + cars[2])
print("fourth element of cars list: " + cars[3])
print("last element of cars list: " + cars[-1])
... | true |
1d001ee57009334fa0394946f4b65c4f46741172 | AgguBalaji/MyCaptain123 | /file_format.py | 380 | 4.71875 | 5 | """Printing the type of file based on the extension used in saving the file
eg:
ip-- name.py
op--it is a python file"""
#input the file name along with the extension as a string
file=input("Input the Filename:")
#it is a python file if it has .py extension
if ".py" in file:
print("The extension of the file is : '... | true |
af8d1a4b71460e9ecd5819fddd63a97d4ccd7bfa | cai-michael/kemenyapprox | /matrix.py | 1,382 | 4.3125 | 4 | """
Defines some matrix operations using on the Python standard library
"""
def generate_zeros_matrix(rows, columns):
"""
Generates a matrix containing only zeros
"""
matrix = [[0 for col in range(columns)] for row in range(rows)]
return matrix
def get_column_as_list(matrix, column_no):
"""
... | true |
37f813e7e6974fe499252e476755e3e7411a037c | khayk/learning | /python/cheatsheet.py | 1,311 | 4.28125 | 4 | # 1. Print two strings with formatting
# see https://www.programiz.com/python-programming/input-output-import
print("Hello %s %s! You just delved into python." % (a, b))
# 2. Map each item from the input to int
integer_list = map(int, input().split())
# Creates a tuple of integers
t = tuple(integer_list)
... | true |
50b86447072eac47a70ad3e35bb1a285cd5a3619 | BTHabib/Lessons | /Lesson 2 Trevot test.py | 820 | 4.21875 | 4 | """
Author: Brandon Habib
Date: 1/21/2016
"""
#Initializing the array
numbers = []
#Initializing A
A = 0
#Printing instructions for the user
print ("Give me an integer Trevor and then type \"Done\" when you are done. When all is finished I will show you MAGIC!")
#A while loop to continue adding numbers to the array... | true |
771de63fb0fd06a32f10e41fd6411f28bd3b985c | mfcarrasco/Python_GIS | /AdvGIS_Course/MyClassPractice.py | 720 | 4.15625 | 4 | class Myclass:
var = "This is class variable"
def __init__(self, name):# first parameter always self in a class
self.name = name
def funct(self):#using method and a function within aclass so ALWAYS start with self
print "This is method print", self.name
foo = Myclass("Malle")... | true |
13ab27733b3c75d0c5f0c278698b43c3dd04d5a3 | haaruhito/PythonExercises | /Day1Question3.py | 495 | 4.125 | 4 | # With a given integral number n, write a program to generate a dictionary that
# contains (i, i x i) such that is an integral number between 1 and n (both included).
# and then the program should print the dictionary.Suppose the following input is
# supplied to the program: 8
# Then, the output should be: {1: 1, 2:... | true |
c142586277e8f59719f324b7c2aea239ecc98680 | kmiroshkhin/Python-Problems | /medium_vowelReplacer.py | 622 | 4.21875 | 4 | """Create a function that replaces all the vowels in a string with a specified character.
Examples
replace_vowels("the aardvark", "#") ➞ "th# ##rdv#rk"
replace_vowels("minnie mouse", "?") ➞ "m?nn?? m??s?"
replace_vowels("shakespeare", "*") ➞ "sh*k*sp**r*"
"""
def replace_vowels(txt,ch):
vowels = ['a'... | true |
561b7063ef63e21a32f425e8aa2cd0060d1e3048 | kmiroshkhin/Python-Problems | /easy_recursion_Sum.py | 353 | 4.25 | 4 | """Write a function that finds the sum of the first n natural numbers. Make your function recursive.
Examples
sum_numbers(5) ➞ 15
// 1 + 2 + 3 + 4 + 5 = 15
sum_numbers(1) ➞ 1
sum_numbers(12) ➞ 78
"""
def sum_numbers(n):
addition=int()
for i in range(1,n+1):
addition+=i
return addi... | true |
9e4a81ce2ea3628967b2f2194caee577914bd1d8 | kmiroshkhin/Python-Problems | /Hard_WhereIsBob.py | 650 | 4.3125 | 4 | """Write a function that searches a list of names (unsorted) for the name "Bob" and returns the location in the list. If Bob is not in the array, return -1.
Examples
find_bob(["Jimmy", "Layla", "Bob"]) ➞ 2
find_bob(["Bob", "Layla", "Kaitlyn", "Patricia"]) ➞ 0
find_bob(["Jimmy", "Layla", "James"]) ➞ -1
"""
... | true |
3700278b8bb878b60eaaf97e88a321ec53e146d0 | erikayi/python-challenge | /PyPoll/main_final.py | 2,013 | 4.21875 | 4 | # Analyze voting poll using data in csv file.
# import csv and os.
import csv
import os
# define the location of the data.
election_csv = "Resources/election_data.csv"
# open the data.
with open(election_csv, 'r') as csvfile:
election_csv = csv.reader(csvfile)
header = next(election_csv)
# define the va... | true |
9e7d6229ad3039076757cff1edf336796064b671 | Sudhijohn/Python-Learnings | /conditional.py | 388 | 4.1875 | 4 | #Conditional
x =6
'''
if x<6:
print('This is true')
else:
print('This is false')
'''
#elif Same as Else if
color = 'green'
'''
if color=='red':
print('Color is red')
elif color=='yellow':
print('Color is yellow')
else:
print('color is not red or yellow')
'''
#Nested if
if color == 'green':
i... | true |
60b2ea5bc3f7100de9f8f05c80dee8b0a803de46 | Aravind2595/MarchPythonProject | /Flow controls/demo6.py | 235 | 4.21875 | 4 | #maximum number using elif
num1=int(input("Enter the number1"))
num2=int(input("Enter the number2"))
if(num1>num2):
print(num1,"is the highest")
elif(num1<num2):
print(num2,"is the highest")
else:
print("numbers are equal") | true |
aa97b8e2e82b353ca5f1d3c14c97471b30d12521 | Aravind2595/MarchPythonProject | /Flow controls/for loop/demo6.py | 237 | 4.15625 | 4 | #check a given number is prime or not
num=int(input("Enter the number"))
flag=0
for i in range(2,num):
if(num%i==0):
flag=1
if(flag>0):
print(num," is not a prime number")
if(flag==0):
print(num,"is a prime number")
| true |
8a48a24a816b1693e493ddd2795f5f44aa958523 | kblicharski/ctci-solutions | /Chapter 1 | Arrays and Strings/1_6_String_Compression.py | 2,506 | 4.375 | 4 | """
Problem:
Implement a method to perform basic string compression using the counts
of repeated characters. For example, the string 'aabcccccaaa' would
become 'a2b1c5a3'. If the "compressed" string would not become smaller
than the original string, your method should return the original
string. You... | true |
61a24ed9b8931c925de092f0116f780e253de52e | kblicharski/ctci-solutions | /Chapter 1 | Arrays and Strings/1_8_Zero_Matrix.py | 2,826 | 4.125 | 4 | """
Problem:
Write an algorithm such that if an element in an MxN matrix is 0,
its entire row and column are set to 0.
Implementation:
My initial, naive approach to the problem was to first find all
occurrences of zeros and add their row and column values to two lists.
Afterwards, we would check th... | true |
86fd334b83e5da79823e2858a504ce50d30ac10c | LevanceWam/DPW | /madlib/madlib.py | 1,650 | 4.40625 | 4 | ice_cream = raw_input("What's your flavor: ")
print "Tom was walking down the street and wanted a "+ice_cream+" Ice cream cone"
friends = ["Monster", "T-Rex", "Jello"]
print "Tom's friends wanted Ice cream too and they all had the same amount of money, Tom already has $5.00"
for f in friends:
print f + ", Has $2... | true |
9d9b4d12ab4445af1644d1f29f7dda9c6cfbe32e | spanneerselvam/Marauders-Map | /marauders_map.py | 1,750 | 4.25 | 4 | print("Messers Moony, Wormtail, Padfoot, and Prongs")
print("Are Proud to Present: The Marauders Map")
print()
print("You are fortunate enough to stuble upon this map. Press 'Enter' to continue.")
input()
name = input("Enter your name: ")
input2 = input("Enter your house (gryffindor, ravenclaw, hufflepuff, slythe... | true |
b5ec6c31ea7a394cbbdf7e2b8a0ea42640d8b1d5 | nagendrakamath/1stpython | /encapsulation.py | 715 | 4.15625 | 4 | calculation_to_unit = 24
name_of_unit ="hours"
user_input = input("please enter number of days\n")
def days_to_units(num_of_days):
return (f"{num_of_days} days are {num_of_days * calculation_to_unit} {name_of_unit}")
def validate():
try:
user_input_number = int(user_input)
if user_input_numbe... | true |
2836cf6c0a9351a3687a244b6034eb760cc2f5ba | pya/PyNS | /pyns/operators/dif_x.py | 636 | 4.1875 | 4 | """
Returns runnig difference in "x" direction of the matrix sent as parameter.
Returning matrix will have one element less in "x" direction.
Note:
Difference is NOT derivative. To find a derivative, you should divide
difference with a proper array with distances between elements!
"""
# ========================... | true |
494cc5b447f85b112110e34dcc16e156f7ff4c2b | raveendradatascience/PYTHON | /Dev_folder/assn85.py | 1,334 | 4.3125 | 4 | #*********************************************************************************#
# 8.5 Open the file mbox-short.txt and read it line by line. When you find a line #
# that starts with 'From ' like the following line: #
# From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 ... | true |
652e6e20d73239960e48d9dea1ad75ce3a802cca | KaustubhDhokte/python-code-snippets | /deep&shallowCopy.py | 1,562 | 4.4375 | 4 | '''
Two types of copy operations are applied to container objects such as lists and dictionaries:
a shallow copy and a deep copy. A shallow copy creates a new object but populates
it with references to the items contained in the original object.
'''
a = [1, 2, [8, 9], 5]
print id(a)
# Output: 47839472
b = list(a)
pri... | true |
11692778a4a716519e08e49f5a129ab743542f7d | KaustubhDhokte/python-code-snippets | /closures_TODO.py | 475 | 4.125 | 4 | # https://realpython.com/blog/python/inner-functions-what-are-they-good-for/
'''
def generate_power(number):
"""
Examples of use:
>>> raise_two = generate_power(2)
>>> raise_three = generate_power(3)
>>> print(raise_two(7))
128
>>> print(raise_three(5))
243
"""
# define the in... | true |
444297ec4f122e9e9419dbc4ea56e5d9752bfec3 | KaustubhDhokte/python-code-snippets | /metaclasses_TODO.py | 2,756 | 4.3125 | 4 | # https://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python
'''
A metaclass is the class of a class.
Like a class defines how an instance of the class behaves, a metaclass defines how a class behaves.
A class is an instance of a metaclass.
'''
'''
When the class statement is executed,
Python first exec... | true |
5193aded8a6ba9ce63f4104567bd714ab6b19887 | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /caesar_cipher.py | 2,421 | 4.53125 | 5 | # Option 1 Difficulty Level: Elementary: One of the first known
# examples of encryption was used by Julius Caesar. Caesar needed
# to provide written instructions to his generals, but he didn’t want
# his enemies to learn his plans if the message slipped into their hands.
# As result, he developed what later became kn... | true |
f88cd2ec59b884787116eb60c476374990109b9b | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /unique_characters.py | 1,124 | 4.40625 | 4 | # Create a program that determines and displays the number of unique characters in a string entered by the user.
# For example, Hello, World! has 10 unique characters while zzz has only one unique character. Use a dictionary or
# set to solve this problem
def unique_characters(text):
# Solution using dictionary
... | true |
34e456552f63f881b56f9e06e924cbc6c4528d4b | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /license_plate.py | 1,408 | 4.59375 | 5 | #License plate
#Option 1 Difficulty Level: Elementary: In a particular jurisdiction,
# older license plates consist of three uppercase letters followed by three numbers.
# When all of the license plates following that pattern had been used, the format was
# changed to four numbers followed by three uppercase
#letters. ... | true |
b01a758c609d2701d59a74f7bf019c7c4bd9f608 | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /calc.py | 1,676 | 4.53125 | 5 | # For this exercise I want you to write a function (calc) that expects a single argument -a string containing
# a simple math expression in prefix notation- with an operators and two numbers, your program will parse the input
# and will produce the appropriate output. For our purposes is enough to handle the six basic ... | true |
76fddfefedace4aca36548cbc3b6f2ab6f9d3188 | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /reverse_lines.py | 814 | 4.3125 | 4 | # In this function, we do a basic version of this idea. The function takes two arguments: the names of the input
# file (to be read from) and the output file (which will be created).
def reverse_lines(orig_f, targ_f):
# Read original file storing one line at the time
with open(orig_f, mode="r") as f_input:
... | true |
b8ceabe1af9f24f1acb694641f32f61c05ca34a6 | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /dice_simulation.py | 2,603 | 4.53125 | 5 | # In this exercise you will simulate 1,000 rolls of two dice. Begin by writing a function that simulates rolling
# a pair of six-sided dice. Your function will not take any parameters. It will return the total that was rolled on
# two dice as its only result.
# Write a main program that uses your function to simulate r... | true |
d52add20d1d0518c2c3fb82ce15f9015ce91890f | jqnv/python_challenges_Bertelsmann_Technology_Scholarship | /vowel_consonant.py | 856 | 4.46875 | 4 | # Option 2: Difficulty Level: Pre-Intermediate: In this exercise
# you will create a program that reads a letter of the alphabet from the user.
# If the user enters a, e, i, o or u then your program should display a message
# indicating that the entered letter is a vowel. If the user enters y
# then your program should... | true |
f52eb17ccbdecf837794acd87b21ee422bbdf6c5 | ak-alam/Python_Problem_Solving | /secondLargestNumberFromList/main.py | 286 | 4.21875 | 4 | '''
For a list, find the second largest number in the list.
'''
lst = [1,3,9,3,7,4,5]
largest = lst[0]
sec_largest = lst[0]
for i in lst:
if i > largest:
largest = sec_largest
largest = i
elif i > sec_largest:
sec_largest = i
print(f'Largest Number: {sec_largest}')
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.