blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
13c7e0cb44617fb8603a0bf69323009f1f69bc39 | kanhaichun/ICS4U | /hhh/Alice/area caculation.py | 2,177 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 15 13:27:35 2018
Program:Area Caculation
purpose:
(1) Find the area under y = sin(x) from x=0 to x = PI.
(2) Find the area under y = 2^x from x = 1 to x = 10
(3) Find the area under a curve of your choice on a range of your choice.
@author: haichunka... | true |
221a34394fc4b1e0b84c55ba7ce76f2796a3d57c | kanhaichun/ICS4U | /Toxicbug/Tony/area calculator.py | 1,482 | 4.25 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jan 16 02:25:04 2018
@author: 11256
"""
#Name: Tony
#Date: January 15, 2018
#Program Title: Area Calculator
#Program Function: This program calcuates the area under curves (mathematical functions)
from math import *
#Variables:
x = 0.0 #This is the starting x va... | true |
5d4b9f87dc3c6f40d962c569eb6bc5cd2c77ddca | kanhaichun/ICS4U | /hhh/Angel/assignment9.py | 2,969 | 4.3125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 5 12:40:11 2018
@author: hailankan
(1) Create two functions: prime1(n) and prime2(n) that take a number that represents the set of integers from which to find prime numbers. For example, n=1000 specifies that the function will look for primes up to... | true |
48bbcc29f747463ca19a87de64d90f71f8791d63 | kanhaichun/ICS4U | /hhh/Angel/assignment4.py | 1,540 | 4.34375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''Name: Angel Kan
Date: January 15, 2018
Program Title: Area Calculator
Program Function: This program calcuates the area under curves (mathematical functions)'''
from math import *
#Variables:
a = 0.0 #This is the starting x value
b = pi #This is the ending x value
n = ... | true |
5daf8a269117a751e02d890c590b5c91bed7ec89 | kanhaichun/ICS4U | /Shutupandbounce/Aurora/aurora2.py | 1,062 | 4.125 | 4 | ucn#(a)assignment2
"""
Write a program that does the following:
(a) Let the user input two numbers.
(b) Convert the numbers to integers
(c) Print the sum, difference, product and quotient of the numbers.
(d) Repeat (b) and (c) for floating point
(e) Convert the numbers to strings.
(f) Output the four results as strings... | true |
a064f2589130b5f59dd4cc65cc7283e5d8ad6cfa | kanhaichun/ICS4U | /hhh/Mark/assignment9.py | 1,993 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Name: Song, Jiwei (Mark)
Date: 2018-02-06
Program Title: Benchmarking Algorithms
Purpose:
(1) Create two functions: prime1(n) and prime2(n) that take a number that represents the set of integers from which to find prime numbers. For example, n=1000 specifies that the function will look for ... | true |
f091b967c81053bbe74c5c97bf464a8d25db7a38 | kanhaichun/ICS4U | /FRC/intro.py | 813 | 4.125 | 4 | #This file is to introduce the basics of Python.
from math import *
from random import *
#a and b are integer variables
a = 5
b = 6
#numeric variables like integers can be used in
#arithmetic expressions
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(sin(a/b)+cos(b*a))
print(sqrt(b))
print(b**a)
#friends is a tex... | true |
31f54338963c78716d330fa64f177b69e02077da | kanhaichun/ICS4U | /hhh/Chris/Assignment 12.py | 1,525 | 4.34375 | 4 | # -*- coding: utf-8 -*-
"""
Assignment 12 - Recursive Algorithms - Towers of Hanoi
Coding convention:
(a) lower case file name
(b) Name, Date, Title, Purpose in multiline comment at the beginning
(c) mixedCase variable names
(1) Create a class with functions for three recursive algorithms.
Include factorials... | true |
fb7b68c1f50ff3c5dfb13828c78920f607ef0852 | kanhaichun/ICS4U | /Ivy232/Lily/A6Jan19.py | 1,909 | 4.125 | 4 | '''
Assignment 6 - Program in a Class
Coding convention:
(a) assignment6
(b) Lily, Jan.18th 2018, Title, Purpose in multiline comment at the beginning
(c) mixedCase variable names
Option A - Make a more complete quiz program using a class structure
(a) Have the program ask for the user's name.
(b) Record the result... | true |
6e5fc847fa9f80fb1634a70803b7df650d930d93 | kanhaichun/ICS4U | /Toxicbug/Jeffrey/assignment1Jeffrey.py | 428 | 4.25 | 4 | """
Author: Jeffrey
Date: 10th January 2018
Title: division
Function: Loop through 1000 numbers, and find the numbers that are divisible by 3 or 19.
"""
#loop from 0 to 1000:
for number in range(0,1000):
if number%3 == 0: #find the number that is divisible by 3
print(number, "is divisible by 3.")
elif... | true |
890607721b60fc8994c44f9719116c96ca1d6def | mail2vels/VelsPythonCode | /2ndlargenumber.py | 1,045 | 4.5625 | 5 | print '''
1. Write a program to implement a method which takes a list as an argument and returns second largest number.
read from standard input and write to standard output.
'''
print "Option 1"
print "========="
print "To find Out Second Largest Number Using Array Sort"
print '-----------------------------------... | true |
1e116bc82ab891199eba6a54aead90d5fbc383ff | parkjuj/E02a-Control-Structures | /main10.py | 2,213 | 4.28125 | 4 | #!/usr/bin/env python3
import sys, random
assert sys.version_info >= (3,7), "This script requires at least Python 3.7"
print('Greetings!') # prints greetings!
colors = ['red','orange','yellow','green','blue','violet','purple'] # defines what colors are
play_again = '' # defines what the play_again variable is
best_c... | true |
2125a79698aa524b6fb99b27de5dcaad490d8667 | LeoDemon/pythonlab | /PythonNow/src/Person.py | 1,867 | 4.71875 | 5 | # filename: Persion.py
# learning python class
class Person:
'''Represents a person'''
population = 0
def __init__(self, name):
'''Initializes the person's data'''
self.name = name
print 'Initializing %s...' % self.name
# When this person is created... | true |
bbe1256760868f9de36b8bd7c1e4ab0f5622051b | lperri/CTCI-Practice-Problems | /chVI_bigO/examples/ex_10.py | 983 | 4.375 | 4 | # check if a number is prime by checking for divisibility on numbers less than it.
# only need to go up to SQRT(n) because if n is divisble by a number greater than its SQRT,
# then it is divisible by something smaller than it.
from math import sqrt
def is_prime(n: int) -> bool:
''' Use while loop '''
x = 2
... | true |
2bf12cc265f899db13119297227544c252fbe25e | lperri/CTCI-Practice-Problems | /ch1_arrays_strings/interview_questions/iq_4.py | 941 | 4.34375 | 4 | # palindrome permutation: write a function to check if a string is a permutation of a palindrome
# the defining property of a palindrome that I will check is that it must have no more than 1 char
# that appears an odd number of times -- all other chars must appear an even number of times
#
def is_permutation_palindro... | true |
0d942835131e7e0c5c9a6a42a3e62c74719874b8 | lperri/CTCI-Practice-Problems | /ch2_linkedlists/interview_questions/implementation.py | 2,186 | 4.375 | 4 | class Node:
def __init__(self, val=None):
''' constructor containing the data in a given node and a pointer to the next node (if a next node exists) '''
self.val = val
self.next = None
class LinkedList:
''' wraps Node class; useful because if head node changes for one obj, other objs ca... | true |
c1af1aaaa7c3e2af6251f334d13d26cfcd75509a | lperri/CTCI-Practice-Problems | /ch2_linkedlists/interview_questions/iq_3.py | 1,324 | 4.125 | 4 | # delete a node in the middle (any node other than first and last) given ONLY access to THAT node
from implementation import *
def delete_a_middle_node(node: Node) -> None:
''' strategy: shift the rest of the linked list (using values) back by one, thus deleting this node '''
rest_of_list_values = []
node_... | true |
ad93e097e9040e6a3265ba54db03520a737294e8 | sgoldenlab/simba | /simba/roi_tools/ROI_size_calculations.py | 2,313 | 4.28125 | 4 | import math
import numpy as np
def rectangle_size_calc(rectangle_dict: dict, px_mm: float) -> dict:
"""
Compute metric height, width and area of rectangle.
:param dict rectangle_dict: The rectangle width and height in pixels.
:param float px_mm: Pixels per millimeter in the video.
:... | true |
0ccca243f2e0c95ec7b519ef346be233efe95b6a | Gajendra28121996/PythonGarden | /Python_List_Function.py | 1,165 | 4.25 | 4 | ## List of number
list_Of_Number=[3,4,6,9,11,13]
friends=["Gajendra","Stan Lee","Repeating","Enstine","Iron Man","Skarlett Jhonson","Repeating","Repeating"]
print(friends)
print(list_Of_Number)
## append() >>> Allows me to append another item to the list
friends.append("Creed")
print(friends)
##Print the Index of Li... | true |
5b35d79e61d1f13c982f86418330e8fbf0fd35b3 | slushhub/mining-mondays | /how-to-read-code/1.py | 1,527 | 4.375 | 4 | """
Variables
Variables are just names for values.
Names help in reading.
Imagine asd vs my_telephone_number, which is more informative?
"""
# my name is Tero
my_name = 'Tero'
# my age is 24
my_age = 24
# teemus age is two times my age
teemus_age = 2 * my_age
"""
Conditionals
The point of... | true |
93fd684abc67c7d66f4dbbe95807eee290f32970 | Ankan002/Python-College-Practical-Code-and-Info | /Practical 11/code.py | 207 | 4.34375 | 4 | string = str(input("Enter the string for which you want to find the ASCII value: "))
new_ascii = ""
for c in string:
new_ascii = new_ascii + str(ord(c))
print("ASCII value of", string, "is:", new_ascii)
| true |
80ae29f7a2c28667febd972edff724c5159df732 | samkit-jpss/DSA | /Queue/queue.py | 943 | 4.15625 | 4 | class Queue:
def __init__(self):
self.items=[]
#Insertion of Element
def Enqueue(self,data):
self.items.insert(0,data)
#Pop the element at the last or first inserted element
def Dequeue(self):
return self.items.pop()
#Returns the size of the list
def qsi... | true |
cafe7dbe26a417237e56b62d26dee6f5a6a37adf | BobIT37/Python3Programming | /venv/07-Built-in Functions/01-Map.py | 645 | 4.4375 | 4 | # map() takes in two or more arguments
# a function and one or more iterables
# syntax
# map(function, iterable...)
# map returns iterator
my_pets = ["alfred", "tabitha", "william", "arla"]
uppered_pets = []
'''
for pet in my_pets:
pet_ = pet.upper()
uppered_pets.append(pet_)
print(uppered_pets)
'''
uppered_... | true |
f58692c3858f078b4aacddaf8a01549d1658c32c | jsjimenez51/holbertonschool-higher_level_programming | /0x10-python-network_0/6-peak.py | 958 | 4.125 | 4 | #!/usr/bin/python3
"""
finds a peak in a list of unsorted integers
"""
def find_peak(list_of_integers):
"""
finds peak using a binary search
"""
if list_of_integers:
start = 0
end = len(list_of_integers) - 1
if start == end:
return list_of_integers[start]
# ... | true |
88f8501b1125a38941f880cf381bf1e5e142c14b | jpicasso/LessonSummary3 | /4Python/5HomeWork/9hw.py | 647 | 4.65625 | 5 |
# Exercise 9.
# A string is a palindrome if it is identical forward and backward. For example “anna”, “civic”, “level” and “hannah” are all examples of palindromic words. Write a program that reads a string from the user and uses a loop to determines whether or not it is a palindrome. Display the result, including a ... | true |
e6936a156c850aaed279bb7cad50e41f91b65a8e | IacovColisnicenco/100-Days-Of-Code | /DAYS_011-020/Day - 19 - Exercise/turtle_race.py | 1,430 | 4.3125 | 4 | from turtle import Turtle, Screen
import random
my_screen = Screen()
my_screen.setup(width=800, height=600)
user_bet = my_screen.textinput(title="Make Your Bet", prompt="Which turtle will win the race? Enter a color: ").lower()
colors = ["red", "orange", "yellow", "green", "DarkBlue", "purple", "SpringGreen", "DarkTur... | true |
15628f246ef699d41ba11f8c27162193a5c0129f | YashaswiniPython/pythoncodepractice | /7_Dictionary.py | 1,413 | 4.25 | 4 | # Python file Created By Bibhuti
d={"a":"d",2:"Python"};
print(d);
# print(type(d));
# print(d.get('a'));
# print(d.get(2));
# print(d.get("b")); # if key is not available it will return None
# print(d.keys()); # it will provide all the keys set
# print(d.values()); # it will provide all the values
# print(d.i... | true |
84462e5404558af15885e666e0783c27a3b05ce9 | Martiboy/Spotlight | /Machiel/word adventure.py | 2,318 | 4.15625 | 4 | def menu(lists, question):
for entry in lists:
print (1 + lists.index(entry))
print (" ) " + entry)
return int(input(question)) - 1
items = ["pot plant","painting","vase","lampshade","shoe","door"]
keylocation = 2
keyfound = 0
loop = 1
print ("Last night you went to sleep in the comfort of ... | true |
c89bf29734f53ac1f3304173ad99b60544f404b6 | Amy7/Python-task | /guessinggame.py | 721 | 4.25 | 4 | import random
number = random.randint(1,10)
#print(number)
n = 3
while(n):
try:
guess = int(input(("please guess the number:")))
while(guess > 10 or guess < 0):
guess = int(input(("please input your number from 1 to 10")))
n -= 1
if(guess == number):
... | true |
c4a15cabe8aa9caefbac67b0326ee84d1e85fade | Samuel1P/Prep | /algorithms/binary_search_using_while.py | 492 | 4.1875 | 4 | # this code will search for a integer in a sorted list using while loop
arr_ = [1, 1, 2, 3, 3, 3, 4, 5, 6, 7]
def binary_search(arr, first, last):
while (first <= last):
mid = (first + last) // 2
if ele == arr[mid]:
return f"Found {ele}"
elif ele < arr[mid]:
last =... | true |
7e22593e514c169076f99900424e42fe3f775463 | davray/lpthw-exercises | /ex15.py | 2,236 | 4.40625 | 4 | # import the function argv from module sys
from sys import argv
# give argv variables to unpack
script, filename = argv
# assign var txt to open var filename
txt = open(filename)
# print string with raw format char with var filename
print "\nHere's your file %r:" % filename
# print var txt contents open(file.read)
prin... | true |
cf68d0df2b2cc12f6ca2b3605628e18e79623d81 | rravitanneru/python | /identical operators.py | 408 | 4.21875 | 4 | # there are two identical operators
# is, is not
# is by default evalutes to true if vars on both sides of operator pointing to same memory location, object,value
# is not by default evalutes to true if vars on both sides of operator pointing to same memory location, object,value
a = 10
b = 10
if(a is b):
... | true |
9942ee03ecf8a05d7e9f4f21c22ec38c6e2035f5 | RasselJohn/AlgorithmExercises | /src/03.py | 859 | 4.28125 | 4 | # Check number on primary.
import math
def is_prime(number):
"""
If number is prime - return True
:param number: int
:return: boolean
>>> is_prime(25)
False
>>> is_prime(12)
False
>>> is_prime(11)
True
>>> is_prime(1)
Traceback (most recent call last):
...
... | true |
e896dd1641e9cd3b823e9cd29c74c05e1c2678cb | BrantLauro/python-course | /module03/ex/ex082.py | 548 | 4.125 | 4 | numbers = []
pair = []
odd = []
choice = ' '
while True:
while choice not in 'NY':
choice = input('Do you want to add a number on the list? [Y/N] ').upper().strip()[0]
if choice == 'N':
break
if choice == 'Y':
number = int(input('Type a number: '))
numbers.append(number)
... | true |
ddd4b58144fcf47fa58039da5129f097d6f38619 | royaldream/Python | /OOPS/Practice/Monk and circular distance.py | 2,083 | 4.28125 | 4 | """Its time for yet another challenge, and this time it has been prepared by none other than Monk himself for Super-Hardworking Programmers like you. So, this is how it goes:
Given N points located on the co-ordinate plane, where the point is located at co-ordinate , , you need to answer q queries.
In the query, yo... | true |
8dce269430fdc7db07ddeb21dfe79ae3940dc3e2 | sjacksondev/bouncy_ball | /bouncy.py | 850 | 4.21875 | 4 | """
PROGRAM: bouncy.py
NAME: Sabrina
DATE: 9/5/19
Program calculate the total difference travelled by a bouncing ball.
User will input:
The starting height of the ball
How bouncy the ball is
How many bounces the ball will make
Output will be the total distance the ball travels
"""
# Request the inputs... | true |
eaa387f7a1ae2943c95610ef6220e15a1eec2328 | martinthk/python-exercises | /code/Ex13_Heron'sConvergence.py | 569 | 4.125 | 4 | # Ex13: Heron’s method of convergence
# compute √𝑎 using Heron's method of Convergence
# Take as input a number (a), and an initial guess for the value of √𝑎
# and repeatedly apply equation 1 until the approximate solution converges to close to the true solution.
import math
a = int(input('Enter the value for a: ... | true |
5e13c84ade3c1b2275afe75f006fd03e3409283a | samjabrahams/anchorhub | /anchorhub/util/hasattrs.py | 736 | 4.4375 | 4 | """
hasattrs() checks a list of string arguments and sees whether the provided
object has all of them. It uses the built-in hasattr() method with each
attribute name
"""
def hasattrs(object, *names):
"""
Takes in an object and a variable length amount of named attributes,
and checks to see if the object h... | true |
5927eacb5f5e6e10ef6874975eb47ffefad6947d | samjabrahams/anchorhub | /anchorhub/util/addsuffix.py | 544 | 4.65625 | 5 | """
File for helper function add_suffix()
"""
def add_suffix(string, suffix):
"""
Adds a suffix to a string, if the string does not already have that suffix.
:param string: the string that should have a suffix added to it
:param suffix: the suffix to be added to the string
:return: the string wit... | true |
3263741eeae211b01761513ce52b0f8c88a20632 | pjgb/dailyprogrammer | /ch287e.py | 2,897 | 4.1875 | 4 | #!/usr/bin/env python3
# Write a function that, given a 4-digit number, returns the largest digit
# in that number. Numbers between 0 and 999 are counted as 4-digit numbers
# with leading 0's.
#
# largest_digit(1234) -> 4
# largest_digit(3253) -> 5
# largest_digit(9800) -> 9
# largest_digit(3333) -> 3
... | true |
7fdfdf1e450cdc5e88cc3db5bf09a3bcabf548fe | pbarton666/learninglab | /begin_advanced/py_class_support.py | 1,671 | 4.28125 | 4 | #py_class_support.py
"""Demonstrate basic class operations"""
#a simple class
class Mammal():
pass
#a class instance (a specific Mammal)
m = Mammal()
#...upgraded to initialize with instance attribute
class Mammal():
def __init__(self):
self.warmblooded=True
#a class instance
m = Mammal()
#single inheritance, ... | true |
8c7460b07a9b10da69dc1bff93c7203ddb263699 | MediaPreneur/Introduction-to-python | /twinx.py | 481 | 4.1875 | 4 | import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0., 100, 1);
y1 = x**2;
# y1 is defined as square of x values
y2 = np.sqrt(x);
# y2 is defined as square root of x values
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1, 'bo');
ax1.set_ylabel('$x^{2}$');
ax2 = ax1.twinx() # tw... | true |
d2447fcd3ecbb9525e41efdcd06c99aee7d2382b | ivddorrka/OP_nutriotionproject | /examples/example_pandas.py | 2,342 | 4.40625 | 4 | '''
This module demonstrates how to use some pandas functionality
'''
import pandas as pd
def series_examples():
'''
This function demonstrates some basic pandas functionality on how to work with Series
'''
nums_list = [1, 7, 2]
nums_list_serie = pd.Series(nums_list, index=["x", "y", "z"])
prin... | true |
9ea487ecec4a6cba47c433571cd4cf2dbf4a15bf | 5-digits/interview-techdev-guide | /Data Structures/Stack/Python/Stack.py | 1,397 | 4.1875 | 4 | # Implementation of stack using list in Python
# Stack is "LIFO(Last In First Out)"
# push method is used to add an item on top of stack
# pop method is used to get the topmost item from stack
import copy
class Stack:
"""
Just for the sake of teaching, this stack is implemented
in such a wa... | true |
60e4b0ea0fccdd254b27bf3db7381ae89f6e142d | 5-digits/interview-techdev-guide | /Data Structures/Trie/Trie.py | 1,648 | 4.15625 | 4 | class TrieNode(object):
def __init__(self):
self.children = [] #will be of size = 26
self.isLeaf = False
def getNode(self):
p = TrieNode() #new trie node
p.children = []
for i in range(26):
p.children.append(None)
p.isLeaf = False
return p... | true |
1c3c733e9237ca2b137a127f4e72afc5569a3fee | ThomasKisner/pythonPractice | /calculator/main.py | 1,224 | 4.15625 | 4 | #import regex
import re
print("Our Magical Calculator")
print("Type 'quit' to exit\n")
#initializing previous total variable
previous = 0
#initializing variable which the calc will refer to to see if it should keep running
run = True
def performMath():
#getting run and previous into the function's scope
globa... | true |
18f0d82657191e25db883856110f164c2ea14eaf | jkcomm113/compciv-2018-jkeel | /week-05/sortsequences/sort_numbers.py | 770 | 4.53125 | 5 | from datastubs import NUMBER_LIST
def reverse_numerical_order():
"""
Sort the list of numbers but in reverse order
"""
return sorted(NUMBER_LIST, reverse=True)
def numerical_order():
"""
Sort the list of numbers in numerical order
"""
return sorted(NUMBER_LIST)
# fill it out
de... | true |
7233fd761b83d8ca2e835fe5f9f2c675734d6528 | damiso15/mini_python_projects | /Tutorial/stringlists.py | 393 | 4.59375 | 5 | # Ask the user for a string and print out whether this string is a palindrome or not.
# (A palindrome is a string that reads the same forwards and backwards.)
palindrome = input("Enter your word: ")
new_word = palindrome[::-1]
if palindrome == new_word:
print(f"This word '{palindrome.upper()}' is a palindrome")
... | true |
68bd9399dd5e6c277088cda5e482911758b6bd63 | damiso15/mini_python_projects | /Tutorial/fibonacci.py | 1,176 | 4.65625 | 5 | # Write a program that asks the user how many Fibonacci numbers to generate and then generates them.
# Take this opportunity to think about how you can use functions.
# Make sure to ask the user to enter the number of numbers in the sequence to generate.
# (Hint: The Fibonacci sequence is a sequence of numbers where th... | true |
4b57628098ef9b0119cf0972c2767a6b01ef128a | RotemHalbreich/Ariel_OOP_2020 | /Classes/week_09/TA/simon_group/3-2-numbers.py | 740 | 4.28125 | 4 | # Type Conversion
x = 1
print(type(x))
y = 3.4
print(type(y))
# convert from int to float:
a = float(x)
# convert from float to int:
b = int(y) # 1.0 will be 1
a = str(3.444)
print(a)
print(type(a))
x = 2
print("Exponentiation is nice", x, "**2 =", x ** 2)
# to make random num
import random
print(random.randrange(... | true |
6d69a1d1ba294f493adc583638dbd9dd022038e8 | RotemHalbreich/Ariel_OOP_2020 | /Classes/week_09/TA/simon_group/6-1-functions.py | 2,069 | 4.71875 | 5 | #__________________________________________functions__________________________________________#
#all python methods is built-in functions
#assign
def my_function():
print("Hello from a function")
# Calling a Function
my_function()
# Parameters
def my_function(fname):
print(fname + " Refsnes")
my_function("E... | true |
53f7b06bcc782e7a45bb253ffbf901b765d4a1b5 | cyyrusli/mit6001 | /finalexam/dict_interdict.py | 569 | 4.125 | 4 | # function f depends on the question
def f(a,b):
return a > b
def dict_interdiff(d1, d2):
'''
d1, d2: dicts whose keys and values are integers
Returns a tuple of dictionaries according to the instructions above
'''
intersect = {}
difference = {}
for key in d1:
if key in d2:
... | true |
7e73037b4d41b3712a758343ce09c5972a0c0e06 | audrec/Information-System-in-Python | /Week2/audrec_hw_2/audrec_hw_2_1_1.py | 870 | 4.375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Yen-Chi Chen
Class: CS 521 - Spring 2
Date: 29-Mar-2021
Homework Problem #: 2.1.1
This program prompts for a number, do calculation on the input,
then print if the result matches the expected calculated value.
"""
def calc_num(num):
num = ((num + 2) * 3 - 6) / 3... | true |
7a126889b92cc23a3af824dae35a16dcbfa08744 | audrec/Information-System-in-Python | /Week3/audrec_hw_3/audrec_hw_3_14_6.py | 1,541 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Yen-Chi Chen
Class: CS 521 - Spring 2
Date: 05-April-2021
Homework Problem #: 3.14.6
Description:
This program check if the input file exists, write in the input,
read the file line by line, write each line into a list, and put and print
these lists of lists as the res... | true |
3bce67d9c5e52b5de880c8b5aeae417dadb61791 | audrec/Information-System-in-Python | /Week2/audrec_hw_2/audrec_hw_2_2_6.py | 1,396 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Yen-Chi Chen
Class: CS 521 - Spring 2
Date: 29-Mar-2021
Homework Problem #: 2.2.6
This program calculates and prints all the leap years from 1899 to 2021 using for-loop
and while-loop.
"""
# Create a list to store the leap year
list_1 = []
# Calculates and prints le... | true |
d206443289bdf15b2eb046a768027b0e86552bd0 | audrec/Information-System-in-Python | /Week2/audrec_hw_2/audrec_hw_2_1_3.py | 882 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Yen-Chi Chen
Class: CS 521 - Spring 2
Date: 29-Mar-2021
Homework Problem #: 2.1.3
This program prompts for a number, converts the input to an
integer and make a calculation on it. Print the result with
comma separation and with the desired format.
"""
# Function to ... | true |
ec92cfcdd172a096c44a4e6fa2fa00fcfcce1cc5 | Rider66code/PythonForEverybody | /bin/ex_04_06.py | 1,989 | 4.4375 | 4 | # 2.3 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking or bad use... | true |
c8deb8da0a3081d6cfa416f07489452b51ec5265 | Rider66code/PythonForEverybody | /bin/p3p_c2w3_ex_003.py | 227 | 4.375 | 4 | #Write a function called subtract_three that takes an integer or any number as input, and returns that number minus three.
def subtract_three(num):
subint=num-3
return subint
number=6
x=subtract_three(number)
print(x)
| true |
19a52856f363659f8fd757c8c1ad2fc5c4b13913 | Rider66code/PythonForEverybody | /bin/ex_08_04.py | 853 | 4.53125 | 5 | # 8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and... | true |
1fcdd81958539b61521e74a6c8391f6591ef034e | Rider66code/PythonForEverybody | /bin/p3p_c2w2_practice011.py | 538 | 4.15625 | 4 | #5. Create a dictionary called lett_d that keeps track of all of the characters in the string product and notes how many times each character was seen. Then, find the key with the highest value in this dictionary and assign that key to max_value.
product = "iphone and android phones"
lett_d={}
for char in product:
... | true |
b441d98f935367351ba393e5d2b69e6eb62fc2e4 | Rider66code/PythonForEverybody | /bin/p3p_c3w2_ex_005.py | 348 | 4.1875 | 4 | #2. The for loop below produces a list of numbers greater than 10. Below the given code, use list comprehension to accomplish the same thing. Assign it the the variable lst2. Only one line of code is needed.
L = [12, 34, 21, 4, 6, 9, 42]
lst = []
for x in L:
if x > 10:
lst.append(x)
print(lst)
lst2=[x for ... | true |
f1f929084315b9ca80a5ad02efb0d3ba11d556bd | Rider66code/PythonForEverybody | /bin/ex_03_03.py | 730 | 4.4375 | 4 | # 3.3 Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table:
# Score Grade
# >= 0.9 A
# >= 0.8 B
# >= 0.7 C
# >= 0.6 D
# < 0.6 F
# If the user enters a value out of range, print a suitable err... | true |
a61a9dd8e303173efe651c956ba240c0c80604ad | Rider66code/PythonForEverybody | /bin/p3p_c3w1_ex_001.py | 619 | 4.1875 | 4 | nested2 = [{'a': 1, 'b': 3}, {'a': 5, 'c': 90, 5: 50}, {'b': 3, 'c': "yes"}]
#write code to print the value associated with key 'c' in the second dictionary (90)
print(nested2[1]['c'])
#write code to print the value associated with key 'b' in the third dictionary
print(nested2[2]['b'])
#add a fourth dictionary add the ... | true |
44b53d49d776e220eddc6b61ecb2b5e817233d74 | Rider66code/PythonForEverybody | /bin/p3p_c3w1_ex_006.py | 562 | 4.59375 | 5 | #2. Below, we have provided a list of lists that contain information about people. Write code to create a new list that contains every person’s last name, and save that list as last_names.
info = [['Tina', 'Turner', 1939, 'singer'], ['Matt', 'Damon', 1970, 'actor'], ['Kristen', 'Wiig', 1973, 'comedian'], ['Michael', 'P... | true |
37081bfd7e273b6261e209e6710ebafab8766439 | Rider66code/PythonForEverybody | /bin/p3p_c4w1_ex_005.py | 1,063 | 4.65625 | 5 | #Create a class called Cereal that accepts three inputs: 2 strings and 1 integer, and assigns them to 3 instance variables in the constructor: name, brand, and fiber. When an instance of Cereal is printed, the user should see the following: “[name] cereal is produced by [brand] and has [fiber integer] grams of fiber in... | true |
aa008441857c91d8dc8c08f4d23a330ff62a5e00 | Rider66code/PythonForEverybody | /bin/p3p_c2w3_ex_005.py | 312 | 4.4375 | 4 | #12. Write a function named intro that takes a string as input. Given the string “Becky” as input, the function should return: “Hello, my name is Becky and I love SI 106.”
def intro(s):
newstr='Hello, my name is {} and I love SI 106.'.format(s)
return newstr
name='Becky'
x=intro(name)
print(x)
| true |
b20cf3e97aab795c3369a0059da6867465207741 | Rider66code/PythonForEverybody | /bin/p3p_c2w5_ex_007.py | 370 | 4.28125 | 4 | #4. Sort the following dictionary’s keys based on the value from highest to lowest. Assign the resulting value to the variable sorted_values.
dictionary = {"Flowers": 10, 'Trees': 20, 'Chairs': 6, "Firepit": 1, 'Grill': 2, 'Lights': 14}
sorted_values=[]
for key,value in sorted(dictionary.items(),key=lambda stock:stock[... | true |
4d464b49cfc49a35a3dd7e6a6e8218db0b3f87ea | Rider66code/PythonForEverybody | /bin/p3p_c2w3_ex_009.py | 241 | 4.125 | 4 | #2. Write a function called count that takes a list of numbers as input and returns a count of the number of elements in the list.
def count(x):
cnum=0
for num in x:
cnum+=1
return cnum
nlist=(1,2,3)
print(count(nlist))
| true |
7eff73ede7c96cb6bfad9696369029c261af97c3 | rahuladream/LeetCode | /April_LeetCode/Week_1/Queue/adding_element_enque.py | 638 | 4.1875 | 4 | class Queue:
def __init__(self):
self.queue = list()
def add_element(self, val):
# Insert element
if val not in self.queue:
self.queue.insert(0, val)
return True
return False
def size(self):
# Size of queue
return len(self.que... | true |
ee2624e6d8dfac12498e1ef101bcb90633d0c4e4 | rohanmahajan1993/pythonlibrary | /generators_iterators.py | 688 | 4.4375 | 4 | '''
Iterators can be passed in to many built in functions and also are used in for loops.
All that is required is that we have a iter method that returns an object that can has next init.
Usually, one class does both.
'''
class IterableObject:
def __init__(self, n):
self.i = 0
self.n = n
def __iter__(self)... | true |
d60a399e157fad6646fd6b94dcbcbf6b59cfeb45 | MANOJPATRA1991/Data-Structures-and-Algorithms-in-Python | /Recursion/factorial_of_a_number.py | 230 | 4.125 | 4 | def factorial(num):
# This is the most efficient base case as it keeps our program from crashing
# if you try to compute the factorial of a negative number.
if num <= 1:
return 1
else:
return num * factorial(num-1)
| true |
5d4a1145efcfe5df20efb15dd010c7116d35304e | MANOJPATRA1991/Data-Structures-and-Algorithms-in-Python | /Trees/Tree_Structure_Using_Classes/__init__.py | 2,034 | 4.3125 | 4 | class BinaryTree:
"""
Creates a Binary Tree with a root, left child and
right child.
Attributes:
rootObj(any): The value of the root of the tree
leftChild(BinaryTree): The left child of the tree
rightChild(BinaryTree): The right child of the tree
"""
def __init__(self... | true |
85cf8486dba0b0a8ea95b8eabe0de226ffb07dc2 | javi12135/FreeCodeCamp-Challenges | /Scientific Computing with Python/Exercises/06 Strings/06-05_EX.py | 404 | 4.5 | 4 | #Exercise 5: Take the following Python code that stores a string:
#str = 'X-DSPAM-Confidence:0.8475'
#Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number
str = 'X-DSPAM-Confidence:0.8475'
... | true |
5b3fa8ced6372df9c2070f4376468fcaedee4552 | javi12135/FreeCodeCamp-Challenges | /Scientific Computing with Python/Exercises/06 Strings/06-03_EX.py | 383 | 4.125 | 4 | #Exercise 3: Encapsulate this code in a function named count, and generalize it so that it accepts the string and the letter as arguments
#_def count(tocount):
# count = 0
# for letter in word:
# if letter == tocount:
# count += 1
# print(count)
word=input("What is your word?: ")
tocount=in... | true |
d12289fa550924c56dd8058922640c952a3ddc3a | kaushiktalukdar/utility_Python | /inheritance/inheritance_demo4.py | 805 | 4.3125 | 4 | # https://www.w3schools.com/python/python_inheritance.asp
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
# now, have a Student class inherit Person class and with __init__ method amd super()
class ... | true |
74f998c6890376ec70bcfde78fcc5443bb6950a3 | richrosenthal/Day3_Choose_Your_Own_Adventure | /main.py | 1,353 | 4.34375 | 4 | #Day 3 Making a choose your own Adventur game
#Author Richard Rosenthal
#Date 5-11-21
import time
print("Welcome to escape Ikea!")
user_name = input("What is your name?")
print(f"Hello {user_name}")
print("\nYou awake on a couch in a darken building")
print("\nAs you come to your senses you realize you fell asle... | true |
8475bf43520d376399d0685774af9639e64b3c37 | karthikeyansa/python-placements-old | /python-day-2/prob4.py | 247 | 4.21875 | 4 | #4)Write a Python program to find the repeated items of a tuple.\
n=tuple(map(int,input("Enter the set of numbers separated by space: ").split()))
m=[]
for i in n:
if i not in m:
m.append(i)
else:
print(i,"repeated items")
| true |
8139dee0d7a7febfb105846a4b8bb298fadf410f | mithrandil444/Make1.2.1 | /leeftijd.py | 809 | 4.3125 | 4 | #!/usr/bin/env python
"""
This script will ask you in which year you were born en calculate how old you are
and in which year you will be 50 years old..
Bron : https://www.youtube.com/watch?v=7lg5BHLrw4E
"""
# IMPORTS
import datetime
__author__ = "Sven De Visscher"
__email__ = "sven.devisscher@student.kdg.be"
__statu... | true |
817b67418e4de2ac72ab26c8686f989d29042a0f | Kotarosz727/python-algorism | /bubble_sort.py | 468 | 4.125 | 4 | def bubble_sort(numbers):
len_numbers = len(numbers)
while len_numbers > 1:
len_numbers -= 1
for i in range(0, len_numbers):
if numbers[i] > numbers[i+1]:
numbers[i] , numbers[i+1] = numbers[i+1], numbers[i]
return numbers
# numbers = [2,5,1,8,7,4,3]
... | true |
1d148131a8f0533658493bf9ad4de3e6f40e8ace | abdalimran/46_Simple_Python_Exercises | /28.py | 324 | 4.1875 | 4 | from functools import reduce
def find_max(x,y):
if x>y:
return x
else:
return y
def find_longest_word(words):
lengths = list(map(len,words))
return (reduce(find_max,lengths))
def main():
words = input("Enter the list of words: ").split()
print(find_longest_word(words))
if __name__=="__main__":
mai... | true |
9d7036a5b7a93956ece880558141aeb556cfebf6 | maherme/python-deep-dive | /Variables_Memory/EverythingObject.py | 1,007 | 4.5 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 24 20:33:42 2021
@author: maherme
"""
#%%
a = 10
print(type(a)) # Notice a is a class
b = int(10) # We can create a new class using the constructor as an integer
print(b)
print(type(b))
#%%
# You can get some help using help(int) for example
# We... | true |
2588dc0d7a0f92cec88cb9d49ad448bc571d9ff8 | maherme/python-deep-dive | /Extras/RandomSeeds.py | 1,783 | 4.21875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 10 00:35:44 2021
@author: maherme
"""
#%%
import random
for _ in range(10):
print(random.randint(10, 20), random.random())
#%%
# Every time you reset the seed the sequence will start with the same values:
random.seed(0)
for _ in range(10):
... | true |
26a1d204dcfbd8f918d2e4cca6f822ed84cac3cf | maherme/python-deep-dive | /Basics/for.py | 1,928 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 9 23:43:32 2021
@author: maherme
"""
#%%
# In Python, an iterable is an object capable of returning values one at a
# time.
# In other lenguages a for loop is similar to: for(int i=0; i<5; i++){...}
# This is similar to a while loop:
i = 0
whi... | true |
706f7af5c7a3c732df5923577dd0321e87630f87 | maherme/python-deep-dive | /Numeric_Types/FloatCoercingToIntegers.py | 751 | 4.34375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 12:01:19 2021
@author: maherme
"""
#%%
# Let's see trunc function:
from math import trunc
print(trunc(10.3), trunc(10.5), trunc(10.9))
# Trunc is used by default for the int constructor:
print(int(10.4), int(10.5), int(10.9))
#%%
# Let's see ... | true |
9a89d50b6d86604378507e92964ab812c49e8fcf | maherme/python-deep-dive | /Numeric_Types/FloatInternalRepresentation.py | 782 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 11:18:51 2021
@author: maherme
"""
#%%
# Let's see the float constructor:
print(float(10))
print(float(10.4))
print(float('12.5'))
print(float('22/7')) # This will fail, you need to create a fraction first
#%%
from fractions import Fraction
a ... | true |
9e222085ac82d074594e896dd8f9ecec93b071f2 | MatsK/python-for-grade-8 | /example01_print_and_variables.py | 255 | 4.34375 | 4 | # My first program
print "Hello, world!"
name = "Your name"
#name = "Someone elses name"
print "Hello %s" % name
# x is a integer variable name
x = 5
print "x=%s" % x
# We can change the value of x with a mathematical operation
x = x + 2
print "x=%s" % x
| true |
c135c6a9d36b791f5c3222d012acfc0911e81b63 | ColdMacaroni/sort-by-ord | /no_sort_by_ord.py | 1,976 | 4.28125 | 4 | ##
# no_sort_by_ord.py
# Sorts input string by the value given by ord(char)
# 2021-03-31
def str_to_ord(string):
"""
Returns a list with the ord of each character.
"""
return [ord(x) for x in string]
def corresp_ord(string):
"""
Returns a dictionary of the equivalent ascii ord... | true |
00194cd3682ef8a32845aa3b52ac7b9f03c582ba | jeffwright13/codewars | /mixed_fraction.py | 2,189 | 4.5625 | 5 | def main():
print mixed_fraction.__doc__
def mixed_fraction(s):
"""
https://www.codewars.com/kata/simple-fraction-to-mixed-number-converter
Task:
Given a string representing a simple fraction x/y, your function must return a string representing the corresponding mixed fraction in the following fo... | true |
341d3ca705d51e831f9bd0aed54b27dc4931da42 | jeffwright13/codewars | /permutation_average.py | 1,623 | 4.25 | 4 | def main():
print permutation_average.__doc__
def permutation_average(n):
"""
A number is simply made up of digits.
The number 1256 is made up of the digits 1, 2, 5, and 6.
For 1256 there are 24 distinct permuations of the digits:
1256, 1265, 1625, 1652, 1562, 1526, 2156, 2165, 2615, 2651, 2561... | true |
d59f595e547df9dff7ecef38724b1729dabc2b23 | jeffwright13/codewars | /sumDig_nthTerm.py | 2,345 | 4.4375 | 4 | def main():
print sumDig_nthTerm.__doc__
def sumDig_nthTerm(initVal, patternL, nthTerm):
"""
We have the first value of a certain sequence, we will name it initVal. We define pattern list, patternL, an array that has the differences between contiguous terms of the sequence. E.g: patternL = [k1, k2, k3, k4]... | true |
a626678ccefac238fdc86942ad04c0f5c6ebfd91 | jeffwright13/codewars | /find_next_square.py | 1,524 | 4.34375 | 4 | def main():
print find_next_square(None)
def find_next_square(sq):
"""
You might know some pretty large perfect squares. But what about the NEXT one?
Complete the findNextSquare method that finds the next integer perfect square after the one passed as a parameter. Recall that an integral perfect squar... | true |
a7d20941cdeb717e3e519c286c059ccdd5cb6e4e | jeffwright13/codewars | /remainder.py | 1,106 | 4.4375 | 4 | def main():
print remainder(None)
def remainder(dividend, divisor):
"""
Task
----
Write a method 'remainder' which takes two integer arguments, dividend and divisor, and returns the remainder when dividend is divided by divisor. Do NOT use the modulus operator (%) to calculate the remainder!
A... | true |
a4af751a08ba85b2009e042f0c31d6eaac5cb57c | wfSeg/py3dahardway | /py16.py | 1,103 | 4.4375 | 4 | # what can you do with files?
# close: close the file
# read: reads the file
# readline: reads just one line of text
# truncate: Empties the file.. so it's not truncate, it's like Erase
# write('stuff'): Writes into the file
# seek(0): Moves the r/w location to beginning of file.. this is like for HDDs
from sys import... | true |
00fcc169bc667b5d259b76bb31e7a6ed1f0d04e0 | wfSeg/py3dahardway | /py31.py | 2,074 | 4.125 | 4 | # I go out for boba everyday, sometimes even twice. :|
print("""You enter a dark room with two doors.
Do you go through the door on the LEFT or the door on the RIGHT?""")
choice = input("> ")
#if choice == "L" or "Left": #hmm capitalization matters. Need a better way to sanitize the input
# doesn't work.
if choice ... | true |
e3829c37aeb3c9cf05a090ed36625b6da355a9f5 | komerela/dataStructAlgosPython | /mergelinkedlists.py | 1,528 | 4.3125 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
"""
1 -> 2 -> 4 1 -> 3 -> 4 -> 5 ->6
l1 l2
new_List 0 -> 1 ->
(start new merged list)
1. set variables
"""
cla... | true |
d6c336ad50bb88fc70f86641b8cbbe40b89a0d63 | airakesh/interviewbits | /arrays/anti_diagonals.py | 722 | 4.375 | 4 | '''
Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details.
Example:
Input:
1 2 3
4 5 6
7 8 9
Return the following :
[
[1],
[2, 4],
[3, 5, 7],
[6, 8],
[9]
]
Input :
1 2
3 4
Return the following :
[
[1],
[2, 3],
[4]
]
'''
class Solution:
... | true |
27c3871b192c088d6c2a2bcf1af6471a05f9ed78 | ScienceStacks/common_python | /common_python/util/dataframe.py | 1,508 | 4.15625 | 4 | """Utilities for DataFrames"""
import pandas as pd
import numpy as np
def isLessEqual(df1, df2):
"""
Tests if each value in df1 is less than or equal the
corresponding value in df2.
"""
indices = list(set(df1.index).intersection(df2.index))
dff1 = df1.loc[indices, :]
dff2 = df2.loc[indices, :]
df = d... | true |
d31914ca5bf9ec1e3b03e53b5b957216fcde80fd | erikayoon/Automate-The-Boring-Stuff-With-Python | /Chapter 4/commaCode.py | 868 | 4.1875 | 4 | # TASK:
# Take a list value as an argument
# Return a string with all the items separated by a comma and space
# With 'and' inserted before the last item
# Ex: apples, bananas, tofu, and cats
# PERSONAL TWIST:
# If the first value of the list is a string
# Capitalize it
### MY CODE BELOW: ###
# Define functi... | true |
69e69ff253c15e514a62aed56a5792ac6ce175c9 | Elvandro/Password-locker | /user.py | 748 | 4.15625 | 4 | class User:
"""
Class that generates new instances of users
"""
user_list = []
def __init__(self, user_name, password):
"""
__init__ method helps us define our object
Args:
user_name: New user name.
password: New user password.
"""
se... | true |
e33f993b6a2a63db6c94b998a3d7aed4d48804b4 | yanyanxumian/Stats507_F21 | /nb/string_df.py | 1,659 | 4.5 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Create a small pandas DataFrame for examples.
@author: James Henderson
@date: August 31, 2021
"""
# 79: ------------------------------------------------------------------------
# libraries: -----------------------------------------------------------------
import pand... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.