blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
639d50d4d0579ee239adf72a08d7b4d78d9b91b6 | blaise594/PythonPuzzles | /weightConverter.py | 424 | 4.21875 | 4 | #The purpose of this program is to convert weight in pounds to weight in kilos
#Get user input
#Convert pounds to kilograms
#Display result in kilograms rounded to one decimal place
#Get user weight in pounds
weightInPounds=float(input('Enter your weight in pounds. '))
#One pound equals 2.2046226218 kilograms
weightI... | true |
53439bc9fed95069408cec769fddd8fc2fc9376d | BryCant/Intro-to-Programming-MSMS- | /Chapter13.py | 2,435 | 4.34375 | 4 | # Exception Handling
# encapsulation take all data associated with an object and put it in one class
# data hiding
# inheritance
# polymorphism ; function that syntactically looks same is different based on how you use it
"""
# basic syntax
try:
# Your normal code goes here.
# Your code should include function ... | true |
2679e524fb70ea8bc6a8801a3a9149ee258d9090 | daviscuen/Astro-119-hw-1 | /check_in_solution.py | 818 | 4.125 | 4 | #this imports numpy
import numpy as np
#this step creates a function called main
def main():
i = 0 #sets a variable i equal to 0
x = 119. # sets a variable x equal to 119 and the decimal makes it a float (do you need the 0?)
for i in range(120): #starting at i, add one everytime the program gets to t... | true |
0d4aad51ef559c9bf11cd905cf14de63a6011457 | mvinovivek/BA_Python | /Class_3/8_functions_with_return.py | 982 | 4.375 | 4 | #Function can return a value
#Defining the function
def cbrt(X):
"""
This is called as docstring short form of Document String
This is useful to give information about the function.
For example,
This function computes the cube root of the given number
"""
cuberoot=X**(1/3)
retur... | true |
53cee6f939c97b0d84be910eee64b6e7f515b12f | mvinovivek/BA_Python | /Class_3/7_functions_with_default.py | 680 | 4.1875 | 4 | # We can set some default values for the function arguments
#Passing Multiple Arguments
def greet(name, message="How are you!"):
print("Hi {}".format(name))
print(message)
greet("Bellatrix", "You are Awesome!")
greet("Bellatrix")
#NOTE Default arguments must come at the last. All arguments before default are... | true |
3cb1bc2560b5771e4c9ec69d429fcfd9c0eadd2c | mvinovivek/BA_Python | /Class_2/7_for_loop_2.py | 1,009 | 4.625 | 5 | #In case if we want to loop over several lists in one go, or need to access corresponding
#values of any list pairs, we can make use of the range method
#
# range is a method when called will create an array of integers upto the given value
# for example range(3) will return an array with elements [0,1,2]
#now we can... | true |
c9a6c2f6b8f0655b3e417057f7e52015794d26d6 | 316126510004/ostlab04 | /scramble.py | 1,456 | 4.40625 | 4 | def scramble(word, stop):
'''
scramble(word, stop)
word -> the text to be scrambled
stop -> The last index it can extract word from
returns a scrambled version of the word.
This function takes a word as input and returns a scrambled version of it.
However, the letters in the beginning and ending do not change.
... | true |
d24514f8bed4e72aaaee68ae96076ec3921f5898 | ChanghaoWang/py4e | /Chapter9_Dictionaries/TwoIterationVariable.py | 429 | 4.375 | 4 | # Two iteration varibales
# We can have multiple itertion variables in a for loop
name = {'first name':'Changhao','middle name':None,'last name':'Wang'}
keys = list(name.keys())
values = list(name.values())
items = list(name.items())
print("Keys of the dict:",keys)
print("Values of the dict:",values)
print("Items of th... | true |
6d325039a3caa4c331ecc6fa6bb058ff431218f8 | ChanghaoWang/py4e | /Chapter8_Lists/note.py | 921 | 4.21875 | 4 | # Chapter 8 Lists Page 97
a = ['Changhao','Wang','scores',[100,200],'points','.']
# method: append & extend
a.append('Yeah!') #Note, the method returns None. it is different with str
a.extend(['He','is','so','clever','!'])
# method : sort (arranges the elements of the list from low to high)
b= ['He','is','clever','!']
... | true |
d593ffafc59015480c713c213b59f6304914d660 | Ayush10/python-programs | /vowel_or_consonant.py | 1,451 | 4.40625 | 4 | # Program to check if the given alphabet is vowel or consonant
# Taking user input
alphabet = input("Enter any alphabet: ")
# Function to check if the given alphabet is vowel or consonant
def check_alphabets(letter):
lower_case_letter = letter.lower()
if lower_case_letter == 'a' or lower_case_letter == 'e' or... | true |
2676477d211e0702d1c44802f9295e8457df21a8 | Ayush10/python-programs | /greatest_of_three_numbers.py | 492 | 4.3125 | 4 | # Program to find greatest among three numbers
# Taking user input
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
# Comparison Algorithm and displaying result
if a > b > c:
print("%d is the greatest number among %d, %d and %d." % (a, a, b, c))
... | true |
e50f8e37210054df2e5c54eb55e7dee381a91aff | super468/leetcode | /python/src/BestMeetingPoint.py | 1,219 | 4.15625 | 4 | class Solution:
def minTotalDistance(self, grid):
"""
the point is that median can minimize the total distance of different points.
the math explanation is https://leetcode.com/problems/best-meeting-point/discuss/74217/The-theory-behind-(why-the-median-works)
the more human language ... | true |
63825db8fd9cd5e9e6aaa551ef7bfec29713a925 | Rohit439/pythonLab-file | /lab 9 .py | 1,686 | 4.28125 | 4 | #!/usr/bin/env python
# coding: utf-8
# ### q1
# In[2]:
class Triangle:
def _init_(self):
self.a=0
self.b=0
self.c=0
def create_triangle(self):
self.a=int(input("enter the first side"))
self.b=int(input("enter the second side"))
self.c=int(input("e... | true |
2991c345efe646cedda8aeaeeebe06b2a4cc6842 | drmason13/euler-dream-team | /euler1.py | 778 | 4.34375 | 4 | def main():
"""
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
test()
print(do_the_thing(1000))
def do_the_thing(target):
numbers = range(1, target)
answer =... | true |
6f1aa43d0614cd211b0c92a48b182cf662e230fa | nmaswood/Random-Walk-Through-Computer-Science | /lessons/day4/exercises.py | 720 | 4.25 | 4 | def fib_recursion(n):
"""
return the nth element in the fibonacci sequence using recursion
"""
return 0
def fib_not_recursion(n):
"""
return the nth element in the fibonacci sequence using not recursion
"""
return 0
def sequence_1(n):
"""
return the nth element in the sequ... | true |
b976f86e302748c97bcd5033499a0f2a928bcbdc | taddes/python-blockchain | /data_structures_assignment.py | 1,053 | 4.40625 | 4 | # 1) Create a list of “person” dictionaries with a name, age and list of hobbies for each person. Fill in any data you want.
person = [{'name': 'Taddes', 'age': 30, 'hobbies': ['bass', 'coding', 'reading', 'exercise']},
{'name': 'Sarah', 'age': 30, 'hobbies': ['exercise', 'writing', 'crafting']},
... | true |
7cdaebe77cfb044dfc16e01576311244caae283f | roshna1924/Python | /ICP1/Source Code/operations.py | 590 | 4.125 | 4 | num1 = int(input("Enter first number: "))
num2 = int(input("Enter Second number: "))
operation = int(input("Enter 1 for addition\n" "Enter 2 for Subtraction\n" "Enter 3 for multiplication\n" "Enter 4 for division\n"))
def arithmeticOperations(op):
switcher = {
1: "Result of addition : " + str(num1 + num2),... | true |
2185999943f7891d33a7519159d3d08feba8e14d | tim-jackson/euler-python | /Problem1/multiples.py | 356 | 4.125 | 4 | """multiples.py: Exercise 1 of project Euler.
Calculates the sum of the multiples of 3 or 5, below 1000. """
if __name__ == "__main__":
TOTAL = 0
for num in xrange(0, 1000):
if num % 5 == 0 or num % 3 == 0:
TOTAL += num
print "The sum of the multiples between 3 and 5, " \
... | true |
78b2dadaa067264258ed93da5a4e13ebf692ec6a | klq/euler_project | /euler41.py | 2,391 | 4.25 | 4 | import itertools
import math
def is_prime(n):
"""returns True if n is a prime number"""
if n < 2:
return False
if n in [2,3]:
return True
if n % 2 == 0:
return False
for factor in range(3, int(math.sqrt(n))+1, 2):
if n % factor == 0:
return False
ret... | true |
1ba8cda2d2376bd93a169031caa473825b3912da | QaisZainon/Learning-Coding | /Practice Python/Exercise_02.py | 795 | 4.375 | 4 | '''
Ask the user for a number
Check for even or odd
Print out a message for the user
Extras:
1. If number is a multiple of 4, print a different message.
2. Ask the users for two numbers, check if it is divisible, then
print message according to the answer.
'''
def even_odd():
num = int(input('Enter a n... | true |
6426ac00f17c7d1c5879ddf994938cfa0a412e62 | ChienSien1990/Python_collection | /Ecryption/Encrpytion(applycoder).py | 655 | 4.375 | 4 | def buildCoder(shift):
"""
Returns a dict that can apply a Caesar cipher to a letter.
The cipher is defined by the shift value. Ignores non-letter characters
like punctuation, numbers, and spaces.
shift: 0 <= int < 26
returns: dict
"""
### TODO
myDict={}
for i in string.as... | true |
1105fd4cb3e9b95294e5e918b0017e7f109d1aac | sujit4/problems | /interviewQs/InterviewCake/ReverseChars.py | 1,023 | 4.25 | 4 | # Write a function that takes a list of characters and reverses the letters in place.
import unittest
def reverse(list_of_chars):
left_index = 0
right_index = len(list_of_chars) - 1
while left_index < right_index:
list_of_chars[left_index], list_of_chars[right_index] = list_of_chars[right_index]... | true |
72f12e63fbac4561a74211964ab031f5ffb29212 | derick-droid/pythonbasics | /files.py | 905 | 4.125 | 4 | # checking files in python
open("employee.txt", "r") # to read the existing file
open("employee.txt", "a") # to append information into a file
employee = open("employee.txt", "r")
# employee.close() # after opening a file we close the file
print(employee.readable()) # this is to check if the file is readable
prin... | true |
95a9f725607b5acc0f023b0a0af2551bec253afd | derick-droid/pythonbasics | /dictexer.py | 677 | 4.90625 | 5 | # 6-5. Rivers: Make a dictionary containing three major rivers and the country
# each river runs through. One key-value pair might be 'nile': 'egypt'.
# • Use a loop to print a sentence about each river, such as The Nile runs
# through Egypt.
# • Use a loop to print the name of each river included in the dictionary.
# ... | true |
935e0579d7cbb2da005c6c6b1ab7f548a6694a86 | derick-droid/pythonbasics | /slicelst.py | 2,312 | 4.875 | 5 | # 4-10. Slices: Using one of the programs you wrote in this chapter, add several
# lines to the end of the program that do the following:
# • Print the message, The first three items in the list are:. Then use a slice to
# print the first three items from that program’s list.
# • Print the message, Three items from the... | true |
5a827e2d5036414682f468fac5915502a784f486 | derick-droid/pythonbasics | /exerdic.py | 2,972 | 4.5 | 4 | # 6-8. Pets: Make several dictionaries, where the name of each dictionary is the
# name of a pet. In each dictionary, include the kind of animal and the owner’s
# name. Store these dictionaries in a list called pets . Next, loop through your list
# and as you do print everything you know about each print it
rex = {
... | true |
d65f32a065cc87e5de526a718aeea6d601e1ac06 | derick-droid/pythonbasics | /iflsttry.py | 2,930 | 4.5 | 4 | # 5-8. Hello Admin: Make a list of five or more usernames, including the name
# 'admin' . Imagine you are writing code that will print a greeting to each user
# after they log in to a website. Loop through the list, and print a greeting to
# each user:
# • If the username is 'admin' , print a special greeting, such as ... | true |
0ed70af907f37229379d7b38b7aaae938a7fc31a | adamkozuch/scratches | /scratch_4.py | 584 | 4.15625 | 4 | def get_longest_sequence(arr):
if len(arr) < 3:
return len(arr)
first = 0
second = None
length = 0
for i in range(1, len(arr)):
if arr[first] == arr[i] or (second and arr[second]== arr[i]):
continue
if not second:
second = i
continue
... | true |
0b303dde589390cf6795a2fc79ca473349c5e190 | SeanLau/leetcode | /problem_104.py | 1,203 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
# 此题可以先序遍历二叉树,找到最长的即可
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def maxDepth(self, root):
"""
:type root: TreeNode
:r... | true |
ef1ebb2ba1f95a2d8c09f3dc32af9d2ffec17499 | CyberTaoFlow/Snowman | /Source/server/web/exceptions.py | 402 | 4.3125 | 4 | class InvalidValueError(Exception):
"""Exception thrown if an invalid value is encountered.
Example: checking if A.type == "type1" || A.type == "type2"
A.type is actually "type3" which is not expected => throw this exception.
Throw with custom message: InvalidValueError("I did not expect that value!")"... | true |
c61d5128252a279d1f6c2b6f054e8ea1ead7b2af | rup3sh/python_expr | /general/trie | 2,217 | 4.28125 | 4 | #!/bin/python3
import json
class Trie:
def __init__(self):
self._root = {}
def insertWord(self, string):
''' Inserts word by iterating thru char by char and adding '*"
to mark end of word and store complete word there for easy search'''
node = self._root
for c in string:
if c not in node:
... | true |
23f20f17dc25cc3771922706260d43751f2584c5 | rup3sh/python_expr | /generators/generator | 1,446 | 4.34375 | 4 | #!/bin/python3
import pdb
import sys
##Reverses words in a corpus of text.
def main(argv):
generatorDemo()
def list_of_even(n):
for i in range(0,n+1):
if i%2 == 0:
yield i
def generatorDemo():
try:
x = list_of_even(10)
print(type(x))
for i in x:
print("EVEN:" + str(i))
the_li... | true |
8fe1986f84ccd0f906095b651aa98ba62b2928b8 | rup3sh/python_expr | /listsItersEtc/listComp | 1,981 | 4.1875 | 4 | #!/bin/python3
import pdb
import sys
##Reverses words in a corpus of text.
def main(argv):
listComp()
def listComp():
the_list = ["stanley", "ave", "fremont", "los angeles", "istanbul", "moscow", "korea"]
print(the_list[0:len(the_list)])
#Slicing
#the_list[2:] = "paz"
#['stanley', 'ave', 'p', 'a', '... | true |
3b597cae9208d703e6479525625da55ddc18b976 | DahlitzFlorian/python-zero-calculator | /tests/test_tokenize.py | 1,196 | 4.1875 | 4 | from calculator.helper import tokenize
def test_tokenize_simple():
"""
Tokenize a very simple function and tests if it's done correctly.
"""
func = "2 * x - 2"
solution = ["2", "*", "x", "-", "2"]
assert tokenize.tokenize(func) == solution
def test_tokenize_complex():
"""
Tokenize a... | true |
4b7dbbf640d118514fa306ca39a5ee336852aa05 | francoischalifour/ju-python-labs | /lab9/exercises.py | 1,777 | 4.25 | 4 | #!/usr/bin/env python3
# coding: utf-8
# Lab 9 - Functional Programming
# François Chalifour
from functools import reduce
def product_between(a=0, b=0):
"""Returns the product of the integers between these two numbers"""
return reduce(lambda a, b: a * b, range(a, b + 1), 1)
def sum_of_numbers(numbers):
... | true |
ba5bce618d68b7570c397bc50d6f96766b600fd9 | francoischalifour/ju-python-labs | /lab4/exercises.py | 1,024 | 4.1875 | 4 | #!/usr/bin/env python3
# coding: utf-8
# Lab 4 - Dictionaries
# François Chalifour
def sums(numbers):
"""Returns a dictionary where the key "odd" contains the sum of all the odd
integers in the list, the key "even" contains the sum of all the even
integers, and the key "all" contains the sum of all integer... | true |
a81ce65a4df9304e652af161f5a00534b35cc844 | Abuubkar/python | /code_samples/p4_if_with_in.py | 1,501 | 4.25 | 4 | # IF STATEMENT
# Python does not require an else block at the end of an if-elif chain.
# Unlike C++ or Java
cars = ['audi', 'bmw', 'subaru', 'toyota']
if not cars:
print('Empty Car List')
if cars == []:
print('Empty Car List')
for car in cars:
if car == 'bmw':
print(car.upper())
elif cars ==... | true |
b583554675d3ec46b424ac0e808a8281a339de67 | NandanSatheesh/Daily-Coding-Problems | /Codes/2.py | 602 | 4.21875 | 4 | # This problem was asked by Uber.
#
# Given an array of integers,
# return a new array such that each element at index i of the
# new array is the product of all the numbers in the original array
# except the one at i.
#
# For example,
# if our input was [1, 2, 3, 4, 5],
# the expected output would be [120, 60, 40, 3... | true |
371ed66d667edb14d59347994462ddf30dde6a84 | Liraz-Benbenishti/Python-Code-I-Wrote | /hangman/hangman/hangman-unit7/hangman-ex7.3.1.py | 836 | 4.25 | 4 | def show_hidden_word(secret_word, old_letters_guessed):
"""
:param secret_word: represent the hidden word the player need to guess.
:param old_letters_guessed: the list that contain the letters the player guessed by now.
:type secret_word: string
:type old_letters_guessed: list
:return: string that comprise... | true |
fda16aa729c019888cb2305fcfb00d782e620db6 | cnulenka/Coffee-Machine | /models/Beverage.py | 1,434 | 4.34375 | 4 | class Beverage:
"""
Beverage class represents a beverage, which has a name
and is made up of a list of ingredients.
self._composition is a python dict with ingredient name as
key and ingredient quantity as value
"""
def __init__(self, beverage_name: str, beverage_composition: dict):
... | true |
7762d9a8c0b8ebb97551f2071f9377fe896b686f | itstooloud/boring_stuff | /chapter_3/global_local_scope.py | 922 | 4.1875 | 4 | ##
####def spam():
#### global eggs
#### eggs = 'spam'
####
####eggs = 'global'
####spam()
####print(eggs)
##
####using the word global inside the def means that when you refer to that variable within
####the function, you are referring to the global variable and can change it.
##
####def spam():
#### global e... | true |
f85f89d07de9f394d7f95646c0a490232bc3b7bc | whoismaruf/usermanager | /app.py | 2,605 | 4.15625 | 4 | from scripts.user import User
print('\nWelcome to user management CLI application')
user_list = {}
def create_account():
name = input('\nSay your name: ')
while True:
email = input('\nEnter email: ')
if '@' in email:
temp = [i for i in email[email.find('@'):]]
if... | true |
4da19128caf20616ecbd36b297022b1d3ccb92ce | PraneshASP/LeetCode-Solutions-2 | /234 - Palindrome Linked List.py | 1,548 | 4.1875 | 4 | # Solution: The idea is that we can reverse the first half of the LinkedList, and then
# compare the first half with the second half to see if it's a palindrome.
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution... | true |
869edf4c975e41ccdee0eacfbda1a636576578fc | jigarshah2811/Python-Programming | /Matrix_Print_Spiral.py | 1,741 | 4.6875 | 5 | """
http://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
Print a given matrix in spiral form
Given a 2D array, print it in spiral form. See the following examples.
Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 1... | true |
4a5fc85b209138408683797ef784cbd59dd978fe | jigarshah2811/Python-Programming | /LL_MergeSort.py | 2,556 | 4.625 | 5 | # Python3 program merge two sorted linked
# in third linked list using recursive.
# Node class
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Constructor to initialize the node object
class LinkedList:
# Function to initialize head
def __init__(self):
s... | true |
28a8e6ee2b125056cfe0c3056d6e3a92ba5e4a65 | sabeeh99/Batch-2 | /fathima_ashref.py | 289 | 4.28125 | 4 | # FathimaAshref-2-HelloWorldAnimation
import time
def animation(word):
"""this function takes the input and displays it
character by character with a delay of 1 second"""
for i in word:
time.sleep(1)
print(i, end="")
animation("Hello World")
| true |
d2f96447565c188fcc5fb24a24254dc68a2f5b60 | hanucane/dojo | /Online_Academy/python-intro/datatypes.py | 763 | 4.3125 | 4 | # 4 basic data types
# print "hello world" # Strings
# print 4 - 3 # Integers
# print True, False # Booleans
# print 4.2 # Floats
# print type("hello world") # Identify data type
# print type(1)
# print type(True)
# print type(4.2)
# Variables
name = "eric"
# print name
myFavoriteInt = 8
myBool = True
myFloat = 4.2
... | true |
eb392b54023303e56d23b76a464539b70f8ee6e8 | shamim-ahmed/udemy-python-masterclass | /section-4/examples/guessinggame6.py | 507 | 4.1875 | 4 | #!/usr/bin/env python
import random
highest = 10
answer = random.randint(1, highest)
is_done = False
while not is_done:
# obtain user input
guess = int(input("Please enter a number between 1 and {}: ".format(highest)))
if guess == answer:
is_done = True
print("Well done! The correct ans... | true |
3d1946247a3518c4bd2128786609946be2ae768c | shamim-ahmed/udemy-python-masterclass | /section-4/exercises/exercise11.py | 638 | 4.21875 | 4 | #!/usr/bin/env python3
def print_option_menu(options):
print("Please choose your option from the list below:\n")
for i, option in enumerate(options):
print("{}. {}".format(i, option))
print()
if __name__ == "__main__":
options = ["Exit", "Learn Python", "Learn Java", "Go swimming", "Have di... | true |
a40410c97ef48d989ce91b6d23262720f60138dc | rajeshberwal/dsalib | /dsalib/Stack/Stack.py | 1,232 | 4.25 | 4 | class Stack:
def __init__(self):
self._top = -1
self.stack = []
def __len__(self):
return self._top + 1
def is_empty(self):
"""Returns True is stack is empty otherwise returns False
Returns:
bool: True if stack is empty otherwise returns False
... | true |
04d70de92bfca1f7b293f344884ec1e23489b7e4 | rajeshberwal/dsalib | /dsalib/Sorting/insertion_sort.py | 547 | 4.375 | 4 | def insertion_sort(array: list) -> None:
"""Sort given list using Merge Sort Technique.
Time Complexity:
Best Case: O(n),
Average Case: O(n ^ 2)
Worst Case: O(n ^ 2)
Args:
array (list): list of elements
"""
for i in range(1, len(array)):
current_num = array[... | true |
6705bd7dfa677bd27dbcf200aaa3f7dc6cd6cb55 | laurenc176/PythonCrashCourse | /Lists/simple_lists_cars.py | 938 | 4.5 | 4 | #organizing a list
#sorting a list permanently with the sort() method, can never revert
#to original order
cars = ['bmw','audi','toyota','subaru']
cars.sort()
print(cars)
#can also do reverse
cars.sort(reverse=True)
print(cars)
# sorted() function sorts a list temporarily
cars = ['bmw','audi','toyota'... | true |
68654f6011396a2f0337ba2d591a7939d609b3ed | laurenc176/PythonCrashCourse | /Files and Exceptions/exceptions.py | 2,711 | 4.125 | 4 | #Handling exceptions
#ZeroDivisionError Exception, use try-except blocks
try:
print(5/0)
except ZeroDivisionError:
print("You can't divide by zero!")
#Using Exceptions to Prevent Crashes
print("Give me two numbers, and I'll divide them")
print("Enter 'q' to quit.")
#This will crash if second number is ... | true |
fbc01f2c549fae60235064d839c55d98939ae775 | martinskillings/tempConverter | /tempConverter.py | 2,231 | 4.3125 | 4 |
#Write a program that converts Celsius to Fahrenheit or Kelvin
continueLoop = 'f'
while continueLoop == 'f':
celsius = eval(input("Enter a degree in Celsius: "))
fahrenheit = (9 / 5 * celsius + 32)
print(celsius, "Celsius is", format(fahrenheit, ".2f"), "Fahrenheit")
#User prompt t... | true |
d5a296818f6bd02b8c03c76b2aa042abbcb4ee17 | AlexanderOHara/programming | /week03/absolute.py | 336 | 4.15625 | 4 | # Give the absolute value of a number
# Author Alexander O'Hara
# In the question, number is ambiguous but the output implies we should be
# dealing with floats so I am casting the input to a flat
number = float (input ("Enter a number: "))
absoluteValue = abs (number)
print ('The absolute value of {} is {}'. format... | true |
faf268ea926783569bf7e2714589f264ed4f3554 | Teddy-Sannan/ICS3U-Unit2-02-Python | /area_and_perimeter_of_circle.py | 606 | 4.1875 | 4 | #!/usr/bin/env python3
# Created by: Teddy Sannan
# Created on: September 16
# This program calculates the area and perimeter of a rectangle
def main():
# main function
print("We will be calculating the area and perimeter of a rectangle")
print("")
# input
length = int(input("Enter the length (mm... | true |
158450f4cb59c6890e6de4931de18e66a4f5ef48 | FraserTooth/python_algorithms | /01_balanced_symbols_stack/stack.py | 865 | 4.21875 | 4 | class Stack:
def __init__(self):
self.items = []
def push(self, item):
"""Adds an item to end
Returns Nothing
Time Complexity = O(1)
"""
self.items.append(item)
def pop(self):
"""Removes Last Item
Returns Item
Time Complexity = O(1)... | true |
14d98d23d3617c08a2aefd1b4ced2d80c5a9378c | 168959/Datacamp_pycham_exercises2 | /Creat a list.py | 2,149 | 4.40625 | 4 | # Create the areas list
areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50]
"# Print out second element from areas"
print(areas[1])
"# Print out last element from areas"
print(areas[9])
"# Print out the area of the living room"
print(areas[5])
"# Create the areas lis... | true |
a65aa34ef32d7fced8a91153dae77e48f5cc1176 | 2019-fall-csc-226/a02-loopy-turtles-loopy-languages-henryjcamacho | /Camachoh- A02.py | 1,133 | 4.15625 | 4 | ######################################################################
# Author: Henry Camacho TODO: Change this to your name, if modifying
# Username: HenryJCamacho TODO: Change this to your username, if modifying
#
# Assignment: A02
# Purpose: To draw something we lie with loop
########... | true |
5c703ed90acda4eaba3364b6f510d28622ddc4a0 | ndenisj/web-dev-with-python-bootcamp | /Intro/pythonrefresher.py | 1,603 | 4.34375 | 4 | # Variables and Concatenate
# greet = "Welcome To Python"
# name = "Denison"
# age = 6
# coldWeather = False
# print("My name is {} am {} years old".format(name, age)) # Concatenate
# Comment: codes that are not executed, like a note for the programmer
"""
Multi line comment
in python
"""
# commentAsString = """
... | true |
61e6633eeadf4384a18603640e30e0fa0a6998c8 | suyash248/ds_algo | /Array/stockSpanProblem.py | 959 | 4.28125 | 4 | from Array import empty_1d_array
# References - https://www.geeksforgeeks.org/the-stock-span-problem/
def stock_span(prices):
# Stores index of closest greater element/price.
stack = [0]
spans = empty_1d_array(len(prices))
# Stores the span values, first value(left-most) is 1 as there is no previous g... | true |
d21394227d4390b898fc1588593e43616ed7e502 | suyash248/ds_algo | /Misc/sliding_window/substrings_with_distinct_elt.py | 2,324 | 4.125 | 4 | '''
Given a string s consisting only of characters a, b and c.
Return the number of substrings containing at least one occurrence of all these characters a, b and c.
Example 1:
Input: s = "abcabc"
Output: 10
Explanation: The substrings containing at least one occurrence of the characters a, b and c are "abc", "abc... | true |
12562fa1658d275e15075f71cff3fac681c119ab | green-fox-academy/Angela93-Shi | /week-01/day-4/data_structures/data_structures/product_database.py | 715 | 4.34375 | 4 | map={'Eggs':200,'Milk':200,'Fish':400,'Apples':150,'Bread':50,'Chicken':550}
# Create an application which solves the following problems.
# How much is the fish?
print(map['Fish'])
# What is the most expensive product?
print(max(map,key=map.get))
# What is the average price?
total=0
for key in map:
total=total+map... | true |
587a7726500b091aea4511e4036f8750c229ecaa | green-fox-academy/Angela93-Shi | /week-05/day-01/all_positive.py | 319 | 4.3125 | 4 | # Given a list with the following items: 1, 3, -2, -4, -7, -3, -8, 12, 19, 6, 9, 10, 14
# Determine whether every number is positive or not using all().
original_list=[1, 3, -2, -4, -7, -3, -8, 12, 19, 6, 9, 10, 14]
def positive_num(nums):
return all([num > 0 for num in nums])
print(positive_num(original_list)) | true |
8fcf16851182307c41d9c5dd77e8d42b783628c7 | green-fox-academy/Angela93-Shi | /week-01/day-4/function/factorial.py | 409 | 4.375 | 4 | # - Create a function called `factorio`
# that returns it's input's factorial
num = int(input("Please input one number: "))
def factorial(num):
factorial=1
for i in range(1,num + 1):
factorial = factorial*i
print("%d 's factorial is %d" %(num,factorial))
if num < 0:
print("抱歉,负数没有阶乘")
elif nu... | true |
c60df7c6d2aa3eaecdc1c95bc7bba9a96eff1add | kasemodz/RaspberryPiClass1 | /LED_on_off.py | 831 | 4.125 | 4 | # The purpose of this code is to turn the led off and on.
# The LED is connected to GPIO pin 25 via a 220 ohm resistor.
# See Readme file for necessary components
#! /usr/bin/python
#We are importing the sleep from the time module.
from time import sleep
#We are importing GPIO subclass from the class RPi. We are ref... | true |
e799fbff3d6be502d48b68fb1094b6dd4bcc4079 | yihangx/Heart_Rate_Sentinel_Server | /validate_heart_rate.py | 901 | 4.25 | 4 | def validate_heart_rate(age, heart_rate):
""" Validate the average of heart rate, and return
the patient's status.
Args:
age(int): patient'age
heart_rate(int): measured heart rates
Returns:
status(string): average heart rate
"""
status = ""
if age < 1:
tachyca... | true |
0f7cfefeb124d76ef25dc904500246c9e843658d | xg04tx/number_game2 | /guessing_game.py | 2,282 | 4.125 | 4 |
def main():
while True:
try:
num = int(
input("Please, think of a number between 1 and 1000. I am about to try to guess it in 10 tries: "))
if num < 1 or num > 1000:
print("Must be in range [1, 100]")
else:
computer_guess... | true |
4deedfe0dea559088f4d2652dfe71479fce81762 | saman-rahbar/in_depth_programming_definitions | /errorhandling.py | 965 | 4.15625 | 4 | # error handling is really important in coding.
# we have syntax error and exceptions
# syntax error happens due to the typos, etc. and usually programming languages can help alot with those
# exceptions, however, is harder to figure and more fatal. So in order to have a robust code you should
# handle the errors and ... | true |
0a8a9a0a4c6ca24fde6c09886c52d1d5c7817a24 | Trietptm-on-Coding-Algorithms/Learn_Python_the_Hard_Way | /ex40b.py | 974 | 4.53125 | 5 | cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."
# ok pay attention!
cities ['_find'] = find_city
while True:
print "State? (ENTER to qui... | true |
5892f0c1c6cb36853a85e541cb6b3259346546e9 | Trietptm-on-Coding-Algorithms/Learn_Python_the_Hard_Way | /ex06.py | 898 | 4.1875 | 4 | # Feed data directly into the formatting, without variable.
x = "There are %d types of people." % 10
binary = "binary"
do_not = "don't"
#Referenced and formatted variables, within a variable.
y = "Those who know %s and those who %s." % (binary, do_not)
print x
print y
#r puts quotes around string
print "I said: %r."... | true |
71a2fe42585b7a6a2fece70674628c1b529f3371 | pltuan/Python_examples | /list.py | 545 | 4.125 | 4 | db = [1,3,3.4,5.678,34,78.0009]
print("The List in Python")
print(db[0])
db[0] = db[0] + db[1]
print(db[0])
print("Add in the list")
db.append(111)
print(db)
print("Remove in the list")
db.remove(3)
print(db)
print("Sort in the list")
db.sort()
print(db)
db.reverse()
print(db)
print("Len in the list")
print(len(db))
pr... | true |
74bda556d528a9346da3bdd6ca7ac4e6bcac6654 | adaoraa/PythonAssignment1 | /Reverse_Word_Order.py | 444 | 4.4375 | 4 | # Write a program (using functions!) that asks the user for a long string containing multiple words.
# Print back to the user the same string, except with the words in backwards order.
user_strings = input('input a string of words: ') # prompts user to input string
user_set = user_strings.split() # converts stri... | true |
7b35393252d51e721ffddde3007105546240e5df | adaoraa/PythonAssignment1 | /List_Overlap.py | 1,360 | 4.3125 | 4 | import random
# Take two lists, say for example these two:...
# and write a program that returns a list that
# contains only the elements that are common between
# the lists (without duplicates). Make sure your program
# works on two lists of different sizes.
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, ... | true |
7036212232a843fe184358c1b41e5e9cb096d31d | andrew5205/MIT6-006 | /ch2/binary_search_tree.py | 1,377 | 4.21875 | 4 |
class Node:
# define node init
def __init__(self, data):
self.left = None
self.right = None
self.data = data
# insert into tree
def insert(self, data):
# if provide data exist
if self.data:
# 1 check to left child
# compa... | true |
e9aa4621abbe5b8b60fa7bc02b3a54ba2f42531a | sharmar0790/python-samples | /misc/findUpperLowerCaseLetter.py | 241 | 4.25 | 4 | #find the number of upper and lower case characters
str = "Hello World!!"
l = 0
u=0
for i in str:
if i.islower():
l+=1
elif i.isupper():
u+=1
else:
print("ignore")
print("Lower = %d, upper = %d" %(l,u)) | true |
ece16e9a25e880eaa3381b787b12cecf86625886 | x223/cs11-student-work-Aileen-Lopez | /March21DoNow.py | 462 | 4.46875 | 4 | import random
random.randint(0, 8)
random.randint(0, 8)
print(random.randint(0, 3))
print(random.randint(0, 3))
print(random.randint(0, 3))
# What Randint does is it accepts two numbers, a lowest and a highest number.
# The values of 0 and 3 gives us the number 0, 3, and 0.
# I Changed the numbers to (0,8) and the res... | true |
016c7e2da4516be168d3f51b34888d12e0be1c5d | adrian-calugaru/fullonpython | /sets.py | 977 | 4.4375 | 4 | """
Details:
Whats your favorite song?
Think of all the attributes that you could use to describe that song. That is: all of it's details or "meta-data". These are attributes like "Artist", "Year Released", "Genre", "Duration", etc. Think of as many different characteristics as you can.
In your text editor, create ... | true |
4ce5c10eaf4a27ff54a1b12c87110659daf3f04a | aubreystevens/image_processing_pipeline | /text_files/Test.py | 1,033 | 4.15625 | 4 | #B.1
def complement(sequence):
"""This function returns the complement of a DNA sequence. The argument,
'sequence' represents a DNA sequence."""
for base in 'sequence':
if 'A' in 'sequence':
return 'T'
elif 'G' in 'sequence':
... | true |
33d73944bf28351346ac72cbee3f910bcf922911 | maneeshapaladugu/Learning-Python | /Practice/Armstrong_Number.py | 763 | 4.46875 | 4 | #Python program to check if a number is Armstrong or not
#If the given number is 153, and 1^3 + 5 ^ 3 + 3 ^ 3 == 153, then 153 is an Armstrong number
def countDigits(num):
result = 0
while num > 0:
result += 1
num //= 10
print(result)
return result
def isArmstrong(... | true |
8071c3f0f77261cb68e0c36d09a814ba95fdb474 | MyoMinHtwe/Programming_2_practicals | /Practical 5/Extension_1.py | 248 | 4.3125 | 4 | name_to_dob = {}
for i in range(2):
key = input("Enter name: ")
value = input("Enter date of birth (dd/mm/yyyy): ")
name_to_dob[key] = value
for key, value in name_to_dob.items():
print("{} date of birth is {:10}".format(key,value)) | true |
a288abbab98175fb70e1c1a34c5c6f4eeeed438a | HarshKapadia2/python_sandbox | /python_sandbox_finished_(by_harsh_kapadia)/tuples_sets.py | 1,269 | 4.25 | 4 | # A Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
# create tuple
fruit_1 = ('mango', 'watermelon', 'strawberry', 'orange', 'dragon fruit')
# using constructor
fruit_2 = tuple(('mango', 'watermelon', 'strawberry', 'orange', 'dragon fruit'))
print(fruit_1, fruit_2)
fruit_3 = ('app... | true |
828e176b7aae604d3f4d38a206d4f1cfa5d49197 | HarshKapadia2/python_sandbox | /python_sandbox_finished_(by_harsh_kapadia)/loops.py | 854 | 4.1875 | 4 | # A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
people = ['Selena', 'Lucas', 'Felix', 'Brad']
# for person in people:
# print(person)
# break
# for person in people:
# if person == 'Felix':
# break
# print(person)
# cont... | true |
622589e96be15dc7e742ce2a1dc83ea91507b5dc | DeepanshuSarawagi/python | /ModulesAndFunctions/dateAndTime/datecalc.py | 354 | 4.25 | 4 | import time
print(time.gmtime(0)) # This will print the epoch time of this system which is usually January 1, 1970
print(time.localtime()) # This will print the local time
print(time.time()) # This will print the time in seconds since epoch time
time_here = time.localtime()
print(time_here)
for i in time_here:
... | true |
91bfc92d73cf257344dc1260e433bdbd9d6cb4d5 | DeepanshuSarawagi/python | /freeCodeCamp/ConditionalExecution/conditionalExecution.py | 309 | 4.1875 | 4 | # This is a python exercise on freeCodeCamp's python certification curriculum
x = 5
if x < 5:
print("X is less than 5")
for i in range(5):
print(i)
if i <= 2:
print("i is less than or equal to 2")
if i > 2:
print("i is now ", i)
print("Done with ", i)
print("All done!")
| true |
7384fbb693486ec0f00158292487d6a2086fc2ac | DeepanshuSarawagi/python | /Data Types/numericOperators.py | 485 | 4.34375 | 4 | # In this lesson we are going to learn about the numeric operators in the Python.
a = 12
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
# We will learn about the operator precedence in the following example.
print(a + b / 3 - 4 * 12) # This should evaluate to -35.0 as per the ... | true |
6d34356e7e6d161aa6e838b8ca588e3dce3b01f4 | DeepanshuSarawagi/python | /100DaysOfPython/Day2/DataTypes/typeConversion.py | 944 | 4.25 | 4 | # In this lesson we are going to convert the int data type to string data type
num_char = len(input("What is your name?\n"))
print("Your name has " + str(num_char) + " characters") # Type conversion happens here. Where we convert
# the type integer to string
# ... | true |
a9aaf4e426597e6a54aff443fdadefad6e4fb9d6 | DeepanshuSarawagi/python | /100DaysOfPython/Day1/main.py | 647 | 4.375 | 4 | print("Print something")
print("Hello World!")
print("Day 1 - Python Print Function")
print("print('what to print')")
print("Hello World!\nHello World again!\nHellooo World!!")
print()
# Day 1. Exercise 2 Uncomment below and debug the errors
# print(Day 1 - String Manipulation")
# print("String Concatenation is done... | true |
34c3bcf8c09826d88ff52370f8c9ae9735d2f966 | DeepanshuSarawagi/python | /100DaysOfPython/Day19/Turtle-GUI-2/main.py | 796 | 4.21875 | 4 | from turtle import Turtle, Screen
tim = Turtle()
screen = Screen()
def move_forward():
tim.forward(10)
screen.listen() # In order for our turtle to listen to the screen events, we need to call this screen method
screen.onkey(fun=move_forward, key="Up") # The Screen.onkey() method accepts two arguments, 1. F... | true |
e9e42890ea221e41dd51181364f24590d1b0ce6e | DeepanshuSarawagi/python | /whileLoop/whileLoop.py | 423 | 4.125 | 4 | # In this lesson we are going to learn about while loops in Python.
# Simple while loop.
i = 0
while i < 10:
print(f"i is now {i}")
i += 1
available_exit =["east", "west", "south"]
chosen_exit = ""
while chosen_exit not in available_exit:
chosen_exit = input("Please enter a direction: ")
if chosen_exi... | true |
ad0cf84f3a01da48c32aa7efae44cf3b964d44d1 | DeepanshuSarawagi/python | /100DaysOfPython/Day2/DataTypes/BMICalculator.py | 209 | 4.28125 | 4 | height = float(input("Enter your height in meters: "))
weight = float(input("Enter your weight in kilograms: "))
print("Your BMI is {}".format(round(weight / (height * height), 2)))
print(8 // 3)
print(8 / 3)
| true |
31a342ddff6fade8595b45f6127868b7525feca1 | DeepanshuSarawagi/python | /DSA/Arrays/TwoDimensionalArrays/main.py | 2,074 | 4.40625 | 4 | import numpy
# Creating two dimensional arrays
# We will be creating it using a simple for loop
two_d_array = []
for i in range(1, 11):
two_d_array.append([i * j for j in range(2, 6)])
print(two_d_array)
twoDArray = numpy.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]])
pr... | true |
c32944fc92021af6a9aab1d68844287921f5f7dd | DeepanshuSarawagi/python | /100DaysOfPython/Day21/InheritanceBasics/Animal.py | 563 | 4.375 | 4 | class Animal:
def __init__(self):
self.num_eyes = 2
def breathe(self):
print("Inhale, Exhale")
# Now we are going to create a class Fish which will inherit properties from the Animal class and also has it's own
# properties
class Fish(Animal):
def __init__(self):
super().__init... | true |
1117ab86b491eca4f879897af51ccc69112e854b | shaonsust/Algorithms | /sort/bubble_sort.py | 1,074 | 4.40625 | 4 | """
Python 3.8.2
Pure Python Implementation of Bubble sort algorithm
Complexity is O(n^2)
This algorithm will work on both float and integer type list.
Run this file for manual testing by following command:
python bubble_sort.py
Tutorial link: https://www.geeksforgeeks.org/bubble-sort/
"""
def bubble_sort(arr):
... | true |
81a8bce1fd4ad1426104d8f4b662f0c0ca3c52c5 | destinysam/Python | /more inputs in one line.py | 435 | 4.15625 | 4 | # CODED BY SAM@SAMEER
# EMAIL: SAMS44802@GMAIL.COM
# DATE: 12/09/2019
# PROGRAM: TAKING MORE THAN ONE INPUT FROM THE USER
name, age, address = "sameer", "23", "tarigam" # ASSIGNING VALUES BY ORDER
print("YOUR NAME,AGE AND ADDRESS IS " + name + " " + age + " " + address)
x = y = z = 2
print(x+y+z)
name, age, address = ... | true |
0eaf2afa9cc1c3f161504fc2c9254b92fb3f4262 | venkatadri123/Python_Programs | /100_Basic_Programs/program_43.py | 280 | 4.53125 | 5 | # 43. Write a program which accepts a string as input to print "Yes"
# if the string is "yes" or "YES" or "Yes", otherwise print "No".
def strlogical():
s=input()
if s =="Yes" or s=="yes" or s=="YES":
return "Yes"
else:
return "No"
print(strlogical()) | true |
01158919c0c3b66a38f8094fe99d22d9d3f53bed | venkatadri123/Python_Programs | /100_Basic_Programs/program_35.py | 322 | 4.15625 | 4 | # 35. Define a function which can generate a dictionary where the keys are numbers between 1 and 20
# (both included) and the values are square of keys. The function should just print the keys only.
def sqrkeys():
d=dict()
for i in range(1,21):
d[i]=i**2
for k in d:
print(k)
sqrkeys... | true |
b1adffe626fa1a1585012689ec2b1c01925c181c | venkatadri123/Python_Programs | /core_python_programs/prog78.py | 334 | 4.15625 | 4 | # Write a python program to accept values from keyboard and display its transpose.
from numpy import*
r,c=[int(i) for i in input('enter rows,columns:').split()]
arr=zeros((r,c),dtype=int)
print('enter the matrix:')
for i in range(r):
arr[i]=[int(x) for x in input().split()]
m=matrix(arr)
print('transpose:')
print(m... | true |
3625b577e1d82afc31436473149cc7ff1e3ce96c | venkatadri123/Python_Programs | /100_Basic_Programs/program_39.py | 318 | 4.1875 | 4 | # 39. Define a function which can generate a list where the values are square of numbers
# between 1 and 20 (both included). Then the function needs to print all values
# except the first 5 elements in the list.
def sqrlis():
l=[]
for i in range(1,20):
l.append(i**2)
return l[5:]
print(sqrlis()) | true |
fa7b092a720e7ce46b2007341f4e70de60f8e6ca | venkatadri123/Python_Programs | /100_Basic_Programs/program_69.py | 375 | 4.15625 | 4 | # 69. Please write assert statements to verify that every number in the list [2,4,6,8] is even.
l=[2,4,6,8]
for i in l:
assert i%2==0
# Assertions are simply boolean expressions that checks if the conditions return true or not.
# If it is true, the program does nothing and move to the next line of code.
# However... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.