blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
a95fb7f69f3169c125d3fa9dfc65380b2ff5efed | JubindraKc/Test_feb_19 | /question2.py | 598 | 4.125 | 4 | '''
2. Create a class Circle which has a class variable PI with value=22/7.
Make two methods getArea and getCircumference inside this Circle class.
Which when invoked returns area and circumference of each ciecle instances.
'''
class Circle:
PI = 22/7
def __init__(self,radius):
self.radius = rad... | true |
ecbdca79b8bca2250d1fc37b4449d4994c143096 | mpowers47/cs1301-intro-to-python | /Unit 3 - Control Structures/WordCount2.py | 1,981 | 4.5 | 4 | # Now let's make things a little more challenging.
#
# Last exercise, you wrote a function called word_count that
# counted the number of words in a string essentially by
# counting the spaces. However, if there were multiple spaces
# in a row, it would incorrectly add additional words. For
# example, it would ha... | true |
8f50331313f4b9b62dbcc35eeda564773bebddf3 | mpowers47/cs1301-intro-to-python | /Unit 4 - Data Structures/AfterSecond.py | 1,592 | 4.4375 | 4 | # Write a function called after_second that accepts two
# arguments: a target string to search, and string to search
# for. The function should return everything in the first
# string *after* the *second* occurrence of the search term.
# You can assume there will always be at least two
# occurrences of the searc... | true |
2b969a489710375589779588bfe13a51025b0dfc | mpowers47/cs1301-intro-to-python | /Unit 2 - Procedural Programming/GoOutToLunch.py | 1,144 | 4.46875 | 4 | hungry = True
coworkers_going = False
brought_lunch = False
# You may modify the lines of code above, but don't move them!
# When you Submit your code, we'll change these lines to
# assign different values to the variables.
# Imagine you're deciding whether or not to go out to lunch.
# You only want to go ... | true |
8b4516e193fc6281abace1fa4c3205446c57d366 | Sameer411/First_Year_Lab_Assignment | /sem 2 Programs/Assignment5/sqrt.py | 499 | 4.3125 | 4 | import math
print("We have to find squareroot of a number:\n")
number=int(input("Please enter the number:"))
if number<0:
print("Please enter valid number:")
else:
print('Squareroot of the number {0} is {1}'.format(number,math.sqrt(number)))
#OUTPUT:
#pl-ii@plii-dx2480-MT:~/Desktop/FE-D-07/ASSIGNMENT6$ python s... | true |
9ec48f6722ff8c3e5e6e21786aab2d10f045cd16 | paluch05/Python-rep | /Task17/Task17.py | 667 | 4.125 | 4 | def longest_sentence_and_most_common_word():
stream = open('artykul.txt', 'r', encoding='utf-8')
try:
content = stream.read()
n = content.split(".")
length_of_sentence = [len(i) for i in n]
from collections import Counter
count = Counter(content.lower().strip().split())
... | true |
5dbd68eb09ca61915dba0136dbd97a4bb5fbe3ad | doitharsha007/ost | /8b.py | 848 | 4.125 | 4 | from math import floor # importing 'floor' function from 'math' module
start = int(input("Enter the start of the Armstrong number range - ")) #lower limit
end = int(input("Enter the end of the Armstrong number range - ")) #upper limit
if start > end or start < 0 or end < 0:
print("Invalid range")
else:
fl... | true |
d12e0cf63a30c0065fd77ded34de601eb64c7369 | doitharsha007/ost | /9b.py | 770 | 4.125 | 4 | # 9b) : Write a program to find maximum element in the list using recursive
# functions
def maximum(numbers):
if len(numbers) == 1: #if length of list is 1
return numbers[0]
else:
max1 = numbers[0]
if max1 > numbers[1]: #if first element > second element
del n... | true |
207c8a802058b19c23dfa1de8d754941c84c74eb | dobrienSTJ/Daniels-Projects | /SpeedDistanceTime.py | 1,153 | 4.28125 | 4 | #A simple Program that calculates the Speed, Distance and Time!
print("This is a simple Program that calculates the Speed, Distance and Time!")
triangle=input("Please choose a number to find out: 1. Speed 2. Distance 3. Time")
if triangle == "1":
print("We will find the Speed")
distance1=(int(input("Please ... | true |
293e24949673b471c1a83d42ca74818f625dfa53 | dobrienSTJ/Daniels-Projects | /Quadratic.py | 991 | 4.25 | 4 | #A simple Program that automically adds the variable on at the start of the calculation in the same unit
def variable(x):
x = (int(x))
x = x**2
xword = (str(x))
print(xword+" is your Variable!!")
print("Now we will move onto the calculating unit") ... | true |
70578b8fa3afdc6a9394a8531ab7a29ea06617dc | aasheeshtandon/Leetcode_Problems | /102_RECURSIVE_binary_tree_level_order_traversal.py | 1,052 | 4.46875 | 4 |
# Recursive Level Order Traversal of a Binary Tree.
## Time Complexity: O(n)^2 where n is number of nodes in the binary tree
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def height(root):
if root is None:
return 0
return max(height(... | true |
51461972405b769a39923c6255218c83f53b0a7f | proneetsharma/maze_solver | /helper.py | 1,318 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
import collections
import string
import copy
def next_movement(position):
x, y = position
next_pos = [(x-1, y), (x, y-1), (x+1, y), (x, y+1)]
return next_pos
def write_to_file(file_name, all_path, maze_map):
"""Function to write o... | true |
a791f10e75505502f07622fd0d08c05994b04216 | chaseyb/python-snake-game-v2 | /Button.py | 1,582 | 4.125 | 4 | class button(object):
"""
This is a button class that makes it easy to create buttons. It includes a button initializer, and several control
functions, such as changing colour when the button is hovered.
"""
def __init__(self, colour, hoverColour, display, text, left, top, width, height, textColour... | true |
bdf38d484f83c59ac00cf2be84ae78236e1eecf1 | joe-bq/dynamicProgramming | /python/LearnPythonTheHardWay/FileSystem/Shelves/ShelvesOperation.py | 1,004 | 4.125 | 4 | '''
Created on 2012-11-16
@author: Administrator
file: ShelvesOperation.py
description: this file will demonstrate the use of the shelv object
what is shelve? shelves is something that gives you some basic persistence so you will be able to retrieve what you have shelved in last session
'''
import ... | true |
292fa24444c2d56dee834171f54e39e819495951 | k-schmidt/Learning | /Data_Structures_and_Algorithms/1_1.py | 442 | 4.25 | 4 | '''
Write a short Python function, is_multiple(n, m), that takes two integer values
and returns True if n is a multiple of m, that is, n = mi for some integer i,
and False otherwise.
'''
def is_multiple(n, m):
try:
return True if (int(n) % int(m) == 0) else False
except ValueError:
print "Numb... | true |
f2bfd56ab1e8b66be51c7646b8d797273457b5c1 | PatrickWalsh6079/Software_Security | /Brute force PIN entry/brute_force_PIN.py | 1,819 | 4.25 | 4 | """
Filename: brute_force_PIN.py
Author: Patrick Walsh
Date: 5/2/2021
Purpose: Program shows a simulation of an ATM display
screen that asks the user for their PIN. The program
is vulnerable to a brute force entry that randomly guesses
the PIN until it finds the right one. The program also
provides a mitigation... | true |
a3ac403d1c99f9eab7c7b0ae8f8f93b25621550f | Sulav13/python-experiments | /cw1/distance.py | 1,023 | 4.6875 | 5 | # A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of
# robot movement is shown as the following:
# UP 5
# DOWN 3
# LEFT 3
# RIGHT 2
# The numbers after the direction are steps. Please write a program to compute the distanc... | true |
024a3571a0078a16507c2afd991a9d21b002e171 | swaroop325/python-programs | /4.py | 305 | 4.125 | 4 | def most_repeated_letters(word_1):
lettersCount = {}
for ch in word_1:
if ch not in lettersCount:
lettersCount[ch] = 1
else:
lettersCount[ch] += 1
return max(lettersCount, key=lettersCount.get)
str=input()
print most_repeated_letters(str)
| true |
e0f2a70c32cf95ed23f08ed72390e37d0adcaa84 | XNetLab/ProbGraphBetwn | /util.py | 548 | 4.1875 | 4 | #! /usr/bin/python
# coding = utf-8
import time
from functools import wraps
def fn_timer(function):
"""
Used to output the running time of the function
:param function: the function to test
:return:
"""
@wraps(function)
def function_timer(*args, **kwargs):
t0 = time.time()
... | true |
18ef3a0b8d402ad9d8d8990d4e659716b1ef9e2f | deepakgit2/Python-Basic-and-Advance-Programs | /polynomial_multiplication_using_cauchy_prod.py | 639 | 4.1875 | 4 | # This function multiply two polynomials using cauchy product formula
# Input : a polynomial can be represent by a list where elements
# of list are the coefficients of polynomial
# Output : This program return multiplication of two polynomails in list form
# a = 1 + 2x can be wriiten as following
a = [1, 2,... | true |
27729bbd7bd225d94e31b088294d9eb1a4334f8d | Shressaajan/AssignmentsCA2020Soln | /FunctionsTask/T5Q11.py | 425 | 4.1875 | 4 | # 11. Write a program which can map() and filter() to make a list whose elements are square of even number in
# [1,2,3,4,5,6,7,8,9,10]
# Hints: Use map() to generate a list.
# Use filter() to filter elements of a list
# Use lambda to define anonymous functions
sqr_list = list(range(1, 11))
even_... | true |
d0fa5db62fd6550b002462d65aa9ccda064500eb | Shressaajan/AssignmentsCA2020Soln | /FunctionsTask/T5Q4.py | 293 | 4.40625 | 4 | # 4. Write a program that accepts a hyphen-separated sequence of words as input and prints the words in a
# hyphen-separated sequence after sorting them alphabetically.
def sorted_output(x):
y = x.split('-')
return print('-'.join(sorted(y)))
sorted_output("a-z-s-x-d-c-f-v-g-b-h-n") | true |
a5fb5007a15661cffee7e630118336a2ec14b11f | Shressaajan/AssignmentsCA2020Soln | /DataStructureTask/T4Q6.py | 259 | 4.15625 | 4 | # 6. Write a program in Python to iterate through the list of numbers in the range of 1,100 and print the number
# which is divisible by 3 and a multiple of 2.
x = []
for i in list(range(1100)):
if i % 3 == 0 and i % 2 == 0:
x.append(i)
print(x)
| true |
aedcdfa645bf5411601773c9cd4606de4d88e3fd | Shressaajan/AssignmentsCA2020Soln | /FunctionsTask/T5Q8.py | 273 | 4.28125 | 4 | # 8. Define a function which can generate and print a tuple where the value are square of numbers between 1 and 20.
def sqr_tuple():
x = list(range(1,21))
y = []
for i in x:
i *= i
y.append(i)
z = tuple(y)
return z
print(sqrt_tuple()) | true |
b083122b51b9cf91469312cb9cd4adc4f559c985 | Shressaajan/AssignmentsCA2020Soln | /DataStructureTask/T4Q8.py | 238 | 4.40625 | 4 | # 8. Write a program in Python to iterate through the string “hello my name is abcde” and print the string which
# has even length of word.
x = 'Hello my name is abcde'
for i in x.split(' '):
if len(i) % 2 == 0:
print(i)
| true |
8d5f5109d6f35772e5b4f564d34c2a6a0262c983 | sudarshan-suresh/python | /core/CalculateGrossPay.py | 276 | 4.3125 | 4 | #!/usr/bin/python
# Problem Statement:-
# user will input number of hours and rate the program has to calculate wage.
input1 = input("Enter Number of hours: ")
hours = int(input1)
input2 = input("Enter the rate perhour: ")
rate = float(input2)
wage = rate * hours
print(wage)
| true |
e8bd0e48bc136bb3fc5af6c340c0d76aa4e7c2ef | muhdibee/holberton-School-higher_level_programming | /0x0B-python-input_output/3-write_file.py | 535 | 4.125 | 4 | #!/usr/bin/python3
def write_file(filename="", text=""):
"""Write string to file
Args:
filename (str): string of path to file
text (str): string to write to file
Returns:
number of characters written
"""
chars_written = 0
with open(filename, 'w', encoding='utf-8') as f... | true |
abb48f87c3e2e1592bbd9a91ee142a05305bf162 | muhdibee/holberton-School-higher_level_programming | /0x07-python-test_driven_development/tests/6-max_integer_test.py | 1,210 | 4.25 | 4 | #!/usr/bin/python3
"""Unittest for max_integer([..])
"""
import unittest
#max_integer = __import__('6-max_integer').max_integer
def max_integer(list=[]):
"""Function to find and return the max integer in a list of integers
If the list is empty, the function returns None
"""
if len(list) == 0:
... | true |
184d8c046ba1e9f415737544602e7f5369aa3c66 | aldo2811/cz1003_project | /module/check.py | 1,845 | 4.375 | 4 | def user_input_index(min_index, max_index):
"""Asks user for input and checks if it matches a number in the specified range.
Args:
min_index (int): Minimum number of user input.
max_index (int): Maximum number of user input.
Returns:
int: An integer that the user inputs if it satis... | true |
a49d33bb74d81fb96198b1353be7a9c06a2eeb7a | RatnamDubey/DataStructures | /LeetCode/7. Reverse Integer.py | 1,314 | 4.125 | 4 | """
7. Reverse Integer
Easy
Add to List
Share
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -ç
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed in... | true |
a301e55ed8c88d1cb3a54af1e6e45b581dd00dc5 | jbailey430/The-Tech-Academy-Python-Projects | /POLYMORPHISM.py | 1,028 | 4.1875 | 4 |
#Parent Class User
class User:
name = "Steve"
email = "Steve@gmail.com"
password = "12345678"
def getLogin(self):
entry_name =("Enter your name: ")
entry_email = input("Enter your email: ")
entry_password = input("Enter your password: ")
if (entry_email == self.email and entry_password ==... | true |
2431c4b7da841c2fbce9387e4b4a633eb1316eaa | 42madrid/remote-challs | /chall04/vde-dios.py | 1,971 | 4.28125 | 4 | #!/usr/bin/env python3
import sys
import re
def error(e , i):
file_name = "stdin" if i == 0 else sys.argv[i]
if (e == 1):
print("%s: %s: Bad format" %(sys.argv[0], file_name))
elif (e == 2):
print("%s: %s: Can't read file" %(sys.argv[0], file_name))
elif (e == 3):
print("%s: ... | true |
dd869008cb29eb27f7e2840ce0cc014c326091e3 | TheArchit/equiduct-test | /exercise2.py | 582 | 4.34375 | 4 | #!/usr/local/bin/python -S
from sys import argv
""" Write a function that takes a list of integers (as arguments) and
returns a response with the average (mean), total/sum of integers, the
maximum and minimum values. Print the average to two decimal places. To
make this a little more straightforward assume that input... | true |
3367d1e03ca47c3aeea059a3b760a8b4d39ab5b6 | petervalberg/Python3-math-projects | /Binomialtest.py | 2,061 | 4.375 | 4 | """
Binomial Distribution Calculator.
---------------------------------
n is the number of times the experiment is performed.
p is the probability of success in decimal.
k is the target number of successes.
"""
from math import factorial
combinations = 0
def binomial_coefficient(n, k):
globals()['co... | true |
ba2a94081ff03d9e2718a9345ccfb6f2f7a703d7 | novdulawan/python-function | /function_stdoutput.py | 390 | 4.15625 | 4 | #!/usr/bin/env python
#Author: Novelyn G. Dulawan
#Date: March 16, 2016
#Purpose: Python Script for displaying output in three ways
def MyFunc(name, age):
print "Hi! My name is ", name + "and my age is", age
print "Hi! My name is %s and my age is %d" %(name, age)
print "Hi! My name is {} ... | true |
eb3c96a2dc281331533d6f20f75c6a7e8f4a6ad4 | SaidRem/just_for_fun | /ints_come_in_all_sizes.py | 361 | 4.125 | 4 | # Integers in Python cab be as big as the bytes in a machine's
# memory. There is no limits in size as there is:
# 2^31 - 1 or 2^63 - 1
# Input
# integers a, b, c, d are given on four separate lines.
# Output
# Print the result of a^b + c^d
a = int(input())
b = int(input())
c = int(input())
d = int(input(... | true |
b478fd8893a353ee3ec536d5083d6faf8fafc372 | LGonzales930/My-Project | /FinalProjectPart2/FinalProjectinput.py | 1,476 | 4.15625 | 4 | # Lorenzo Gonzales
# ID: 1934789
# Final Project part 2
# The Following program outputs information about an Electronics stores inventory
import csv
# The Dictionary ID is created to connect the other values together as a key, Everything else acts as a value
# Everything is connected using
ID = {}
with open("Manufactu... | true |
d6e0f39b05b2fc88e1d6b55943d81f4a9ac031b5 | MarkisDev/python-fun | /Competitive Programming/fibonacci.py | 733 | 4.28125 | 4 | """
Fibonacci Series
This script prints Fibonacci series for n value of numbers using variable swap to implement recursion.
@author : MarkisDev
@copyright : https://markis.dev
@source : https://www.geeksforgeeks.org/program-for-nth-fibonacci-number/
"""
number = int(input('Enter the maximum numbers to be dis... | true |
bd484643860671de6ee0259cf719d67c10fc4efd | sakurashima/my-python-exercises-100 | /programming-exercises/34-打印字典从1到20.py | 493 | 4.1875 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件 :34.py
@说明 :Define a function which can print a dictionary where the keys are numbers between 1 and 20
(both included) and the values are square of keys.
@时间 :2020/09/02 16:03:17
@作者 :martin-ghs
@版本 :1.0
'''
def print_dict():
my_dict ... | true |
136df51b61bfd054a757839411aae2c8db8c1b49 | sakurashima/my-python-exercises-100 | /programming-exercises/58-59-re在放送一遍成功过.py | 800 | 4.4375 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件 :58.py
@说明 :Assuming that we have some email addresses in the "username@companyname.com" format, please
write program to print the user name of a given email address. Both user names and company names
are composed of letters only.
@时间 :2... | true |
c5c9391a9220edf57014300e0c71292377f1cab7 | sakurashima/my-python-exercises-100 | /programming-exercises/21-坐标轴自己选取数据结构.py | 1,311 | 4.53125 | 5 | """
Question A robot moves in a plane starting from the original point (0,0). The robot can move toward UP,
DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following: UP 5 DOWN
3 LEFT 3 RIGHT 2 ¡ The numbers after the direction are steps. Please write a program to compute the
di... | true |
bf8e6248c0d6df71d96446e0e6fa2e0f1c699720 | sakurashima/my-python-exercises-100 | /programming-exercises/91.py | 495 | 4.125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件 :91.py
@说明 :By using list comprehension, please write a program to print the list after removing the 0th,
4th,5th numbers in [12,24,35,70,88,120,155].
@时间 :2020/09/11 16:34:42
@作者 :martin-ghs
@版本 :1.0
'''
def main():
li = [12, 24, 35,... | true |
476ac61e9f8b8a4b5f20b2ddaaf9c36818e094af | sakurashima/my-python-exercises-100 | /programming-exercises/02-求n!.py | 524 | 4.15625 | 4 | # Question: Write a program which can compute the factorial of a given numbers.
# The results should be printed in a comma-separated sequence on a single line.
# Suppose the following input is supplied to the program: 8 Then, the output should be: 40320
def main():
given_num = input("enter the num: ")
sum = 1... | true |
8c4b74f17278c12cb587509679b1c1f7fec6548a | sakurashima/my-python-exercises-100 | /programming-exercises/40-还是列表索引.py | 600 | 4.3125 | 4 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件 :40.py
@说明 :Define a function which can generate a list where the values are square of numbers between 1
and 20 (both included). Then the function needs to print all values except the first 5 elements
in the list.
@时间 :2020/09/02 16:22:1... | true |
68dd0bda0d33c5ac3ce00bf9c7d5eab867627220 | deepabalan/python-practice-book | /2_working_with_data/38.py | 269 | 4.34375 | 4 | # Write a function invertdict to interchange keys and values in a
# dictionary. For simplicity, assume that all values are unique.
def invertdict(d):
res = {}
for i, v in d.items():
res[v] = i
return res
print invertdict({'x': 1, 'y': 2, 'z': 3})
| true |
1138dd8c34c4dbb343e3089ba6caf3a28c1c213b | deepabalan/python-practice-book | /2_working_with_data/6.py | 396 | 4.5 | 4 | # Write a function reverse to reverse a list. Can you do this without
# using list slicing?
# reverse([1, 2, 3, 4]) gives [4, 3, 2, 1]
# reverse(reverse([1, 2, 3, 4])) gives [1, 2, 3, 4]
def reverse_list(l):
rev = []
i = len(l) - 1
while i >= 0:
rev.append(l[i])
i -= 1
return rev
prin... | true |
770782703584c23ed76a71ece31eaf997c6f0427 | carlhinderer/python-algorithms | /classic_cs_problems/code/ch01/fibonacci.py | 1,449 | 4.15625 | 4 | # Different approaches for generating Fibonacci numbers
#
# First attempt just shows what happens if you forget a base case
#
# Naive attempt with base case
def fib2(n):
if n < 2:
return n
return fib2(n-1) + fib2(n-2)
# Use memoization
MEMO = {0: 0, 1: 1}
def fib3(n):
if n not in MEMO:
... | true |
961f9d2658e2fbf0e1642457c0b552117d72fefc | saurabh0307meher/Python-Programs | /basic programs/3nos.py | 232 | 4.15625 | 4 | #largest of two numbers
a=int(input("Enter 1st nos"))
b=int(input("Enter 2nd nos"))
c=int(input("Enter 3rd nos"))
if (a>b and a>c):
print(a,"is greatest")
elif (b>c):
print(b,"is greatest")
else:
print(c,"is greatest")
| true |
8b660b989bb61fd07afd32bf8b18253e705c3fa4 | ruchikpatel/abbdemo | /sort/insertion/reverseOrder_IS.py | 679 | 4.46875 | 4 | '''
Author: Ruchik Patel
Date: 09/16/2017
File: randromNumbers_IS.py
Description: Insertion sort algorithm that sorts reverse orderintegers.
'''
import sys #import system library/package
n = int(sys.argv[1]) #System argument
# For reverse:
nums = list(range(n, 0, -1))
print("Unsorted array: \n ", nums)#Pr... | true |
5c42eb4b6ae9288a1675c24a6491bbf82941714d | ruchikpatel/abbdemo | /sort/selectionSort/selectionSort_reverse.py | 718 | 4.34375 | 4 | '''
Author: Ruchik Patel
Date: 09/16/2017
File: selectionSort_reverse.py
Description: Selection sort algorithm that sorts reverse orderintegers.
'''
import sys #import system library/package
n = int(sys.argv[1]) #System argument
# For reverse:
nums = list(range(n, 0, -1))
print("Unsorted array: \n ", nums... | true |
0941cffce853d5953f81e0d19afd1cc4ea21e435 | greyreality/python_tasks | /Codility/StrSymmetryPoint_my.py | 1,530 | 4.3125 | 4 | # Write a function: def solution(S)
# that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character
# is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
# Note: reversing an empty str... | true |
b1729397c045e0a3b0bd4486e74cf1374a29b880 | greyreality/python_tasks | /Other_tasks/triangle_validity.py | 613 | 4.46875 | 4 | # Python3 program to check if three
# sides form a triangle or not
# У треугольника сумма любых двух сторон должна быть больше третьей.
def checkValidity(a, b, c):
if (a + b <= c) or (a + c <= b) or (b + c <= a):
return False
else:
return True
# Operator Meaning Example
# and True if both the o... | true |
d5808e4eadd351292439c619cd5b73a1d35ede29 | Ankur-v-2004/Python-ch-6-data-structures | /prog_q1.py | 597 | 4.28125 | 4 | #Inserting element in a queue
Queue = []
rear = 0
def Insertion_Queue(Queue, rear):
ch = 'Y'
while ch == 'y' or ch=='Y':
element = input("Enter the element to be added to the Queue :")
rear = rear + 1 #rear is incremented by 1 and then insertion takes place
Queue.append(eleme... | true |
218ea769330f80223324f5dda2c9749953d34b26 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH06/EX6.26.py | 483 | 4.25 | 4 | # 6.26 (Mersenne prime) A prime number is called a Mersenne prime if it can be written
# in the form for some positive integer p. Write a program that finds all
# Mersenne primes with and displays the output as follows:
# p 2^p - 1
# 2 3
# 3 7
# 5 31
# ...
from CH6Module import MyFunctions
print("P", " ", "2^p - 1")... | true |
6f40c592f87d09d6a2d046b25fabd3e80395a695 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH11/EX11.38.py | 1,372 | 4.59375 | 5 | # 11.38 (Turtle: draw a polygon/polyline) Write the following functions that draw a
# polygon/polyline to connect all points in the list. Each element in the list is a list of
# two coordinates.
# # Draw a polyline to connect all the points in the list
# def drawPolyline(points):
# # Draw a polygon to connect all the p... | true |
9e08660316315554e6272d205261e69d86626036 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH10/EX10.28.py | 1,735 | 4.34375 | 4 | # 10.28 (Partition of a list) Write the following function that partitions the list using the
# first element, called a pivot:
# def partition(lst):
# After the partition, the elements in the list are rearranged so that all the elements
# before the pivot are less than or equal to the pivot and the element after
# the ... | true |
45f193d1594484a857709fae36c7d96fd39a9a4c | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH04/EX4.11.py | 1,227 | 4.40625 | 4 | # (Find the number of days in a month) Write a program that prompts the user to
# enter the month and year and displays the number of days in the month. For example,
# if the user entered month 2 and year 2000, the program should display that
# February 2000 has 29 days. If the user entered month 3 and year 2005, the p... | true |
60621aebebf46e1bab7bdf1bf90f28e68e9d18b7 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH06/EX6.12.py | 545 | 4.53125 | 5 | # 6.12 (Display characters) Write a function that prints characters using the following
# header:
# def printChars(ch1, ch2, numberPerLine):
# This function prints the characters between ch1 and ch2 with the specified
# numbers per line. Write a test program that prints ten characters per line from 1
# to Z.
def print... | true |
0d4bfdb03fa72aad73ca5a0f74298eb85078720b | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH11/EX11.4.py | 832 | 4.1875 | 4 | # 11.4 (Compute the weekly hours for each employee) Suppose the weekly hours for all
# employees are stored in a table. Each row records an employee’s seven-day work
# hours with seven columns. For example, the following table stores the work hours
# for eight employees. Write a program that displays employees and thei... | true |
7e1bb35e01e8e7fbf698a954f8627d381029cb24 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH05/EX5.19.py | 465 | 4.21875 | 4 | # 5.19 (Display a pyramid) Write a program that prompts the user to enter an integer
# from 1 to 15 and displays a pyramid, as shown in the following sample run:
n = int(input("Enter number of lines: "))
x = n * 2
for i in range(1, n + 1):
s = n + x
sp = str(s) + "s"
print(format(" ", sp), end='')
for ... | true |
3f49290f5bdfe6b67bdabef777e17c8051905f1b | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH08/EX8.5.py | 855 | 4.34375 | 4 | # 8.5 (Occurrences of a specified string) Write a function that counts the occurrences of a
# specified non-overlapping string s2 in another string s1 using the following header:
# def count(s1, s2):
# For example, count("system error, syntax error", "error") returns
# 2. Write a test program that prompts the user to e... | true |
5f3c2905fc6851de987bad08f1a0ff2c9d0ec4c5 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH13/EX13.9.py | 582 | 4.40625 | 4 | # 13.9 (Decrypt files) Suppose a file is encrypted using the scheme in Exercise 13.8.
# Write a program to decode an encrypted file. Your program should prompt the
# user to enter an input filename and an output filename and should save the unencrypted
# version of the input file to the output file.
infile = input("En... | true |
11d4ed6ac8734971cdf7cf91f29e57747b72df47 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH05/EX5.44.py | 323 | 4.25 | 4 | # 5.44 (Decimal to binary) Write a program that prompts the user to enter a decimal integer
# and displays its corresponding binary value.
d = int(input("Enter an integer: "))
bin = ""
value = d
while value != 0:
bin = str(value % 2) + bin
value = value // 2
print("The binary representation of", d, "is", bi... | true |
40dba80ab9881ee0d5f18a1ef881c6202c707b20 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH08/EX8.8.py | 654 | 4.34375 | 4 | # 8.8 (Binary to decimal) Write a function that parses a binary number as a string into a
# decimal integer. Use the function header:
# def binaryToDecimal(binaryString):
# For example, binary string 10001 is 17
# So, binaryToDecimal("10001") returns 17.
# Write a test program that prompts the user to enter a binary st... | true |
dac980495e1d018450893bb6247da7049abe78db | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH07/EX7.1.py | 1,244 | 4.875 | 5 | # 7.1 (The Rectangle class) Following the example of the Circle class in Section
# 7.2, design a class named Rectangle to represent a rectangle. The class
# contains:
# ■ Two data fields named width and height.
# ■ A constructor that creates a rectangle with the specified width and height.
# The default values are 1 an... | true |
0a9788e3aca817a8e3c9bfdd55cc60dddfa710ba | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH05/EX5.43.py | 341 | 4.125 | 4 | # 5.43 (Math: combinations) Write a program that displays all possible combinations for
# picking two numbers from integers 1 to 7. Also display the total number of combinations.
count = 0
for i in range(1, 8):
for j in range(i+1, 8):
print(i, " ", j)
count += 1
print("The total number of all comb... | true |
c27897d3dd75790a1778be71ae337c7483f29183 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH15/EX15.11.py | 512 | 4.40625 | 4 | # 15.11 (Print the characters in a string reversely) Rewrite Exercise 15.9 using a helper
# function to pass the substring for the high index to the function. The helper
# function header is:
# def reverseDisplayHelper(s, high):
def reverseDisplay(value):
reverseDisplayHelper(value, len(value) - 1)
def reverseDi... | true |
e9ce060de5debd11b74c64e81cbcdb2149776bea | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH15/EX15.34.py | 1,848 | 4.40625 | 4 | # 15.34 (Turtle: Hilbert curve) Rewrite the Hilbert curve in Exercise 15.33 using Turtle,
# as shown in Figure 15.20. Your program should prompt the user to enter the
# order and display the corresponding fractal for the order.
import turtle
def upperU(order):
if order > 0:
leftU(order - 1)
turtle... | true |
a97533ceba4eff0dfc8f651a353d21c931c380e4 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH03/EX3.5.py | 632 | 4.15625 | 4 | # (Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in
# which all sides are of the same length and all angles have the same degree (i.e., the
# polygon is both equilateral and equiangular). The formula for computing the area
# of a regular polygon is
# Here, s is the length of a side. Write... | true |
050e743c103dbe2f59ddb3451709031d30ca5b1f | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH13/EX13.2.py | 554 | 4.21875 | 4 | # 13.2 (Count characters, words, and lines in a file) Write a program that will count the
# number of characters, words, and lines in a file. Words are separated by a whitespace
# character. Your program should prompt the user to enter a filename.
filename = input("Enter a filename: ").strip()
file = open(filename, 'r... | true |
ccea56d0aaed3b2e976259cc6decbd3516bde27c | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH15/EX15.01.py | 493 | 4.3125 | 4 | # 15.1 (Sum the digits in an integer using recursion) Write a recursive function that computes
# the sum of the digits in an integer. Use the following function header:
# def sumDigits(n):
# For example, sumDigits(234) returns Write a test program
# that prompts the user to enter an integer and displays its sum.
def ... | true |
7ad21495c9581d74dc9b9f02930fbfe7dd7c3f12 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH06/EX6.7.py | 1,140 | 4.3125 | 4 | # 6.7 (Financial application: compute the future investment value) Write a function that
# computes a future investment value at a given interest rate for a specified number of
# years. The future investment is determined using the formula in Exercise 2.19.
# Use the following function header:
# def futureInvestmentVal... | true |
cfa8e99d7f24ebcbb5c4237e74f1f475ba1e5704 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH06/EX6.38.py | 557 | 4.3125 | 4 | # 6.38 (Turtle: draw a line) Write the following function that draws a line from point
# (x1, y1) to (x2, y2) with color (default to black) and line size (default to 1).
# def drawLine(x1, y1, x2, y2, color = "black", size = 1):
import turtle
def drawLine(x1, y1, x2, y2, color="black", size=1):
turtle.color(color... | true |
02b3e59d523a56be6ae7df5c11687f7a168db030 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH10/EX10.5.py | 540 | 4.28125 | 4 | # 10.5 (Print distinct numbers) Write a program that reads in numbers separated by a
# space in one line and displays distinct numbers (i.e., if a number appears multiple
# times, it is displayed only once). (Hint: Read all the numbers and store
# them in list1. Create a new list list2. Add a number in list1 to list2.
... | true |
808f4c21115654ed8553ba1e529b933b1e258b79 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH03/EX3.11.py | 344 | 4.25 | 4 | # (Reverse number) Write a program that prompts the user to enter a four-digit integer
# and displays the number in reverse order.
num = eval(input("Enter an integer: "))
n1 = num % 10
num = num // 10
n2 = num % 10
num = num // 10
n3 = num % 10
num = num // 10
n4 = num
print(n1, end='')
print(n2, end='')
print(n3, end... | true |
9ef95ef743118f21adfb7b048d4744122da08dc5 | 6igsm0ke/Introduction-to-Programming-Using-Python-Liang-1st-edtion | /CH05/EX5.40.py | 429 | 4.15625 | 4 | # 5.40 (Simulation: heads or tails) Write a program that simulates flipping a coin one
# million times and displays the number of heads and tails.
import random
print("Simulating flipping a coin 1000000 times")
head = 0
tail = 0
print("Wait....")
for i in range(0, 1000000):
if random.randint(0, 1) == 0:
... | true |
159c18a4adce4d20d774ab866e3198b710b00376 | jcontreras12/Moduel-6 | /factorial.py | 336 | 4.3125 | 4 | # problem 6 use a for statement to calculate the factorial of a users input value
import math
x = int(input("Enter a number:"))
number = 1
for i in range(1, x+1):
number = number * i
print("Factorial of {} using for Loop {}".format(x, number))
print(" Factorial of {} using inbuilt function: {}".format(x, mat... | true |
5e84a356985f8bc40ccb7758b6ea9acc233626fa | kutay/workshop-intro | /python-sqlite3/main.py | 1,339 | 4.3125 | 4 | import sqlite3
from sqlite3 import Error
# https://www.sqlitetutorial.net/sqlite-python/
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
conn = None
tr... | true |
3fd5c20428b51725c133e7702fed0de0412d05b1 | inaram/workshops | /python3/fitnessChallenge.py | 899 | 4.21875 | 4 | def fitnessChallenge():
challengeLength = int(input("How many days do you want your fitness challenge to last? "))
totalMinutes = 0
totalDays = 0
for day in range(1, challengeLength + 1):
answer = input("Have you exercised today? (y/n): ")
if answer == "y" or answer == "yes" or answer ... | true |
a6e07131d153747bbeeb90472617f2fe6322aef9 | grahamrichard/COMP-123-fall-16 | /PycharmProjects/Oct03/whileloops.py | 2,820 | 4.46875 | 4 | """ ==================================================
File: whileloops.py
Author: Susan Fox
Date: Spring 2013
This file contains examples of while and for loops for the Iteration
activity. """
# ====================================================
# Simple while loop examples
# loop 1
def printEveryFifth(x):
... | true |
0b141796ccdf60dd04b46e419ee0254db7e79d18 | grahamrichard/COMP-123-fall-16 | /PycharmProjects/FINAL/Q1.py | 2,130 | 4.65625 | 5 | # In this question you are provided a function to determine
# if a string is a palindrome. This function is recursive
# you have several tasks
# 1. Using comments, label each line of code as either
# part of a base case or a recursive case. If there are
# more than one base case or recursive case number the
# cases (I... | true |
cbbe95857a99d7b349eff3d726b944f5dbf48a20 | grahamrichard/COMP-123-fall-16 | /PycharmProjects/FINAL/Q2.py | 589 | 4.4375 | 4 | # This question has you write a function named greater.
# The Greater function takes a dictionary whose keys are
# numbers and whose values are numbers. The function
# returns a list of all keys that are larger than their
# values. The original dictionary should not be modified.
# See the included example for more info... | true |
cfcac0732131c1af470b48fee911605cd4b45d07 | cabudies/Python-Batch-3-July-2018 | /5-July.py | 539 | 4.28125 | 4 | # use input() function to take input from user
# use int() function to convert string to int
number = int(input('Enter the number of rows for star pattern: '))
for i in range(0, number):
for j in range(0, i):
print("*", end=" ")
print()
# use def to create a function
def printUserDetails():
... | true |
f5d5c595241d3b20830f30c314114a2e00cb7379 | Grinch101/data_structure | /algorithms/sorting_algorithms/merge_sort.py | 2,196 | 4.1875 | 4 | # merge sort:
# The divide-and-conquer paradigm involves three steps at each level of the recursion:
# Divide the problem into a number of subproblems that are smaller instances of the
# same problem.
# Conquer the subproblems by solving them recursively. If the subproblem sizes are
# small enough, however, just solve... | true |
86d2fb4f5f5739055fb0dfbffa1250b7d0ea6840 | roctubre/compmath | /serie6/6_3_lists.py | 2,262 | 4.1875 | 4 | from itertools import permutations
# a)
def has_duplicates(n):
""" Check if the given list has unique elements
Uses the property of sets:
If converted into a set it is guaranteed to have unique elements.
-> Compare number of elements to determine if the list contains duplicates
"""
... | true |
c441f91a6bf19db24c245518efaebc4306217d64 | WomenWhoCode/WWCodePune | /Python/running_with_python/exercise.py | 1,164 | 4.15625 | 4 | """
1). Create function without/ with none/default arguments.
2). Try passing args and kwargs
3). Call a lambda function inside a function.
4). Try r,r+,w,w+,a modes with file handling
5). Import modules from different and same directories
6). Create a class and try using __init__ method
7). Try calling a funct... | true |
987052f4c5e9bf33254a569ecf1a14b7b1fc814f | beatwad/algorithm | /find_max_subarray_recursive.py | 1,541 | 4.125 | 4 | import math
def find_max_sublist(_list, low, high):
""" Recursively find max sublist of list. Difficulty is O(n*lg(n)) """
if low == high:
return low, high, _list[low]
else:
mid = divmod(low + high, 2)[0]
left_low, left_high, left_sum = find_max_sublist(_list, low, mid)
rig... | true |
e58ba82afdc2622c981e0211369580ba6dbc6549 | devjinius/algorithm | /Hackerrank/Left_Rotation.py | 941 | 4.1875 | 4 | '''
HackerRank Left Rotation
문제
https://www.hackerrank.com/challenges/array-left-rotation/problem
문제
A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left.
For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2].
입... | true |
02cbcf7ee03758c630aa0ffccf4943cd23591960 | NathanSouza27/Python | /ING/005 - Predecessor and successor.py | 231 | 4.125 | 4 | #Make a program that reads an integer and shows your successor and predecessor on the screen.
n = int(input('Type it a value:'))
a = n - 1
s = n + 1
print('The predecessor de {} is {} and successor is {}'.format(n, a, s)) | true |
0ccadc8754ff399cbb3f4e544e68fd33ed2dbc04 | NathanSouza27/Python | /ING/010 - Currency converter.py | 294 | 4.15625 | 4 | #Create a program that reads how much money a person has in their wallet and shows how many dollars they can buy.
# Consider 1U$ = R$ 3,27.
mon = float(input('How much money do you have in your wallet? U$ '))
con = mon * 3.27
print('With U$ {} you can buy R$ {:.2f}'.format(mon, con)) | true |
8f7ccc28ea13ded236db2056040a22bf6fa5209f | audy018/tech-cookbook | /python/python-package-example/module_package/techcookbook/caseconvert.py | 299 | 4.34375 | 4 | """
module to convert the strings to either lowercase or uppercase
"""
def to_lowercase(given_strings):
""""convert given strings to lower case"""
return given_strings.lower()
def to_uppercase(given_strings):
""""convert given strings to upper case"""
return given_strings.upper()
| true |
aaed8f499f38230ddbfad6373945a2146898cf58 | tinali0923/orie5270-ml2549 | /hw2/optimize.py | 1,121 | 4.15625 | 4 | import numpy as np
from scipy import optimize
def Rosenbrock(x):
"""
This is the function for Rosenbrock with n=3
:param x: a list representing the input vector [x1,x2,x3]
:return: a number which is the Rosenbrock value
"""
return 100 * (x[2] - x[1] ** 2) ** 2 + (1 - x[1]) ** 2 + 100 * (x[1] -... | true |
b8f77afc83bca627d39c2e2373f89a0568e09fd7 | PeterMurphy98/comp_sci | /sem_1/programming_1/prac9/p17p1.py | 500 | 4.3125 | 4 | # Define a function to return a list of all the factors of a number x.
def divisor(x):
"""Finds the divisors of a."""
# Initialise the list of divisors with 1 and x
divisors = (1,x)
# Check if i divides x, from i = 1 up to i = x/2.
# If it does, add i to the divisors list.
for i in range(2, int(... | true |
7f267e86ab6e1a5132f8a794bc4e1b8a9501a9dd | PeterMurphy98/comp_sci | /sem_1/programming_1/prac10/p19p1.py | 463 | 4.125 | 4 | def new_base(x, b):
"""Takes a number, x, in base 10 and converts to base b."""
# Initialise the new number as a string
new = ''
# While the division result is not equal to 0
while x != 0:
# add the remainder to the string
remainder = x % b
new += str(remainder)
x =... | true |
4c3d05ee24ea643e24813638c1c5592db7776d95 | PeterMurphy98/comp_sci | /sem_1/programming_1/test2/exam-q1.py | 675 | 4.375 | 4 | def isPal(text):
# Initialise new string
new = ""
# Add all letters, numbers and spaces from input string to new string
for i in range (len(text)):
if text[i].isalnum() or text[i] == " ":
new += text[i]
# Check if new string is the same when reversed
if new == new[::-1]:
... | true |
365a0eef3630dd6ae3e85e1527154ef3b154af26 | coder91x/Linked_Lists | /linked_list_swap.py | 1,410 | 4.125 | 4 | class Node(object):
def __init__(self, data):
self.data = data
self.next = None
class LinkedList(object):
def __init__(self):
self.head = None
def push(self, new_data):
new_node = Node(new_data)
new_node.next = self.head
self.head = new_node
... | true |
a0f0acdef772a13a5c7c3666b9e3c0755a1de519 | kevna/python-exercises | /src/sorting/stupid_sort.py | 956 | 4.28125 | 4 | from sorting.sorter import Sorter, SortList
class StupidSort(Sorter): # pylint: disable=too-few-public-methods
"""Implementation of stupid sort, also known as gnome sort.
If the current pair are out of order swap them and move back one
otherwise step forward.
"""
def sort(self, items: SortList, ... | true |
f9eb94c80dc1c3ecb13f02972c98c3f9f7a98adb | acode-pixel/YT_Tutorials | /Python/Password Generator/passwordgen.py | 938 | 4.4375 | 4 | import random
import string
import pyperclip # pip install pyperclip
# Alphabet, letters will be picked out of this randomly
alphabet = string.ascii_letters + string.digits + string.digits + string.punctuation
# Output password
password = ""
# Desired password length
password_length = 0
# Try to parse password ... | true |
0843641cd5ea25605cacc906a8ab988d83e20afb | kaiqinhuang/Python_hw | /lab8.py | 1,348 | 4.40625 | 4 | """
lab8.py
Name: Kaiqin Huang
Date: 1/17/2017
A module of functions count_merge(), count_as(), and split_evens().
"""
def count_merge(set1, set2):
'''Merges two sets and returns the length of the new set
Args:
set1 and set2: Two sets
Returns:
len: The l... | true |
08f51d0480b9941cb45193217932ed301858120e | broepke/GTx | /part_2/3.4.3_leap_year.py | 1,529 | 4.6875 | 5 | # A year is considered a leap year if it abides by the
# following rules:
#
# - Every 4th year IS a leap year, EXCEPT...
# - Every 100th year is NOT a leap year, EXCEPT...
# - Every 400th year IS a leap year.
#
# This starts at year 0. For example:
#
# - 1993 is not a leap year because it is not a multiple of 4.
# ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.