blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
545k
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
545k
b9464ee8d171f7742f72aa3cd511dd2db6e693dc
Vinit43/Python_Programs
/MultipleInheritance/Main.py
578
3.921875
4
class Base1: def __init__(self): self.i =10 self.j =20 print("Inside base1 constructor") class Base2: def __init__(self): self.a =100 self.b =200 print("Inside base2 constructor") class Derived(Base1,Base2): def __init__(self): Base1.__init__(self) Base2.__init...
6d748f6b7968254b148afdee23c755e5ac8bcfc5
KashEight/AtCoder-Samples
/Python/ABC/107/ABC107B.py
186
3.515625
4
h, w = map(int, input().split()) a = [[s for s in input()] for _ in range(h)] b = [] for i in range(h): for j in range(w): if a[i][j] == "#": b.append([i, j])
addebb72b22b1bbcc6a0934c10b43a18c98cc780
JeffRuben/Project-Euler
/Problem 1.py
115
3.578125
4
z = 0 for x in range(1,1000): if x%3 == 0: z=x+z elif x%5 == 0: z=x+z print z
06467fa1f2daaeedbeb09cc0aff53c37c95358ec
lucaslb767/pythonWorkOut
/pythonCrashCourse/chapter4/TY_4.2.py
148
3.90625
4
animals = ['dog', 'cat', 'turtle', 'dragon'] for animal in animals: print('A ' +animal+' would make a great pet') print('All pets are slaves')
9cc468276b5308886cc02b3dbe4d33db6bd86d16
lucaslb767/pythonWorkOut
/pythonCrashCourse/chapter2/name.py
211
3.921875
4
name = 'lucas barrozo' print(name.title()) print('all uppercase', name.upper()) print('all lowercase,', name.lower()) first_name = 'lucas' last_name = "barrozo" full_name = first_name +' '+ last_name print(full_name)
2abf138571dade8a451492c21d7c044dfe44249d
lucaslb767/pythonWorkOut
/pythonCrashCourse/chapter3/TY_3.4.py
201
3.65625
4
guests = ['Schumpeter', 'Einstein', 'Seu Zé'] for i in range(0,len(guests)): print('Dear ' + guests[i] + ' would you like to grab a lunch?') #YT_3.9 print('\n the guest number is: ', len(guests))
94b508503ea89642213964b07b0980ca81e354e2
lucaslb767/pythonWorkOut
/pythonCrashCourse/chapter6/favorite_languages.py
567
4.375
4
favorite_languages = { 'jen':'python', 'sarah':'C', 'jon':'ruby' } print('Jon favorite language is ', favorite_languages['jon']) friends = ['sarah'] #using a list to sort a dictionary's value for name in favorite_languages: print(name.title()) if name in friends: print('Hi', name.title()...
edbbf4dcd54805315da241cb80ca67be5414b4d2
lucaslb767/pythonWorkOut
/pythonCrashCourse/chapter4/TY_4.11.py
402
4.0625
4
pizzas = ['calabresa', 'peperoni', 'frago com catupiry'] for pizza in pizzas: print('Probably my favorite pizza is',pizza) print('I kinda enjoy pizza') friend_pizzas = pizzas[:] pizzas.append('ham') friend_pizzas.append('4 cheese') print('My favorite pizzas are: ') for pizza in pizzas: print(pizza) prin...
957820ec21da87bd16f7b56757ed2720ff19176a
coxlab/physiology_analysis
/physio/timeseries/ranges.py
1,004
3.9375
4
#!/usr/bin/env python def overlap(a, b): """ test if two ranges a and b of type (start, stop) overlap """ if (a[0] > b[1]) or (a[1] < b[0]): return False else: return True def combine(a, b): """ combine two overlapping time ranges """ return [min(a[0],b[0]), max(a[1...
9887bcecf4f7707e7a379ae56f89213dd365c20d
emanmacario/xgcd
/extended_euclid.py
1,495
3.859375
4
# COMP90043 Cryptography and Security # Assignment 1, Semester 2 2019 # Question 2 # # Name: Emmanuel Macario <macarioe> # Student Number: 831659 # Date: 21/08/19 def extended_gcd(a, b): """ Computes the GCD of a and b by extended Euclid's algorithm :param a: first integer :param b: second integer ...
0b24a6d417f9d3dc4c79ef407d7a0b689d24925f
bobae31/homeworks
/w3_d1_quadratic_sorts.py
7,938
4.3125
4
# # Homework 07 - Quadratic Sorts # # Problem 1: Insertion Sort # # Prompt: Given an unsorted list of integers, return the list sorted # using insertion sort. # # What are the time and auxilliary space complexity? # # Input: input {List} # Output: {List} # # Example: [3,9,1,4,7...
6c543e8cfcb156f3265e3bbd01b287af45c318f3
MariaBT/IS105
/ex3.py
961
4.34375
4
# Only text describing what will be done print "I will count my chickens:" # Print the result of the number of hens print "Hens", 25 + 30 / 6 # Print the result of the number of roosters print "Roosters", 100 - 25 * 3 % 4 # Plain text explaining what will be done next print "Now I will count the eggs:" # The resu...
bf53c3cc6c767665e250b411724508ce6a6306d8
rnaimehaom/UW-Molecular-Data-Mining
/scripts/scrape_sciencedirect_urls.py
7,252
3.515625
4
""" This code is used to scrape ScienceDirect of publication urls and write them to a text file in the current directory for later use. """ import selenium from selenium import webdriver import numpy as np import pandas as pd import bs4 from bs4 import BeautifulSoup import time from sklearn.utils import shuffle def s...
6d607e68594bb717711d711df2e8e64fca2c37dc
VasNatal/lab2_repo
/str_algs.py
72
3.734375
4
s = "Hello, world" def re(s): return s[::-1] print(re(s))
879c5858fa8ab9debf0c78559777687fbd2e2d6f
saikrishna-ch/five_languages
/pyhton/NpowerN.py
252
4.28125
4
Number = int(input("Enter a number to multilply to itself by it's number of times:")) print("{} power {} is".format(Number, Number), end = "") Product = 1 for Counter in range(Number): Product = Product * Number print(" {}.".format(Product))
4ebec8721ceca3f1b4659a12b97433c18ac2da3f
oscarmellizoangulo/prueba_fedesoft
/python/005_tipos_datos.py
94
3.734375
4
print type(2) print type('Hola') x = 'hola' y = 'casa' z = x + y a = x * 3 print z print a
2d943c418c9e86e3c9e93cc7b94d5d699da7d550
ilovepeppa/python-data-structure
/pythonds/arrayList.py
1,313
3.734375
4
class Node: def __init__(self, data): self.data = data self.next = None def get_data(self): return self.data def get_next(self): return self.next def set_data(self, data): self.data = data def set_next(self, next): self.next = next class ArrayLis...
ecd7770a7fef55c7432f65db81a64beb0e50a165
ilovepeppa/python-data-structure
/chapter4/rec_mc.py
1,300
3.5
4
def rec_mc(coins, change, known_results): min_coins = change if change in coins: return 1 elif known_results[change] > 0: return known_results[change] else: for i in [c for c in coins if c < change]: nums = 1 + rec_mc(coins, change - i, known_results) if n...
5fb27e2912ba8402244113d50c90b98dd1219978
pekkajauhi/Breakout
/scoreboard.py
2,351
3.515625
4
import pygame.font class Scoreboard(): """A class to report scoring information.""" def __init__(self, bo_settings, screen, stats): """Initialize scorekeeping attributes.""" self.screen = screen self.screen_rect = screen.get_rect() self.bo_settings = bo_settings self.st...
20ba808e87b872a2a1ac48438d957e1fe29ccf07
lnandi1/Selection_Statements_Python
/Year8_04DEC2018/Program4_Message.py
116
3.96875
4
# Program 4 # Asking for user input and printing the message Message = input("Enter a Message ") print(Message)
5e2a9c9558d2e3c3fc0c60b37a84c2cde94b590c
soonsam123/Session01
/Add_Questions.py
531
3.828125
4
# Name: Soon Sam R Santos # Date: February 15, 2017 # Session: 1 # Add_Questions.py ############ WK.1.4.3: List Comprehensions ############### # Part1 - Even Squares def evenSquares(list): new_list = [x**2 for x in list if x % 2 == 0] return new_list # Test Cases print evenSquares([1,2,3,4,5,6]) # 4, 16, 36...
7a912ae9174f8fc67f65af2a4060fa22cc6a8f8c
sanskar112/pythoncode
/ma.py
116
3.578125
4
age=input("age") country=input("country") name=input("name") print("welcome to world ",age ,country,name,"hello ")
3627d9bcc7b3cd16c7eac8856a1428ba8d5bd875
LintCroft/currency-converter
/togbp.py
2,220
3.53125
4
import os import argparse import requests url = "https://api.exchangeratesapi.io/latest" parser = argparse.ArgumentParser("Convert to GBP") parser.add_argument("-i", "--input-amount", help="Amount to be converted to GBP", type=float) parser.add_argument("-c", "--currency", help="Currency (defaults is PHP)", type=str.u...
d483ffaf93193ba7c563690c5e19eab469905680
KarinaChumak/databases
/Cities.py
1,323
3.609375
4
from city import City class Cities: def __init__(self): self.cities = [] def add(self, city): if not any(c.cityId == city.cityId for c in self.cities): self.cities.append(city) else: raise Exception("City with such Id exists already") def delete(self, city...
392d866770a34569c3d4a927d0690c8363d8b9cb
chaitrasurapaneni/pythonhackerrank
/list1.py
918
3.828125
4
if __name__ == '__main__': n = int(input()) dataList = [] # insert 0 6 for x in range(n): commandList = input().split(" ") command = commandList[0] if (command == 'insert'): index = int(commandList[1]) value = int(commandList[2]) dataList.inser...
9bef3afcbb0807fe3498d47ba1ffc313d3a632ad
foppsomms/ACADIA_Workshop
/network-shortest-path_EDIT.py
2,978
3.796875
4
"""Network 01: Shortest path """ import compas import json from compas.utilities import pairwise from compas.datastructures import Network from compas.topology import dijkstra_path from compas.visualization import NetworkPlotter # make a network from a sample file with open('data.json', 'r') as f: lines = json...
db448b5e949c2f5fbcb930780aa8bfd0ed8c9ccc
kangli-bionic/HackBG
/Week7/SQL/table_creator.py
1,571
3.78125
4
import sqlite3 class TableCreator: def __init__(self, database): self.db = sqlite3.connect('table.db') self.db.row_factory = sqlite3.Row self.table_query = self.db.cursor() self.table_query.execute(""" CREATE TABLE IF NOT EXISTS employees( id INTEGER PRIMARY KEY,...
0e3d003f0ffb99df30859668a4dbaa533cd9c505
jemadux/hex-bin
/hexadecimal-bin.py
1,199
3.953125
4
#!/usr/bin/env python # -*- coding: utf-8 -*- # hexadecimal-bin.py # # Copyright 2013 Klearchos-Angelos Gkountras <kleagkou@gmail.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; ...
92430037c78bcf0f3a4f7fa55052349715e54d34
Landes1977/Automate-the-Boring-Stuff-with-Python
/strongPassword.py
366
3.921875
4
# Programmer: Matthew Landes # Date: March 29, 2020 import re print('Enter a password:') password = input() passwordRegex = re.compile(r'''( [a-z]+ # at least 1 lowercase [A-Z]+ # at least 1 uppercase [0-9]+ # at least )''', re.VERBOSE) if (len(password) > 7) & (passwordRegex.search(password) != ''): pr...
2d2568b72455819f93605b9b0ca03224e71e9b0f
pinstinct/wps-basic
/day6/practice/p4.py
131
3.65625
4
def return_sum_sub(arg1, arg2): return(arg1 + arg2, arg1 - arg2 if arg1 > arg2 else arg2 - arg1) print(return_sum_sub(5, 3))
83d64472efeab83b8b86036ebfd02cdb26aa79ea
pinstinct/wps-basic
/day6/practice/p2.py
612
4.21875
4
def what_fruits(color): ''' 문자열 color 값을 매개변수로 받아 문자열이 red면 apple, yellow면 banana, green이면 melon을 반환한다. 어떤 경우도 아니라면 I don't know 반환 ''' if color == 'red': return 'apple' elif color == 'yellow': return 'banana' elif color == 'green': return 'melon' else...
5004a3d9d95e73fcdc0d8b9700588977d6a75742
aucoeur/CS2.1
/in-class/bucket_sort.py
3,049
4.125
4
from string import ascii_lowercase def insertion_sort(items): """Sort given items by taking first unsorted item, inserting it in sorted order in front of items, and repeating until all items are in order. Running time: - Worst/Avg: O(n^2) when items are in reverse sorted order or randomly scramble...
965992bc0175b0a56e74c0c80d049b8d487347eb
aucoeur/CS2.1
/in-class/sort_items.py
520
4.03125
4
# def is_sorted(items): # #TODO: return a bool indicating whether the items are sorted or not # for index in range(len(items)-1): # if items[index] >= items[index+1]: # return False # return True def is_sorted(items): # O(n) linear because looks at everything once for index, i...
d51f78adced21aa103b44ebd2e5e1836d86e662a
prachuryanath/DSA-Problems
/Easy/21. Merge Two Sorted Lists/ans.py
342
3.5625
4
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: head = ListNode() curr = head while l1 and l2: while l1 and l2 and l1.val <= l2.val: curr.next = l1 l1 = l1.next curr = curr.next while l1 and l2 and l2.val <= l1.val: curr.next = l2 l2 = l2.next curr = curr.next curr.next = l1 o...
a9a396dbba0299d6ca3a4624ff2cd961e194d998
AnikaJerin/Basic-Python
/rock-pap-scissors.py
2,101
4
4
import random lst=['rock','paper','scissor'] chance=10 cp=0 hp=0 i=0 print("LeT's PlAy Rock, PapeR, SciSSoR") print("r=rock,p=paper,s=scisor") while i<chance: inp=input("enter r,p or s \n ") ci=random.choice(lst) #ci=computer input if inp == ci: print("It's a tie") print(f"your ...
5b432a0bd35a50427b5cab7426c48c502188653d
Dhadhazi/PD27-MilesToKmConverter
/main.py
698
4.03125
4
from tkinter import * def calculate(miles): km = round(miles*1.60934,2) calculated_label.config(text=km) window = Tk() window.title("Mile to Km Converter") window.config(padx=50, pady=50) equal_label = Label(text="is equal to") equal_label.grid(column=0, row=1) miles_label = Label(text="Miles") miles_labe...
37de50b3ea4f055d17ab775b4d9b4d0ed3fcf7aa
phanthainam2002/btvn-buoi-2
/3.py
887
3.796875
4
flocklist=[5,7,300,90,24,50,75] print("Hello, my name is Nam and these are my ship sizes") print(flocklist) a = flocklist.index(max(flocklist)) print("Now my biggest sheep has size",max(flocklist),"let's shear it") flocklist[a] = 8 print("After shearing, here is my flock") print(flocklist) for time in range(4): for...
6846280e9db61f9f18ad2b2270b9d425dcd32e1f
fagan2888/DP-Python
/coin_change.py
1,113
3.78125
4
''' You are given n types of coin denominations of values v(1) < v(2) < ... < v(n) (all integers). Assume v(1) = 1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins as possible. map to integer knapsack problem, with each item havi...
5589f4174e2c3e3ad5e864c4d922be8d01988557
TruePhad/projects
/Chatting bot.py
1,500
4.09375
4
import time def greet(bot_name, birth_year): print(f"Hello! My name is {bot_name}.\nI was created in {birth_year}.") def remind_name(): print("Please, remind me your name.") name = input() print(f"What a great name you have, {name}!") def guess_age(): print("Let me guess your age.\nEnter remaind...
36ce9fef17dcfba1ec0fd295f74531c52d923bd1
DLobosky/CS5600-Computer-Networking
/CS5600_From_linuxhome/ProjectMidterm/ProjectMidterm/TrackingServer/server.py
1,079
3.6875
4
import sys from socket import * from threaded_server import ThreadedServer import netifaces as ni server_ip = ni.ifaddresses('eth0')[2][0]['addr'] portMin = 8000 portMax = 9000 def main(): if (len(sys.argv) == 2 and int(sys.argv[1]) >= portMin and int(sys.argv[1]) <= portMax): # Grabbing...
cb9b83208c36a9a9c5bd2ed0f1d6ed976e237d04
bamvoo/A12-GaMe
/game.py
5,177
3.796875
4
#!/bin/python3 import randomGen def showInstructions(): # print a main menu and the commands print(''' RPG Game ======== Get to the Garden with a key and a potion Avoid the monsters! Commands: w + ENTER --> north d + ENTER --> east s + ENTER --> south a + ENTER --> weast SPACE + ENTER --> get it...
9032f579764b613d85744bcfc8fa524b610b2feb
CS-433/cs-433-project-2-answer42
/SNIP_and_partially_trained_tickets/train.py
1,750
3.640625
4
def eval_net(net, data_loader, device): """Returns accuracy of the passed network on the given dataset Parameters ---------- net: nn.Module Neural network data_loader: torch.utils.data.DataLoader Loader that should be iterable and return batches of data device Device to ...
aa3794eb564960493f8be746b42a59d0d2e7036a
Brakahaugen/Peg-solitaire-RL
/hexgames/cell.py
1,275
3.875
4
import math class Cell: def __init__(self, x,y): self.x, self.y = x, y self.empty = False self.neighbours = [] # Function for adding neighbours for all cells in the grid, # based on a list of defining connectivity in the neighbourhood # This way to do it does not scale v...
6b26a6c121e3d54489fa7af370a3979ac6fdef1c
haroldmei/MLAI
/CS221_2019_Spring/intvw/bykeracers.py
1,410
3.53125
4
#!/bin/python3 import os import sys #overlapping matches # # Complete the bikeRacers function below. # def bikeRacers(bikers, bikes): # # Write your code here. # def dist(a,b): return (a[0] - b[0])**2 + (a[1] - b[1])**2 dFirst = sys.maxsize dSecond = sys.maxsize i = 0 j = 0 ...
34cf006f2e6a93c0e7faa15b11ff93223e7fe97f
sunhongdou/PythonDemo
/demo01/demo01.py
368
3.78125
4
# this is my first python file. print("hello") """ 这是多行注释。。。。 多行注释 """ print("hello3") # this is hello3 print("中国人") print(10//4) print(9%2) print(2**3) print("-"*40) print("对不起 "*5) print("-"*40) # 变量 qq = "zhangsan" print(qq) # 买苹果 price = 5.0 weight = 3.2 money = price * weight money = money - 5 print(money)
1c8b2dccc6f1a60944e377168de7feb39163c94f
ivan-yosifov88/python_oop_june_2021
/python_advanced_retake_18_08_2021/bees.py
1,168
3.578125
4
from collections import deque working_bees = deque([int(el) for el in input().split()]) nectar_to_collect = [int(el) for el in input().split()] honey_process = deque(input().split()) total_honey_collect = 0 def get_honey_value(bee, honey, symbol): if symbol == "+": result = bee + honey elif symbol...
3b13c3ebbc61e5371cfd1a4bc2af89f7ed032107
cmalone/rosalind
/grph.py
529
3.546875
4
"""Solution for Overlap Graphs problem -- Currently doesn't work""" import fasta def overlaps(s, t, k): """Determines whether or not the length k suffix of s matches the length k prefix of t""" suffix = s[len(s) - k: len(s)] prefix = t[0:k] return suffix == prefix def computeOverlap(filename, overlap_length): re...
0a6e7c97d3a9db2c03b7c18e4d07db69ba793007
lydia-duncan/chplforpyp-docs
/docs/source/examples/cond.switch.py
267
4
4
# light = raw_input("Which color is the traffic light?\n") if light=="green": print "You can cross the street now." elif light=="yellow": print "CAUTION!" elif light=="red": print "Do not cross!" else: print "WARNING! Traffic-light is broken!"
830e8fe9edff116d1f314bda7bfdadf09c47319e
DanielTsiang/CS50x
/pset6/hello/hello.py
140
4.25
4
# Script to take user's name as input and prints hello followed by user's name name = input("What is your name?: ") print(f"hello, {name}")
528cf4a5aa9220a109fba050f325a4e0124279a1
jsween/pythonPractice
/exercise3.py
765
4.03125
4
def cut_off_high(numList, maxNum, emptyList): for x in numList: if(x < maxNum): emptyList.append(x) return emptyList def check_if_num(string): isInteger = False while not isInteger: num = input(string) isInteger = represents_int(num) if(isInteger): ...
32cdb2cbda0c2016a27329ed8457036b5e923e3b
etorr86/WGU-C950
/ReadCSV.py
1,745
3.890625
4
import csv # Open CSV File from Distance import Distance from HashTable import HashTable from Packages import Packages # Class used for loading every file needed in the application class CSVDataLoader: # function that gets call to return a list of package objects into a custom hash table def load_packages(s...
0539475cdd15d71efe19632eee344fce478b287a
CarlosW1998/IA2-Class
/Pacman/game.py
7,484
3.5625
4
import arcade from maze import make_maze from states import State, AgentState from random import randint from agents import Player, Gosth, Coin from heapq import * SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Pacman" class MyGame(arcade.Window): def __init__(self, width, height, title): super(...
eff66e25423e884613d98d1093088ec9a4ae084c
thebishaldeb/ClassAssignments
/Algorithms/Assign7/main.py
1,710
4.25
4
#=============== FUNCTIONS START =============== # merge function for merge sort algorithm to sort an array def merge(arr, l, m, r ): n1 = m - l + 1 n2 = r - m L = [0] * (n1) R = [0] * (n2) for i in range(0 , n1): L[i] = arr[l + i] for j in range(0 , n2): R[j] = arr[m + ...
baf1307dfe88b63e00bebd58aff86921d017e331
acronoo/lesson1
/homework1.1.py
737
4.28125
4
# 1. Поработайте с переменными, создайте несколько, выведите на экран, # запросите у пользователя несколько чисел и строк и сохраните в переменные, выведите на экран. a = 5 print("a = ", a) b = 20 print("b = ", b) value = a + b print(f"a + b = {a} + {b} = {value}") user_input1 = input("Что бы получить результат умножен...
1bcb53ceb6c9e7d03304180b1154146d91b5684a
fajarzuhrihadiyanto/python-one-liner
/module/factor.py
335
4.09375
4
""" Factor Lambda Function Description : This Lambda function is used to get list of factor pair of the given number Example : input : 20 output : [(1, 20), (2, 10), (4, 5)] """ import math factor = lambda number: [(x, number // x) for x in range(1, int(math.sqrt(number) + 1)) if nu...
db757f8b01960eef6aa110d730668082c83030ed
JasonVann/Udacity
/DesignOfComputerPrograms/logic_puzzle.py
3,147
4.3125
4
""" UNIT 2: Logic Puzzle You will write code to solve the following logic puzzle: 1. The person who arrived on Wednesday bought the laptop. 2. The programmer is not Wilkes. 3. Of the programmer and the person who bought the droid, one is Wilkes and the other is Hamming. 4. The writer is not Minsky. 5. Neither Knu...
d8fc4df5b1fdee29f030ae28845fbb2c37aabafe
caterpillarAttack/MNIST_Keras
/mnist_verbose.py
8,392
3.96875
4
print('Importing Libraries. (All of the goodies needed.)') from keras.datasets import mnist from keras import models from keras import layers from keras.utils import to_categorical input('Press any key to continue.\n') # The Simplified Big Picture of How Most Supervised Networks Work # The Just of It # [1] Dr...
90cb2d16b1457623097c5c0edbe7170b3756e767
MahadiRahman262523/Python_Code_Part-1
/practice_problem-28.py
485
4.40625
4
#write a program to print multiplication table of a given number #using for loop # num = int(input("Enter any number : ")) # for i in range(1,11): # # print(str(num) + " X " + str(i) + " = " + str(i*num)) # print(f"{num} X {i} = {i*num}") #write a program to print multiplication table of a given...
b4e26837cb1813bb939df3c6f783aea9f0d7eb88
MahadiRahman262523/Python_Code_Part-1
/operators.py
883
4.53125
5
# Operators in Python # Arithmetic Operators # Assignment Operators # Comparison Operators # Logical Operators # Identity Operators # Membership Operators # Bitwise Operators # Assignment Operator # print("5+6 is ",5+6) # print("5-6 is ",5-6) # print("5*6 is ",5*6) # print("5/6 is ",5/6) # print("16//6...
20f68772f0cf502a5b4f0800f48d9a90f4aa2ea7
MahadiRahman262523/Python_Code_Part-1
/practice_problem-7.py
594
4.0625
4
# create a class c2-d vector and use it to create another class # representing a 3-d vector class C2dVec: def __init__(self,i,j): self.icap = i self.jcap = j def __str__(self): return f"{self.icap}i + {self.jcap}j" class C3dVec(C2dVec): def __i...
377f7632417faaed3d23bd456f29ec516b5c024c
MahadiRahman262523/Python_Code_Part-1
/practice_problem-39.py
231
4.25
4
# Write a python function to print first n lines of # the following pattern : # * * * # * * for n = 3 # * n = int(input("Enter any number to print pattern : ")) for i in range(n): print("*" * (n-i))
d5075d4831f900cb4f12665365babefb4ecd098e
MahadiRahman262523/Python_Code_Part-1
/practice_problem-18.py
488
4.1875
4
# Write a program to input eight numbers from the user and display # all the unique numbers num1 = int(input("Enter number 1 : ")) num2 = int(input("Enter number 2 : ")) num3 = int(input("Enter number 3 : ")) num4 = int(input("Enter number 4 : ")) num5 = int(input("Enter number 5 : ")) num6 = int(input("Ente...
4ecab443b544dba37f473597b1b413033b9f70eb
MahadiRahman262523/Python_Code_Part-1
/practice_problem-34.py
200
4.4375
4
# Write a program to print multiplication table of n # using for loop in reversed order tabl=int(input("Enter any number : ")) for i in range(10,-1,-1): print(tabl,"*",i,"=",i*tabl)
6141032532599c2a7f307170c680abff29c6e526
MahadiRahman262523/Python_Code_Part-1
/practice_problem-25.py
340
4.34375
4
# Write a program to find whether a given username contaoins less than 10 # characters or not name = input("Enter your name : ") length = len(name) print("Your Name Length is : ",length) if(length < 10): print("Your Name Contains Less Than 10 Characters") else: print("Your Name Contains greater ...
5a36d939d7f668af7f986c9d4f38b28130e53a58
kalioz/wordmaggedon
/wordmaggedon.py
1,768
3.59375
4
#/bin/python3 # Created by Clement Loiselet import urllib.request letters = "abcdef" word_size = 5 word_pattern = "ex_mpl_" word_list_url = "https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt" def findWordsByLetters(letters, word_size): with urllib.request.urlopen(word_list_ur...
9cd02585f1a310d287df7c1c01c3c17bdf3d9838
rmartinez2/Python_Design_Patterns
/Proxy/Proxy.py
2,317
3.6875
4
''' Created on Nov 5, 2017 @author: rene ''' from _pyio import __metaclass__ from abc import ABCMeta, abstractmethod class Actor(object): def __init__(self): self.is_busy = False def occupied(self): self.is_busy = True print(type(self).__name__, "is occupied with current...
954adbffeb15bcf1f31bc49161c1eb6b63279e6d
AidanaKaripbayeva/Algorithms-for-Data-Analytics
/Programming Assignment 4 Working in an Unfair-World!/progr4_aidana2.py
4,642
4.25
4
#!/usr/bin/env python3 # coding: utf-8 # Three-sided Unfair Dice into other RV distributions # # IE531: Algorithms for Data Analytics # Written by Prof. R.S. Sreenivas # import sys import argparse import random import numpy as np import time import math import matplotlib.pyplot as plt from scipy.stats import uniform s...
f91ae0c6123389f40fd80deb340fb90f6544ecec
xuelang201201/FluentPython
/08_对象引用、可变性和垃圾回收/fp_05_元组的相对不可变性.py
571
4.09375
4
# 一开始,t1 和 t2 相等,但是修改 t1 中的一个可变元素后,二者不相等了 t1 = (1, 2, [30, 40]) # t1 不可变,但是 t1[-1] 可变。 t2 = (1, 2, [30, 40]) # 构建元组 t2,它的元素与 t1 一样。 print(t1 == t2) # 虽然 t1 和 t2 是不同的对象,但是二者相等————与预期相符。 print(id(t1[-1])) # 查看 t1[-1] 列表的标识。 t1[-1].append(99) # 就地修改 t1[-1] 列表。 print(t1) print(id(t1[-1])) # t1[-1] 的标识没变,只是值变了。 print(...
cb463758eb9e0d202954d2bda52ae8d950c569d2
xuelang201201/FluentPython
/02_数据结构/fp_05_用生成器表达式初始化元组和数组.py
436
3.78125
4
import array symbols = '$¢£¥€¤₽' # 如果生成器表达式是一个函数调用过程中的唯一参数, # 那么不需要额外再用括号把它围起来 print(tuple(ord(symbol) for symbol in symbols)) # array 的构造方法需要两个参数,因此括号是必需的。 # array 构造方法的第一个参数指定了数组中数字的存储方式 print(array.array('I', (ord(symbol) for symbol in symbols)))
e948c889e9443b2d4ded69459a273ad43f72b0c0
xuelang201201/FluentPython
/03_字典和集合/fp_10_集合论.py
1,047
4.1875
4
# 集合的本质是许多唯一对象的聚集。因此,集合可以用于去重。 my_list = ['spam', 'spam', 'eggs', 'spam'] print(set(my_list)) print(list(set(my_list))) """ 例如,我们有一个电子邮件地址的集合(haystack),还要维护一个较小 的电子邮件地址集合(needles),然后求出 needles 中有多少地址同时 也出现在了 haystack 里。借助集合操作,我们只需要一行代码就可以了。 """ # needles 的元素在 haystack 里出现的次数,两个变量都是 set 类型 # found = len(need...
c80b3653e10b8cc8e1452b1449347fabd6d49a7d
xuelang201201/FluentPython
/14_可迭代的对象、迭代器和生成器/fp_19_组合学生成器函数会从输入的各个元素中产出多个值.py
898
3.78125
4
import itertools # 'ABC' 中每两个元素(len()==2)的各个组合;在生成的元组中,元素的顺序无关紧要(可以视作集合)。 print(list(itertools.combinations('ABC', 2))) # [('A', 'B'), ('A', 'C'), ('B', 'C')] # 'ABC' 中每两个元素(len()==2)的各种组合,包含相同元素的组合。 print(list(itertools.combinations_with_replacement('ABC', 2))) # [('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'B'), ('B',...
b282ba54703d292c9d9a30aebdcf88913905b2a5
xuelang201201/FluentPython
/02_数据结构/fp_13_一个包含3个列表的列表,嵌套的3个列表各自有3个元素来代表井字游戏的一行方块.py
589
4.125
4
# 建立一个包含3个列表的列表,被包含的3个列表各自有3个元素。打印出这个嵌套列表。 board = [['_'] * 3 for i in range(3)] print(board) # 把第1行第2列的元素标记为 X,再打印出这个列表。 board[1][2] = 'X' print(board) # 等同于 board = [] for i in range(3): # 每次迭代中都新建了一个列表,作为新的一行(row)追加到游戏板(board)。 row = ['_'] * 3 board.append(row) print(board) board[2][0] = '...
f6af76b3dd4fadc0d4f6e0633a51f307524f5ecd
xuelang201201/FluentPython
/08_对象引用、可变性和垃圾回收/fp_04_alex与charles比较的结果相等但alex不是charles.py
678
3.625
4
""" 每个变量都有标识、类型和值。对象一旦创建,它的标识绝不会变;你可以把标识理解为对象在内存中的地址。 is 运算符比较两个对象的标识;id() 函数返回对象表示的整数表示。 """ from fp_03_charles和lewis指代同一个对象 import charles alex = {'name': 'Charles L. Dodgson', 'born': 1832, 'balance': 950} # alex 指代的对象与赋值给 charles 的对象内容一样。 print(alex == charles) # 比较两个对象,结果相等,这是因为 dict 类的 __eq__ 方法就是这样实现的。 print(...
d4a34a235e1ceacf6f84c10ef787c6e46ebdeaa7
xuelang201201/FluentPython
/16_协程/fp_09_coroaverager2.py
1,585
3.921875
4
# 定义一个求平均值的协程,让它返回一个结果 """ 说明 averager 行为的 doctest >>> coro_avg = averager() >>> next(coro_avg) >>> coro_avg.send(10) # <1>这一版不产出值。 >>> coro_avg.send(30) >>> coro_avg.send(6.5) # <2>发送 None 会终止循环,导致协程结束,返回结果。一如既往,生成器对象会 # 抛出 StopIteration 异常。异常对象的 value 属性保存着返回的值。 >>> coro_avg.send(No...
7d16bbe1cd82314c4e932b7d4a0035382341e164
xuelang201201/FluentPython
/02_数据结构/fp_04_使用列表推导计算笛卡儿积.py
557
3.828125
4
colors = ['black', 'white'] sizes = ['S', 'M', 'L'] # 这里得到的结果是先以颜色排列,再以尺码排列 t_shirts = [(color, size) for color in colors for size in sizes] print(t_shirts) # 注意,这里两个循环的嵌套关系和上面列表推导中 for 从句的先后顺序一样 for color in colors: for size in sizes: print((color, size)) # 如果想依照先尺码后颜色的顺序来排列,只需要调整从句的顺序 t_shir...
c56d513e3e9ba8a7951cf3ceebaffa8cfe33f94b
xuelang201201/FluentPython
/03_字典和集合/fp_01_泛映射类型.py
687
3.6875
4
""" collections.abc 模块中有 Mapping 和 MutableMapping 这两个抽象基类, 它们的作用是为 dict 和其他类似的类型定义形式接口。这些抽象基类的主要 作用是作为形式化的文档,它们定义了构建一个映射类型所需要的最基本的接口。 然后它们还可以跟 instance 一起被用来判定某个数据是不是广义上的映射类型。 """ from collections import abc my_dict = {} # 用 instance 而不是 type 来检查某个参数是否为 dict 类型, # 因为这个参数有可能不是 dict,而是一个比较另类的映射类型 print(isinstance(my_di...
d9384ad6ce2365fe49d22ee161da8cdf2dc70792
xuelang201201/FluentPython
/02_数据结构/fp_21_一个浮点型数组的创建、存入文件和从文件读取的过程.py
1,077
3.5625
4
# 如果我们需要一个只包含数字的列表,那么 array.array 比 list 更高效。数组支持所有跟 # 可变序列有关的操作,包括 .pop、.insert 和 .extend。另外,数组还提供从文件读取和存 # 入文件的更快方法,如 .frombytes 和 .tofile。 from array import array # 引入 array 类型 from random import random # 利用一个可迭代对象来建立一个双精度浮点数组(类型码是'd'), # 这里我们用的可迭代对象是一个生成器表达式。 floats = array('d', (random() for i in range...
6513e31ba36626776feed28477af37202b8aafbe
jvmoraisr6597/Projeto01_AlgoProg
/Labirinto/main.py
3,652
3.5625
4
import time score = 0 def primeiraDecisao(fpath): f = open(fpath + "primeiraDecisao.txt", "r") escolha = input("\n" + f.read()) if escolha == "a": print("\nVocê caminha, então, à direita, adentrando uma sala cuja porta se fecha em seguida, tornando impossível uma possibilidade de retorno. O prim...
77ad8ddbd26a3666f68dcb44df09a7a9e6fde06b
s3cur3/SimulateGeneticDrift3Alleles
/team_2_settings.py
1,595
3.5
4
""" This file is used to set the parameters for the genetic drift modeler. It's pure Python, so if you want to use some complex functions to define your parameters, you can. Young, Gibson, Jennings, and Smith """ # The fixed number of individuals in the population at each generation popSize = (43+40+1...
e9df8d956ddbb574787e33f7c7af6bd99861c47d
sahilrupani/CN-file
/chatClient.py
1,210
3.71875
4
# Python program to implement client side of chat room. import socket import select import sys s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) IP_address = '127.0.0.1' Port = 12345 s.connect((IP_address, Port)) while True: # maintains a list of po...
3241187af39f7e9740dd4d7a5f4db54b5a52fe8e
lukipro/foobar
/elevators.py
945
3.671875
4
#!/usr/local/bin/python2 def sorted_by(a,b): a = a.split('.') if len(a) == 2: a = list(a) a.append(-1) if len(a) == 1: a = list(a) a.append(-1) a.append(-1) b = b.split('.') if len(b) == 2: b = list(b) b.append(-1) if len(b) == 1: ...
af5c63efc65dc1c5da1d574014a9197cc368b978
sfwan2014/Python-
/thread.py
3,166
4.1875
4
#!/usr/bin/python # -*- coding: UTF-8 -*- import thread import time import threading """ # 为线程定义一个函数 def print_time(threadName, delay): count = 0 while count < 5: time.sleep(delay) count += 1 print "%s: %s" % (threadName, time.ctime(time.time())) # 创建两个线程 try: thread.start_new_thre...
67cfb8b22f3b068ba1ef9d88765fbee1192d23e0
DanteZMedina/Python_Basico
/Conversor de Monedas/conversor de monedas.py
1,355
4.03125
4
menu = """ Bienvenido al conversor de monedas 👌👌 1 - Pesos Colombianos 2 - Pesos Argentinos 3 - Pesos Mexicanos Elige una opcion: """ def conversion(tipo_pesos, valor_dolar): pesos = float(input ("Ingrese los pesos " + tipo_pesos + " a cambiar: \n")) dolares = pesos / valor_dolar dolares = round(dol...
9ef906ae918956dbdb2f48ea660293284b719a94
asselapathirana/pythonbootcamp
/2023/day3/es_1.py
2,425
4.34375
4
import numpy as np """Fitness function to be minimized. Example: minimize the sum of squares of the variables. x - a numpy array of values for the variables returns a single floating point value representing the fitness of the solution""" def fitness_function(x): return np.sum(x**2) # Example: minimiz...
6c375d41e8430694404a45b04819ef9e725db959
asselapathirana/pythonbootcamp
/archives/2022/day1/quad.py
781
4.15625
4
# first ask the user to enter three numbers a,b,c # user input is taken as string(text) in python # so we need to convert them to decimal number using float a = float(input('Insert a value for variable a')) b = float(input('Insert a value for variable b')) c = float(input('Insert a value for variable c')) # now print ...
cddcfc2c1a2d3177bcf784c7a09fd3fb1f2a69ec
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 1/Problem/Mathematics/Exactly 3 Divisors.py
1,438
4.25
4
Exactly 3 Divisors Given a positive integer value N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3. Example 1: Input: N = 6 Output: 1 Explanation: The only number with 3 divisor is 4. Example 2: Input: N = 10 Output: 2 Explanation...
519a1790c47049f2f6a47a6362d45a6821c3252b
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 3/Strings/Problems/Convert to Roman No.py
1,354
4.3125
4
Convert to Roman No Given an integer n, your task is to complete the function convertToRoman which prints the corresponding roman number of n. Various symbols and their values are given below. I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Example 1: Input: n = 5 Output: V Example 2: Input: n =...
dab1464351b112f48570a5bf6f23c42912163925
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 9/Heap/Problems/Nearly sorted.py
2,018
4.1875
4
Nearly sorted Given an array of n elements, where each element is at most k away from its target position, you need to sort the array optimally. Example 1: Input: n = 7, k = 3 arr[] = {6,5,3,2,8,10,9} Output: 2 3 5 6 8 9 10 Explanation: The sorted array will be 2 3 5 6 8 9 10 Example 2: Input: n = 5...
741480f8b2500ef939b9951b4567f5b16172379a
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 1/Problem/Arrays/Find Transition Point.py
1,237
4.1875
4
Find Transition Point Given a sorted array containing only 0s and 1s, find the transition point. Example 1: Input: N = 5 arr[] = {0,0,0,1,1} Output: 3 Explanation: index 3 is the transition point where 1 begins. Example 2: Input: N = 4 arr[] = {0,0,0,0} Output: -1 Explanation: Since, there i...
b874b3db65ef90aa8fb37867bb5f2d0eed80b4d4
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 1/Problem/Mathematics/GP Term.py
1,519
4.09375
4
GP Term Given the first 2 terms A and B of a Geometric Series. The task is to find the Nth term of the series. Example 1: Input: A = 2 B = 3 N = 1 Output: 2 Explanation: The first term is already given in the input as 2 Example 2: Input: A = 1 B = 2 N = 2 Output: 2 Explanation: Common ratio = ...
b967c230a11ad2967de5ebea92f93fe41275a1fe
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 4/Linked LIst/Add two numbers represented by linked lists.py
3,719
4.09375
4
Add two numbers represented by linked lists Given two numbers represented by two linked lists of size N and M. The task is to return a sum list. The sum list is a linked list representation of the addition of two input numbers. Example 1: Input: N = 2 valueN[] = {4,5} M = 3 valueM[] = {3,4,5} Output: 3 9 ...
0e9e0bab41e6810a4b6c41d69ae01df699977570
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 3/Matrix/Transpose of Matrix.py
1,798
4.59375
5
Transpose of Matrix Write a program to find the transpose of a square matrix of size N*N. Transpose of a matrix is obtained by changing rows to columns and columns to rows. Example 1: Input: N = 4 mat[][] = {{1, 1, 1, 1}, {2, 2, 2, 2} {3, 3, 3, 3} {4, 4, 4, 4}} Output: ...
48c9c87ca2976207c5f379fd9b42df86faa877b5
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 4/Linked LIst/Reverse a Linked List in groups of given size.py
2,725
4.25
4
Reverse a Linked List in groups of given size. Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list. Example 1: Input: LinkedList: 1->2->2->4->5->6->7->8 K = 4 Output: 4 2 2 1 8 7 6 5 Explanation: The first 4 elements 1,2,2,4 are r...
b1acad41a07b4a5a1b38fdad15619ebeec5dd70d
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 3/Bit Magic/Rightmost different bit.py
1,708
4.15625
4
Rightmost different bit Given two numbers M and N. The task is to find the position of the rightmost different bit in the binary representation of numbers. Example 1: Input: M = 11, N = 9 Output: 2 Explanation: Binary representation of the given numbers are: 1011 and 1001, 2nd bit from right is differen...
27f267d66c25e89ed823ddd1f003b33fe09cc3cc
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 1/Problem/Arrays/Remove duplicate elements from sorted Array.py
1,554
4.1875
4
Remove duplicate elements from sorted Array Given a sorted array A of size N, delete all the duplicates elements from A. Example 1: Input: N = 5 Array = {2, 2, 2, 2, 2} Output: 2 Explanation: After removing all the duplicates only one instance of 2 will remain. Example 2: Input: N = 3 Array = ...
b1e346a2c9f70f2bb1aec43034e8803d25b27159
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 8/Trees/Check if Tree is Isomorphic.py
4,358
4.3125
4
Check if Tree is Isomorphic Given two Binary Trees. Check whether they are Isomorphic or not. Example 1: Input: T1 1 T2: 1 / \ / \ 2 3 3 2 / / 4 4 Output: No Example 2: Input: T1 1 T2: 1 / \ / \ 2 3 3 2 /...
4a44a1c4851060d4114ea4ae3d509800781378e0
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 3/Strings/Problems/Longest Substring Without Repeating Characters.py
2,507
4.125
4
Longest Substring Without Repeating Characters Given a string S, find the length of its longest substring that does not have any repeating characters. Example 1: Input: S = geeksforgeeks Output: 7 Explanation: The longest substring without repeated characters is "ksforge". Example 2: Input: S = abbcd...
e101fcad48330d468664dbe3d69a8ebf923454db
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 3/Strings/Problems/Longest Palindrome Substring.py
4,664
4.09375
4
Longest Palindrome Substring Given a string S of length N, find the longest palindromic substring in S. Substring of string S: S[ i . . . . j ] where 0 ≤ i ≤ j < len(S). Palindrome string: A string which reads the same backwards. More formally, S is palindrome if reverse(S) = S. Incase of conflict, return the subst...
ad0f8db650e5bca1db6d63d96eaa8f0d80bf6cd7
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week_10/Greedy/Huffman Decoding.py
5,319
3.875
4
Huffman Decoding Given a encoded binary string and a Huffman MinHeap tree, your task is to complete the function decodeHuffmanData(), which decodes the binary encoded string and return the original string. Note: Each node of the min heap contains 2 data members, a character and an integer to denote its frequenc...
a32f144ec3a7a6b162f3c8142d3ab61cc5cf28d8
Harini-Pavithra/GFG-11-Week-DSA-Workshop
/Week 2/Searching and Sorting/Search in a Sorted and Rotated Array.py
1,155
4.0625
4
Search in a Sorted and Rotated Array Given a sorted and rotated array A of N distinct elements which is rotated at some point, and given an element K. The task is to find the index of the given element K in the array A. Example 1: Input: N = 9 A[] = {5 6,7,8,9,10,1,2,3} K = 10 Output: 5 Explanation: 10 i...