blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
80ce0b6a98ffad061eeb45a97c81851afe42a216 | Venkatesh123-dev/100-Days-of-code | /Day_06_2.py | 1,860 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 13 19:28:24 2020
@author: venky
There are two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location and moves at a rate of meters per jump. The second kangaroo st... | true |
2fc9577d7073827d48449eb4c3988998e55da166 | DizzyMelo/python-tutorial | /numbers.py | 288 | 4.25 | 4 | # There are three numeric types in python
# int, float and complex
import random
x = 1 # int
y = 2.8 # float
z = 1j # complex
print(complex(x))
print(int(y))
print(type(z))
# the last number is not included, then, numbers from 1 to 9 will show up
print(random.randrange(1, 10))
| true |
115e1cc9db1fc292b214b1f31ff5b23b62dbd684 | DizzyMelo/python-tutorial | /ifelse.py | 1,263 | 4.375 | 4 | # Python Conditions and If statements
# Python supports the usual logical conditions from mathematics:
# Equals: a == b
# Not Equals: a != b
# Less than: a < b
# Less than or equal to: a <= b
# Greater than: a > b
# Greater than or equal to: a >= b
# These conditions can be used in several ways, most commonly in "if s... | true |
6869f7ccbbe5124779270653201b7bfeb5b12ba5 | DizzyMelo/python-tutorial | /trycatch.py | 1,830 | 4.375 | 4 | # The try block lets you test a block of code for errors.
# The except block lets you handle the error.
# The finally block lets you execute code, regardless of the result of the try- and except blocks.
# Exception Handling
# When an error occurs, or exception as we call it, Python will normally stop and generate an... | true |
16ad2f811290b82e99ad541713ca0b48adc99f87 | gauravlahoti80/Project-97-Number-Guessing-Game | /guessing Game/main.py | 1,899 | 4.21875 | 4 | #importing modules
import random
import pyttsx3
#welcome screen
input_speak = pyttsx3.init()
input_speak.say("Enter your name: ")
input_speak.runAndWait()
#taking name input from the user
user_name = input("Enter your name: ")
#showing hello to the user
input_speak.say(f"Hello,{user_name}")
input_speak... | true |
bf5e398738221308a2c5fa8462c32ff1d8de1cbb | emmanuelaboah/Data-Structures-and-Algorithms | /Solved Problems/Data structures/Recursion/String-Permutations.py | 1,790 | 4.125 | 4 | # Problem Statement
# Given an input string, return all permutations of the string in an array.
# Example 1:
# string = 'ab'
# output = ['ab', 'ba']
# Example 2:
# string = 'abc'
# output = ['abc', 'bac', 'bca', 'acb', 'cab', 'cba']
# Note - Strings are Immutable
# Recursive Solution
"""
Param - input string
Return... | true |
2eff58b50c69128a2999948651acc3cb11701e98 | emmanuelaboah/Data-Structures-and-Algorithms | /Solved Problems/Data structures/Recursion/Reverse _string_input.py | 1,389 | 4.53125 | 5 |
def reverse_string(input):
"""
Return reversed input string
Examples:
reverse_string("abc") returns "cba"
Args:
input(str): string to be reversed
Returns:
a string that is the reverse of input
"""
# (Recursion) Termination condition / Base condition
if ... | true |
0424290f9aa1009976c74c19bfc41f65da59146e | ParthRoot/Basic-Python-Programms | /Fectorial.py | 285 | 4.1875 | 4 | num=int(input("enter the num"))
factorial=1
if num < 0:
print("sorry factorial doesnot exit negative num")
elif num == 0:
print("factorial always start 1")
else:
for i in range(1,num+1):
factorial = factorial * i
print("the factorial of",num,factorial) | true |
bb328aa070b6889b12d9dac1b3508801da268fd6 | daniel-laurival-comp19/slider-game-1o-bimestre | /getStartingBoard.py | 574 | 4.25 | 4 | def getStartingBoard():
''' Return a board data structure with tiles in the solved state. For example, if BOARDWIDTH and BOARDHEIGHT are both 3, this function returns [[1, 4, 7], [2, 5, 8], [3, 6, BLANK]]''' counter = 1 board = []
for x in range(BOARDWIDTH):
column = []
for y in ... | true |
d3911c904e2e9cae6da70563f707270a07aae8f6 | jnegro/knockout | /knockout_steps/knockout_step3.py | 2,339 | 4.46875 | 4 | #!/usr/bin/python
# STEP 3 - Code the 'main' function to play the game
# In this step we replace the 'main' function with code that runs the game
from __future__ import print_function
# We need to import the 'random' Python library in order to generate random numbers
import random
class Boxer(object):
"""
... | true |
0ae1e723b9a16cd4c9a5bad9d756158888ccfe27 | SabiqulHassan13/python3-programiz-try | /NumberIsOddOrEven.py | 290 | 4.46875 | 4 | # python program to check a number is even or odd
#take input a number to check from the user
num = float(input("Enter a number: "))
# checking a number is odd or even
if num % 2 == 0:
print("{} is even number".format(num))
elif num % 2 == 1:
print("{} is odd number".format(num)) | true |
886979bbd25e5a15e02eef4cad6519d56f710c6c | SabiqulHassan13/python3-programiz-try | /FindFactorsOfANumber.py | 251 | 4.4375 | 4 | # python program to find the factors of a number
# take input a number
num = int(input("Enter a positive integer: "))
# print the factors
print("The factors of {} are: ".format(num))
for i in range(1, num + 1):
if num % i == 0:
print(i)
| true |
2a14971a28aee88ed93ee3aefb06dc1ec2fc0151 | rickyqiao/data-structure-sample | /binary_tree.py | 1,401 | 4.125 | 4 | class Node:
def __init__(self, data):
self.left = None
self.right = None
self.parent = None
self.data = data
self.height = 0
class BinaryTree:
def __init__(self):
self.root = None
def __str__(self, node = 0, depth = 0, direction_label = ""):
"The tr... | true |
9670dc0c87a0205c248e98154aa92186b48addba | arinmsn/My-Lab | /Books/PythonCrashCourse/Ch8/8-6_CityNames.py | 720 | 4.53125 | 5 | # Write a function called city_country() that takes in the name
# of a city and its country. The function should return a string formatted like this:
# "Santiago, Chile"
# Call your function with at least three city-country pairs, and print the value
# that’s returned.
def city_country(city, country):
message = ci... | true |
de0f6049fdf79eddf97e30129d1c449999dc4cab | slayer96/codewars_tasks | /pattern_craft_decorator.py | 1,691 | 4.5 | 4 | """
The Decorator Design Pattern can be used, for example, in the StarCraft game to manage upgrades.
The pattern consists in "incrementing" your base class with extra functionality.
A decorator will receive an instance of the base class and use it to create a new instance with the new things you want "added on it".
... | true |
5a31b5a75acc5bba977ad3117973e674063ffcc8 | joseph-guidry/dot | /mywork/ch5_ex/ex7.py | 636 | 4.125 | 4 | #! /usr/bin/env python3
def update_value(dictionary, num):
"""Take a dictionary and number to add values. Returns an updated
dictionary"""
for key in dictionary:
dictionary[key] += num #with no return
dict_value = {"cats":0, "dogs":0}
#get input and convert to int
number = int(input("What va... | true |
5380d9d84232b3c71cac9aa3e622a86d34dd1939 | dayna-j/Python | /codingbat/not_string.py | 238 | 4.375 | 4 | # Given a string, return a new string where "not " has been added
# to the front. However, if the string already begins with "not", return the string unchanged.
def not_string(str):
if str[0:3]=='not':
return str
return 'not '+str
| true |
aa5611dd17a02c0642afabcb5d37e5816079631d | deepakgd/python-exercises | /class7.py | 719 | 4.1875 | 4 | # multiple inheritance init call analysis
class A:
def __init__(self):
print("init of A")
def feature1(self):
print("Feature 1-A")
def featurea(self):
print("Feature A")
class B:
def __init__(self):
print("init of B")
def feature1(self):
print("Fea... | true |
f87730c01046eddf792665e051463ff59fde7aa0 | LilMelt/Python-Codes | /Rock_Paper_Scissors.py | 1,880 | 4.1875 | 4 | import random
def opponent():
choice = random.choice(["rock", "paper", "scissors"])
print("Your opponent chose " + choice)
return choice
def main():
game = True
score = 0
opponent_score = 0
while game:
# input user move
user_move = input("Type \"rock\", \"paper\" or \"sci... | true |
0a749ccfccd2d7b18168455fca9c7701f26177fd | Pankhuriumich/EECS-182-System-folder | /Homeworks/HW5/printmovie.py | 994 | 4.25 | 4 | '''TASK: Fill in the code to generate the HTML-formatted string
from the fields of a movie. See the README.txt for the
format
'''
def print_movie_in_html(movieid, movie_title, moviedate, movieurl):
'''STUB code. Needs to change so that the return value
contains HTML tags, as explained in README.txt.'''
resul... | true |
30e6b14d953e87fb0f37066e53f5222755743ddb | Pankhuriumich/EECS-182-System-folder | /Lecture_Code/Recursion/stone_to_dust_simulation/stonetodust.py | 797 | 4.21875 | 4 | def turn_stone_into_dust(stone):
if (isdust(stone)):
print "We got a dust piece! Nothing more to do on the piece!";
return;
else:
(piece1, piece2) = strike_hammer(stone);
turn_stone_into_dust(piece1);
turn_stone_into_dust(piece2);
def isdust(stone):
# Stones of size 1 or ... | true |
92d1c7f8015d4d552bb11fa8c818f81840d49646 | lavenderLatte/89926_py | /homework/helperfunctions.py | 536 | 4.34375 | 4 | """
Create a python module helperfunctions.py with the following functions.
add - returns the sum of two numbers
diff - returns the difference between two numbers
product - returns the product of two numbers
greatest - returns the greatest of two numbers.
Import this module in your python program and use the functions ... | true |
54bc71f87b9de5e9956881744c63d1501c24ddd4 | saragregory/hear-me-code | /pbj_while.py | 1,801 | 4.28125 | 4 | # Difficulty level: Beginner
# Goal #1: Write a new version of the PB&J program that uses a while loop. Print "Making sandwich #" and the number of the sandwich until you are out of bread, peanut butter, or jelly.
# Example:
# bread = 4
# peanut_butter = 3
# jelly = 10
# Output:
# Making sandwich #1
# Making sandwi... | true |
a9d2ac3204cf92eb968c39fcc51ba887805b9645 | coolguy-kr/questions | /py-multiple_inheritance.py | 826 | 4.4375 | 4 | # The following code is an example. The tree structure of class inheritance relationships is displayed as a list on the console.
class X:
pass
class Y:
pass
class Z:
pass
class A(X, Y):
pass
class B(Y, Z):
pass
class M(B, A, Z):
pass
print(M.mro())
# So, It displays a result as a list.
... | true |
511f378d45e5474c7a7eb679a78a14af4bac5cbf | asikurr/Python-learning-And-Problem-Solving | /3.Chapter three/elseif_stste.py | 350 | 4.125 | 4 | age = input("Input Your Age : ")
age = int(age)
if 0<age<=3:
print("Ticket is free for you. ")
elif 3<age<=10:
print("Ticket price is 150 tk.")
elif 10<age<=20:
print("Ticket price is 250 tk.")
elif 20<age<=150:
print("Ticket Price is 350 tk.")
elif age == 0 or 0>age or age>150:
print("Sorry... Yo... | true |
1ba6cdf92840fef7f2deef408520de98826d61e9 | asikurr/Python-learning-And-Problem-Solving | /8.Chapter eight SET/set.py | 499 | 4.28125 | 4 | # Set is unordered collection of unique data item
# why we user set method
# Because it contain unique data
#but we cannot user 'list' and 'dictionary' in set
# what is we do by set functon
# list data unique and tuple data unique
s = {1,2,3}
# print(s)
list1 = [6,3,4,5,4,3,5,4,4,3,3,4,6,8]
l = list(set(list1)) # Re... | true |
0b9b8fe6fabd72a052c5317ff141064693f21d96 | erikaosgue/python_challenges | /easy_challenges/16-minimun_by_key.py | 984 | 4.40625 | 4 | #!/usr/bin/python3
# As a part of this problem, we're going to build, piece-by-piece,
# the part of a relational database that can take a list of rows and
# sort them by multiple fields:
# i.e., the part that implements
# ORDER BY name ASC, age DESC
# Step 1: we want to write a function that returns the record... | true |
7bf8176a07d3a2573cc4047176e80da80944baec | ThomasSessions/Rock-Paper-Scissors | /RPSgame.py | 2,369 | 4.53125 | 5 | # Rock, paper, scissors game B05:
from random import randint # Allows the generation of random numers, "randint" means random integer
# Lets define some values
player_score = 0
computer_score = 0
x = player_score
y = computer_score
# Using a dictionary with winning results makes for a much cleaner results s... | true |
ee2a377708e520e9f316eefcb10665f07d4b816b | Zakir44/Assignment.4 | /04.py | 203 | 4.125 | 4 | #Accept number from user and calculate the sum of all number from 1 to a given number
a = int(input("Enter The Value: "))
SUM = 0
for i in range(a, 0, -1):
SUM = SUM+i
print("Sum :", SUM)
| true |
310f09091114e7e0068f092a986cb8021891fa80 | jalondono/holbertonschool-machine_learning | /math/0x05-advanced_linear_algebra/0-determinant.py | 1,270 | 4.125 | 4 | #!/usr/bin/env python3
"""Determinant"""
def check_shape(matrix):
"""
Check if is a correct matrix
:param matrix: matrix list
:return:
"""
if len(matrix):
if not len(matrix[0]):
return 3
if not isinstance(matrix, list) or len(matrix) == 0:
return 2
for row i... | true |
b31231c2ef1775c518afe43afd92db7d235df346 | jalondono/holbertonschool-machine_learning | /supervised_learning/0x00-binary_classification/0-neuron.py | 840 | 4.125 | 4 | #!/usr/bin/env python3
""" Neuron """
import numpy as np
class Neuron:
"""Neuron Class"""
def __init__(self, nx):
"""
constructor method
nx is the number of input features to the neuron
"""
if not isinstance(nx, int):
raise TypeError('nx must be an integer'... | true |
0e10d0d6502e8acb640f20d509ec37ea9319b9d5 | bpbpublications/Advance-Core-Python-Programming | /Chapter 02/section_2_2.py | 783 | 4.15625 | 4 | class Students:
student_id = 50
# This is a special function that Python calls when you create new instance of the class
def __init__(self, name, age):
self.name = name
self.age = age
Students.student_id = Students.student_id + 1
print('Student Created')
# Thi... | true |
34965ac46691239e08b86dab83ee6b52929c9900 | palani19/thilopy | /12.py | 220 | 4.15625 | 4 | a=int(input("Enter a value for a"))
b=int(input("Enter a value for b"))
#comparing no.
if(a>b):
print(a,"is greater than ",b)
elif(a==b):
print(a,"is equal to",b)
elif(b>a):
print(a,"is greater than",b) | true |
5f8b0aa422823da65f7d147ec85a0b3901f73982 | galenscovell/Project-Euler | /Python/Euler02.py | 736 | 4.1875 | 4 |
# Each new term in the Fibonacci sequence is generated by adding the previous two terms.
# By considering the terms in the Fibonacci sequence whose values do not exceed four million,
# find the sum of the even-valued terms.
# Personal challenge: Find sum of even or odd value terms up to given input value.
limit = ... | true |
3a299e5a203d3d4e54d2e92e06ed4d8c82c8c35d | Python-Geek-Labs/learn-python- | /tut16 - functions and docstrings.py | 695 | 4.21875 | 4 | # Built-In function (pre-defined fucntions)
# for eg - sum(param) where param must be an iterable var
# like list, tuple, set
# c = sum((9, 8)) or c = sum([9, 8]) or c = sum({9, 8})
def func():
print('Hello, u are in function')
func() # only print the hello statement
print(func()) # print hello statement and ... | true |
69773915f28a21e255badc11e9288ab18b914483 | Python-Geek-Labs/learn-python- | /tut7 - set, set functions.py | 1,237 | 4.1875 | 4 | s = set()
print(s)
# s = set(1, 2, 3, 4, 5) ----> Wrong !!
s = set([1, 2, 3, 4, 5, 10]) # ----> Right :)
# print(type(s))
l = [1, 2, 3, 4, 4]
setFromList = set(l)
print(setFromList)
print(type(setFromList))
print(len(s))
print(min(s))
print(max(s))
s.add(6)
s.remove(10)
print(s)
newSet = {2, 3, 45, 'hello cool d... | true |
3a489ad75cbae06ce788c1acf29103630a841b83 | ohduran/problemsolvingalgorithms | /LinearStructures/Queue/hotpotato.py | 592 | 4.125 | 4 | from queue import Queue
def hot_potato(names, num):
"""
Input a list of names,
and the num to be used for counting.
It returns the name of the last person
remaining after repetitive counting by num.
Upon passing the potato, the simulation
will deque and immediately enqueue that person.
... | true |
1f3963d9ac195ac26cc3c4129f719f66a5cc37bc | ohduran/problemsolvingalgorithms | /Trees and Tree Algorithms/trees.py | 1,652 | 4.1875 | 4 | """Tree Data Structures."""
class BinaryTree():
"""A Binary Tree is a Tree with a maximum of two children per node."""
def __init__(self, key):
"""Instantiate a Binary Tree."""
self.key = key
self.left_child = None
self.right_child = None
def get_left_child(self):
... | true |
0bc39ebe68a11c02e724e50f4af7cdada6e47628 | hyperc54/ml-snippets | /supervised/linear_models/linear_regression.py | 1,644 | 4.28125 | 4 | #!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 13:17:51 2018
This example is about using Linear Regression :
- in 1D with visualisation
- in ND
Resources
Trying to understand the intercept value :
http://blog.minitab.com/blog/adventures-in-statistics-2/regression-analysis-how-to-... | true |
bc91c6f05a549c07334497025e8329e558d306a2 | leemarreros/coding-challenges-explained | /max-sum-of-pyramid/pyramid-reduce-solution.py | 998 | 4.25 | 4 | from functools import reduce
# The returned value of 'back_slide' will become 'prev_array'
# in the next iteration.
# At first, we only take the last two arrays of 'pyramid'.
# After we calculate the greatest path between those two
# arrays, that same result is represented by 'prev_array'
# and computed again
# The '... | true |
85725c7b415e438578303cc522456b9fdb0f020d | Nishimirwe/python-algorithms | /src/interview_questions/recursionAndDynamicProgramming/easy/flatten.py | 558 | 4.1875 | 4 | # Flatten --> write a recursion function called flatten
# which accepts an array of arrays and returns a new array with all the values flattened
def flatten(arr):
resultArr = []
for custItem in arr:
if type(custItem) is list:
resultArr.extend(flatten(custItem))
else:
r... | true |
fa1f73a816833b275067a434c25e5f7362eeb9ce | Nishimirwe/python-algorithms | /src/interview_questions/recursionAndDynamicProgramming/hard/robot_in_a_grid.py | 2,263 | 4.21875 | 4 | #Robot in a Grid: Imagine a robot sitting on the upper left corner of grid with r rows and c columns.
#The robot can only move in two directions, right and down, but certain cells are "off limits"
#such that the robot cannot step on them. Design an algorithm to find a path for the
#robot from the top left to the bot... | true |
c1111f1933aeab8fa21b81df7299979e7ab2ff68 | Nishimirwe/python-algorithms | /src/interview_questions/recursionAndDynamicProgramming/easy/isPalindrome.py | 1,395 | 4.375 | 4 | # IsPalindrome --> Write a recursive function if the string passed to is a palindrome, otherwise return false
def isPalindrome(str):
strLength = len(str)
assert strLength > 0, "Length of string should be greater than 0"
# if initial length of string is one -> it definitely a palindrome
# Also handles,... | true |
8267427bbd6bc2c91ec94852d0f64f80e47c7d16 | Supernovacs/python | /main.py | 476 | 4.125 | 4 | def encrypt(text,s):
result = ""
for i in range(len(text)):
char = text[i]
if (char.isupper()):
result += chr((ord(char) + s-65) % 26 + 65)
elif (char == " "):
result += " "
else:
result += chr((ord(char) + s-97) % 26 + 97)
return result
p... | true |
e414ae359f0c48d04fa08f3535a62a137b7dd299 | VVivid/python-programs | /list/16.py | 217 | 4.1875 | 4 | """Write a Python program to generate and print a list of first and last 5 elements
where the values are square of numbers between 1 and 30 (both included)."""
l = [i ** 2 for i in range(1,31)]
print(l[:5],l[-5:])
| true |
cc9865ca878ab7af94ad00db8d1f6b7cf722e23a | VVivid/python-programs | /array/9.py | 297 | 4.125 | 4 | """Write a Python program to append items from a specified list."""
from array import *
array_test = array('i', [4])
num_test = [1, 2, 3, 4]
print(f"Items in the list: {num_test}")
print(f"Append items from the list: ")
array_test.fromlist(num_test)
print("Items in the array: "+str(array_test)) | true |
6d2f899345647d05fcb2666489eef6588c6df66d | VVivid/python-programs | /array/3.py | 263 | 4.34375 | 4 | """Write a Python program to reverse the order of the items in the array."""
from array import *
array_test = array('i',[1,2,3,4,5,6,7])
array_test_reverse = array_test[::-1]
print(f"Original Array: {array_test}\n"
f"Reverse Array: {array_test_reverse}")
| true |
d6cb540d3560e112018ee3372a8cc1151f5c8497 | VVivid/python-programs | /Strings/2.py | 229 | 4.21875 | 4 | """Write a Python program to count the number of characters (character frequency) in a string."""
Sample_String = 'google.com'
result = dict()
for item in Sample_String:
result[item] = Sample_String.count(item)
print(result) | true |
df5f7843f3a344c0ab4591dff759180561116413 | VVivid/python-programs | /Strings/3.py | 430 | 4.34375 | 4 | """Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string.
If the string length is less than 2, return instead of the empty string."""
def string_both_ends(user_input):
if len(user_input) < 2:
return 'Length smaller than 2'
return user_input[0:2] + user_... | true |
79762246ffac80b3d8e2acb35c05a13fdc843598 | VVivid/python-programs | /array/2.py | 260 | 4.125 | 4 | """Write a Python program to append a new item to the end of the array. """
from array import *
array_test = array('i', [1, 2, 3, 4, 5, 6, 7, 8, 9])
print("Original Array {}".format(array_test))
array_test.append(10)
print('Update array :')
print(array_test)
| true |
6a24b4feda7f21aea7fcbc9e137ec929a8f02ac2 | david-weir/Programming-3-Data-Struct-Alg- | /week3/slice.py | 651 | 4.15625 | 4 | #!/usr/bin/env python3
def get_sliced_lists(lst):
final = []
no_last = lst[:-1]
no_first_or_last = lst[1:-1]
reverse = lst[::-1]
final.append(no_last)
final.append(no_first_or_last)
final.append(reverse)
return final
# def main():
# # read the list from stdin
# nums = []
# ... | true |
416ee19ddef2547d51537911b5fc40298318f4fc | alextodireanu/check_palindrome_app | /check_palindrome.py | 877 | 4.5625 | 5 | # an app that checks if a given word is a palindrome
# first method using a reversed string
def check_palindrome(word):
"""Method to validate if a word is a palindrome"""
if word == word[::-1]:
return True
else:
return False
word_to_be_checked = input('Please type the word you want to che... | true |
bf5c393937be0e9fb8c5fbf17b55ef45baeb60a5 | joon628/ReadingJournal | /shapes.py | 1,706 | 4.5 | 4 | import turtle
#------------------------------------------------------------------------------
# Starter code to get things going
# (feel free to delete once you've written your own functions
#------------------------------------------------------------------------------
# Create the world, and a turtle to put in it
b... | true |
17bdeb8ccdb7aca974227a921418230411756335 | RobertNeuzil/leetcode | /fatherson.py | 497 | 4.125 | 4 | """
Use a recursion function to find out when the father will be twice as old as his son
"""
def father_son(fatherAge, sonAge):
while sonAge < 1000:
if fatherAge / 2 == sonAge:
print (f"The father will be twice as old as the son when the son is {sonAge} and the father is {fatherAge}")
... | true |
082f48d4ab9ce8e939954ca0eeb3244e7f08344c | stanmark2088/FizzBuzz | /fizzbuzz/fizbuzz.py | 516 | 4.25 | 4 | """
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”.
"""
def fizzbuzz():
for i in range(1, 101):
if i % 3 == 0 a... | true |
78ff2fa79302a923062788129b316090657da57d | sudhamshu4testing/PracticePython | /Program_to_count_vowels.py | 316 | 4.15625 | 4 | #Program to count the vowels in a given sentence/word
#Vowels
v = 'aeiou'
statement = 'Sudhamshu'
#Take input from the user
#statement = input("Enter a sentence or word: ")
statement = statement.casefold()
count = {}.fromkeys(vowels,0)
for char in statement:
if char in count:
count[char] += 1
print(count) | true |
51b1a59808f936b2dbbdcfcaab3dd5fa18b06348 | sudhamshu4testing/PracticePython | /ConverToListAndTuple.py | 447 | 4.4375 | 4 | #Program to convert the user entered values to List and Tuple
#Ask user to provide a sequence of comma seperated numbers
numbers = input("Proved the sequence of comma seperated numbers: ")
l = list(numbers)
#list can also be written as follow
#l = numbers.split(",")
t = tuple(numbers)
print("The sequence of the numb... | true |
c320948b0612cf1459bbcaae34aa045c6a03d084 | sudhamshu4testing/PracticePython | /Rock_Scissor_Paper_Game.py | 1,434 | 4.4375 | 4 | #Program for a game to play between 2 users and decide who wins the "Rock, Scissor and Paper" game
#Importing "sys" module to use "exit"
import sys
#Let's say if user1 selects "Rock" and user2 selects "Scissor", user1 will win because "Scissor" can't break the rock
#Similar way if user1 selects "Paper" and user2 sele... | true |
4c8756c4a16ee1fa314cf15aff1527902709cbf7 | sudhamshu4testing/PracticePython | /Email_Extraction.py | 209 | 4.125 | 4 | #Program to understand the regular expressions in detail
import re
pattern = r"([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)"
str = "Please contact test@email.com"
match = re.search(pattern,str)
if match:
print(match.group()) | true |
6043f021003d5daf6a77c89e5d5d1b5493465b96 | abhimanyupandey10/python | /even_function_sum.py | 345 | 4.1875 | 4 | # This program finds sum of even numbers of array using function
def findSumOfEvenNmbers (numbers):
sum = 0
for x in numbers:
if x % 2 == 0:
sum = sum + x
return sum
####################### Main code starts #####################
numbers = [6,7,8,9,1,2,3,4,5,6]
sum = findSumOfEvenNmb... | true |
9ae92c18a01a8ac79334573b3488606ccd9889a9 | AmreshTripathy/Python | /35_pr6_05.py | 226 | 4.1875 | 4 | names = ['harry', 'subham', 'rohit', 'Aditi', 'sipra']
name = input('Enter the name to check:\n')
if (name in names):
print ('Your name is present in the list')
else:
print ('Your name is not present in the list') | true |
6669679241d42a449d45ceb9c3a1601bd29e0e0a | ConradMare890317/Python_Crash.course | /Chap07/even_or_odd.py | 349 | 4.25 | 4 | prompt = "Enter a number, and I'll tell you if it's even or odd: "
prompt += "\nEnter 'quit' to end the program. "
active = True
while active:
number = input(prompt)
if number == 'quit':
active = False
elif int(number) % 2 == 0:
print(f"\nThe number {number} is even.")
elif int(number) % 2 != 0:
print(f"\nT... | true |
caf7c299c5edfb43bd8a7e4d2d01506a72c62494 | samarthgowda96/oop | /interface.py | 911 | 4.375 | 4 | # Python Object Oriented Programming by Joe Marini course example
# Using Abstract Base Classes to enforce class constraints
from abc import ABC,abstractmethod
class JSONify(ABC):
@abstractmethod
def toJSON(Self):
pass
class GraphicShape(ABC):
def __init__(self):
super().__init__()
@a... | true |
50e430e625a115ba20ab470dc0e5c36e9cf4ee8d | kerrymcgowan/AFS_505_u1_spring_2021 | /assignment2/ex6_studydrill1.py | 829 | 4.34375 | 4 | # Make a variable
types_of_people = 10
# Make a variable with an fstring
x = f"There are {types_of_people} types of people."
# Make a variable
binary = "binary"
# Make a variable
do_not = "don't"
# Make a variable with an fstring
y = f"Those who know {binary} and those who {do_not}."
# Print a variable
print(x)
# Pri... | true |
0761ca27262a5e66f956eddf201448f3a5f35cc1 | BMorgenstern/MergeSort | /MergeSort/mtest.py | 1,034 | 4.28125 | 4 | from mergesort import *
import sys
def getIntArray():
retlist = []
while True:
num = input("Enter an integer value to add to the array, or hit Enter to stop inputting values ")
if num == "":
return retlist
try:
retlist.append(int(num,10))
except ValueError:
print(num+" is not a number")
def main(ar... | true |
9fa47ad84849bdc739cff0462629cd2b1a31e594 | adriandrag18/Tema1_ASC | /tema/consumer.py | 1,679 | 4.21875 | 4 | """
This module represents the Consumer.
Computer Systems Architecture Course
Assignment 1
March 2021
"""
from threading import Thread, current_thread
from time import sleep
class Consumer(Thread):
"""
Class that represents a consumer.
"""
def __init__(self, carts, marketplace, retry_wait_time, **k... | true |
83c85f73f8dfac3b5d543f189e2f6939bf47dfc1 | nadia1038/Assignment-4 | /OneFour.py | 485 | 4.4375 | 4 | #1. Write a Python program to calculate the length of a string
String = "abcdefghijklmnopqrstuvwxyz"
print(len(String))
#4. Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.
#Sample String: 'restart'
#Expected... | true |
607d16b743dddf662f6a306422e65b936277e375 | milenaS92/HW070172 | /L04/python/chap3/exercise02.py | 472 | 4.28125 | 4 | # this program calculates the cost per square inch
# of a circular pizza
import math
def main():
print("This program calculates the cost per square inch of a circular pizza")
diam = float(input("Enter the diameter of the pizza in inches: "))
price = float(input("Enter the price of a pizza: "))
radius =... | true |
9b692103e23ee713b3c9e166c9832cad321c9f54 | milenaS92/HW070172 | /L04/python/chap3/exercise11.py | 318 | 4.25 | 4 | # This program calculates the sum of the first n natural numbers
def main():
print("This program calculates the sum of the first n natural numbers")
n = int(input("Please enter the natual number: "))
sum = 0
for i in range(0,n+1):
sum += i
print("The sum of the numbers is: ", sum)
main()
| true |
925177ca3178674f1b11986f0fd85ba0c2edac1a | milenaS92/HW070172 | /L05/python/chap7/excercise05.py | 459 | 4.125 | 4 | # exercise 5 chap 7
def bmiCalc(weight, height):
bmi = weight * 720 / (height**2)
if bmi < 19:
return "below the healthy range"
elif bmi < 26:
return "within the healthy range"
else:
return "above the healthy range"
def main():
weight = float(input("Please enter your weight... | true |
7a30a96b59ea58675216e5f9d00d2b4e243303e8 | kjempire9/python-beginner-codes | /factorial.py | 354 | 4.4375 | 4 |
# The following codes takes in a number and returns its factorial.
# For example 5! = 120.
def factorial(a):
try:
if int(a) == 1:
return 1
else:
return int(a)*factorial(int(a)-1)
except ValueError:
print("You did not enter an integer!!")
x = input("Enter an i... | true |
0e861f7d9e7fb8da98ddbc0cdd1256bf5e0ff958 | feeka/python | /[4]-if else try-catch.py | 447 | 4.15625 | 4 | # -*- coding: utf-8 -*-
x=int(input("Enter 1st number: "))
y=int(input("Enter 2nd number: "))
#line indenting plays great role in this case!
if x>y:
print(str(x)+" is GREATER than "+str(y))
elif x<y:
print(str(x)+" is LESS than "+str(y))
else:
print(str(x)+" is EQUAL to "+str(y))
#try-catc... | true |
6cc15739329b791ad5f36f630fd163814e946e24 | ppmx/cryptolib | /tools/hamming.py | 1,394 | 4.375 | 4 | #!/usr/bin/env python3
""" Package to compute the hamming distance.
The hamming distance between two strings of equal length is the number of
of positions at which the corresponding symbols are different.
"""
import argparse
import unittest
def hamming(string_a, string_b):
""" This function returns the hamming ... | true |
44e69f64edbe5493a73bc28b79ed4c14262163c5 | melissafear/CodingNomads_Labs_Onsite | /week_01/04_strings/05_mixcase.py | 682 | 4.625 | 5 | '''
Write a script that takes a user inputted string
and prints it out in the following three formats.
- All letters capitalized.
- All letters lower case.
- All vowels lower case and all consonants upper case.
'''
text = "here is a string of text"
print(text.upper())
print(text.lower())
# OPTION ONE
... | true |
4dffd43a38bb6413563021c5d20009090238120b | melissafear/CodingNomads_Labs_Onsite | /week_02/06_tuples/01_make_tuples.py | 615 | 4.34375 | 4 | '''
Write a script that takes in a list of numbers and:
- sorts the numbers
- stores the numbers in tuples of two in a list
- prints each tuple
Notes:
If the user enters an odd numbered list, add the last item
to a tuple with the number 0.
'''
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sorted_list = sort... | true |
158c564cc85e5e7ebb9c6943f67f1672c1ea0d4f | melissafear/CodingNomads_Labs_Onsite | /week_02/08_dictionaries/09_01_duplicates.py | 483 | 4.1875 | 4 | '''
Using a dictionary, write a function called has_duplicates that takes
a list and returns True if there is any element that appears more than
once.
'''
# count the occurrences of each item and store them in ther dictionary
def has_duplicates(list_):
my_dict = {}
for item in my_list:
if item in my... | true |
09c9533f5c28e11aff42f91813f61e4fae6891f4 | melissafear/CodingNomads_Labs_Onsite | /week_03/02_exception_handling/04_validate.py | 537 | 4.625 | 5 | '''
Create a script that asks a user to input an integer, checks for the
validity of the input type, and displays a message depending on whether
the input was an integer or not.
The script should keep prompting the user until they enter an integer.
'''
isinteger = "nope"
while isinteger == "nope":
user_input = ... | true |
bd8e455a8c043737ed67f8db322bea469758e3ac | melissafear/CodingNomads_Labs_Onsite | /week_02/07_conditionals_loops/Exercise_02.py | 799 | 4.3125 | 4 | '''
Take in a number from the user and print "Monday", "Tuesday", ...
"Sunday", or "Other" if the number from the user is 1, 2,... 7,
or other respectively. Use a "nested-if" statement.
'''
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun", "That's not a day of the week!"]
user_input = int(input("pls... | true |
b9ade628410db43de3d0448901ff69ecd70762c3 | treetrunkz/CalorieTracker | /caltrack.py | 1,648 | 4.3125 | 4 |
# this function uses sum and len to
# return the sum of the numbers=
def list_average(nums_list):
return sum(nums_list) + len(nums_list)
print('\n Welcome to the calorie goals calculator! \n \n We will be going through your diet and calculating and comparing your calorie goals and your caloric intake. \n')
goals = ... | true |
2e58bc18c81abfb4563c2c74d99bcc131255e304 | anmol-sinha-coder/LetsUpgrade-AI_ML | /Week-1/Assignment-1.py | 2,186 | 4.3125 | 4 | #!/usr/bin/env python
# coding: utf-8
# # <font color="blue">Question 1: </font>
# ## <font color="sky blue">Write a program to subtract two complex numbers in Python.</font>
# In[1]:
img1=complex(input("Enter 1st complex number: "))
img2=complex(input("Enter 2nd complex number: "))
print("\nSubtracting 2nd complex... | true |
35801887a4e6628db3c7175e0aa7360949426435 | vivekdevaraju/Coding-Challenges | /letterCount.py | 936 | 4.1875 | 4 | '''
Have the function LetterCountI(str) take the str parameter being passed
and return the first word with the greatest number of repeated letters. For
example: "Today, is the greatest day ever!" should return 'greatest' because
it has 2 e's (and 2 t's) and it comes before 'ever' which also has 2 e's. If
there ar... | true |
50b7cecd46498a3bc6bc7cc5383f2152b3f3b2ba | christian-miljkovic/interview | /Leetcode/Algorithms/Medium/Arrays/CampusBikes.py | 2,282 | 4.3125 | 4 | """
On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker and bike is a 2D coordinate on this grid.
Our goal is to assign a bike to each worker. Among the available bikes and workers, we choose the (worker, bike) pair with the shortest Manhattan distance between each other, an... | true |
643ebd3619eef099d5bc905e5d05944720fe4f5f | christian-miljkovic/interview | /Leetcode/Algorithms/Easy/Trie/LongestWordInDict.py | 2,397 | 4.125 | 4 | """
Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest lexicographical order.
If there is no answer, return the empty str... | true |
c97cda747343a105c055e5f66bcbc6230d193aff | christian-miljkovic/interview | /Algorithms/TopologicalSort.py | 1,182 | 4.25 | 4 | # Topological sort using Tarjan's Algorithm
from DepthFirstSearch import AdjacencyList
def topologicalSort(graph, vertexNumber, isVisited, stack):
"""
@graph: an adjacency list representing the current
@vertex: vertex where we want to start the topological sort from
@isVisited: list that determines if ... | true |
15cd88ccd33ef96a95b333f5bae7db1037c8b674 | christian-miljkovic/interview | /CrackingCodingInterview/ArraysStrings/Urlify.py | 571 | 4.375 | 4 | """
Chapter 1 Array's and Strings URLify problem
Write a method to replace all spaces in a string with '%20'. You may assume that the string
has sufficient space at the end to hold the additional characters, and that you are given the "true"
length of the string.
"""
def urlIfy(strToUrl):
str_list = strToUrl.spli... | true |
68198a14cc31ac3625adc8b9bdf7946f051304b9 | christian-miljkovic/interview | /Leetcode/Algorithms/Easy/DynamicProgramming/ClimbingStairs.py | 1,406 | 4.125 | 4 | """
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
Example 1:
Input: 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2.... | true |
8abe091f2738279cee6ca403284c1217dcea9e2c | christian-miljkovic/interview | /CrackingCodingInterview/DynamicProgramming/RobotGrid.py | 931 | 4.3125 | 4 | """
Chapter 8 Dynamic Programming and Recursion
Problem - Robot in a Grid: Imagine a robot sitting on the upper left corner of grid with r rows and c columns.
The robot can move in two direction, right and down, but certain cells are "off limits" such that
the robot cannot step on them. Design an algorithm to find a p... | true |
6711996b47819cb7d35bca835c41e2f80637b5e6 | christian-miljkovic/interview | /CrackingCodingInterview/ArraysStrings/RotateMatrix.py | 802 | 4.21875 | 4 | """
Chapter 1
Problem - Rotate Matrix: Rotate a Matrix 90 degrees
"""
def rotateMatrix(matrix):
size = len(matrix)
for layer in range(size//2):
first = layer
last = size - layer - 1
for i in range(first, last):
top = matrix[layer][i]
# left to top
... | true |
de80743e4c1e82678c0c543317bf6d5fa09f6ff9 | cooltreedan/NetworkProgrammability | /tried/json-example.py | 783 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding=utf-8 -*-
# Python contains very useful tools for working with JSON, and they're
# part of the standard library, meaning they're built into Python itself.
import json
# We can load our JSON file into a variable called "data"
with open("json-example.json") as f:
data = f.read(... | true |
d648148ab5acd683aacf3b8cef81dbd0c53a0213 | joeysal/astr-119-hw-2 | /dictionary.py | 467 | 4.375 | 4 | #define a dictionary data structure
#dictionaries have key:valyue pairs for the elements
example_dict = {
"class" : "ASTR 119",
"prof" : "Brant",
"awesomeness" : 10
}
print ("The type of example_dict is ", type(example_dict))
#get value via key
course = example_dict["class"]
print(course)
example_dict["awesomene... | true |
1dd908f565bfacec361dcfec080dac61c86146ca | Tahaa2t/Py-basics | /filing.py | 1,020 | 4.5625 | 5 |
#-----------------Reading from file-------------------------------
#Normal way to open and close a file
file = open("py_file.txt") #it will give error if no file exist with that name
contents = file.read()
print(contents)
file.close()
#this works same but you don't need to close file in the end
with open("py_fil... | true |
94e5da06b5afd9f2583b47047f37eda1cf7e6efe | amitdshetty/PycharmProjects | /PracticePythonOrg/Solutions/30_Pick_Word.py | 910 | 4.40625 | 4 | """
Problem Statement
This exercise is Part 1 of 3 of the Hangman exercise series. The other exercises are: Part 2 and Part 3.
In this exercise, the task is to write a function that picks a random word from a list of words from the SOWPODS dictionary.
Download this file and save it in the same directory as your Python... | true |
63b280c5c5791f4c2a98663fb56cc4c44dc3703f | amitdshetty/PycharmProjects | /PracticePythonOrg/Solutions/13_Fibonacci_Sequence.py | 833 | 4.4375 | 4 | """
Problem Statement
Write a program that asks the user how many Fibonnaci 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 Fibonnaci seqence is a sequence of nu... | true |
cbaffbcb484261206d837878922e062c9d929b0c | NealWhitlock/cs-module-project-algorithms | /moving_zeroes/moving_zeroes.py | 1,239 | 4.21875 | 4 | '''
Input: a List of integers
Returns: a List of integers
'''
# def moving_zeroes(arr):
# # Loop through items in array
# for i, num in enumerate(arr):
# # If item zero, pop off list and put at end
# if num == 0:
# arr.append(arr.pop(i))
# # Return array
# return arr
def moving_... | true |
94bc19906a2eeab0ed695d1a408b7c748efc8bd6 | rajashekharreddy/second_repo | /practice/3_tests/8_conversion_system.py | 752 | 4.21875 | 4 | """
This problem was asked by Jane Street.
The United States uses the imperial system of weights and measures, which means
that there are many different, seemingly arbitrary units to measure distance.
There are 12 inches in a foot, 3 feet in a yard, 22 yards in a chain, and so on.
Create a data structure that can e... | true |
1e2323818c35fae23972cb1c1ec9b532a43abf15 | heartnoxill/cpe213_algorithm | /divide_and_conquer/quicksort_1.py | 977 | 4.21875 | 4 | # Alphabetically QuickSort
__author__ = "Samkok"
def quick_sort(unsorted_list):
# Initiate the hold lists
less = []
equal = []
greater = []
# if list has more than one element then
if len(unsorted_list) > 1:
print("------------------------------")
pivot = unsorted_list[0]
... | true |
e80156d1329c7813d41d867c878155827cb2dddf | madhumati14/Assignment2 | /Assignment2_1.py | 714 | 4.21875 | 4 | #1.Create on module named as Arithmetic which contains 4 functions as Add() for addition, Sub()
#for subtraction, Mult() for multiplication and Div() for division. All functions accepts two
#parameters as number and perform the operation. Write on python program which call all the
#functions from Arithmetic module by a... | true |
ea564ec3f1fb1b9fb08550bebcf80f38ab3f7320 | rajpravali/Simple_chatbot | /index.py | 1,040 | 4.25 | 4 | from tkinter import * #importing tkinter library used to create GUI applications.
root=Tk() #creating window
def send():#function
send="YOU =>"+e.get()
txt.insert(END,'\n'+send)
if(e.get()=="hello"):
txt.insert(END,'\n'+"Bot => hi")
elif(e.get()=="hi"):
txt.insert(END,'\n'+"Bot => Hello... | true |
baa5e4999ca07b308b9c1bc3ef2bc3a603d39beb | jmocay/solving_problems | /linked_list_reverse.py | 1,212 | 4.1875 | 4 | """
Given the head of a singly linked list, reverse it in-place.
"""
class LinkedListNode(object):
def __init__(self, val=None):
self.val = val
self.next = None
def reverse_linked_list(head):
prev = None
curr = head
while curr != None:
curr_next = curr.next
... | true |
716d36f828edf84625bcaceec67f7a5d0d024815 | jwhitenews/computers-mn | /tk/Snowmobiles.py | 1,761 | 4.15625 | 4 | import sqlite3
from tkinter import *
def create_table():
#connect to db
conn = sqlite3.connect("lite.db")
#create cursor object
cur = conn.cursor()
#write an SQL query
cur.execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER , price REAL )")
#commit changes
conn.com... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.