blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
3ac26042891246dead71c85f0fd59f5f7316a516 | akhilpgvr/HackerRank | /iterative_factorial.py | 408 | 4.25 | 4 | '''
Write a iterative Python function to print the factorial of a number n (ie, returns n!).
'''
usersnumber = int(input("Enter the number: "))
def fact(number):
result = 1
for i in range(1,usersnumber+1):
result *= i
return result
if usersnumber == 0:
print('1')
elif usersnumber < 0:
print(... | true |
a412e958ac2c18dd757f6b5a3e91fd897eda6658 | akhilpgvr/HackerRank | /fuzzbuzz.py | 435 | 4.1875 | 4 | '''
Write a Python program to print numbers from 1 to 100 except for multiples of 3
for which you should print "fuzz" instead, for multiples of 5 you should print
'buzz' instead and for multiples of both 3 and 5, you should print 'fuzzbuzz' instead.
'''
for i in xrange(1,101):
if i % 15 == 0:
print 'fuzzb... | true |
0cacf9f1b270d2814847c7d4091de5592bc47bad | SherriChuah/google-code-sample | /python/src/playlists.py | 1,501 | 4.1875 | 4 | """A playlists class."""
"""Keeps the individual video playlist"""
from .video_playlist import VideoPlaylist
class Playlists:
"""A class used to represent a Playlists containing video playlists"""
def __init__(self):
self._playlist = {}
def number_of_playlists(self):
return len(self._playlist)
def get_all_p... | true |
861ada8af86a6060dfc173d19e0364e2132a447e | DataActivator/Python3tutorials | /Decisioncontrol-Loop/whileloop.py | 944 | 4.21875 | 4 | '''
A while loop implements the repeated execution of code based on a given Boolean condition.
while [a condition is True]:
[do something]
As opposed to for loops that execute a certain number of times, while loops are conditionally based
so you don’t need to know how many times to repeat the code going in.
'''
... | true |
7646890051144b6315cd22fd1b5e04a44d9b266a | jabedude/python-class | /projects/week3/jabraham_guessing.py | 1,625 | 4.1875 | 4 | #!/usr/bin/env python3
'''
This program is an implementation of the "High-Low Guessing Game".
The user is prompted to guess a number from 1 to 100 and the
program will tell the user if the number is greater, lesser, or
equal to the correct number.
'''
from random import randint
def main():
'''
This function i... | true |
fcdebbb78ba2d4c5b41967801b0d537c35e85c3a | jabedude/python-class | /chapter5/ex6.py | 384 | 4.125 | 4 | #!/usr/bin/env python3
def common_elements(list_one, list_two):
''' returns a list of common elements between list_one and list_two '''
set_one = set(list_one)
set_two = set(list_two)
return list(set_one.intersection(set_two))
test_list = ['a', 'b', 'c', 'd', 'e']
test_list2 = ['c', 'd', 'e', 'f', ... | true |
53c1ca380af737aabe9ce0e265b18011a3e290a2 | jabedude/python-class | /chapter9/ex4.py | 655 | 4.3125 | 4 | #!/usr/bin/env python3
''' Code for exercise 4 chapter 9 '''
import sys
def main():
'''
Function asks user for two file names and copies the first to the second
'''
if len(sys.argv) == 3:
in_name = sys.argv[1]
out_name = sys.argv[2]
else:
in_name = input("Enter the name of ... | true |
4bfff67203f0ab60a696bdb49cbc00de7db79767 | govindak-umd/Data_Structures_Practice | /LinkedLists/singly_linked_list.py | 2,864 | 4.46875 | 4 | """
The code demonstrates how to write a code for defining a singly linked list
"""
# Creating a Node Class
class Node:
# Initialize every node in the LinkedList with a data
def __init__(self, data):
# Each of the data will be stored as
self.data = data
# This is very important becaus... | true |
dc8e36cdd048bcff0c3bfaa69c71923fd53ec7bc | pgrandhi/pythoncode | /Assignment2/2.VolumeOfCylinder.py | 367 | 4.15625 | 4 | #Prompt the use to enter radius and length
radius,length = map(float, input("Enter the radius and length of a cylinder:").split(","))
#constant
PI = 3.1417
def volumeOfCylinder(radius,length):
area = PI * (radius ** 2)
volume = area * length
print("The area is ", round(area,4), " The volume is ", round(vo... | true |
670e2caa200e7b81c4c67abe0e8db28c9d3bce5d | pgrandhi/pythoncode | /Class/BMICalculator.py | 584 | 4.3125 | 4 | #Prompt the user for weight in lbs
weight = eval(input("Enter weight in pounds:"))
#Prompt the user for height in in
height = eval(input("Enter height in inches:"))
KILOGRAMS_PER_POUND = 0.45359237
METERS_PER_INCH = 0.0254
weightInKg = KILOGRAMS_PER_POUND * weight
heightInMeters = METERS_PER_INCH * height
#Compute ... | true |
7b8241125841ad4f17077ed706af394576f6a0dc | briand27/LPTHW-Exercises | /ex20.py | 1,172 | 4.15625 | 4 | # imports System
from sys import argv
# creates variables script and input_file for arguments
script, input_file = argv
# define a function that takes in a file to read
def print_all(f):
print f.read()
# define a function that takes in a file to seek
def rewind(f):
f.seek(0)
# defines a function that prints... | true |
03389bd8ab6b7f1a14d681c6f209c264e2e27aad | mlbudda/Checkio | /o_reilly/index_power.py | 440 | 4.15625 | 4 | # Index Power
def index_power(array: list, n: int) -> int:
"""
Find Nth power of the element with index N.
"""
try:
return array[n] ** n
except IndexError:
return -1
# Running some tests..
print(index_power([1, 2, 3, 4], 2) == 9, "Square")
print(index_power([1, 3, 10, 100], 3)... | true |
473d7d7500ffc160f056d661b0ef8a1d297a84a7 | mnsupreme/artificial_intelligence_learning | /normal_equation.py | 2,911 | 4.3125 | 4 | #This code solves for the optimum values of the parameters analytically using calculus.
# It is an alternative way to optimizing iterarively using gradient descent. It is usually faster
# but is much more computationally expensive. It is good if you have 1000 or less parameters to solve for.
# complexity is O(n^3)
# ... | true |
ef2fb36ea0588d36aa6b49ad55d57ee4a5d64bc0 | dguest/example-text-parser | /look.py | 1,851 | 4.15625 | 4 | #!/usr/bin/env python3
import sys
from collections import Counter
from csv import reader
def run():
input_name = sys.argv[1]
csv = reader(open(input_name), skipinitialspace=True)
# first read off the titles
titles = next(csv)
indices = {name:number for number, name in enumerate(titles)}
# ke... | true |
21ebaf035e0a5bda9b9836a8c77221f20c9f4388 | timomak/CS-1.3 | /First try 😭/redact_problem.py | 692 | 4.21875 | 4 | def reduct_words(given_array1=[], given_array2=[]):
"""
Takes 2 arrays.
Returns an array with the words from the first array, that were not present in the second array.
"""
output_array = [] # Array that is gonna be returned
for word in given_array1: # For each item in the first array, ... | true |
dfa668f57584dc42dbc99c5835ebc0a5c0b1e0cd | avir100/ConsultAdd | /task2/task2_10.py | 815 | 4.125 | 4 | from random import randint
'''
Write a program that asks five times to guess the lucky number. Use a while loop and a counter, such as
counter=1
While counter <= 5:
print(“Type in the”, counter, “number”
counter=counter+1
The program asks for five guesses (no matter whether the correct number was ... | true |
8fdb362aa4fb0de01b740a5a840904bf329b5f22 | lzeeorno/Python-practice175 | /terminal&py.py | 696 | 4.125 | 4 | #how to use python in terminal
def main():
while True:
s = input('do you come to learn how to open py doc in terminal?(yes/no):')
if s.lower() == 'yes':
print('cd use to enter doc, ls to look the all file, python filename.py to open the py document')
s1 = input('do you unders... | true |
5952daff834f8f713be39ef520f25d896034a006 | sahthi/backup2 | /backup_files/practice/sample/exp.py | 374 | 4.125 | 4 | import math
x=[10,-5,1.2,'apple']
for i in x:
try:
fact=math.factorial(i)
except TypeError:
print("factorial is not supported for given input:")
except ValueError:
print ("factorial only accepts positive integers")
else:
print ("factorial of a", x, "is",fact)
fin... | true |
b3b0800b6add715999684c41393d1df9a636459d | All-I-Do-Is-Wynn/Python-Codes | /Codewars_Challenges/get_sum.py | 547 | 4.28125 | 4 | # Given two integers a and b, which can be positive or negative,
# find the sum of all the integers between and including them and return it.
# If the two numbers are equal return a or b.
# Note: a and b are not ordered!
def get_sum(a,b):
sum = 0
if a < b:
for x in range(a,b+1):
sum += x
... | true |
15fdbc037475927e58bf3b36a60c5cffc95264bc | rayvantsahni/after-MATH | /Rotate a Matrix/rotate_matrix.py | 1,523 | 4.40625 | 4 | def rotate(matrix, n, d):
while n:
matrix = rotate_90_clockwise(matrix) if d else rotate_90_counter_clockwise(matrix)
n -= 1
return matrix
def rotate_90_counter_clockwise(matrix):
"""
The function rotates any square matrix by 90° counter clock-wise.
"""
for row in matrix:
... | true |
c6d2d5095d319fdfe43ad2dc712cd97cbe44cb9e | rohit-kuma/Python | /List_tuples_set.py | 1,822 | 4.1875 | 4 | courses = ["history", "maths", "hindi"]
print(courses)
print(len(courses))
print(courses[1])
print(courses[-1])
print(courses[0:2])
courses.append("art")
courses.insert(1, "Geo")
courses2 = ["Art", "Education"]
print(courses)
#courses.insert(0, courses2)
#print(courses)
courses2.extend(courses)
print(courses2)
print(co... | true |
598a1c47c454c6e31408824cdec50d9d4a262cef | mswinkels09/Critters_Croquettes_server | /animals/petting_animals.py | 2,463 | 4.3125 | 4 | # import the python datetime module to help us create a timestamp
from datetime import date
from .animals import Animal
from movements import Walking, Swimming
# Designate Llama as a child class by adding (Animal) after the class name
class Llama(Animal):
# Remove redundant properties from Llama's initialization,... | true |
c27892b565bb1731b02f2fa7f6258419bad34edd | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day42_RedactText.py | 1,421 | 4.6875 | 5 |
# Day 42 Challenge: Redacting Text in a File
# Sensitive information is often removed, or redacted, from documents before they are released to the public.
# When the documents are released it is common for the redacted text to be replaced with black bars. In this exercise
# you will write a program that redacts all ... | true |
dc24942f5115667462dd5c11064d903c92d38825 | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day67_LastlineFile.py | 553 | 4.46875 | 4 | # Day 67 Challenge: Print last Line of a File.
# Function iterates over lines of file, store each line in lastline.
# When EOF, the last line of file content is stored in lastline variable.
# Print the result.
def get_final_line(fname):
fhand = open(fname, "r")
for line in fhand:
fhand = line.rstrip()... | true |
ec508478bbd76531f1ef8e2a7a849254092cb3e4 | Uma-Ravi22/Bertelsmann-Technology-Scholarship-Python-Challenges | /Day45_RecurStr.py | 689 | 4.28125 | 4 | # Day 45: Recursive (String) Palindrome
def Palindrome(s):
# If string length < 1, return TRUE.
if len(s) < 1:
return True
else:
# Last letter is compared with first, function called recursively with argument as
# Sliced string (With first & last character removed.)
if s[0... | true |
1645420882248e7ffa84200b538f9294884da028 | jmohit13/Algorithms-Data-Structures-Misc-Problems-Python | /data_structures/queue.py | 1,719 | 4.25 | 4 | # Queue Implementation
import unittest
class Queue:
"""
Queue maintain a FIFO ordering property.
FIFO : first-in first-out
"""
def __init__(self):
self.items = []
def enqueue(self,item):
"""
Adds a new item to the rear of the queue.
... | true |
1a6b2d6da21f7e87c107dd45b2ffeec143c2aef6 | nivetha-ashokkumar/python-basics | /factorial.py | 459 | 4.125 | 4 | def factorial(number1, number2):
temp = number1
number1 = number2
number2 = temp
return number1, number2
number1 = int(input("enter first value:"))
number2 = int(input("enter second vakue:"))
result = factorial(nnumber1, number2)
print("factorial is:", result)
def check(result):
if(result != int... | true |
231490f1ba7aa8be510830ec4a16568b5e4b2adb | THUEishin/Exercies-from-Hard-Way-Python | /exercise15/ex15.py | 503 | 4.21875 | 4 | '''
This exercise is to read from .txt file
Pay attention to the operations to a file
Namely, close, read, readline, truncate, write(" "), seek(0)
'''
from sys import argv
script, filename = argv
txt = open(filename)
print(f"Here is your file {filename}")
#readline() is to read a line from the file
#strip(*) is to ... | true |
5cfafd423c1d2d315dadc17c6796ec3cc860dad4 | aav789/pengyifan-leetcode | /src/main/python/pyleetcode/keyboard_row.py | 1,302 | 4.4375 | 4 | """
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American
keyboard like the image below.
Example 1:
Input: ["Hello", "Alaska", "Dad", "Peace"]
Output: ["Alaska", "Dad"]
Note:
- You may use one character in the keyboard more than once.
- You ... | true |
98ca0cf6d09b777507091ea494f28f756f6ca1e1 | aav789/pengyifan-leetcode | /src/main/python/pyleetcode/Reverse_Words_in_a_String_III.py | 682 | 4.40625 | 4 | """
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not... | true |
1af36f5047e5ed15218cdc84f3b2bc9ea77bc57c | faridmaamri/PythonLearning | /PCAP_Lab Palindromes_method2.py | 1,052 | 4.34375 | 4 | """
EDUB_PCAP path: LAB 5.1.11.7 Plaindromes
Do you know what a palindrome is?
It's a word which look the same when read forward and backward. For example, "kayak" is a palindrome, while "loyal" is not.
Your task is to write a program which:
asks the user for some text;
checks whether the entered text is a ... | true |
7a7e4c2393928ca31e584f184f4a6c51689a42c5 | DominiqueGregoire/cp1404practicals | /prac_04/quick_picks.py | 1,351 | 4.4375 | 4 | """asks the user how many "quick picks" they wish to generate. The program then generates that
many lines of output. Each line consists of 6 random numbers between 1 and 45.
pseudocode
get number of quick picks
create a list to hold each quick pick line
generate a random no x 6 to make the line
print the line
repeat th... | true |
b78ec391ca8bbc6943de24f6b4862c8793e3cc14 | cat-holic/Python-Bigdata | /03_Data Science/2.Analysis/3.Database/2.db_insert_rows.py | 1,218 | 4.375 | 4 | # 목적 : 테이블에 새 레코드셋 삽입하기
import csv
import sqlite3
# Path to and name of a CSV input file
input_file = "csv_files/supplier_data.csv"
con = sqlite3.connect('Suppliers.db')
c = con.cursor()
create_table = """CREATE TABLE IF NOT EXISTS Suppliers(
Supplier_Name VARCHAR(20),
Invoic... | true |
e84ee8da19f091260bef637a5d7104b383f981a5 | apriantoa917/Python-Latihan-DTS-2019 | /LOOPS/loops - pyramid block.py | 366 | 4.28125 | 4 | # 3.1.2.14 LAB: Essentials of the while loop
blocks = int(input("Enter the number of blocks: "))
height = 0
layer = 1
while layer <= blocks:
blocks = blocks - layer #jumlah blok yang disusun pada setiap layer , 1,2,3...
height += 1 #bertambah sesuai pertambahan layer
layer += 1
... | true |
02fc00ec75f78c552b47cf4376c8d655b1012cc6 | apriantoa917/Python-Latihan-DTS-2019 | /LOOPS/loops - the ugly vowel eater.py | 282 | 4.21875 | 4 | # 3.1.2.10 LAB: The continue statement - the Ugly Vowel Eater
userWord = input("Enter the word : ")
userWord = userWord.upper()
for letter in userWord :
if (letter == "A" or letter == "I" or letter == "U" or letter == "E" or letter == "O"):
continue
print(letter) | true |
83c51994945f1fc21ad3cd97c257143b23604909 | LukaszRams/WorkTimer | /applications/database/tables.py | 1,559 | 4.15625 | 4 | #!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This file will store the data for the database queries that will be called to create the database
"""
# Table of how many hours an employee should work per month
class Monthly_working_time:
table_name = "MONTHLY_WORKING_TIME"
data = {
"id": ("integer", "... | true |
928511975d3b85c7be7ed6c11c63ce33078cc5a1 | Silentsoul04/FTSP_2020 | /Python_CD6/reverse.py | 874 | 4.25 | 4 | # -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 11:41:04 2020
@author: Rajesh
"""
"""
Name:
Reverse Function
Filename:
reverse.py
Problem Statement:
Define a function reverse() that computes the reversal of a string.
Without using Python's inbuilt function
Take input from User
Sample I... | true |
953ebb6e03cbac2798978798127e144ac2eee85f | Silentsoul04/FTSP_2020 | /Python_CD6/generator.py | 930 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 17:46:18 2020
@author: Rajesh
"""
"""
Name:
generator
Filename:
generator.py
Problem Statement:
This program accepts a sequence of comma separated numbers from user
and generates a list and tuple with those numbers.
Data:
Not required
E... | true |
7ad064ce2fc4150f351ef3ce360dd3d7230a34f6 | Silentsoul04/FTSP_2020 | /Python_CD6/weeks.py | 2,024 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Wed Jan 22 17:01:28 2020
@author: Rajesh
"""
"""
Name:
weeks
Filename:
weeks.py
Problem Statement:
Write a program that adds missing days to existing tuple of days
Sample Input:
('Monday', 'Wednesday', 'Thursday', 'Saturday')
Sample Output:
('Monday... | true |
ce643b9df8113ce2ea53623aecf9d548398eea7e | Silentsoul04/FTSP_2020 | /Durga Strings Pgms/Words_Str_Reverse.py | 299 | 4.21875 | 4 | # WAP to print the words from string in reverse order and take the input from string.
# s='Learning Python is very easy'
s=input('Enter some string to reverse :')
l=s.split()
print(l)
l1=l[: :-1] # The Output will be in the form of List.
print(l1)
output=' '.join(l1)
s.count(l1)
print(output)
| true |
899db6e84ffad7514dbac57c7da77d04d78acb70 | Silentsoul04/FTSP_2020 | /Python_CD6/pangram.py | 1,480 | 4.3125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 17:37:41 2020
@author: Rajesh
"""
"""
Name:
Pangram
Filename:
pangram.py
Problem Statement:
Write a Python function to check whether a string is PANGRAM or not
Take input from User and give the output as PANGRAM or NOT PANGRAM.
Hint:
Pan... | true |
f35d17401b20f52dd943239a2c40cb251fa53d03 | jimkaj/PracticePython | /PP_6.py | 342 | 4.28125 | 4 | #Practice Python Ex 6
# Get string and test if palindrome
word = input("Enter text to test for palindrome-ness: ")
start = 0
end = len(word) - 1
while end > start:
if word[start] != word[end]:
print("That's not a palindrome!")
quit()
start = start + 1
end = end -1
print(word,"... | true |
668b160fffc014a4ef3996338f118fc9d4f1db6a | jimkaj/PracticePython | /PP_9.py | 782 | 4.21875 | 4 | # Practice Python #9
# Generate random number from 1-9, have use guess number
import random
num = random.randrange(1,10,1)
print('I have selected a number between 1 and 9')
print("Type 'exit' to stop playing")
count = 0
while True:
guess = input("What number have I selected? ")
if guess == 'exit':
... | true |
9749245820a806a3da1f256446398a3558cabc6a | darthlyvading/fibonacci | /fibonacci.py | 369 | 4.25 | 4 | terms = int(input("enter the number of terms "))
n1 = 0
n2 = 1
count = 0
if terms <= 0:
print("terms should be > 0")
elif terms == 1:
print("Fibonacci series of ",terms," is :")
print(n1)
else:
print("Fibonacci series is :")
while count < terms:
print(n1)
total = n1 + n2
... | true |
5c96d7745ba921694275a5369cc4993c6bb5d023 | inmank/SPOJ | /source/AddRev.py | 2,292 | 4.3125 | 4 | '''
Created on Jun 20, 2014
@author: karthik
The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies.
Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies.
Obviously, this work is very hard because the basic s... | true |
c95369771981b2f1a1c73b49a0156ede63aa3675 | ginalamp/Coding_Challenges | /hacker_rank/arrays/min_swaps.py | 1,383 | 4.34375 | 4 | '''
Given an unsorted array with consecutive integers, this program
sorts the array and prints the minimum amount of swaps needed
to sort the array
'''
def main(arr):
'''
@param arr - an array of consecutive integers (unsorted)
@return the minimum amount of swaps needed to sort the giv... | true |
340a802c8c77fdc2c4428926a8a2904fe8a388d0 | chirag111222/Daily_Coding_Problems | /Interview_Portilla/Search/sequential_seach.py | 513 | 4.15625 | 4 |
'''
Python => x in list --> How does it work?
Sequential Search
-----------------
'''
unorder = [4,51,32,1,41,54,13,23,5,2,12,40]
order = sorted(unorder)
def seq_search(arr,t):
found = False
for i in arr:
print(i)
if i == t:
found = True
return found
def ord_seq_search(arr... | true |
d9f9a0c1350d5d68c8e651a6c59b5f6cdd8bfbf1 | chirag111222/Daily_Coding_Problems | /DailyCodingProblem/201_max_path_sum.py | 1,816 | 4.125 | 4 |
'''
You are given an array of arrays of integers, where each array corresponds to a row in a triangle of numbers. For example, [[1], [2, 3], [1, 5, 1]] represents the triangle:
1
2 3
1 5 1
We define a path in the triangle to start at the top and go down one row at a time to an adjacent value,
eventually ending w... | true |
72cbfa9e3e72c688bf1f321b2e23d975f50fba79 | silvium76/coding_nomads_labs | /02_basic_datatypes/1_numbers/02_04_temp.py | 554 | 4.3125 | 4 | '''
Fahrenheit to Celsius:
Write the necessary code to read a degree in Fahrenheit from the console
then convert it to Celsius and print it to the console.
C = (F - 32) * (5 / 9)
Output should read like - "81.32 degrees fahrenheit = 27.4 degrees celsius"
'''
temperature_fahrenheit = int(input("Please enter th... | true |
e1b588a089bfc843ac186549b1763db5e55b70bd | umunusb1/PythonMaterial | /python3/02_Basics/02_String_Operations/f_palindrome_check.py | 621 | 4.46875 | 4 | #!/usr/bin/python3
"""
Purpose: Demonstration of Palindrome check
palindrome strings
dad
mom
Algorithms:
-----------
Step 1: Take the string in run-time and store in a variable
Step 2: Compute the reverse of that string
Step 3: Check whether both the strings are equal or not
Step 4: If equal, pr... | true |
4bfc733c59848c52302a52b5366704fbedce4c94 | umunusb1/PythonMaterial | /python3/04_Exceptions/13_custom_exceptions.py | 564 | 4.15625 | 4 | #!/usr/bin/python3
"""
Purpose: Using Custom Exceptions
"""
# creating a custom exception
class InvalidAge(Exception):
pass
try:
age = int(input('Enter your age:'))
age = abs(age)
if age < 18:
# raise InvalidAge('You are not eligible for voting')
raise InvalidAge(f'You are short by {18... | true |
e53448ad9ec7cd295a7570fc4e75187533c4c134 | umunusb1/PythonMaterial | /python3/10_Modules/03_argparse/a_arg_parse.py | 1,739 | 4.34375 | 4 | #!/usr/bin/python
"""
Purpose: importance and usage of argparse
"""
# # Method 1: hard- coding
# user_name = 'udhay'
# password = 'udhay@123'
# server_name = 'issadsad.mydomain.in'
# # Method 2: input() - run time
# user_name = input('Enter username:')
# password = input('Enter password:')
# server_name = input('Enter... | true |
2a202dd5ba552f4bda62adb4bfc92342d867d895 | umunusb1/PythonMaterial | /python2/04_Collections/01_Lists/02_lists.py | 1,791 | 4.59375 | 5 | #!/usr/bin/python
# -*- coding: utf-8 -*-
"""
List can be classified as single-dimensional and multi-dimensional.
List is representing using [].
List is a mutable object, which means elements in list can be changed.
It can store asymmetric data types
"""
numbers = [88, 99, 666]
# homogenous
print 'type(numbers)', ty... | true |
f74b9eacbdbf872d13578b2802622482f5cf0f28 | umunusb1/PythonMaterial | /python2/15_Regular_Expressions/re7/f1.py | 274 | 4.1875 | 4 | #!/usr/bin/python
import re
string = raw_input("please enter the name of the string:")
reg = re.compile('^.....$',re.DOTALL)
if reg.match(string):
print "our string is 5 character long - %s" %(reg.match(string).group())
else:
print "our string is not 5 characate long"
| true |
b6330d881e53e6df85ec6e4a3e31822d8166252e | umunusb1/PythonMaterial | /python2/07_Functions/practical/crazy_numbers.py | 832 | 4.65625 | 5 | #!python -u
"""
Purpose: Display the crazy numbers
Crazy number: A number whose digits are when raised to the power of the number of digits in that number and then added and if that sum is equal to the number then it is a crazy number.
Example:
Input: 123
Then, if 1^3 + 2^3 + 3^3 is equal to 123 then it is a crazy n... | true |
dedb7dacef7ef63861c76784fc7cff84cf8ca616 | umunusb1/PythonMaterial | /python3/10_Modules/09_random/04_random_name_generator.py | 775 | 4.28125 | 4 | from random import choice
def random_name_generator(first, second, x):
"""
Generates random names.
Arguments:
- list of first names
- list of last names
- number of random names
"""
names = []
for i in range(x):
names.append("{0} {1}".format(choice(fi... | true |
8f6d1952edb0858a9f9c9b96c6719a1dd5fcb6d2 | umunusb1/PythonMaterial | /python2/08_Decorators/06_Decorators.py | 941 | 4.59375 | 5 | #!/usr/bin/python
"""
Purpose: decorator example
"""
def addition(num1, num2):
print('function -start ')
result = num1 + num2
print('function - before end')
return result
def multiplication(num1, num2):
print('function -start ')
result = num1 * num2
print('function - before end')
ret... | true |
df4858753ba98281c0dcef4e1cfc795d3e153ae3 | OmishaPatel/Python | /miscalgos/reverse_integer.py | 391 | 4.125 | 4 | import math
def reverse_integer(x):
if x > 0:
x= str(x)
x = x[::-1]
x = int(x)
else:
x = str(-x)
x = x[::-1]
x = -1 * int(x)
if x <= math.pow(2, 31) -1 and x >= math.pow(-2,31):
return x
return 0... | true |
65ad7a18009d3595863f35760e7cc8f0ae78657d | OmishaPatel/Python | /datastructure/linked_list_insertion.py | 1,290 | 4.3125 | 4 | class Node:
def __init__(self,data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def print_list(self):
cur_node = self.head
while cur_node:
print(cur_node.data)
cur_node = cur_node.next
de... | true |
3683f4b62501faa80cb0a67e3979cabe0fdc7e54 | ingoglia/python_work | /part1/5.2.py | 1,063 | 4.15625 | 4 | string1 = 'ferret'
string2 = 'mouse'
print('does ferret = mouse?')
print(string1 == string2)
string3 = 'Mouse'
print('is a Mouse a mouse?')
print(string2 == string3)
print('are you sure? Try again')
print(string2 == string3.lower())
print('does 3 = 2?')
print(3 == 2)
print('is 3 > 2?')
print(3 > 2)
print('is 3 >= 2... | true |
ebf65f149efb4a2adc6ff84d1dce2d2f61004ce4 | ingoglia/python_work | /part1/8.8.py | 633 | 4.375 | 4 | def make_album(artist, album, tracks=''):
"""builds a dictionary describing a music album"""
if tracks:
music = {'artist': artist, 'album':album, 'number of tracks':tracks}
else:
music = {'artist': artist, 'album':album}
return music
while True:
print("\nPlease tell me an artist an... | true |
b4a24b3ca29f09229589a58abfa8f0c9c4f3a094 | marcellenoukimi/CS-4308-CPL-Assignment-3 | /Student.py | 2,681 | 4.34375 | 4 | """
Student Name: Marcelle Noukimi
Institution: Kennesaw State University
College: College of Computing and Software Engineering
Department: Department of Computer Science
Professor: Dr. Sarah North
Course Code & Title: CS 4308 Concepts of Programming Languages
Section 01 Fall 2021
Date: Oct... | true |
51e015545046b6411f88bcf969c22b69529464d3 | bigmoletos/WildCodeSchool_France_IOI-Sololearn | /soloearn.python/sololearn_pythpn_takeAshortCut_1.py | 1,353 | 4.375 | 4 | #Quiz sololearn python test take a shortcut 1
#https://www.sololearn.com/Play/Python
#raccouri level1
from _ast import For
x=4
x+=5
print (x)
#*************
print("test 2")
#What does this code do?
for i in range(10):
if not i % 2 == 0:
print(i+1)
#*************
print("test 3")
#What is the output of this c... | true |
da0cd5a8d5ed63e56893410eec04ab7eb3df7cff | ARCodees/python | /Calculator.py | 458 | 4.21875 | 4 | print("this is a calculator It does all oprations but only with 2 numbers ")
opration = input("Enter your opration in symbolic way ")
print("Enter Your first number ")
n1 = int(input())
print("Enter Your second number ")
n2 = int(input())
if opration == "+":
print(n1 + n2)
elif opration == "-":
pri... | true |
797cdc5d2c7d19a64045bc0fc1864fcefe0633b4 | carlmcateer/lpthw2 | /ex4.py | 1,065 | 4.25 | 4 | # The variable "car" is set to the int 100.
cars = 100
# The variable "space_in_a_car" is set to the float 4.0.
space_in_a_car = 4
# The variable "drivers" is set to the int 30.
drivers = 30
# The variable "passengers" is set to the int 90.
passengers = 90
# The variable cars_not_driven is set to the result of "cars" m... | true |
093233f29bfc50e37eb316fdffdf3a934aa5cea3 | manasjainp/BScIT-Python-Practical | /7c.py | 1,470 | 4.40625 | 4 | """
Youtube Video Link :- https://youtu.be/bZKs65uK1Eg
Create a class called Numbers, which has a single class attribute called
MULTIPLIER, and a constructor which takes the parameters x and y (these should
all be numbers).
i. Write a method called add which returns the sum of the attributes x and y.
ii. Write a class... | true |
d916840b3ec5c3efbb4ee0b1c1aea1ad42844d66 | omushpapa/minor-python-tests | /Large of three/large_ofThree.py | 778 | 4.40625 | 4 | #!/usr/bin/env python2
#encoding: UTF-8
# Define a function max_of_three()
# that takes three numbers as arguments
# and returns the largest of them.
def max_of_three(num1, num2, num3):
if type(num1) is not int or type(num2) is not int or type(num3) is not int:
return False
num_list = [num1, num2, n... | true |
e6134ced3a1fc1b67264040e64eba2af21ce8e1d | omushpapa/minor-python-tests | /List Control/list_controls.py | 900 | 4.15625 | 4 | #!/usr/bin/env python2
#encoding: UTF-8
# Define a function sum() and a function multiply()
# that sums and multiplies (respectively) all the numbers in a list of numbers.
# For example, sum([1, 2, 3, 4]) should return 10, and
# multiply([1, 2, 3, 4]) should return 24.
def sum(value):
if type(value) is no... | true |
6c58ca9f940f7ab15d3b99f27217b3bd485b01f9 | omushpapa/minor-python-tests | /Operate List/operate_list.py | 1,301 | 4.1875 | 4 | # Define a function sum() and a function multiply()
# that sums and multiplies (respectively) all the numbers in a list of numbers.
# For example, sum([1, 2, 3, 4]) should return 10,
# and multiply([1, 2, 3, 4]) should return 24.
def check_list(num_list):
"""Check if input is list"""
if num_list is Non... | true |
a193124758fc5b01168757d0f98cf67f9b98c664 | omushpapa/minor-python-tests | /Map/maps.py | 388 | 4.25 | 4 | # Write a program that maps a list of words
# into a list of integers representing the lengths of the correponding words.
def main():
word_list = input("Enter a list of strings: ")
if type(word_list) != list or len(word_list) == 0 or word_list is None:
print False
else:
print map... | true |
96f5fbe27bf7bd62b365d50f0266ce8297042094 | amanotk/pyspedas | /pyspedas/dates.py | 1,592 | 4.15625 | 4 | # -*- coding: utf-8 -*-
"""
File:
dates.py
Description:
Date functions.
"""
import datetime
import dateutil.parser
def validate_date(date_text):
# Checks if date_text is an acceptable format
try:
return dateutil.parser.parse(date_text)
except ValueError:
raise ValueError("Incorre... | true |
5e0ca56488a3cda328eb88bd0a1fdd7ba6cb2bb8 | sreckovicvladimir/hexocin | /sqlite_utils.py | 1,702 | 4.125 | 4 | import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
conn = None
try:
conn = sqlite3.connect(db_file)
ret... | true |
04da350a513c7cc103b948765a1a24b9864686e1 | JayHennessy/Stack-Skill-Course | /Python_Intro/pandas_tutorial.py | 631 | 4.28125 | 4 | # Python Pandas tutorial (stackSkill)
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
data = pd.read_csv('C:/Users/JAY/Desktop/Machine_Learning_Course/KaggleCompetions/titanic_comp/data/test.csv')
# shows data on screen
print(data.head())
data.tail()
#print the number of rows (incldu... | true |
f62bd2ec440e3929c5aee99d0b90fd726e3f3eff | aniket0106/pdf_designer | /rotatePages.py | 2,557 | 4.375 | 4 | from PyPDF2 import PdfFileReader,PdfFileWriter
# rotate_pages.py
"""
rotate_pages() -> takes three arguements
1. pdf_path : in this we have to pass the user pdf path
2. no_of_pages : in this we have to pass the number of pages we want to rotate if all then by
default it takes zero then we re-intialize it to total n... | true |
e340d8b94dc7c2f32e6591d847d8778ed5b5378b | liorkesten/Data-Structures-and-Algorithms | /Algorithms/Arrays_Algorithms/isArithmeticProgression.py | 666 | 4.3125 | 4 | def is_arithmetic_progression(lst):
"""
Check if there is a 3 numbers that are arithmetic_progression.
for example - [9,4,1,2] return False because there is not a sequence.
[4,2,7,1] return True because there is 1,4,7 are sequence.
:param lst: lst of diff integers
:return: True... | true |
6101f3df70700db06073fd8e3723dba00a02e9d9 | liorkesten/Data-Structures-and-Algorithms | /Algorithms/Arrays_Algorithms/BinarySearch.py | 577 | 4.21875 | 4 | def binary_search_array(lst, x):
"""
Get a sorted list in search if x is in the array - return true or false.
Time Complexity O(log(n))
:param lst: Sorted lst
:param x: item to find
:return: True or False if x is in the array
"""
if not lst:
return False
i... | true |
a0e52ed563d1f26e274ef1aece01794cce581323 | samanthaWest/Python_Scripts | /DataStructsAndAlgorithms/TwoPointersTechnique.py | 784 | 4.3125 | 4 | # Two Pointers
# https://www.geeksforgeeks.org/two-pointers-technique/
# Used for searching for pairs in a sorted array
# We take two pointers one representing the first element and the other representing the last element
# we add the values kept at both pointers, if their sum is smaller then target we shift left... | true |
9a02e277ab565469ef0d3b768b7c9a0c053c2545 | JamesRoth/Precalc-Programming-Project | /randomMulti.py | 554 | 4.125 | 4 | #James Roth
#1/31/19
#randomMulti.py - random multiplication problems
from random import randint
correctAns = 0
while correctAns < 5: #loop until 5 correct answers are guessed
#RNG
num1 = randint(1,10)
num2 = randint(1,10)
#correct answer
ans = num1*num2
#asking the user to give the answe... | true |
ddda27bf9906caf8916deb667639c8e4d052a05f | AXDOOMER/Bash-Utilities | /Other/Python/parse_between.py | 918 | 4.125 | 4 | #!/usr/bin/env python
# Copyright (c) Alexandre-Xavier Labonte-Lamoureux, 2017
import sys
import numbers
# Parser
def parse(textfile):
myfile = open(textfile, "r")
datastring = myfile.read()
first_delimiter = '\"'
second_delimiter = '\"'
index = 0
while(index < len(datastring)):
first = datastring.find(fir... | true |
49c33bb519c6142f0832435d2a66054baceadf1a | cmedinadeveloper/udacity-data-structures-algorithms-project1-unscramble | /Task1.py | 666 | 4.25 | 4 | """
Read file into texts and calls.
It's ok if you don't understand how to read files.
"""
import csv
phone_nums = []
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
for text in list(reader):
phone_nums.extend(text[:2])
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
for cal... | true |
f150c2160c0c5b910fde7e3a05c40fc26e3c213c | HopeFreeTechnologies/pythonbasics | /variables.py | 1,419 | 4.125 | 4 | #So this file has some examples of variables, how they work, and more than just one output (like hi there.py did).
#######################
#
#Below is a variable by the name vname. V for variable and name for, well name.
# Its my first ever variable in Python so by default it's awesome, so i let it know by giving it t... | true |
d22a954c0a50eb89bd5c24f37cf69a53462e1d0c | dinabseiso/HW01 | /HW01_ex02_03.py | 1,588 | 4.1875 | 4 | # HW01_ex02_03
# NOTE: You do not run this script.
# #
# Practice using the Python interpreter as a calculator:
# 1. The volume of a sphere with radius r is 4/3 pi r^3.
# What is the volume of a sphere with radius 5? (Hint: 392.7 is wrong!)
# volume: 523.3
r = 5
pi = 3.14
volume = (4 * pi * r**3) / 3
print(volume)
... | true |
b3c9b758ea0b683aa4762a1e8e30bfffb2074a00 | spsree4u/MySolvings | /trees_and_graphs/mirror_binary_tree.py | 877 | 4.21875 | 4 |
"""
Find mirror tree of a binary tree
"""
class Node:
def __init__(self, data):
self.data = data
self.left = self.right = None
def mirror(root):
if not root:
return
mirror(root.left)
mirror(root.right)
temp = root.left
root.left = root.right
root.right = temp
... | true |
f29923bcb48d0f6fd0ea61207249f57ca0a69c6a | spsree4u/MySolvings | /trees_and_graphs/post_order_from_pre_and_in.py | 1,526 | 4.21875 | 4 |
# To get post order traversal of a binary tree from given
# pre and in-order traversals
# Recursive function which traverse through pre-order values based
# on the in-order index values for root, left and right sub-trees
# Explanation in https://www.youtube.com/watch?v=wGmJatvjANY&t=301s
def print_post_order(start, ... | true |
965e5afce19c0ab3dcaf484bdafa554dd4d51e4d | spsree4u/MySolvings | /trees_and_graphs/super_balanced_binary_tree.py | 2,240 | 4.125 | 4 | """
Write a function to see if a binary tree is "super-balanced".
A tree is "super-balanced" if the difference between the depths of any two
leaf nodes is no greater than one.
Complexity
O(n) time and O(n) space.
"""
class Node:
def __init__(self, data):
self.data = data
self.left = None
... | true |
3e92fa31734cdd480a102553fda5134de7aed2ba | aryansamuel/Python_programs | /jumble.py | 819 | 4.375 | 4 | # Aryan Samuel
# arsamuel@ucsc.edu
# prgramming assignment 6
# The following program asks the user for a jumbled word,
# then unjumbles and prints it.
# Note: The unjumbled word should be in the dictionary that is read by the prog.
def main(file):
file = open(file,'r')
word_list = file.read().split()
... | true |
203e35f62d3a64a25c87b1f88f8ba9b7ad33c112 | Shobhits7/Programming-Basics | /Python/factorial.py | 411 | 4.34375 | 4 | print("Note that facotrial are of only +ve integers including zero\n")
#function of facorial
def factorial_of(number):
mul=1
for i in range(1,num+1):
mul=mul*i
return mul
#take input of the number
num=int(input("Enter the number you want the fatcorial of:"))
#executing the function
if num<0 ... | true |
e98f42af716c60f62e9929ed5fa9660b3a1d678a | Shobhits7/Programming-Basics | /Python/palindrome.py | 364 | 4.46875 | 4 | # First we take an input which is assigned to the variable "text"
# Then we use the python string slice method to reverse the string
# When both the strings are compared and an appropriate output is made
text=input("Enter the string to be checked: ")
palindrom_text= text[::-1]
if text==palindrom_text:
print("Pal... | true |
1b2ec70312c8bf5d022cf2832fb3dfbf93c0d0f2 | Shobhits7/Programming-Basics | /Python/fibonacci_series.py | 1,110 | 4.40625 | 4 | # given a variable n (user input), the program
# prints fibinacci series upto n-numbers
def fibonacci(n):
"""A simple function to print fibonacci sequence of n-numbers"""
# check if n is correct
# we can only allow n >=1 and n as an integer number
try:
n = int(n)
except ValueError:
... | true |
537bfed643c059426bc9303f369efb0e1a9cc687 | MS642/python_practice | /objects/objects.py | 1,445 | 4.28125 | 4 | class Line:
"""
Problem 1 Fill in the Line
class methods to accept coordinates as a pair of tuples and return the slope and distance of the line.
# EXAMPLE OUTPUT
coordinate1 = (3, 2)
coordinate2 = (8, 10)
li = Line(coordinate1, coordinate2)
li.distance()
... | true |
22202840ae1c77f10c7e1f301ec5c0262b92e4e3 | lucasflosi/Assignment2 | /nimm.py | 2,011 | 4.40625 | 4 | """
File: nimm.py
-------------------------
Nimm is a 2 player game where a player can remove either 1 or 2 stones. The player who removes the
last stone loses the game!
"""
STONES_IN_GAME = 20 #starting quantity for stones
def main():
stones_left = STONES_IN_GAME
player_turn = 1
while stones_left > 0:
... | true |
e6d7b94ab9ee72d64ee17dee3db7824653bd5c51 | mgyarmathy/advent-of-code-2015 | /python/day_12_1.py | 1,078 | 4.1875 | 4 | # --- Day 12: JSAbacusFramework.io ---
# Santa's Accounting-Elves need help balancing the books after a recent order. Unfortunately, their accounting software uses a peculiar storage format. That's where you come in.
# They have a JSON document which contains a variety of things: arrays ([1,2,3]), objects ({"a":1, "b"... | true |
040fcf183a0db97e0e341b7a3e9fec2f8adf24eb | BlueMonday/advent_2015 | /5/5.py | 1,778 | 4.15625 | 4 | #!/usr/bin/env python3
import re
import sys
VOWELS = frozenset(['a', 'e', 'i', 'o', 'u'])
NICE_STRING_MIN_VOWELS = 3
INVALID_SEQUENCES = frozenset(['ab', 'cd', 'pq', 'xy'])
def nice_string_part_1(string):
"""Determines if ``string`` is a nice string according to the first spec.
Nice strings contain at leas... | true |
10a4575fc55bc35c004b6ca826f7b50b9d269855 | jackedjin/README.md | /investment.py | 579 | 4.1875 | 4 | def calculate_apr():
"Calculates the compound interest of an initial investment of $500 for over 65 years"
principal=500
interest_rate=0.03
years=0
while years<65:
"While loop used to repeat the compounding effect of the investment 65 times"
principal=principal*(1+interest_rate)
"compound interest calculatio... | true |
f44cda077b7939465d6add8a9e845b3f72bc03c2 | NSLeung/Educational-Programs | /Python Scripts/python-syntax.py | 1,166 | 4.21875 | 4 | # This is how you create a comment in python
# Python equivalent of include statement
import time
# Statements require no semicolon at the end
# You don't specify a datatype for a variable
franklin = "Texas Instruments"
# print statement in python
print (franklin)
# You can reassign a variable any datat... | true |
dc7b6fdbee9d6a43089e7e1bccadd98deb2d7efc | Mezz403/Python-Projects | /LPTHW/ex16.py | 592 | 4.25 | 4 | from sys import argv # Unpack arguments entered by the user
script, filename = argv # unpack entered arguments into script and filename
txt = open(filename) # open the provided filename and assign to txt
print "Here's your file %r: " % filename # display filename to user
print txt.read() # print the contexts of the ... | true |
0b7f5b3f5e1b5e5d4bd88c37000bbfa0843af2bd | rachelsuk/coding-challenges | /compress-string.py | 1,129 | 4.3125 | 4 | """Write a function that compresses a string.
Repeated characters should be compressed to one character and the number of
times it repeats:
>>> compress('aabbaabb')
'a2b2a2b2'
If a character appears once, it should not be followed by a number:
>>> compress('abc')
'abc'
The function should handle letters, whitespac... | true |
744a17e55227470c63ceb499957400bd486113ab | oddporson/intro-python-workshop | /strings.py | 721 | 4.1875 | 4 | # strings are a sequence of symbols in quote
a = 'imagination is more important than knowledge'
# strings can contain any symbols, not jus tletters
b = 'The meaning of life is 42'
# concatenation
b = a + ', but not as important as learning to code'
# functions on string
b = a.capitalize()
b = a.upper()
b = b.lower()... | true |
d761e36ff3db8724b77a83d79537ee72db4e9129 | shirishavalluri/Python | /Objects & Classes.py | 2,574 | 4.25 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
# Import the library
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
# In[12]:
class Circle(object):
#Constructor
def __init__(self, radius=3, color='blue'):
self.radius = radius;
self.color = color;
... | true |
687e8141335fe7d529dc850585f29ad5e50c4cbb | spacecoffin/OOPproj2 | /buildDict.py | 1,677 | 4.1875 | 4 | # Assignment does not specify that this program should use classes.
# This program is meant to be used in the __init__ method of the
# "Dictionary" class in the "spellCheck" program.
import re
def main():
# The program buildDict should begin by asking the user for a
# list of text files to read ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.