blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
240bc6c0de44d0094fa5df6b7aa8cad32a0e9f51 | SaberWSQ/MOUDLES | /file_read_write.py | 1,340 | 4.4375 | 4 | """
Program: file_read_write.py
Author: Shiqi Wang
Last date modified: 10/05/2020
The purpose of this program is to read and write a file.
"""
def write_to_file(content_tuple):
"""Add content tuple at the end of the file
:param tuple content_tuple: content
:return: None
"""
with open(... | true |
e64396282c15a2c0d1d097a7a8df136fd581725a | SaberWSQ/MOUDLES | /string_functions.py | 404 | 4.5625 | 5 | """
Program: string_function.py
Author: Shiqi Wang
Last date modified: 10/01/2020
The purpose of this program is to write a function to print parameter multiple times
"""
def multiply_string(message, n):
"""Return a string contains n times message
:param str message: the string to be printed... | true |
5bcac18761a0bef38bdb2f74ed31502cf5b07177 | greenfox-zerda-lasers/bednayb | /week-04/day-03/exercise-04.py | 465 | 4.21875 | 4 | # create a 300x300 canvas.
# create a line drawing function that takes 2 parameters:
# the x and y coordinates of the line's starting point
# and draws a line from that point to the center of the canvas.
# draw 3 lines with that function.
from tkinter import *
root = Tk()
canvas = Canvas(root, width='300', height='3... | true |
48ec4a90d6985c40cb2c72415ac2c3d3d9a7f726 | sharanjitsandhu/Data-Structures | /binary_search_tree/binary_search_tree.py | 2,483 | 4.3125 | 4 | class BinarySearchTreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
# 'insert' adds the input value to the binary search tree,
# adhering to the rules of the ordering of elements in a binary search tree.
def insert(self, value):
if value ... | true |
8535e4f4c9004f1ecd0fbf3d5c10e87f241efdd6 | vaibhavmule/learning-python | /learn-python-hard-way/ex4.py | 1,313 | 4.1875 | 4 | # This is Exercise 4 : Variables and Names
# cars given value of 100
cars = 100
# assigning 4.0 value to space_in_a_car variable
space_in_a_car = 4
# There are 30 drivers
drivers = 30
# There are 90 Passengers
passengers = 90
# Calculate how many cars are not driven by subtracting "drivers" from "cars".
cars_not_d... | true |
2b35674758116a963b8d530bafc8a659feca3442 | vaibhavmule/learning-python | /learn-python-hard-way/ex12.py | 437 | 4.21875 | 4 | # This is Exercise 12: Promptig People
# Asking person's age and storing in a variable
age = raw_input("How old are you?")
# Asking person's height and storing in a variable
height = raw_input("How tall are you?")
# Asking for weight and storing it in a variable
weight = raw_input("How much do you weigh?")
# Printi... | true |
f15d0133e43db5a429ed912195d1ca779f587a90 | vaibhavmule/learning-python | /learn-python-hard-way/ex19.py | 1,257 | 4.1875 | 4 | # this is exercise 19: Functions and Variables
# a function that ask for cheese and crackers
def cheese_and_crackers(cheese_count, boxes_of_crackers):
# print how many cheese you have
print "You have %d cheeses!" % cheese_count
# print how many boxes of crackers
print "You have %d boxes of crackers" % boxes_of_cra... | true |
3004893dbf22ba4c3d831998da74fbccce73bc60 | skelsec/jackdaw | /jackdaw/utils/table.py | 740 | 4.125 | 4 |
def print_table(lines, separate_head=True):
"""Prints a formatted table given a 2 dimensional array"""
#Count the column width
widths = []
for line in lines:
for i,size in enumerate([len(x) for x in line]):
while i >= len(widths):
widths.append(0)
if size > widths[i]:
widths[i] = size
... | true |
5488fa1a5fc2e7ced40b2945a4d6d5fda5242c45 | teshkh/Phython-program-Hello-World | /hello world.py | 839 | 4.25 | 4 | #Hitesh Khurana
#This program prints "hello world" on a single line.
#program version 3.0
#Phython version 3.5.1
#3/16/2016
print("hello world");
#See below for version 2.0
hello = 'this is a variable'
print("hello world ", hello)
#See below for version 3.0
#Printing a string backwards
#Len populates... | true |
8b2c0391a89d3bc7ad2575e85bd2b2766331c057 | liasaysyay/biosystems-analytics-2020 | /exercises/03_crowsnest/crowsnest_02.py | 1,319 | 4.125 | 4 | #!/usr/bin/env python3
"""
Author : lia
Date : 2020-01-27
Purpose: Accepts a single positional argument
Prints a statement and chooses 'a' or 'an' according to the argument
Version: 2 - uses if expression instead of if statement
uses str.format instead of concatenation
"""
import argparse
impor... | true |
1f4576461ab18599029b331a85f2118a140ee504 | johannesgrobb/Sites | /codeSnippets/python/subjects/dataStructures.py | 2,894 | 4.1875 | 4 | # -*- coding: utf-8 -*-
#Methods of list objects
fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
#Add an item to the end of the list.
fruits.append('grape')
#Extend the list by appending all the items from the iterable.
fruits.extend(iterable)
#Insert an item at a given position. The firs... | true |
341cd0976baacba7861ece23d93edb978470a343 | theakhiljha/Ultimate-Logic | /Encryption/Reverse Cipher/reverse.py | 519 | 4.15625 | 4 | # an implementation of the ReverseCipher
# Author: @ladokp
class ReverseCipher(object):
def encode(self, message: str):
return message[::-1]
def decode(self, message: str):
return self.encode(message)
# Little test program for ReverseCipher class
message = input("Enter message to encrypt: "... | true |
5ce022cd0a346451c9af3afd4b0eff2487bf311b | theakhiljha/Ultimate-Logic | /Sorting/sorting in Python/selectionsort.py | 806 | 4.25 | 4 | # -*- coding: utf-8 -*-
"""
@author: Nellman1508
"""
import numpy as np
def selection_sort(x):
"""Implementation of selection sort.
Takes integer list as input,
returns sorted list.
"""
print("Starting selection sort on list:\n", x)
iteration = 0
for i in range(0, (len(x)-1)):
it... | true |
72fd8d708c68b0b409b4532d78d0b793bbd62863 | jenayarenea/python-mini-projects | /CTI110-master/Module 6/M6T2 Feet to Inches/M6T2_CurryJenaya.py | 563 | 4.375 | 4 | #CTI 110
#M6T2 Feet to Inches
#Jenaya Curry
#16 November 2017
#This program converts feet to inches.
#Defines a constant for the number of inches per foot.
INFOOT = 12
# main function
def main():
# Get a number of feet from the user.
feet = float(input('Enter the number of feet: '))
# Conve... | true |
eec7377f32756570a3450ada34c891504bbfd4e3 | lsj2319/learning | /testing_loops.py | 996 | 4.3125 | 4 | #testing_loops.py
"""n = 1
# while the value of n is less than 5, print n. add 1 to n each time
# use while loops for infinate loops or for a set number of executions/loops
while n<5:
print(n)
n = n + 1"""
"""
num = float(input("Enter a postive number:"))
while num <= 0:
print("That's not a positive numbe... | true |
76d37f3f7811538bf61586eb1e17b17ef9457498 | SouravNautiyal1/assignment3 | /assignment 3.py | 2,014 | 4.125 | 4 | #!/usr/bin/env python
# coding: utf-8
# # Q1.Write a Python Program to implement your own myreduce() function which works exactlylike Python's built-in function reduce()
#
# In[2]:
def myreduce(func,values):
result=values[0]
for i in values[1:]:
result=func(result,i)
return result
# In[3]... | true |
dae0f11e99d5a907abb56d81774791fd26cff840 | ElCuffigno/coincoin | /assignment_1.py | 680 | 4.21875 | 4 | # Assignment 1 involving variables and functions
name = input('What is your name? ')
age = input('What is your age? ')
def print_name_age():
""" Prints the input variables """
print('My name is ' + name + ' and I am ' + age + ' years old.' )
def print_any(person_name, person_age):
""" Accepts 2 variable... | true |
ff215b713a6c101571d3916ec29edaf9f89df57a | cjriggs27/lpthw | /ex3.py | 670 | 4.1875 | 4 | #this line prints the statement
print("I will now count my chickens:")
#this line prints the statement followed buy calculating the number of "Hens"
print("Hens",25.0+30.0/6.0)
print("Roosters", 100.0-25.0*3.0%4.0)
#prints statement
print("Now I will go count the eggs:")
#egg math print
print(3.0+2.0+1.0-5.0+4.0%2.0-1.... | true |
b99aee38cb6ca2beaf38a9e676c6d69f205485dd | oneuptim/python-fun | /hello.py | 1,130 | 4.375 | 4 | # Varibale to set our greeting message
greeting = "What's up,"
# Screen prompt to ask user for their name
print 'What is your name?'
# Input for user to enter their name
name = raw_input()
# Screen instruction to ask for user's age
print 'How old are you?'
# Prompt input to ask user for their age
age = input()
# R... | true |
40807fe61d44195721d2f9c90c5477c30106f8b6 | Tanmeetsinghreel/Faulty-Calculator-program-through-python | /faulty_calculater.py | 1,305 | 4.25 | 4 |
#Design a calculator which will corectly solve all the problems except the following ones:
# 45 * 3 = 555, 56+9 = 77, 56/6 = 4
#your programe should take operator and the two numbers as input from the user and then return the result.
print(" press 1 for addition\n"
" press 2 for division\n press 3 for m... | true |
7e23f5598ccfe9aff74d43eb662f860b0404b7ec | jasmina-dzurlic/hack-program | /python-package/python-package.py | 745 | 4.21875 | 4 | #!/usr/bin/env python
"""
A package that determines the current day of the week.
"""
from datetime import date
import calendar
# Set the first day of the week as Sunday.
calendar.firstday(calendar.SUNDAY)
def day_of_the_week(arg):
"""
Returns the current day of the week.
"""
if arg == "day":
... | true |
2a5ec40d748962ff784cb2803d8af3b345c1a640 | AceMouty/Python | /3.Booleans_and_Conditionals/exercises/rps.py | 1,709 | 4.1875 | 4 |
from random import choice
# some global vars
rock = "rock"
paper = "paper"
scissors = "scissors"
def main():
print("Which do you choose...?")
print(f"{rock} {paper} or {scissors}")
user_choice = input()
options = [rock, paper, scissors]
while (user_choice not in options):
print("Please... | true |
d7f550efc08f9a7f4d3beb45e79a6ca31ab8586f | ElAntagonista/progress-devops | /Lectures/Python-Intro/python_basics_1.py | 880 | 4.3125 | 4 | #! /usr/local/bin/python3
""" Python 1 on 1
This should serve you as a reference point for python basics
For starters this is how you create a multiline comment
"""
# This is a single line comment
# Variables
"""Python is a dynamicly typed language.
In simple terms this means that you don't have to decl... | true |
dd1de4b30ee16ba048636b784128f109317bdb2a | affanfarid/DailyProblems | /largestNumber.py | 2,132 | 4.375 | 4 | '''
Given a list of non negative integers, arrange them such that they form the largest number.
Example 1:
Input: [10,2]
Output: "210"
Example 2:
Input: [3,30,34,5,9]
Output: "9534330"
Note: The result may be very large, so you need to return a string instead of an integer.
'''
'''
[98,8]
988
330
strat:
-sort... | true |
56c1d99998d6d86f5ace921db22a1312c2bb7562 | affanfarid/DailyProblems | /mergeIntervals.py | 1,328 | 4.25 | 4 | '''
Given a collection of intervals, merge all overlapping intervals.
Example 1:
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2:
Input: [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,4] and [4,5] are... | true |
5b6ec980aead99d9f5e009e09714d40096261042 | affanfarid/DailyProblems | /Problem Sets/problemSet1/embeddedPassword.py | 1,895 | 4.28125 | 4 | '''
The letters of a secret password have been embedded, in order, in an alpha-only string at index numbers N, 2N, 3N ... N42 where the value of N starts at 4 and
increases until the string can no longer support N*2. Index numbers start at 1. The criteria for the password are:
-The first and last characters of the pas... | true |
4006d4554ae860489de98c11f811dabf7cc621c3 | Roc-J/jianzhioffer | /problem045.py | 657 | 4.21875 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: qjk
class Solution:
def IsContinuous(self, numbers):
# write code here
if not numbers:
return False
numbers.sort()
kings = 0
diff = 0
for i in range(len(numbers)-1):
if numbers[i] == 0:
... | true |
8862517e004faaaf45a01e16b1fd3426c096fa7a | stupns/SoftServe | /adam_and_eva.py | 603 | 4.21875 | 4 | # You have to do God's job. The creation method must return an array of length 2 containing objects (representing
# Adam and Eve). The first object in the array should be an instance of the class Man. The second should be an
# instance of the class Woman. Both objects have to be subclasses of Human. Your job is to impl... | true |
6f8fc8465924c15da0eb30f810f3e6f18a535ac6 | AntonioPelayo/leetcode | /top-interveiw-questions/strings/reverse-string.py | 863 | 4.15625 | 4 | ''' Antonio Pelayo Mar 1, 2020
Problem: 334 Reverse String
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters ... | true |
841c1ae10d3ad14c1dda38735ac993f7a6bbd601 | jawang35/project-euler | /python/lib/problem57.py | 1,811 | 4.1875 | 4 | # coding=utf-8
'''
Problem 57 - Square Root Convergents
It is possible to show that the square root of two can be expressed as an
infinite continued fraction.
√ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213...
By expanding this for the first four iterations, we get:
1 + 1/2 = 3/2 = 1.5
1 + 1/(2 + 1/2) = 7/5 = 1.4... | true |
f71fefe31c72078572d251470fb729b93c0181b1 | sgekar/git_training | /code2_3d_planes.py | 2,113 | 4.1875 | 4 | #!python3
"""
Find Torsional Angle from HackerRank
https://www.hackerrank.com/challenges/class-2-find-the-torsional-angle/problem
You are given four points and in a 3-dimensional Cartesian coordinate system. You are required to print the angle between the plane made by the points and in degrees(not radians)
... | true |
7dae15b26e1736debcbd530fa8a809f313b46aeb | HamnYce/Codewars | /SimpleEncryption#1-AlternatingSplit_S/SimpleEncryption#1-AlternatingSplit.py | 1,588 | 4.34375 | 4 | #Take every 2nd char from the string, then the other chars, that are not every 2nd char, and concat them as new String.
def encrypt(text, n):
if text == None:
encrypted_text = None
else:
encrypted_text = ""
if n >= 1:
#the algorithm takes the even numbered indexes and ... | true |
c079f65925cdf6f7cce6fece7e7ccf4d3582723b | bridaisies/elements-of-computers-and-programming | /a3_day.py | 2,460 | 4.125 | 4 | # File: Day.py
# Description: Prints the day when a year, month and day is inputed.
# Student Name: Brionna Huynh
# Student UT EID: bph637
# Course Name: CS 303E
# Unique Number: 51345
# Date Created: 9/24/17
# Date Last Modified: 9/25/17
def main():
year=int(input("Enter year: ")... | true |
1af059f84c0d4d904a4eb624be1fe9cbd9f92bb2 | BUEC500C1/quality-afatyga | /hw1.py | 876 | 4.5625 | 5 | #EC500 Building Software
#HW1 Alex Fatyga
#arabic number to roman numeral function
def conversion(arabic):
if not isinstance(arabic,int): #returns error string on errors
return "ERROR - not an int"
if arabic < 1 or arabic > 4000:
return "ERROR - not within range"
nums = { 1 : "I", 4 : "IV", 5 : "V", 9 : "IX",... | true |
2a407165af55a03e12d439a44877fbbab74243bc | VamsiKrishnaRachamadugu/python_solutions | /problemset3/8.abecedarian.py | 522 | 4.25 | 4 | """8.Write a function called is_abecedarian that returns True if the letters in a word appear
in alphabetical order (double letters are ok). How many abecedarian words are there? (i.e) "Abhor"
or "Aux" or "Aadil" should return "True" Banana should return "False"
"""
def is_abecedarian(word):
for i in range(len(wo... | true |
4e5f3f7d107b1928cac5b1a316dee047f1541231 | VamsiKrishnaRachamadugu/python_solutions | /problemset1/6.SumOfDecimalNumbers.py | 358 | 4.1875 | 4 | """6.Let s be a string that contains a sequence of decimal numbers separated by commas,
e.g., s = '1.23,2.4,3.123'. Write a program that prints the sum of the numbers in s."""
deci_numbers = input('Enter decimal values by using , :')
deci_numbers_list = deci_numbers.split(',')
total = 0
for i in deci_numbers_list:
... | true |
e5c1f76d6e2107b5170e2c06f2683511f633fa67 | VamsiKrishnaRachamadugu/python_solutions | /problemset3/2.RotateWord.py | 1,158 | 4.4375 | 4 | """2.Write a function called rotate_word() that takes a string and an integer as parameters,
and that returns a new string that contains the letters from the original string "rotated" by
the given amount. For example, "cheer" rotated by 7 is "jolly" and "melon" rotated by -10 is "cubed".
You might want to use the built... | true |
1900a553c7a31a94c4be1ded0626117bb47c5791 | VamsiKrishnaRachamadugu/python_solutions | /problemset2/2.Power.py | 452 | 4.34375 | 4 | """2.A number, a, is a power of b if it is divisible by b and a/b is a power of b.
Write a function called is_power that takes parameters a and b and returns True if a is a power of b.
Note: you will have to think about the base case."""
def is_power(num1, num2):
quot = num1 / num2
if quot != num2:
if... | true |
b139b40571b54f3ef8468ef96ce55ee871231a07 | broadlxx/171-172-271python- | /da3/animating_snow2.py | 2,288 | 4.34375 | 4 | """
Animating multiple objects using a list.
based on Sample Python/Pygame Programs
Simpson College Computer Science
"""
# Import libraries 'pygame' and 'random'
import pygame
import random
def recolour_snowflake(s):
s[1]=random.choice(color)
return s
def keep_snowflake(d):
delete_number=15
choos... | true |
9a0f687bb3b4ca3802834c68f6689fd32548f43b | vengrinovich/python | /random_pw_generator.py | 1,388 | 4.46875 | 4 | """Write a password generator in Python. Be creative with how you generate passwords -
strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols.
The passwords should be random, generating a new password every time the user asks
for a new password. Include your run-time code in a main... | true |
cb5b912e9a8e950e74dd35f024dc3bc67bccf4cb | vengrinovich/python | /bank_account.py | 1,120 | 4.1875 | 4 | # creates class for the bank account function that shows the user their balance,
# and has availibility to deposit/withdraw/show balance
class BankAccount(object):
balance = 0
def __init__(self, name):
self.name = name
def __repr__(self): #The __repr__() method defines what represents the object when a user ... | true |
d6044c65ad5daa6075e14ae506a5d0844b7d56a4 | voidGlitch/Python-Development | /Day3/leapyear.py | 280 | 4.21875 | 4 | year = int(input("please enter your year to check"))
leap = year / 4
print(leap)
if(year % 4 == 0):
if(year % 100 == 0):
if(year % 400 == 0):
print("it is leap year")
else:
print("it is a leap year here shusd")
else:
print("it is not a leap year") | true |
54d8eec1e75a59e37e4a845bf41a4308bf9876d2 | voidGlitch/Python-Development | /Day3/project.py | 841 | 4.1875 | 4 | user = input("you're at the cross road . Where do you wnt to go ?Type 'left' or'right' : \n")
if(user == "left"):
user2 = input("you came to a lake. There is an island in hte middle of the lake . Type 'wait' to wait for the boat.Type 'swim' to swim across : \n ")
if(user2 == "wait"):
user3 = input("you ... | true |
9d7f5f39eb4e6ca253b58759e8d1ed5741c0ec0e | mdoradocode/REST-APIs-with-Flask-and-Python | /Python Refresher/classComposition.py | 1,010 | 4.4375 | 4 | #!class BookShelf:
#!def __init__(self, quantity):
#!self.quantity = quantity
#!def __str__(self):
#!return f"BookShelf with {self.quantity} books."
#!shelf = BookShelf(300)
##Requires the quanity to be present (inherited from the BookShelf) the Book is a Bookshelf and more. which makes no s... | true |
f9719ff0a87a3667669c3b843e43c18728707c9d | mdoradocode/REST-APIs-with-Flask-and-Python | /Python Refresher/StringFormatting.py | 655 | 4.40625 | 4 | name = 'Bob'
greeting = f'Hello, {name}'
##That f is an f string which allows for variables to be embbeded inside of strings in python
print(greeting)
name = 'Frank'
print(greeting)
print(f'Hello, {name}')
greeting = "Hello, {}"
with_name = greeting.format(name)
##Calls the format function (which is a constructor I... | true |
32e47701ca106b72d607b8386e01ce75c4998c81 | mdoradocode/REST-APIs-with-Flask-and-Python | /Python Refresher/Dictionaries.py | 846 | 4.5 | 4 | ##used in a key value pair
friend_ages = {"Rolf": 24, "Adam": 30, "Anne": 27}
##Dictionary with 3 key value pairs
friend_ages["Bob"] = 20
##This accesses the "Bob" Key and adds the value. if the key already exist, then you can just use the existing key and modify its value
friends = [
{"name": "Rolf Smith", "age":... | true |
9720640a5fa2126100107a2d02e9ddaa195fea08 | znalbert/rice_university_coursera_iipp | /01_rock_paper_scissors_lizard_spock/rpsls.py | 2,712 | 4.3125 | 4 | # The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
#
# 0 - rock
# 1 - Spock
# 2 - paper
# 3 - lizard
# 4 - scissors
import random
def valid_choice(name):
"""str -> bool
Checks to see if the player choice is valid.
"""
retur... | true |
2916648d70d6661587c83fd567c1337d59549003 | kylerlmy/pythonpractice | /src/examine/first/topic5.py | 1,018 | 4.1875 | 4 | # 请根据自己的理解编写计数算法,接收如下文字,输出其中每个字母出现的次数,以字典形式输出;(忽略大小写)
# 文字内容:
# Understanding object-oriented programming will help you see the world as a programmer does.
# It will help you really know your code, not just what is happening line by line, but also the bigger concepts behind it.
# Knowing the logic behind classes will t... | true |
6949aca3ab6b77d69d206fc18c8c3782aba8b00f | jsneed/TheModernPython3Bootcamp | /Section-036/coding-exercise-123.py | 1,569 | 4.21875 | 4 | '''
Write a function called sum_up_diagonals which accepts an NxN list of lists and sums the two main diagonals in the array: the one from
the upper left to the lower right, and the one from the upper right to the lower left.
EXAMPLES:
list1 = [
[ 1, 2 ],
[ 3, 4 ]
]
sum_up_diagonals(list1) # 10
list2 = [
... | true |
b3e98241767506a8487cd19e2d8ea3316d3bb16f | jsneed/TheModernPython3Bootcamp | /Section-030/exercise-313.py | 975 | 4.1875 | 4 | '''
Write a function called find_and_replace, which takes in a file name, a word to search for, and a replacement word. Replaces all instances
of the word in the file with the replacement word.
(Note: we've provided you with the first chapter of Alice's Adventures in Wonderland to give you some sample text to work wi... | true |
562d90197dfe5ee5eba9ec47fa36dca4b299a067 | jsneed/TheModernPython3Bootcamp | /Section-036/coding-exercise-135.py | 794 | 4.1875 | 4 | '''
Generator Exercise
Write a function called next_prime, which returns a generator that will yield an unlimited number of primes, starting from the first
prime (2).
Recall that a prime number is any whole number that has exactly two divisors: one and the number itself. The first few
primes are 2, 3, 5, 7, 11, ...... | true |
d1dc7c885283cb14d1fb79e30403f9730e04d15e | edsUlalan/python-cheatsheet | /statements.py | 1,151 | 4.1875 | 4 | # conditional tests
x = 12
x == 42 # equals => false
x != 42 # not equals => true
x > 24 # greater than => false
x >= 42 # greater or equal => false
x < 42 # less than => true
x <= 42 # less or equal => true
# conditional test with list
bikes = ['one', 'two', 'three']
'one' in bikes # True
'four' not in bikes # True
... | true |
f84a69796bc67fdf1ebe40c203a8a04733f57434 | OCulzac/importing-data-in-python-2 | /3-diving-deep-into-the-twitter-api/4_twitter_data_to_dataframe.py | 622 | 4.21875 | 4 | """ Twitter data to DataFrame
Now you have the Twitter data in a list of dictionaries, tweets_data, where each dictionary corresponds to a single tweet. Next, you're going to extract the text and language of each tweet. The text in a tweet, t1, is stored as the value t1['text']; similarly, the language is stored in t1[... | true |
ccbaa8726a48a09a9b3433df14721a762fe9756b | aciorra83/CCBC_Python | /python_practice/Lesson1_Introducing_Python.py/Variables.py | 311 | 4.3125 | 4 | # Exercise 5: Checking the Type of a Value
# int
print(type(7))
# str
print(type("7"))
# Type conversion one example is done with the str() method
print(type(str(7)))
print(type(int("3")))
# Assigning variables
number = 7
print(number)
# Multiple assignment
a, b, c = 1, 2, 3
print(a)
print(b)
print(c)
| true |
5acc3a8ef06978580ac9dc4608b6d90a948da13f | aciorra83/CCBC_Python | /python_practice/Lesson6_Dictionaries/Iterating_Through_Dictionaries.py | 536 | 4.40625 | 4 | dictionary1 = dict(
state = 'NY',
city = 'New York'
)
for item in dictionary1:
print(item)
##You can use the key() or value() method to return a list of values in the dictionary
for item in dictionary1.values():
print(item)
##you can also use both in the same for loop
for key, value in dictionary1.it... | true |
91cc03ca76357b26e5c26cfbfff599f50d717a58 | aciorra83/CCBC_Python | /python_practice/Lesson9_Error_Handling.py/Ex50_Try_Except_Else_Block.py | 880 | 4.125 | 4 | # the code in the else block is always executed IF NO ERROR OCCURRED
try:
with open('input.txt', 'r') as myinputfile:
for line in myinputfile:
prin(line)
except FileNotFoundError:
print('Whoops! File does not exist.')
except ValueError:
print('A value error occurred.')
except Except... | true |
846e06c8c26799b1cd3e7c77d0e46cac2522d02e | aciorra83/CCBC_Python | /python_practice/Lesson5_Lists_and_Tuples/Lesson5_labs.py | 1,607 | 4.46875 | 4 | #Using list methods
# Complete the Python code that will perform the following things using list methods:
wild = ["Tiger", "Zebra", "Panther", "Antelope"]
print (wild)
# Add the value cat to the list named wild using the built-in append() method.
wild.append("Cat")
print(wild)
# Create an empty list named creatu... | true |
22b70411e19fffdcb880235ad0f4af2d5b4229c6 | inaveen9/PythonBasicToAdvance | /python_type_fuction_example.py | 276 | 4.28125 | 4 | #program to undetstand python "type()" function.
'''
You can get the type of the variable with a type function.
'''
x=3
y='Tony'
#Dispay the type of the variables x and y
print(type(x)) # will print type of variable x
print(type(y)) # will print type of variable y
| true |
3a0286478d6bd69ad9a3ffd304cdc753fb33b894 | alonsovidales/interview_questions | /google/pos_neg_arr.py | 1,623 | 4.15625 | 4 | """
Given an array of positive and negative numbers, arrange them in an alternate fashion such that every positive number is followed by negative and vice-versa maintaining the order of appearance.
Number of positive and negative numbers need not be equal. If there are more positive numbers they appear at the end of t... | true |
c0278b5428d83bf27ca4702e83ff6d54ad02108c | ewhite79/Surv895 | /exercises/exercise2.py | 1,171 | 4.125 | 4 | # Python program to find the
# H.C.F of two input number
# define a function
def hcf( x, y ):
"""This function takes two
integers and returns the H.C.F"""
# choose the smaller number
if x > y:
smaller = y
else:
smaller = x
#-- END check to find slmaller number ... | true |
8134c04358c3541cd5fdeffdd29a39087a3c0ce5 | github-markdown-ui/github-markdown-ui | /githubmarkdownui/blocks/table.py | 2,980 | 4.21875 | 4 | from enum import Enum
from typing import List, Optional
class TableAlignmentError(Exception):
"""Raised when the alignment parameter is not the same length as the number of columns in the table."""
class TableDimensionError(Exception):
"""Raised when each row of the table does not have the same number of co... | true |
03c744b46d41d27dd50535000edf075d5335f074 | sivaram10/Algorithms | /02 Insertion Sort.py | 903 | 4.125 | 4 | # Insertion Sort
#Function to sort integers in ascending order
def Ainsertionsort(A):
print(A)
for i in range(1,len(A)):
key = A[i]
sortedindex = i-1
while sortedindex>=0 and A[sortedindex] > key:
A[sortedindex+1]= A[sortedindex]
sortedindex = sortedind... | true |
8e03bcd46f6c510c18e95b90b08f45cf8c32ea92 | i-aditya-kaushik/geeksforgeeks_DSA | /Recursion/Codes/sumofdig.py | 921 | 4.21875 | 4 | """
Sum of Digits of a Number
You are given a number n. You need to find the sum of digits of n.
Input:
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains one line of input containing n.
Output:
For each testcase, in a newline, print the sum of digits of n.... | true |
51365c6bd84287c7563c2a105bf7c8c8ef4188f5 | i-aditya-kaushik/geeksforgeeks_DSA | /Matrix/Codes/mat_spiral.py | 2,762 | 4.40625 | 4 | """
Spirally traversing a matrix
Given a matrix mat[][] of size M*N. Traverse and print the matrix in spiral form.
Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test cases follow. Each testcase has 2 lines. First line contains M and N respectively separated b... | true |
fedd83b0aecd5bb55de8436c094270c0e54e500d | i-aditya-kaushik/geeksforgeeks_DSA | /Searching/Codes/majority.py | 1,360 | 4.28125 | 4 | """
Majority Element
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Input:
The first line of the input contains T denoting the number of testcases. The first line of the test case will be ... | true |
b52ed30629de5374a60e18e0730974ea3c932250 | i-aditya-kaushik/geeksforgeeks_DSA | /Sorting/Codes/sortABS.py | 1,483 | 4.125 | 4 | """
Sort by Absolute Difference
Given an array of N elements and a number K. The task is to arrange array elements according to the absolute difference with K, i. e., element having minimum difference comes first and so on.
Note : If two or more elements are at equal distance arrange them in same sequence as in the giv... | true |
0677e47c2563c9dc78610a30bf045c3a0a0ad6c5 | i-aditya-kaushik/geeksforgeeks_DSA | /Sorting/Codes/bubble_sort.py | 1,016 | 4.375 | 4 | """
Bubble Sort
The task is to complete bubble function which is used to implement Bubble Sort!
Input:
First line of the input denotes the number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Output:
For each testcase, in a new line, print the sorted a... | true |
570d2801e21e3eb5b8875b228326fb0c3561618b | i-aditya-kaushik/geeksforgeeks_DSA | /Matrix/Codes/transpose.py | 1,296 | 4.4375 | 4 | """
Transpose of Matrix
Write a program to find transpose of a square matrix mat[][] of size N*N. Transpose of a matrix is obtained by changing rows to columns and columns to rows.
Input:
The first line of input contains an integer T, denoting the number of testcases. Then T test cases follow. Each test case contains ... | true |
29288758841cbd4e380ef3d44c956d18ab032f10 | i-aditya-kaushik/geeksforgeeks_DSA | /Sorting/Codes/quick_sort.py | 1,706 | 4.21875 | 4 | """
Quick Sort
Given an array arr[] of size N. The task is to complete partition() function which is used to implement Quick Sort.
Input:
First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Output:
For each testcase, in... | true |
bed7c67759a52f18c3e9eccda62d4b0c4e8c4a88 | i-aditya-kaushik/geeksforgeeks_DSA | /Sorting/Codes/counting_triangles.py | 1,310 | 4.25 | 4 | """
Count possible triangles
Given an unsorted array arr of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles.
Input:
The first line of the input contains T denoting the number of testcases. First line of test case is the len... | true |
6a78c30395f64a06a10595531e2c49e88c58b481 | kulvirvirk/python_filter_function | /main.py | 440 | 4.3125 | 4 | # The filter() method filters the given sequence with the help of a function that tests each element in the sequence to be true or not.
def fun(variable):
letters = ['a', 'e', 'i', 'o', 'u']
if (variable in letters):
return True
else:
return False
sequence = ['g', 'e','e', 'j', 'k', 's', 'p', 'r']
#usi... | true |
87313908b986cbafb4512b6f1395328e5c704bf1 | rcdmelhado/project_euler | /problem_09.py | 642 | 4.28125 | 4 | """Problem 09 - Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a² + b² = c²
For example, 3² + 4² = 9 + 16 = 25 = 5².
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
"""
def product_pythagorean_triplet(numbers_s... | true |
dd0c8ef497d332bdc016b8d186662f1a16fd80e8 | bingli8802/leetcode | /0101_Symmetric_Tree.py | 1,435 | 4.1875 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
# recursively 递归
class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
... | true |
9e6d11229767ff582b9c145e2ebdd3655ef0bed2 | ayushi8795/Python-Training | /PythonTask2/9)2).py | 254 | 4.25 | 4 | number = -1
again = "yes"
while number != 5 and again != "no":
number = int(input("Guess the lucky number: "))
if number != 5:
print ("That is not the lucky number")
again = input("Would you like to guess again? Type yes or no ")
| true |
f3eea09ec4982a09c63497ba80ff4ac311e50341 | FatherAvocado/RandomCodeFROMCodeWarsETC | /Number of trailing zeros.py | 1,184 | 4.1875 | 4 | #Write a program that will calculate the number
# of trailing zeros in a factorial of a given number.
#N! = 1 * 2 * 3 * ... * N
#Be careful 1000! has 2568 digits...
#My solution
import math
def zeros(n):
if n > 0:
accum = 1
#for multiplier in range(1, n + 1):
# accum = accum * multiplie... | true |
3dae294e3a4a67c875d8c6ec99d895774ba51ff3 | jockaayush/My-Codes | /File Writer.py | 862 | 4.3125 | 4 | from sys import argv
a,b = argv
print "Write Add Of file To Open\n"
b = raw_input("File To Open")
c = open(b,'w')
print "Hold Your Breath"
print """"Now I am Clearing the content of your file
if you don't want to do it press 'Ctrl+C'
Else press 'Return'"""
raw_input(">")
c.truncate()
print "Now i am gona a... | true |
e8cfa63f481ccf2a882761befb7e09c6f223a77a | Tamalika1995/Udemy_Practice | /Practice_100/p49.py | 519 | 4.28125 | 4 | '''Define a class named Shape and its subclass Square. The Square class has an init
function which takes a length as argument.
Both classes have a area function which can print the area of the shape where Shape's area is 0 by default.'''
class Shape():
def __init__(self):
pass
def area(self):
re... | true |
3c3052b4b9ac450734485dc13d13340db61caa74 | KrushikReddyNallamilli/python | /count number of llines,words,characters in a file.py | 407 | 4.125 | 4 | filename=input("Enter filename : ")
filename=open(filename,'r')
lines=0
words=0
characters=0
for line in filename:
word_list=[]
word_list=line.split()
lines=lines+1
words=words+ sum(word_list)
characters=charactes+len(line)
print("Numbers of lines in the file are : ",lines)
print("Numbers of words i... | true |
d97ee82679a915a177cbb1169a96c5540e76b2b7 | makosa-irvin/python-fundamentals-exercises | /ch3ex2-program mimicks an address book.py | 1,908 | 4.1875 | 4 | #Exercise 2
#A menu driven that works with an adress book file
#Menu should have:1)Look up person by last name
#2)Add a person to address book
#3)Quit
#The menu
menu = input('Welcome to the address book.\nChoose your options:\n'
' 1) Look u... | true |
8ac9f8ddb3d154170bb150cf2859406bbc711b72 | makosa-irvin/python-fundamentals-exercises | /ch5exercises/ch5ex3-draw polygon func.py | 333 | 4.25 | 4 | #exercise 3
#A function that draws a polygon given no. of sides and side length
import turtle
import random
def drawPoly(n,length):
t = turtle.Turtle()
screen = t.getscreen()
angle = 360 / n
for i in range(n):
t.left(angle)
t.forward(length)
t.ht()
screen.exitonclick()
dr... | true |
9900fe807fd02cdef4e1d66f93e6694c5550ea3a | cornel-kim/Python_Class | /lesson2b.py | 449 | 4.1875 | 4 | #nested if else statement
Age = int(input("Input your age:"))
if Age > 17:
print("Can donate blood")
weight = float(input("Please input your weight:"))
if weight < 55:
print("Your age is more than 17 years hence can donate but you weight is less hence not eligible")
else:
print("Both yo... | true |
38f10d1f3f2c932d16bedcd59110497b3e9e0fb9 | cornel-kim/Python_Class | /lesson2a.py | 766 | 4.3125 | 4 | #we have make decisions- statements
# student_name = str(input("Enter student name:"))
# student_marks = int(input("Enter student marks:"))
#
# if student_marks < 350:
# remark = "Please repeat the class"
# print("Student name is ", student_name, "and you scored", student_marks, "marks", remark)
#
# else:
# ... | true |
8a71b66bc7d72c69ae363c75f7932aaebeb6e7d1 | EssamSami5155/PyCampaign20 | /pycampaign10[set].py | 1,821 | 4.59375 | 5 | # sets
# what is a set?
# a set is a type of data that stores a set of things.
# this is actually a set of unique things.
# this means a set doesn't contains same elements multiple time.
# how to create a set?
# using set function.
a= set()
# this is a empty set.
# example of a set with elements
s=set([1,2,3,4,5,6])
... | true |
bbd22fe997e9fd8e12023d6a581c98fb70c48164 | ctnswb/python-practice | /count_vowels.py | 774 | 4.125 | 4 | # Write a method that takes a string and returns the number of vowels
# in the string. You may assume that all the letters are lower cased.
# You can treat "y" as a consonant.
#
# Difficulty: easy.
def count_vowels(string):
count = 0
for i in range(len(string)):
if (string[i] == "a")| (string[i] == "e"... | true |
072de8a19f5a9bdc7bb27f10394a0ddb730d40b7 | ctnswb/python-practice | /reverse.py | 475 | 4.3125 | 4 | # Write a method that will take a string as input, and return a new
# string with the same letters in reverse order.
#
# Don't use String's reverse method; that would be too simple.
#
# Difficulty: easy.
def reverse(s):
rString = ''
for i in range(len(s)-1,-1,-1):
rString += s[i]
return rString
... | true |
0f213d8dd1ec7a658623f0215997a3592e0df9ed | ejonakodra/holbertonschool-machine_learning-1 | /math/0x02-calculus/10-matisse.py | 1,055 | 4.4375 | 4 | #!/usr/bin/env python3
""" defines a function that calculates the derivative of a polynomial """
def poly_derivative(poly):
"""
calculates the derivative of the given polynomial
Parameters:
poly (list): list of coefficients representing a polynomial
the index of the list represents th... | true |
2cf2b6a7452b27cab0cc6cace810516450ffa17b | ejonakodra/holbertonschool-machine_learning-1 | /supervised_learning/0x03-optimization/1-normalize.py | 911 | 4.1875 | 4 | #!/usr/bin/env python3
"""
Defines function that normalizes a matrix
"""
def normalize(X, m, s):
"""
Normalizes a matrix
parameters:
X [numpy.ndarray of shape (d, nx)]:
matrix to normalize
d: number of data points
nx: the number of features
m [numpy.nda... | true |
1e088946cde247c13755aabca64feefe1d6129d4 | ejonakodra/holbertonschool-machine_learning-1 | /supervised_learning/0x07-cnn/3-pool_backward.py | 2,284 | 4.125 | 4 | #!/usr/bin/env python3
"""
Defines a function that performs backward propagation
over a pooling layer of a neural network
"""
import numpy as np
def pool_backward(dA, A_prev, kernel_shape, stride=(1, 1), mode='max'):
"""
Performs backward propagation over a pooling layer of neural network
parameters:
... | true |
f6b2c000a0aeb61f2f09e99d3f0a07b3d221dfe1 | jakemiller13/School | /MITx 6.00.1x - Introduction to Computer Programming Using Python/Problem Set 4 - Scrabble Game/updateHand.py | 1,031 | 4.125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 2 06:34:20 2017
@author: Jake
"""
def updateHand(hand, word):
"""
Assumes that 'hand' has all the letters in word.
In other words, this assumes that however many times
a letter appears in 'word', 'hand' has at least as
man... | true |
ca6b2280adb43a92348179ef074364b467c948b2 | jakemiller13/School | /MITx 6.00.1x - Introduction to Computer Programming Using Python/Problem Set 4 - Scrabble Game/calculateHandlen.py | 476 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 3 06:41:34 2017
@author: Jake
"""
def calculateHandlen(hand):
"""
Returns the length (number of letters) in the current hand.
hand: dictionary (string int)
returns: integer
"""
hand_length = 0
for n... | true |
aa3f3b959c46700e1af9b506fc38ad7a51253a5f | hairstoa/Advent_of_Code2019 | /AoC_1_AH.py | 2,390 | 4.1875 | 4 | #----------------------------------------------------------
# Title: Santa's Fuel Calcator
# Programmer: Adriane
# Date: December 1, 2019
# Notes: This file requires a text file companion.
# Text file contains integers seperated by \n.
#
# Description: Fuel is needed for... | true |
4373736956162f022bf27a97d4b770fa31cc0b27 | jimtough/python-sandbox | /008_references_to_functions.py | 1,753 | 4.25 | 4 |
# define a trivial function
def hello():
print("Hello!")
# output info about the type of 'hello' (a function) and then execute it
print(type(hello))
print(hello.__name__)
hello()
# now create another reference to this function
ref_to_hello = hello
# output info about the type of 'ref_to_hello' and then execute... | true |
4bb6bcaa0f00bd92828b35c35c42dfa68eabf3fa | mentortechabc/play | /homework-python/magic_methods/new.py | 625 | 4.15625 | 4 | """
https://howto.lintel.in/python-__new__-magic-method-explained/
"""
class Singleton(object):
_instance = None # Keep instance reference
def __new__(cls, *args, **kwargs):
print(f"running __new__ with cls = {cls}")
if not cls._instance:
cls._instance = object.__new__(cls)
... | true |
9cda7612a5d7970c6a3b6558030f1ab992f6b6a4 | manishdadhich1004/Python-Programs | /Bmi_Cal.py | 317 | 4.125 | 4 | # Python
print("Adult body mass index Calculator")
weight=float(input("Enter the weight in KG= "))
height=float(input("Enter your height in meter= "))
Bmi=(weight/height)/height
print("Bmi=",Bmi)
if(Bmi<=18):
print("Underweight")
elif(Bmi>18 and Bmi<=24):
print("Weight is ohk")
else:
print("Owerweight")
| true |
02a989de2a4238e5160687adad020d568eb09b11 | danghung-dev/cbd-assignment | /assignment1/cbd1.py | 1,177 | 4.125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
questions = {
"strong": "Do ye like yer drinks strong?",
"salty": "Do ye like it with a salty tang?",
"bitter": "Are ye a lubber who likes it bitter?",
"sweet": "Would ye like a bit of sweetness with yer poison?",
"fruity": "Are ye one for a fruity ... | true |
4640fece091e1ec5eedf8874ecbcf1ab8e7bedc5 | NotChristianGarcia/Engineering-Computation-Lab | /homework/3/python_script_full_of_errors_fixed.py | 1,738 | 4.3125 | 4 | #! /usr/bin/env python
_life_expectancy = 120; print( '\n' + 'The life expectancy for the millennials is projected to be %d years! (But don''t believe it...)' % (_life_expectancy) + '\n' )
print("""
A recent study published in the journal of Nature, discovered that over the past century,
although the life expe... | true |
7facf8e297a6d6d22eb9b7b6e164a35161dc8143 | sherly083/pythonexamples | /,.py | 537 | 4.125 | 4 | black_list = ['sherly','sharon''dharshini''john']
num_students = int(input('enter number of students:'))
student_list = []
white_list = []
for student in range(num_students):
prompt = input('input a name:')
while prompt == '':
prompt = input('input non-empty name:')
student_list.append(prom... | true |
6978cfdeb56431e34c39153e796dc6c8f1f1a150 | janoah-policarpio/Python-Projects | /Basic Scripting Projects/draw_MSPaint_pyautogui_mouse_example.py | 836 | 4.21875 | 4 | #draw a rectangular spiral on MS Paint
import pyautogui
pyautogui.click() #click to put drawing program in focus. Place mouse at MS Paint.
distance = 200
duration = 1
while distance > 0:
print(distance,0)
pyautogui.dragRel(distance, 0, duration = duration) #move right
distance = distance - ... | true |
fe6b20bdaeb5c285b5d61537a4fd875ff662a320 | Mojoo25/fall2021mr | /python_plotting/lesson6/sine_example.py | 373 | 4.21875 | 4 | '''
How does a computer program create a sine wave?
The python math library has a sin function
sin(x) returns the sine of x in radians, numeric value in range [-1, 1]
'''
import math
print(math.sin(0)) # 0 degrees
print(math.sin(math.pi/4)) # 45 degrees
print(math.sin(math.pi/2)) # 90 d... | true |
d7b271e018f6faf31832298fc46b1faedd561aa2 | Mojoo25/fall2021mr | /intro_python/lesson1/lesson1c.py | 369 | 4.34375 | 4 | '''
lesson1c
input function reads from the keyboard
returns a string type
assignment operator - stores data returned in a variable
type() returns data type
str() converts to string
concatentation operator + adds two strings together
'''
inMsg = input('Enter some text: ')
print("inMsg: " + inMsg)
p... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.