blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
0c88f5339afa4f38aed6329807946abfe389b444 | pingsoli/python | /python_cookbook_3rd/chap04/03.py | 895 | 4.28125 | 4 | # 4.3 Creating New Iteration Patterns with Generators
# Generator:
# yield expression
def frange(start, stop, increment):
x = start
while x < stop:
yield x
x += increment
#for n in frange(0, 4, 0.5):
# print(n)
# Output:
# 0
# 0.5
# 1.0
# 1.5
# 2.0
# 2.5
# 3.0
# 3.5
#print(list(frange(0, ... | true |
c505a87327e50349660c754c42a8be2f94e05257 | pingsoli/python | /advanced/metaclass.py | 1,941 | 4.125 | 4 | # Python Metaclass
# Pay attention to Python 2.x and 3.x difference
# Python 2.x use __metaclass__
# class MyClass:
# __metaclass__ = MyMetaClass
# pass
#
# Python 3.x use metaclass= as a arguments
# class MyClass(metaclass=MyMetaClass):
# pass
#
# NOTE:
# Python 2.x and 3.x is not compatible.
#... | true |
a46c034379d9cac88eb3ebcf93d5a87e0a1a0d0b | pingsoli/python | /basics/tuple.py | 715 | 4.4375 | 4 | thistuple = ("apple", "banana", "cherry")
print(thistuple) # ('apple', 'banana', 'cherry')
print(thistuple[1]) # banana
# thistuple[1] = "blackcurrant" # got error
# print(thistuple)
# Traceback (most recent call last):
# File "tuple.py", line 5, in <module>
# thistuple[1] = "blackcurrant"
# TypeError: 'tu... | true |
86d85b989ccdc34a8de26670d7191c294210883f | gymk/Study-Python | /InventWithPython/JokeProgram.py | 659 | 4.21875 | 4 | #!/usr/bin/env python
# Have questions as keys, its answers as values for those keys
questions = {
'What do you get when you cross a snowman with a vampire?' : 'Frostbite'
, 'What do dentists call an astronuat\'s cavity' : 'A black hole'
}
# Loop over the question and show the answer
for question, answer in ... | true |
e0c966bb62773300b6f0a506c8921c0a541f976c | akhil-s-kumar/id-python-ifed | /nearest_square.py | 541 | 4.5 | 4 | import math
# Importing math for mathematical functions
def nearest_square(n):
'''nearest_square
Parameters:
n (int): To get the nearest square below n
Returns:
int 0 : if n is less than 0
int i : nearest square number but less than n
'''
if n<0:
return 0
else:
... | true |
2b2fe54d9f0955586ace9a0325ff79c33b506a3d | Rishit123344/countingwordsfromfile | /countingwordsfromfiles.py | 325 | 4.28125 | 4 | def countingwordsfromfile():
filename=input("enter the file name")
f=open(filename,'r')
numberofwords=0
for line in f:
words=line.split()
print(words)
numberofwords=numberofwords+len(words)
print(numberofwords)
print(numberofwords)
countingwordsfromfile(... | true |
4a83c594d67b82b335be853e9e8599ed346a989d | vishalpurkuti/pythonEXE1 | /list/anagram.py | 222 | 4.125 | 4 | def anagram(a, b):
if sorted(a) == sorted(b):
return True
else:
return False
if anagram(input("Enter str 1:"), input("Enter str2:")) == True:
print("anagram")
else:
print("Not anagram")
| true |
0764a9bf3727e3d4c816b7e2ba27d0880fffff9f | fionavaleri/ICTPRG-Python | /Week5_Quiz_3_Array.py | 444 | 4.15625 | 4 | # Given the following python code
values = [89, 456, 4, 55, 232, 2, 54, 78, 65, 45, 12, 459, 35616, 45 ,78]
# 1. Sum all of the numbers and output the result
valuessum = sum(list(values))
print("Total of all Values: ", valuessum)
# 2. Average all of the numbers and output the result
avg = valuessum/len(values)
print("... | true |
e2fe901e37eb19e3afadaaf2c31ecdb410ec0e97 | 1Saras/module2 | /ch7_debugging/ch7_sarika.py | 1,424 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sun Dec 16 19:18:26 2018
@author: Sara
"""
#There are different ways to debug
#---------1. Print Function---------
#Get the following error TypeError: unsupported operand type(s) for -: 'str' and 'int':
userInput = input('Please give a number ')
result = userInput - 2
#Ca... | true |
bd8131323ac69219803716a799793c03eac6c2cc | stephanmah/Discrete-Term-Project | /aThousandBubbleSortedArrays.py | 1,040 | 4.15625 | 4 | import sys
import numpy as np
import time
#Takes an integer as input
print("Enter a positive nonzero integer")
user_number = int(input())
print("This is array has", user_number, "numbers")
def bubble_sort(randnums):
n = len(randnums)
for i in range(n-1):
for j in range(0, n-i-1):
if randn... | true |
12667d483de64462332988455e1feaa056ed179e | nlucasti/git_lab_1 | /clean_phone.py | 422 | 4.34375 | 4 | import pandas as pd
def validate_phone(phone_number):
"""
Tests if phone numbers are valid
Arguments:
phone_number - A Pandas Series of phone_numbers as string object
Return:
A boolean Pandas Series
"""
bool_phone = phone_number.str.contains("^\d{3}[-]?\d{3}[-]?\d{4}")
return bool... | true |
aa9074a2935173ac1365948ca288e2cdcc1eb442 | feladie/D04 | /HW04_ch08_ex04.py | 2,345 | 4.59375 | 5 | #!/usr/bin/env python
# HW04_ch08_ex04
# The following functions are all intended to check whether a string contains
# any lowercase letters, but at least some of them are wrong. For each
# function, describe (is the docstring) what the function actually does.
# You can assume that the parameter is a string.
# Do not... | true |
4071fff7557c76752c99344e6f9b3888ba1f604e | devnetlearning/python | /basics of python/Variables.py | 1,885 | 4.21875 | 4 | """
Variable - label mapped to the object.
Rules in assigning variables:
- Must start with letter or underscore character
- Can't start with number.
- Name is case sensitive.
"""
#example
name = "mark" # Variable assigned to string
age = 9 # Variable assigned to integer
married = True #Variable assigned to Boolean
ful... | true |
555d720dfc8de034827492e70a48acf3749d712b | mrbrianevans/sorting | /Counting Sort/counting_sort.py | 442 | 4.1875 | 4 | def counting_sort(array: list) -> list:
"""Sorts a list of numbers in ascending order"""
element_count = [0] * (max(array) + 1)
sorted_list = []
for i in array:
element_count[i] += 1
for i in range(len(element_count)):
for j in range(element_count[i]):
sorted_list.append(... | true |
940aabf999e10c26f8372265c5dc8498d88a682b | waliyismail/lab01 | /fib.py | 943 | 4.25 | 4 | '''
task = produce list of fibonacci numbers of length n
DIFFICULTY = EASY
TOPICS = lists, variables, loops
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
'''
def produceFibsList(n):
'''
>>> produceFibsList(0)
[]
>>> produceFibsList(1)
[1]
>>> produceFibsList(2)
[1, 1]
>>> produceFibs... | true |
73f9979d9fa9e9c1858ed33afc64fe3b0734898d | AlexaVega-lpsr/class-samples | /ApplyCipher.py | 2,180 | 4.46875 | 4 | import string
# applyCipher.py
# A program to encrypt/decrypt user text
# using Caesar's Cipher
# Im doing comments for once, what a change ;)
# Author: rc.vega.alexa [at] leadps.org
# makes a mapping of encoded alphabet to decoded alphabet
# arguments: key
# returns: dictionary of mapped letters
def createDictiona... | true |
a717d907d24b5615a9ed8e472175708114d2fe4b | jkoren/CodeWarsChallengesPython | /05 - Square Every Digit.py | 931 | 4.34375 | 4 | '''
Welcome. In this kata, you are asked to square every digit of a number.
For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1.
Note: The function accepts an integer and returns an integer
time: 35 minutes
'''
def square_digits(number):
number_as_char = str(num... | true |
e91bc921aeb4d5a213ce2e1505456978f9930db5 | jkoren/CodeWarsChallengesPython | /13 - find the missing letter.py | 1,952 | 4.40625 | 4 |
'''
'#Find the missing letter
Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.
You will always get an valid array. And it will be always exactly one letter be missing.
The length of the array will always be at least 2.
The array will al... | true |
09da8ca086a508473cc816bfed4b1fac1aa95200 | william-cheng/leetcode | /medium/itinerary.py | 2,906 | 4.4375 | 4 | #
#
"""
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.
Note:
If there are multiple valid itineraries, you should return the itinera... | true |
620b0e1c3df3ddfd5a1d011bac4a60d63a84ea7f | Guneesh/PythonPrograms | /median.py | 351 | 4.125 | 4 | a=int(input("enter the first integer: "))
b=int(input("enter the second integer: "))
c=int(input("enter the third integer: "))
median=0
if a>b:
if a<c:
median=a
elif b>c:
median=b
else:
median=c
else:
if b<c:
median=b
elif a>c:
median=a
else:
mdian... | true |
bfe6a8216f3dad94b88530a4ec987c62b5d07628 | Guneesh/PythonPrograms | /factorial.py | 232 | 4.1875 | 4 | n=int(input("enter an integer: "))
if n<0:
print("factorial can't be determined!!")
elif n==0:
print("factorial is 1")
else:
fact=1
for i in range(1,n+1):
fact=fact*i
print("factorial of ",n," is ",fact)
| true |
b59b85564aed14517f84ed93a73f3b08ddfeac0e | prasanna86/fun_with_programming | /greedy/greedy_florist.py | 916 | 4.1875 | 4 | ## Hackerrank: Greedy algorithms --- Greedy florist
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the getMinimumCost function below.
def getMinimumCost(k, c):
cost = 0
## Sorting pricing of flowers in ascending order
sorted_c = sorted(c)
for i in range(k):
... | true |
e0c1521e9922d80a67fe2b307d5d5b8840f15a26 | WillLuong97/Heap-Data-Structure | /findKthSmallest.py | 2,830 | 4.21875 | 4 | #Python3 program to implement heap to find the kth smallest element in any kind of search space
#Problem statement
'''
378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.
Note that it is the... | true |
90a09e28b6ee4b26b94aa2c02d6b44b3e66d73f8 | mochba/Python-Regular-Expression | /Example4.py | 787 | 4.375 | 4 | # Read file to find numbers on lines that start with the string “X-” such as:
# "X-DSPAM-Confidence: 0.8475"
# Search for lines that start with 'X' followed
# by any non whitespace characters and ':'
# followed by a space and any number.
# The number can include a decimal.
import re
filename = input("Enter a file :")
... | true |
ccccdf0e3fa8cce46104c58c750dc6858d9d963c | jefftavlin/100-days-of-code | /Day #10/calculator-final.py | 977 | 4.21875 | 4 | from art import logo
from replit import clear
print(logo)
#Calculator
def add(n1, n2):
return n1 + n2
def subtract(n1,n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
'+':add,
'-':subtract,
'*':multiply,
'/':divide
}
num1 = float(input("Wh... | true |
6e90ca72b078328f43bd9abe56198b52fa0adf94 | praveen-95572/Nptel-the-joy-of-computing-using-python- | /28 Collatz Conjecture.py | 249 | 4.125 | 4 | def check(num):
iterations=1
while(num!=1):
if num%2==0:
num=int(num/2)
else:
num=3*num+1
iterations+=1
print(num,iterations)
num=int(input("Enter the number"))
check(num)
| true |
321afb10a038df8cf90224393a73e0bb889ee6ae | Jadams29/Coding_Problems | /Lists/List_Generator.py | 473 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Jun 25 09:54:37 2018
@author: joshu
"""
import random
rand_list = [random.randrange(1,10) for i in range(5)]
for k in rand_list:
print(k, end=", ")
print()
# This will sort the list
rand_list.sort()
# This will sort the list in reverse
rand_list.reverse()
# Change va... | true |
97627f038fc1baa7469c30cf9f5efbbac8dafbd4 | Jadams29/Coding_Problems | /List_Comprehension/Generator_Expressions.py | 204 | 4.15625 | 4 | double = (x * 2 for x in range(10))
print("Double : ", next(double))
print("Double : ", next(double))
print("Double : ", next(double))
print("Double : ", next(double))
for num in double:
print(num+) | true |
8e64a982c51e2fa487239581b8210e69611a0dae | emmassr/MM_python_quiz | /week2_exercise.py | 2,519 | 4.53125 | 5 | # For this exercise you will need the Pandas package. You can import this using:
#Q1: Create a Pandas dataframe with 3 columns: User, Fruit and Quantity.
#Insert Junaid, Tom, Dick, Harry as Users.
#Insert Apple, Oranges, Bananas, Mango as Fruit
#Insert 4, 3, 11, 7 as Quantity
#Each user should have their own row, this... | true |
6021f8c694f6bc930dcf08fc7c5524b7282820f5 | scottherold/python_refresher_6 | /ScopeAndNamespace/filesanddirectories.py | 1,308 | 4.125 | 4 | # a good use of recursion is obtaining a list of files in a directory
# The only things that screate scope in Python are: Modules, Functions
# and Classes
import os
def list_directories(s):
# scoped function
def dir_list(d):
# creates a properly scoped variable
# nonlocal tells python to loo... | true |
a1a8e7eaf448f73270d98e1be523dbea33640e50 | scottherold/python_refresher_6 | /datesanddatetime/timechallenge.py | 1,743 | 4.34375 | 4 | # Create a program that allows a user to choose one of up to 9 time
# zones from a menu. You can choose any zones you want from the
# all_timezones list.
#
# The program will then display the time in that timezone, as well as
# the local time and the UTC time.
#
# Display the dates and times in a format suitable for th... | true |
55e4e6951d39659b845130969ecde5ff95f39514 | Adam-Crockett/Python-Projects | /PigLatin/poor_man_bar_chart.py | 1,072 | 4.15625 | 4 | import pprint
from collections import defaultdict
def statement_request():
entry = input("Enter a phrase for us to deconstruct:\n").lower()
return entry
def deconstruct(entry):
"""
Function to create a deconstructed list of the statement letters
:param entry: The string input from user
:retu... | true |
c329c95d0352d20df0a0bda9fd9283c3a1f1950f | codingwen/playground | /hardway/function.py2.py | 714 | 4.15625 | 4 | #! /usr/local/bin/python
# -*- coding: utf-8 -*-
def add(a, b):
"""Do add calculation"""
print "Adding %d + %d" % (a, b)
return a + b
def subtract(a, b):
print "Subtracing %d - %d" % (a, b)
return a - b
print "Let's do some math with just functions!"
age = add(30, 5)
height = subtract(78, 4)
pr... | true |
c7e95b590c49bb5ecc8ca44c6ecd9d73f7b3dbcc | aronhr/SC-T-111-PROG-Aron-Hrafnsson | /Lokaverkefni/Upprifjun/Assignment 18/daemi1.py | 739 | 4.1875 | 4 | """
Write a class 'Pair' that initializes two values 'v1' and 'v2' to '0' by default.
It should print the values in this form: "Value 1: 20, Value 2: 30".
When two objects of this class are added together using the '+' operator, the result is 'v1' of object 1
gets added to 'v1' of object 2 and 'v2' of object 1 gets ad... | true |
11c06e703b55e0fed83a557ee29dc2c259e0bbae | Shmuco/DI_Bootcamp | /Week4/Day1/Ex_XP.py | 1,001 | 4.21875 | 4 | # # Ex 1
# sen = "Hello World\n"
# print(sen*5)
# #Ex 2
# print ((99**3)*8)
# #Ex 4
# computer_brand = "Mac"
# print(f'I have a {computer_brand} computer')
# #Ex 5
# name="Shmuel"
# age="27"
# shoe_size="7"
# info=f'My name is {name} i am {age} and my shoe size is {shoe_size}....just in case you were wondering'
# ... | true |
9792dd191d6f576dddcd12704552f7732a321fa7 | Shmuco/DI_Bootcamp | /Week4/Day4/Ex_XP_Gold.py | 2,553 | 4.40625 | 4 | # import random
# # Create a function called get_random_temp().
# # This function should return an integer between -10 and 40 degrees (Celsius), selected at round(random.
# # Test your function to make sure it generates expected results.
# def get_random_temp(season):
# if season == "winter":
# return ro... | true |
90549e68ea4f8ff141fc92911f71e8aa2d7f9572 | marioeid/Machine-Learning-Simple-Linear-Regression | /simple_linear_regression.py | 1,450 | 4.34375 | 4 | # Simple Linear Regression
# Importing libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing our data set
dataset=pd.read_csv('Salary_Data.csv')
X=dataset.iloc[:, :-1].values
y=dataset.iloc[:,1].values
# Splitting the dataset into the Training set and Test set
from sklearn.m... | true |
511114b13320232ebac2b513611f1a5891e7a2e6 | navin106/20186106_cspp-1 | /cspp1-practice/m10/biggest Exercise/biggest_exercise.py | 1,161 | 4.25 | 4 | '''
#Exercise : Biggest Exercise
#Write a procedure, called biggest, which returns the key corresponding to\
the entry with the largest number of values associated \
with it. If there is more than one such entry, return any one of the matching keys.
'''
def biggest(a_dict):
'''
a_dict: A dictionary, wh... | true |
0e5da6a91bf3fe13b6c43dd9bd6d56f3ed2a5f9a | dataneer/freecodecamp | /Scientific_Computing_Python/Probability_Calculator/test_environment.py | 1,831 | 4.15625 | 4 | import random
import itertools
from collections import Counter
{'first': 'Geeks', 'mid': 'for', 'last': 'Geeks'}
balls_dict = {'black': 3, 'green': 2, 'red': 2}
balls_list = ['black', 'black', 'black', 'green', 'green', 'red', 'red']
removed_balls = []
"""
The `Hat` class should have a `draw` method that accepts an... | true |
b8b62fc96c655833e3cd233c50499432f8a8602d | FredericoIsaac/mail_project | /corresponding_date.py | 544 | 4.15625 | 4 | import datetime
def month_in_reference():
"""
:return a Tuple of the corresponding Month and Year of SAFT
Example: current month 1 (January) of 2021 returns 12 (December) of 2020
"""
months = [n for n in range(1, 13)]
current_date = datetime.date.today()
current_month = current_date.timetu... | true |
b6484cf378380be813a9edc3eb236aa7f9c299a2 | Alex-Weatherhead/minhash | /clean.py | 2,942 | 4.1875 | 4 | import re
import string
import html
def remove_in_text_citations (text):
"""
Removes in-text citations by naively tossing out everything in
() and [] brackets. This approach was chosen because there are
too many possible styles of in-text citation to consider for any
non-trivial collection of do... | true |
343b6e9fba725803144e6f8eca081131e7f997f4 | joelhoelting/algorithms | /leetcode/iteration/20_valid_parentheses.py | 1,031 | 4.1875 | 4 | """
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Example 1:
Input: s = "()"
Output: true
Exa... | true |
b1ae2b00502ec1eda02b9dc33ea49a0513f98848 | laurivoipio/MLBP | /Round 1 - Introduction/Codes/1.py | 1,155 | 4.125 | 4 | #Important libraries to import:
# NumPy: is the fundamental package for scientific computing with Python.
# matplotlib.pyplot: provides a MATLAB-like plotting framework.
import matplotlib.pyplot as plt #define shorthand "plt" for package matlobplit.pyplot
import numpy as np #define shorthand "np" for the numpy package... | true |
0770ddcce50626201b6a11278f3275363215519c | aking1998/Python-Programs | /Hot_Cold_Day_(IF-ELSE).py | 454 | 4.34375 | 4 | """
Problem Statement : Use if-elif-else concept
If it's hot
It's a hot day
Drink plenty of water
otherwise if its cold:
It's a cold day
Wear warm clothes
otherwise
It's a lovely day
"""
is_hot = False
is_cold = True
if is_hot:
print("It's a hot day")
print("Drink plent... | true |
f25ea58cce3be3074e66479502c132e384e9245b | xyLynn/Python_HackerRank | /02_BasicDataTypes/01_Lists.py | 1,421 | 4.5 | 4 | """
Consider a list (list = []). You can perform the following commands:
insert i e: Insert integer e at position i.
print: Print the list.
remove e: Delete the first occurrence of integer e.
append e: Insert integer e at the end of the list.
sort: Sort the list.
pop: Pop the last element from the list.
reverse: Rever... | true |
8111928e055af8e8f47617fafd814ca9bb160483 | mjwestcott/projecteuler | /python/problem62.py | 1,088 | 4.125 | 4 | """
problem62.py
https://projecteuler.net/problem=62
The cube, 41063625 (345**3), can be permuted to produce two other cubes:
56623104 (384**3) and 66430125 (405**3). In fact, 41063625 is the smallest cube
which has exactly three permutations of its digits which are also cube. Find the
smallest cube for which exactly... | true |
dcb0eaa979eb60a1c145ff0e5e963e6e22ff51df | lunatic-7/ZTM-git- | /file.py | 2,713 | 4.6875 | 5 | # File I/O ---> It means file Input/Output
# It means, I want you to input something from the outside world, and output something into the outside world.
# For ex. We sometimes want to write a script to input an image and output a compressed version of it.
# So, I have created a txt file and written something in it. ... | true |
2ca0546ef48c25713b2437e3d1a789fb7ff7af56 | lunatic-7/ZTM-git- | /exercise_6.py | 360 | 4.125 | 4 | # Find Duplicates (Exercise)
# Check for duplicates in list and print them in a list.
some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n']
duplicates = []
for value in some_list:
if some_list.count(value) > 1:
if value not in duplicates: # This is imp. to not print b and n twice in output.
du... | true |
2f42b2d1c58cd9a2abbe1ef793e1f489f7cc479e | fredd5901/Udemy-Python3 | /ticctactoe_2.py | 2,951 | 4.625 | 5 | # Tic Tac Toe Game version 2
# 2 players should be able to play the game (both sitting at the same computer)
# The board should be printed out every time a player makes a move
# You should be able to accept input of the player position and then place a symbol on the board
# 1 | 2 | 3 1
# ------------ 2
# 4 | 5 | 6... | true |
0bef54087e81cc843b7db3521b425ac062eb3cd6 | saurabhmithe/cheat-sheets | /python_cheat_sheet/1_VariablesAndStrings.py | 2,045 | 4.28125 | 4 | # This is a comment in Python. It is a good practice to leave a space after the '#' symbol.
# Let's look at the variables. Variables don't need the type specifiers like other languages.
# Just as in Java, strings in Python are immutable.
message = 'Hello World!'
print message
# String variables can also be declared u... | true |
25b9e7a338e642358285ef07c42ecf2688d93ddc | saurabhmithe/cheat-sheets | /python_cheat_sheet/2_Lists.py | 1,324 | 4.53125 | 5 | # Lists in Python are pretty powerful.
# Unlike strings, lists are mutable.
fruits = ['Apple', 'Banana', 'Strawberry', 'Cherry']
# They pretty much work like arrays in other languages.
print fruits[0]
# The elements of the list can be accessed using index.
second_fruit = fruits[1]
print second_fruit
# The indexes w... | true |
b697c2884794888a6803cb3f257f59d6e8af9ade | ccjoness/CG_StudentWork | /Garrett/Week3/Homework/tug_o_war.py | 1,977 | 4.125 | 4 | # Two teams of 5 members will face off, the strongest of which will prevail. Each team member will be assigned a
# strength rating (1-9), with the most powerful members having a rating of 9. Your goal is to determine, based on
# the cumulative strength of the members of each team, which team will win the war.
#
# The t... | true |
435ff43459937884ce7e85ee5d56c91d2dd625d8 | ccjoness/CG_StudentWork | /Juan/Exercises/Week3/Homework/int_product.py | 362 | 4.25 | 4 | # You have a list of integers, and for each index you want to find the product of every integer except the integer at that index.
# Write a function that takes a list of integers and returns a list of the products.
#
# For example, given:
# [1, 7, 3, 4]
#
# your function would return:
# [84, 12, 28, 21]
#
# by calc... | true |
dbac65990699db5a67624633477157cf13e91c76 | ccjoness/CG_StudentWork | /Garrett/Week2-js/cryptogram.py | 1,030 | 4.4375 | 4 | The goal is to create a program that will take a string, create a random letter dictionary and
print the jumbled string under a series of blanks. (Think newspaper jumble)
import random
def make_dash(string):
'''input a string and return a string that is made up only of dashes.
Be sure that spaces in the stri... | true |
beae716e6a9d3152cd6214821734e980edbda416 | ccjoness/CG_StudentWork | /Juan/Exercises/Week2/functional/apply_it.py | 394 | 4.34375 | 4 | # write a function (mult) that takes two numbers and returns the result
# of multiplying those two numbers together
def mult(x, y):
return x * y
# now write a function(apply_it) that takes three arguments: a function,
# and two arguments and returns the result of calling the function with
# the two arguments
def... | true |
0d3bec4a3fef2189a062c092f8bd1923b5c6ab3c | ccjoness/CG_StudentWork | /Juan/Exercises/Week1/function_fun.py | 1,421 | 4.15625 | 4 | # The string inside triple quotes """ is called the docstring,
# short for "documentation string." I will ask you to include a
# docstring in all of your functions (create good habits).
#
# A docstring should describe what the function outputs and
# what the function inputs. As you see below, it may include
# other im... | true |
289bdd5bf04426ddcf7eab9c61e10f8646b6e9a2 | ccjoness/CG_StudentWork | /Garrett/Week1/simple_list.py | 855 | 4.25 | 4 | # write a program that prints out all the elements of the list that are less
# than 10. Bonus for letter a user decide the threshold.
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# write a function that checks if a string (first argument) ends with
# the given target string (second argument).
# i.e. confirm_endin... | true |
5fad321d31f5ee81737e460c03be38dea62306b8 | ccjoness/CG_StudentWork | /Garrett/Week3/Homework/overlap.py | 1,311 | 4.1875 | 4 | # A meeting is stored as tuples of integers (start_time, end_time). These integers represent the number
# of 30-minute blocks past 9:00am.
#
# For example:
#
# (2, 3) # meeting from 10:00 – 10:30 am
# (6, 9) # meeting from 12:00 – 1:30 pm
#
# Write a function condense_meeting_times() that takes a list of meeting tim... | true |
56fc7fe6dd7a9f85ec928bcc06a54f8ce4422033 | Barshon-git/Test | /if statement and comparison.py | 314 | 4.3125 | 4 | def max(num1, num2, num3):
if num1>=num2 and num1>=num3:
return num1
elif num2>=num1 and num2>=num3:
return num2
else:
return num3
num1=input("Enter the first number: ")
num2=input("Enter the second number: ")
num3=input("Enter the third number: ")
print(max(num1,num2,num3)) | true |
c842d7f626a26c026ed740903aca6a0f5159b348 | jerryasher-challenges/challenge-interviewcake | /27-reverse-words.py | 2,920 | 4.125 | 4 | #!python
from __future__ import print_function
import unittest
######################################################################
# this problem is from
# https://www.interviewcake.com/question/python/reverse-words
#
# You're working on a secret team solving coded transmissions.
# Your team is scrambling to dec... | true |
4092955806c90df4f4a8eb490b9be9fb19dbe253 | Mvahini/Python-Programs | /Grade_Calculator.py | 1,617 | 4.28125 | 4 | #!/usr/bin/env python3
# Activity3
# Vahini Madipalli
# Course: ISQA3900-850: Web Application Development
# Creating python program that takes numeric grade as input and displays letter grade as output.
# define function to display title
def display_title():
print("Welcome to the Grade Calculator")
# define func... | true |
86c64db6fc9afc33780e2483544c05dee885548f | Lennyc123/pands-problems-2020 | /Week 7 Number of e's.py | 1,147 | 4.3125 | 4 | # The following program reads in a text file
# and outputs the number of "e's" it contains.
filename = input("Enter file name: ") # User is prompted to input the name of a .txt file
l = str("e") # The program is told which letter to look for i.e "e"
k = 0 # used as a place holder for number of e's
with open(filename... | true |
dff506515eb844edb38a4e935bac7cd0c99ec463 | mirage22/pythonDesignPatterns | /basicsReview.py | 786 | 4.125 | 4 | # Python Basics
# inheritance, encapsulation, abstraction, Polymorphism
class Vehicle():
def __init__(self):
print("construct vehicle")
class SportCar(Vehicle):
def __init__(self, name, ps):
super().__init__()
print("construct sport car")
self.name = name
self.ps = ps
... | true |
0839502ef2a18c8c0ee87475bbb7ab8e312a5c4f | erikbatista42/SPD-2.4 | /two_sum_bin_tree.py | 2,893 | 4.1875 | 4 | # Given a binary search tree containing integers and a target integer,
# come up with an efficient way to locate two nodes in the tree whose sum is
# equal to the target value.
from binarytree import BinaryTreeNode, BinarySearchTree
def two_sum_bin_tree(tree, target):
# * Check for edge cases
if target == N... | true |
7619e992d2a419303e50a43246992399e9a8ad48 | Saksham1970/School_Python_Project | /11. Armstrong Number.py | 751 | 4.28125 | 4 | #This program tells if a number is armstrong or not
#This program is made by Saksham Gupta
#This function makes sure input is a positive integer
def IntegerGetter(str):
while True:
try:
num = int(input(str))
except ValueError:
print("That's not an Integer. Please Enter Detai... | true |
4af132b8246c8b6ab75526bfdf2a1f7d62117aad | Saksham1970/School_Python_Project | /10. Find prime upto a limit.py | 722 | 4.15625 | 4 | #This program tells all the prime numbers upto a limit
#This program is made by Saksham Gupta
#This function makes sure input is a positive integer
def IntegerGetter(str):
while True:
try:
num = int(input(str))
except ValueError:
print("That's not an Integer. Please Enter De... | true |
7faca351f08f32d439435f3b1a4deb29a8c68ee2 | Meena25/python-75-hackathon | /while.py | 672 | 4.3125 | 4 | """
While Loop
to generate odd numbers from 1 upto the number user specified
"""
i = 1
print("Enter the number : ")
n = int(input())
print("Odd numbers upto ",n)
while i < n:
print(i)
i += 2
# break and continue statements in while
print("When we use break :")
i = 0
while i < 10:
i += 2
if i == 6 :
... | true |
22cddb8e6dbe9410204a0bb60905f36b1f522766 | Meena25/python-75-hackathon | /sets.py | 1,266 | 4.5 | 4 | """
Set :
Collection which is unordered or unindexed
"""
set1 = {"java","python","c++"}
print("Set : ",set1)
#Adding items to a set
set1.add("c")
print("Added set :",set1)
#Adding multiple items to the set
set1.update(["unix", "linux", "c#"])
print("Updated set : ",set1)
#Length of the set
print("Length of the set ... | true |
e4c927cc4e17ec7fbefc6c992b46ef7ebbbbcc3c | preethi900/python | /reversewords.py | 210 | 4.15625 | 4 | #Reverse words in sentence
def reversed_sent(inputstring):
return " ".join(word[::-1] for word in inputstring.split(" "))
string = raw_input("enter a sentence:")
output = reversed_sent(string)
print output
| true |
dd182297ac9a780f41c786485eefa4faef990d6d | koumik/Python_Practice | /count strings firstlast same.py | 411 | 4.15625 | 4 | """ 3) To count the number of strings where the string length is 2 or more and
the first and last character are same from a given list of strings. """
#str_list=['ab','abc','xyz',213,9000,'ui','aab','acb']
def com(word):
x = 0
for i in word:
if len(i) > 1 and i[0] == i[-1]... | true |
e8a51eb6ccc919926824a6adaca0ee896314bf65 | koumik/Python_Practice | /palindrome.py | 301 | 4.21875 | 4 | # 6)To enter a number and check this number is Palindrome or Not.
num=input(" Enter a number = \n")
temp=num
reverse=0
while (num>0):
x=num%10
reverse=reverse*10+x
num=num/10
if (temp==reverse):
print "Number is Palindrome"
else:
print "Number is not Palindrome"
| true |
2b847debdb4e3d37cecc1b3ba10b7dd4c5aef682 | koumik/Python_Practice | /stringsort.py | 284 | 4.4375 | 4 | # 8) To enter a String and Sort word in alphabetic order.
string=raw_input("Enter the String : ")
"""sorted_string=sorted(string)
print "Sorted string of %s is : %s" %(string,sorted_string)"""
print "Sorted String of %s is : %s "%(string, ''.join(sorted(string)))
| true |
4ff7f39f0de5cbe8e36c0b88612f3e21139bba1d | deakkon/SemanticVIRT | /_utils/testFiles/testNoPP.py | 1,322 | 4.25 | 4 | #!/usr/bin/python
# File: sum_primes.py
# Author: VItalii Vanovschi
# Desc: This program demonstrates parallel computations with pp module
# It calculates the sum of prime numbers below a given integer in parallel
# Parallel Python Software: http://www.parallelpython.com
import math, sys, time
import pp
def isprime(n... | true |
ae22b65e60024f0e27e3ca30b1aefe69ff04a5cb | Bishwajit-Shil/Python | /chapter11/exercise1.py | 603 | 4.1875 | 4 | def function(*args):
cubic = []
if args:
for i in args:
cubic.append(i**3)
return cubic
else:
return "You didn't pass any value "
print(function(1,2,3,4))
# ------------------------------------------------------------
def function(*args):
if args:
... | true |
64083a29dd67f7ea3ea268b396f0f8a928c83fb9 | tusharongit/Python | /pytraining/302classesA.py | 2,521 | 4.25 | 4 | # declare a class to represent a person
class Person(object): # first letter caps convention; 'object' is inherited by default
# def __init__(self): # every class MUST declare function init using self; self is like this
# def __init__(self, s): # every class MUST declare function init using self; self is l... | true |
0aa1bcb77194123611d41f17268fbafce4324015 | AswinBarath/python-dev-scripts | /I Basics/17 List Methods.py | 1,701 | 4.375 | 4 | # Built in function
basket = [1, 2, 3, 4, 5]
print(len(basket))
# List Methods
# adding
basket.append(100)
new_list = basket
print('append method')
print(basket)
print(new_list)
basket.insert(4, 100)
print('Insert method')
print(basket)
basket.extend([101])
print('Extend method')
print(basket)
#... | true |
5197b0f9dd12c30aa420a35813ff9f1cd9132c27 | 12seetharaman/algo_ds | /array/rotate_array.py | 655 | 4.34375 | 4 | """
Given an array of size n and multiple values around which we need to left rotate the array.
How to quickly print multiple left rotations?
Input : arr[] = {1, 3, 5, 7, 9}
k1 = 1
k2 = 3
k3 = 4
k4 = 6
Output : 3 5 7 9 1
7 9 1 3 5
9 1 3 5 7
3 5 7 9 1
"""
def... | true |
6824f46b2f578fb343c9657fa0f1f7997fbcce6d | amightyo/Learning-Journal | /unit7LJ.py | 2,293 | 4.6875 | 5 | # Learning Journal Unit 7
# Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.
# Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the desi... | true |
5134ce5a2030c53a7b419d14079f9e97de0afe15 | zwarshavsky/Sprint-Challenge--Algorithms | /recursive_count_th/count_th.py | 608 | 4.15625 | 4 | '''
Your function should take in a single parameter (a string `word`)
Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters.
Your function must utilize recursion. It cannot contain any loops.
'''
count = 0
def count_th(word):
global count
# print(word)
i... | true |
e7c1ad0657962a7015f89888b973fce1eaefad68 | ndilhara/HacktoberFest2021-2 | /Python/checkprimeornot.py | 359 | 4.15625 | 4 | number = int(input("Enter The Number"))
if number > 1:
for i in range(2,int(number/2)+1):
if (number % i == 0):
print(number, "is not a Prime Number")
break
else:
print(number,"is a Prime number")
# If the number is less than 1 it can't be Prime
else:
... | true |
63454b2317420377f6e35e63daacabfb53ca245b | varsha-shewale/github_python_problems | /c_odd.py | 462 | 4.4375 | 4 | '''
Create a function that checks if a number is odd.
Expect negative and decimal numbers too. For negative numbers, return true if its absolute value is odd.
For decimal numbers, return true only if the number is equal to its integer part and the integer part is odd.
'''
def is_odd(n):
if isinstance(n,basestring... | true |
a072e9155bf3bbfddefd1a4635fac399d3dad574 | varsha-shewale/github_python_problems | /19_itemgetter_for_sorting.py | 1,204 | 4.46875 | 4 | '''
Question 19
Level 3
Question:
You are required to write a program to sort the (name, age, height) tuples by ascending order where name is string,
age and height are numbers. The tuples are input by console. The sort criteria is:
1: Sort based on name;
2: Then sort based on age;
3: Then sort by score.
The... | true |
708cfcc9d364d73ee569dad637edd57b8ca51607 | varsha-shewale/github_python_problems | /swap_case.py | 651 | 4.25 | 4 | '''
You are given a string S. Your task is to swap cases. In other words, convert all lowercase letters to uppercase
letters and vice versa.
For Example
Www.HackerRank.com -> wWW.hACKERrANK.COM
Pythonist 2 -> pYTHONIST 2
'''
def swap_case():
inp_str = raw_input('Provide string to swap case ')
inp_list = lis... | true |
f0ede8e065ca68137db9f7ed9ff4a9128d182579 | varsha-shewale/github_python_problems | /q1.py | 2,399 | 4.40625 | 4 | '''
The challenge is to create a text content analyzer. This is a tool used by writers to find statistics such as word and
sentence count on essays or articles they are writing.
Write a Python program that analyzes input from a file and compiles statistics on it.
The program should output:
1. The total word count
... | true |
dbdb9ceb222215944fdb6a25775c4098cd1b9eb6 | varsha-shewale/github_python_problems | /32_Circle_class.py | 878 | 4.4375 | 4 | '''
7.2
Question:
Define a class named Circle which can be constructed by a radius.
The Circle class has a method which can compute the area.
Hints:
Use def methodName(self) to define a method.
'''
import math
class Circle:
radius = 1
color = 'transparent'
def __init__(self, r): #whatever ... | true |
7c674127b10d5a5e9cda3df9859eee39bdfb1b9d | varsha-shewale/github_python_problems | /18_password_validity.py | 1,145 | 4.34375 | 4 | '''
Question:
A website requires the users to input username and password to register. Write a program to check the validity of password input by users.
Following are the criteria for checking the password:
1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
1. At least 1 letter between [A-Z]
3... | true |
708c3319732702a16535f6958192af8be6fab0f7 | sturner18/ProgrammingNotes | /Loops.py | 1,206 | 4.15625 | 4 | # Loops and Random Number
# FOR LOOPS
for i in range(10):
print(i)
for i in range(1, 11):
print(i)
for i in range(-5, 5):
print(i)
for i in range(5, 15, 3): # (start, stop, step)
print(i)
# Random Numbers
import random
# random integers
print(random.randrange(10))
print(random.randrange(5, 16)) # ... | true |
723ae6f9a294d45151b9e80d649d71704cead1b5 | WisemanB/python_june_2017 | /bailey_wiseman/dojofiles/python/scores_and_grades.py | 715 | 4.28125 | 4 | # Assignment: Scores and Grades
# Write a function that generates ten scores between 60 and 100.
# Each time a score is generated, your function should display what the grade is for a particular score. Here is the grade table:
# Score: 60 - 69; Grade - D Score: 70 - 79; Grade - C Score: 80 - 89; Grade - B Score: 90 -... | true |
eababcff61191fccdf7ae1ca58c581c6be9cc4b0 | WisemanB/python_june_2017 | /bailey_wiseman/dojofiles/python/dictionary_basics.py | 551 | 4.4375 | 4 | # Assignment: Making and Reading from Dictionaries
# Create a dictionary containing some information about yourself. The keys should include name, age, country of birth, favorite language.
# Write a function that will print something like the following as it executes:
# My name is Anna
# My age is 101
# My country of... | true |
1237475f7524007d89329157da4fa541b98d82e6 | shiftypanda/tutorial-bit-python | /week-1/guess_and_check.py | 1,147 | 4.3125 | 4 | # to cover learning about guessing and checking
# exhaustive enumeration example
def guess_and_check_cube_root():
"""Used to guess and check cube root"""
x = int(input('Enter an integer: '))
ans = 0
while ans**3 < abs(x): # generates a guess
ans = ans + 1
if ans**3 != abs(x):
p... | true |
6015677828b334601f04fc9c2f42d7747768569a | 121910313014/LAB-PROGRAMS | /L9-STACK USER CHOICE.py | 806 | 4.15625 | 4 | class Stack:
def __init__(self):
self.s=[]
def push(self,data):
self.s.append(data)
def pop(self):
return self.s.pop()
def printStack(self):
print(self.s)
s=Stack()
print('Select the operation of your choice:\n1. Push\n2. Pop\n3. Display\n4. Exit')
k=1
while k... | true |
0ef42a6914711ff4ac79a1a2697164957a1e3ec7 | 121910313014/LAB-PROGRAMS | /L2-RECURSION-G.C.D.py | 411 | 4.15625 | 4 | #gcd of two numbers
#method for finding gcd
def gcdNumber(a,b):
if b==0:
return a
else:
return gcdNumber(b,a%b)
#taking two numbers from the user
a=int(input('enter 1st number : '))
b=int(input('enter 2nd number : '))
... | true |
7738c46beecc37238e42f840450494f49ac8a455 | petr-tik/misc | /fib_base.py | 2,283 | 4.3125 | 4 | #! /usr/bin/env python
"""
https://www.reddit.com/r/dailyprogrammer/comments/5196fi/20160905_challenge_282_easy_unusual_bases/
Fibbonacci base is when instead of binary the 1 or 0 shows how many times you take the fib number of this index
dec 8 = 10110 in fib
Write a converter that takes base (dec or fib) and ret... | true |
96894718b4476a3e756746ab18b9d5e786c277c1 | petr-tik/misc | /sherlock_n_beast.py | 1,026 | 4.28125 | 4 | #! usr/bin/env/ python
# https://www.hackerrank.com/challenges/sherlock-and-array
"""
need to generate numbers from threes of 5's or fives of 3's
the greatest decent number has as many fives as possible, then as many threes as possible
given N, iterate fives from N to 0, and threes from 0 to N.
As soon as you have... | true |
8cc4378f0a36365025612874347d325060759a73 | petr-tik/misc | /trees.py | 1,622 | 4.3125 | 4 | # what is a binary tree
# class for a node in a binary tree
class Node(object):
def __init__(self, value, left_c=None, right_c=None):
self.value = value
self.left_child = left_c
self.right_child = right_C
# NEEDS a value as well as record of left and right children. Doesn't have to... | true |
7d18c8912f2bc161a91f7ac5b3d9b07057aa99c7 | petr-tik/misc | /max_subarrays.py | 2,445 | 4.1875 | 4 | #! /usr/bin/env python
# https://www.hackerrank.com/challenges/maxsubarray
import unittest
MAX_INT_VALUE = 1000
"""
Given an array of ints between -MAX_VALUE < int < MAX_VALUE
return the sum of maximum contiguous and non-contiguous subarrays
"""
def max_cont(arr, res):
"""
Given an array and a starting v... | true |
9aecda19bdd83dd5c3f73b37ca3cff3937516ed9 | gc893/python-lab1 | /excercise2.py | 446 | 4.21875 | 4 | # Write the code that:
# Prompts the user to enter a phrase: Please enter a word or phrase:
# Print the following message:
# What you entered is xx characters long
# Return to step 1, unless the word 'quit' was entered.
while True:
newInput = input('Enter a word or phrase: ')
print(f'This text is {len(newInpu... | true |
e2f67137022548b5a9101c6b367bd6affc2a68d4 | bradlee2hayden/UWE | /Python Practicals/Semester 1/Week 2/Answers/Season from Month and Day.py | 997 | 4.4375 | 4 | ##
# Determine and display the season associated with a date.
#
# Read the date from the user
month = input("Enter the name of the month; ")
day = int(input("Enter the day number: "))
# Determine the season
if month == "january" or month == "February":
season = "Winter"
elif month == "March":
if d... | true |
f0b27ef60a8a40938cedcf24b8508adb64b975cd | momentum-cohort-2018-10/w1d2-house-hunting-RDavis2005 | /househunting.py | 791 | 4.375 | 4 | annual_salary = int(input("Enter your annual salary:"))
monthly = annual_salary / 12
portion_saved = float(input("Enter the percent of your salary to save,as a decimal:"))
annual_rate_of_return = float(input("Enter the expected annual rate of return:") or "0.04")
total_cost = int(input("Enter the cost of your dream... | true |
08c56c14fe0c58e2040ba24fa7d998cf9165a53c | HystericHeeHo/testingPython | /tstp/ch5chal4.py | 369 | 4.25 | 4 | my_dict = {
'height': "5'10\"",
'color': 'Black',
'author': 'George Orwell',
'game': 'Shin Megami Tensei',
'band': 'Coheed and Cambria'
}
key = input('What do you want to know? I\'ll tell you all my favorites.(Please choose one of the following: height, color, author, game, or band): ')
print('Wha... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.