blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
deb7b21d9a08444b3681c1fce4ce1f82e38a6192 | kelpasa/Code_Wars_Python | /6 кю/Selective Array Reversing.py | 893 | 4.46875 | 4 | '''
Given an array, return the reversed version of the array (a different kind of reverse though), you reverse portions of the array, you'll be given a length argument which represents the length of each portion you are to reverse.
E.g
selReverse([1,2,3,4,5,6], 2)
//=> [2,1, 4,3, 6,5]
if after reversing some portion... | true |
2b6315a9c117156389761fb6d25ec1d375ed9d1b | kelpasa/Code_Wars_Python | /5 кю/Human Readable Time.py | 690 | 4.15625 | 4 | '''
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS)
HH = hours, padded to 2 digits, range: 00 - 99
MM = minutes, padded to 2 digits, range: 00 - 59
SS = seconds, padded to 2 digits, range: 00 - 59
The maximum time never exceeds 359999 (... | true |
f67afbb5da9f57dd033101e6b219a495e466b392 | kelpasa/Code_Wars_Python | /6 кю/Duplicate Arguments.py | 584 | 4.25 | 4 | '''
Complete the solution so that it returns true if it contains any duplicate argument values. Any number of arguments may be passed into the function.
The array values passed in will only be strings or numbers. The only valid return values are true and false.
Examples:
solution(1, 2, 3) --> false
solu... | true |
421b1232a36a6718cce0560efee1260a906f84fb | miguel-nascimento/coding-challenges-stuffs | /project-euler/004 - Largest palindrome product.py | 375 | 4.1875 | 4 | # Find the largest palindrome made from the product of two 3-digit numbers.
# A palindromic number reads the same both ways
def three_digits_palindome():
answer = max(i * j
for i in range(100, 1000)
for j in range(100, 1000)
if str(i * j) == str(i * j)[:: -1])
... | true |
50e6dc86d6a2dcec1df9cac643815c3e9c3a7f06 | ArnoBali/python-onsite | /week_01/03_basics_variables/08_trip_cost.py | 402 | 4.46875 | 4 | '''
Receive the following arguments from the user:
- miles to drive
- MPG of the car
- Price per gallon of fuel
Display the cost of the trip in the console.
'''
miles = int(input("please input miles to drive:" ))
mpg = int(input("please input MPG of the car:" ))
p_gallon = int(input("please input Price ... | true |
1bdcfa5db635cbba8f5f54f3d651187ee1865810 | ArnoBali/python-onsite | /week_02/07_conditionals_loops/Exercise_05.py | 532 | 4.375 | 4 | '''
Take two numbers from the user, an upper and lower bound. Using a loop, calculate the sum
of numbers from the lower bound to the upper bound. Also, calculate the average of numbers.
Print the results to the console.
For example, if a user enters 1 and 100, the output should be:
The sum is: 5050
The average ... | true |
d2dd93a12035f03644a19898b5e8356a16320a02 | ArnoBali/python-onsite | /week_02/07_conditionals_loops/Exercise_01.py | 382 | 4.5625 | 5 | '''
Write a program that gets a number between 1 and 1,000,000,000
from the user and determines whether it is odd or even using an if statement.
Print the result.
NOTE: We will be using the input() function. This is demonstrated below.
'''
input_ = int(input("Please input a number between 1 - 1,000,000,000: "))
if ... | true |
c3eafe4b5b245cf0ad6e77460780af570a92560c | chandrakant100/Assignments_Python | /Practical/assignment4/factorial.py | 246 | 4.28125 | 4 | # To find factorial of a number using recursion
def rec_fact(num):
if num <= 1:
return 1
return num * rec_fact(num - 1)
num = int(input("Enter a number: "))
print("Factorial of {0} is {1}".format(num, rec_fact(num)))
| true |
349d17c98133a3970fe6f20f369a802ab59d8c3b | govindarajanv/python | /programming-practice-solutions/exercises-set-1/exercise-01-solution.py | 968 | 4.21875 | 4 | #1 printing "Hello World"
print ("Hello World")
#Displaying Python's list of keywords
import keyword
print ("List of key words are ..")
print (keyword.kwlist)
#2 Single and multi line comments
# This is the single line comment
''' This is multiline
comment, can be
used for a paragraph '''
#3 Multi line state... | true |
4f5ad33e6485de134980f5523cb21c41b51bfb99 | govindarajanv/python | /gui-applications/if-else.py | 338 | 4.15625 | 4 | #
number = 23
# input() is used to get input from the user
guess = int(input('Enter an integer : '))
if guess == number:
print('Congratulations, you guessed it.') # New block starts here
elif guess < number:
print('No, it is a little higher than that') # Another block
else:
print('No, it is a little l... | true |
6658ab77e9521efd122e1348c1860401d6b7abda | govindarajanv/python | /regex/regex-special-sequences.py | 1,679 | 4.34375 | 4 | import re
pattern = r"(.+) \1"
print ("pattern is",pattern)
match = re.match(pattern, "word word")
if match:
print ("Match 1")
match = re.match(pattern, "?! ?!")
if match:
print ("Match 2")
match = re.match(pattern, "abc cde")
if match:
print ("Match 3")
match = re.match(pattern, "abc ab")
if match:
... | true |
170ffd1a881e4043e7e9be7d70841c5652443d9d | govindarajanv/python | /regex/regex.py | 1,061 | 4.125 | 4 | import re
# Methods like match, search, finall and sub
pattern = r"spam"
print ("\nFinding \'spam\' in \'eggspamsausagespam\'\n")
print ("Usage of match - exact match as it looks at the beginning of the string")
if re.match(pattern, "eggspamsausagespam"):
print("Match")
else:
print("No match")
print ("\nUsag... | true |
8638bd18648d6ed7aceaffd6c842e42a0cad680b | govindarajanv/python | /functional-programming/loops/fibonacci.py | 539 | 4.1875 | 4 | """
0,1,1,2,3,5,8,13...n
"""
def factorial(n):
first_value = 0
second_value = 1
for i in range(1,n,1):
if i == 1:
print ("{} ".format(first_value))
elif i==2:
print ("{} ".format(second_value))
else:
sum = first_value + second_value
pri... | true |
04db43932905662ea741f34a135cd9097941e469 | govindarajanv/python | /regex/regex-character-classes.py | 1,794 | 4.6875 | 5 | import re
#Character classes provide a way to match only one of a specific set of characters.
#A character class is created by putting the characters it matches inside square brackets
pattern = r"[aeiou]"
if re.search(pattern, "grey"):
print("Match 1")
if re.search(pattern, "qwertyuiop"):
print("Match 2")
if... | true |
10e85d68d0c5c121457de9a464b8cc8a22bf62db | Achraf19-okh/python-problems | /ex7.py | 469 | 4.15625 | 4 | print("please typpe correct informations")
user_height = float(input("please enter your height in meters"))
user_weight = float(input("please enter your weight in kg"))
BMI = user_weight/(user_height*user_height)
print("your body mass index is" , round(BMI,2))
if(BMI <= 18.5):
print("you are under weight")
elif(BMI... | true |
e5e26adc9ce9c5c85bd2b8afdb2bc556746f8d20 | azhar-azad/Python-Practice | /07. list_comprehension.py | 770 | 4.125 | 4 | # Author: Azad
# Date: 4/2/18
# Desc: Let’s say I give you a list saved in a variable:
# a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100].
# Write one line of Python that takes this list a and makes a new list
# that has only the even elements of this list in it.
# ------------------------------------... | true |
bcd76925689d3e401ce55f7efe88aa323b02c0d0 | azhar-azad/Python-Practice | /10. list_overlap_comprehensions.py | 995 | 4.3125 | 4 | # Author: Azad
# Date: 4/5/18
# Desc: Take two lists, say for example these two:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# and write a program that returns a list that
# contains only the elements that are common between the li... | true |
900685d187fce72a3edb34daef753d90395b2a8b | ARBUCHELI/100-DAYS-OF-CODE-THE-COMPLETE-PYTHON-PRO-BOOTCAMP-FOR-2021 | /Guess the Number/guess_the_number.py | 1,951 | 4.4375 | 4 | #Number Guessing Game Objectives:
# Include an ASCII art logo.
# Allow the player to submit a guess for a number between 1 and 100.
# Check user's guess against actual answer. Print "Too high." or "Too low." depending on the user's answer.
# If they got the answer correct, show the actual answer to the player.
# Trac... | true |
4e51ccfe4bbdf4401dd6c2741d3f2d8ca63ef3c2 | tzyl/ctci-python | /chapter9/9.2.py | 1,672 | 4.125 | 4 | def number_of_paths(X, Y):
"""Returns the number of paths to move from (0, 0) to (X, Y) in an X by Y
grid if can only move right or down."""
if X == 0 or Y == 0:
return 1
return number_of_paths(X - 1, Y) + number_of_paths(X, Y - 1)
def number_of_paths2(X, Y):
"""Solution using mat... | true |
9f8201a7a55fd59dc02cdd24fbd64ee8cd10ebfc | tzyl/ctci-python | /chapter5/5.5.py | 736 | 4.28125 | 4 | def to_convert(A, B):
"""Clears the least significant bit rather than continuously shifting."""
different = 0
C = A ^ B
while C:
different += 1
C = C & C - 1
return different
def to_convert2(A, B):
"""Using XOR."""
different = 0
C = A ^ B
while C:
... | true |
2e925cbed4eaeb10f9f822f1b7600823bf8f0603 | carlosmertens/Python-Introduction | /default_argument.py | 2,221 | 4.59375 | 5 | """ DEFAULT ARGUMENTS """
print("\n==================== Example 1 ====================\n")
def box(width, height, symbol="*"):
"""print a box made up of asterisks, or some other character.
symbol="*" is a default in case there is not input
width: width of box in characters, must be at least 2
height... | true |
62ce698cea9b770dd6f641a27aec07034898d2e8 | usmanwardag/Python-Tutorial | /strings.py | 1,619 | 4.28125 | 4 | import sys
'''
Demonstrates string functions
'''
def stringMethods():
s = 'Hello, how are you doing?'
print s.strip() #Removes whitespaces
print s.lower()
print s.upper() #Changes case
print s.isalpha()
print s.isdigit()
print s.isspace() #If all characters belong to a class
print s.startswith('H'... | true |
16d8dd34584e0b7bddc27bd9bddddbea2be24baf | fibeep/calculator | /hwk1.py | 1,058 | 4.21875 | 4 | #This code will find out how much money you make and evaluate whether you
#are using your finances apropriately
salary = int(input("How much money do you make? "))
spending = int (input("How much do you spend per month? "))
saving = salary - spending
#This line will tell you if you are saving enough money to eventual... | true |
7d090650fc7fc908e6a8914310b12878ce38dd80 | SpencerBeloin/Python-files | /factorial.py | 228 | 4.21875 | 4 | #factorial.py
#computes a factorial using reassignment of a variable
def main():
n= eval(input("Please enter a whole number: "))
fact = 1
for factor in range(n,1,-1):
fact = fact*factor
print fact
main()
| true |
0e4b133eba2337b2e30e389d1fe95606bf439233 | annettemathew/rockpaperscissors | /rock_paper_scissors.py | 2,038 | 4.1875 | 4 | #Question 2
# Write a class called Rock_paper_scissors that implements the logic of
# the game Rock-paper-scissors. For this game the user plays against the computer
# for a certain number of rounds. Your class should have fields for how many rounds
# there will be, the current round number, and the number of wins ... | true |
50888ff04c2d2ad05058c3ff77a6a94a2cd93fcf | atulmkamble/100DaysOfCode | /Day 19 - Turtle Race/turtle_race.py | 1,896 | 4.46875 | 4 | """
This program implements a Turtle Race. Place your bet on a turtle and tune on to see who wins.
"""
# Import required modules
from turtle import Turtle, Screen
from random import randint
from turtle_race_art import logo
def main():
"""
Creates turtles and puts them up for the race
:return: nothing
... | true |
d70fb4d40081bda2356d7f9909c5873a7ab3a126 | atulmkamble/100DaysOfCode | /Day 21 - Snake Game (Part 2)/main.py | 1,529 | 4.125 | 4 | """
This program implements the complete snake game
"""
from turtle import Screen
from time import sleep
from snake import Snake
from food import Food
from scoreboard import Scoreboard
def main():
# Setup the screen
screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor('black')
scr... | true |
cec29c33017cd1b9398ea08710e6ff219a43933c | atulmkamble/100DaysOfCode | /Day 10 - Calculator/calculator.py | 1,736 | 4.21875 | 4 | """
This program implements the classic calculator functionality (Addition, Subtraction, Multiplication & Division)
"""
from calculator_art import logo
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
... | true |
02089de9852f240b5ff07e1ca47e8e41e19537c2 | atulmkamble/100DaysOfCode | /Day 4 - Rock Paper Scissors/rock_paper_scissors.py | 2,029 | 4.3125 | 4 | """
This program is a game of rock, paper and scissors. You and the program compete in this game to emerge as a
winner. The program is not aware of your choice and it's a fair game. Please follow the directions in the program.
"""
from random import randint
from time import perf_counter
from time import process_time
... | true |
f97594ad3514fa073068bc4f54194ab13abeaec3 | duochen/Python-Kids | /Lecture06_Functions/Homework/rock-paper-scissors-game.py | 891 | 4.15625 | 4 | print("Welcome to the Rock Paper Scissors Game!")
player_1 = "Duo"
player_2 = "Mario"
def compare(item_1, item_2):
if item_1 == item_2:
return("It's a tie!")
elif item_1 == 'rock':
if item_2 == 'scissors':
return("Rock wins!")
else:
return("Paper wins!")
elif... | true |
c2abe9e5d0fce7f2cfbb6657e98349b4cfcbd591 | JohannesHamann/freeCodeCamp | /Python for everybody/time_calculator/time_calculator.py | 2,997 | 4.4375 | 4 | def add_time(start, duration, day= None):
"""
Write a function named add_time that takes in two required parameters and one optional parameter:
- a start time in the 12-hour clock format (ending in AM or PM)
- a duration time that indicates the number of hours and minutes
- (optional) a starting day... | true |
e4fc4b53e49fb44be9d4f1a0879948264fbf635d | prasannarajaram/python_programs | /palindrome.py | 340 | 4.6875 | 5 | # Get an input string and verify if it is a palindrome or not
# To make this a little more challenging:
# - Take a text input file and search for palindrome words
# - Print if any word is found.
text = raw_input("Enter the string: ")
reverse = text[::-1]
if (text == reverse):
print ("Palindrome")
else:
print... | true |
9fbf936bdf5c6f4798aa4ce97146394de3dadc40 | evanmiracle/python | /ex5.py | 1,230 | 4.15625 | 4 | my_name = 'Evan Miracle'
my_age = 40 #comment
my_height = 72 #inches
my_weight = 160 # lbs
my_eyes = 'brown'
my_teeth = 'white'
my_hair = 'brown'
# this works in python 3.51
print("Test %s" % my_name)
# the code below only works in 3.6 or later
print(f'Lets talk about {my_name}.')
print(f"He's {my_heigh... | true |
5204daaef67721495cd2bf137d21ff70c374b393 | adeshshukla/python_tutorial | /loop_for.py | 719 | 4.15625 | 4 | print()
print('--------- Nested for loops---------')
for i in range(1,6):
for j in range(1,i+1):
print(j, end=' ') # to print on the same line with space. Default it prints on next line.
#print('\t')
print()
print('\n') # to print two lines.
print('-------- For loop In a tuple with break ----------------')
# f... | true |
ca0e358ea678b2c375709e2efb286194b58cc697 | Annie677/me | /week3/exercise3.py | 2,483 | 4.40625 | 4 | """Week 3, Exercise 3.
Steps on the way to making your own guessing game.
"""
import random
def not_number_rejector(message):
while True:
try:
your_input = int(input(message))
print("Thank you, {} is a number.".format(your_input))
return your_input
except:
... | true |
10054b21be49bc24ea3b3772c97c116bf425533b | L51332/Project-Euler | /2 - Even Fibonacci numbers.py | 854 | 4.125 | 4 | '''
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued... | true |
ed2527878b79f75db82f16c90f223922834bd933 | Joyojyoti/intro__to_python | /using_class.py | 618 | 4.21875 | 4 | #Defining a class of name 'Student'
class Student:
#defining the properties that the class will contain
def __init__(self, name, roll):
self.name = name
self.roll = roll
#defining the methods or functions of the class.
def get_details(self):
print("The Roll number of {} is {}.".format(self.name, self.ro... | true |
0df7f56ad62d036dee1dc972a5d35984cfebcbec | snpushpi/P_solving | /preorder.py | 1,020 | 4.1875 | 4 | '''
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal display... | true |
c4cd3e7b687b65968f2863e2e19fb4fa303d4612 | snpushpi/P_solving | /1007.py | 1,356 | 4.125 | 4 | '''
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the ... | true |
602dd4b4552f050d3e799cc9bc76fc3816f40358 | snpushpi/P_solving | /next_permut.py | 1,499 | 4.1875 | 4 | '''
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place and use only constant extra memory.
Here a... | true |
82d7b5ebca2d850aea48cc1a4719ef53f7bd09de | snpushpi/P_solving | /1041.py | 1,536 | 4.25 | 4 | '''
On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions:
"G": go straight 1 unit;
"L": turn 90 degrees to the left;
"R": turn 90 degress to the right.
The robot performs the instructions given in order, and repeats them forever.
Return true if and o... | true |
9b6d023f110699aee047ab231e17a18989abd40d | snpushpi/P_solving | /search.py | 906 | 4.15625 | 4 | '''
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).
You are given a target value to search. If found in the array return true, otherwise return false.
Example 1:
Input: nums = [2,5,6,0,0,1,2], target = 0
Output: t... | true |
101f7b9e37b22819c534e66c6319e363a4cfa99f | Ahmodiyy/Learn-python | /pythonpractice.py | 1,142 | 4.21875 | 4 | # list comprehension
number_list = [1, 2, 3, 5, 6, 7, 8, 9, 10]
oddNumber_list = [odd for odd in number_list if odd % 2 == 1]
print(oddNumber_list)
number_list = [1, 2, 3, 5, 6, 7, 8, 9, 10]
oddNumber_list = [odd if odd % 2 == 1 else None for odd in number_list]
print(oddNumber_list)
# generator as use to get Iterato... | true |
2c3370cfb32e84cc709f9fbeaa99e961aa0a8ce0 | Asresha42/Bootcamp_day25 | /day25.py | 2,902 | 4.28125 | 4 | # Write a program to Python find the values which is not divisible 3 but is should be a multiple of 7. Make sure to use only higher order function.
def division(m):
return True if m % 3!= 0 and m%7==0 else False
print(division(23))
print(division(35))
# Write a program in Python to multiple the element of list by... | true |
d0f1e4c5434d246faf1d73097a00a8b87af298b4 | anjmehta8/learning_python | /Lecture 1.py | 1,113 | 4.375 | 4 | print(4+3+5)
#this is a comment
"""
hello
this is a multiline comment
"""
#values
#data types
#date type of x is value.
#Eg. 4 is integer. The 4 is value, integer is data type
"""
#integer
4 7 9 15 100 35 0 -3
#float
3.0 4.6 33.9 17.80 43.2
"""
print(6/3)
print(6//3)
print(7/2)
print(7//2)
#// rounds downward
... | true |
278942c8419ff38e9fe29adfb040ab2607afa0f7 | geekmj/fml | /python-programming/panda/accessing_elements_pandas_dataframes.py | 2,626 | 4.21875 | 4 | import pandas as pd
items2 = [{'bikes': 20, 'pants': 30, 'watches': 35},
{'watches': 10, 'glasses': 50, 'bikes':15,'pants': 5 }
]
store_items = pd.DataFrame(items2, index = ['Store 1', 'Store 2'])
print(store_items)
## We can access rows, columns, or individual elements of the DataFrame
# by usin... | true |
900ff84b08de1fb33a0262702f2e79dd11125470 | geekmj/fml | /python-programming/panda/accessing_deleting_elements_series.py | 2,231 | 4.75 | 5 | import pandas as pd
# Creating a Panda Series that stores a grocerry list
groceries = pd.Series(data = [30, 6, 'Yes', 'No'], index = ['eggs', 'apples', 'milk', 'bread'])
print(groceries)
# We access elements in Groceries using index labels:
# We use a single index label
print('How many eggs do we need to buy:', groc... | true |
dc0168556ef464beab6eb6371d24d7a726a08df0 | ads2100/pythonProject | /72.mysql3.py | 1,748 | 4.15625 | 4 | # 71 . Python MySql p2
"""
# The ORDER BY statement to sort the result in ascending or descending order.
# The ORDER BY keyword sorts the result ascending by default. To sort the result in
descending order, use the DESC keyword
# Delete: delete records from an existing table by using the "DELETE FROM" statement
# ... | true |
e3476d68e724f57e66131177f595e38d0ec492fe | ads2100/pythonProject | /15.list.py | 658 | 4.34375 | 4 | # 15. List In python 3
"""
# List Methods
len() the length of items
append() add item to the list
insert() add item in specific position
remove() remove specified item
pop() remove specified index, remove last item if index is not specified
clear() remove all items
"""
print("Lesson 15: List M... | true |
61a30c2c64aa88706a32b898c7fca786775c8ae1 | ads2100/pythonProject | /59.regularexpression3.py | 994 | 4.4375 | 4 | # 59. Regular Expressions In Python p3
"""
# The sub() function replaces the matches with the text of your choice:
# You can control the number of replacements by specifying the count parameter. sub('','',string,no)
# Match Object: A Match Object is as object containing information about the search and the result.... | true |
4c36b5214ebd5c63b66233c33a2c3bc59701e770 | ads2100/pythonProject | /16.tuple.py | 655 | 4.1875 | 4 | # 16. Tuple in Python
"""
# A tuple is a collection which is ordered and unchangeable.
# In Python tuples are written with round brackets ().
# if the tuple has just one item... ("item",)
# acces item in tuple with referring [index]
# You cannot change its values. Tuples are unchangeable.
# You cannot add item... | true |
4054eb15aa4e1c1a406a7766e5874288d321232b | tianyunzqs/LeetCodePractise | /leetcode_61_80/69_mySqrt.py | 956 | 4.15625 | 4 | # -*- coding: utf-8 -*-
# @Time : 2019/7/3 9:44
# @Author : tianyunzqs
# @Description :
"""
69. Sqrt(x)
Easy
Implement int sqrt(int x).
Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
Since the return type is an integer, the decimal digits are truncated and... | true |
f87328e58228e7fd3e3d16ffd999638ff38cf8f9 | AlanRufuss007/Iceberg | /python day1.py | 319 | 4.125 | 4 | num1 = 10
num2 = 20
sum = num1+num2
print("sum of {0} and {1} is {2}".format(num1,num2,sum))
num1 = input("Enter the number:")
num2 = input("/n Enetr the number:")
sum = float(num1)+float(num2)
print("The sum of {0} and {1} is {2}".format(num1,num2,sum))
a = 10
b = 20
maximum = max(a,b)
print(maximum)
| true |
f7c446009fd894559fb63c4a6b928ad6fc4a61e1 | eddy-v/flotsam-and-jetsam | /checkaba.py | 1,114 | 4.21875 | 4 | # eddy@eddyvasile.us
# how to check validity of bank routing number (aba)
# multiply the first 8 digits with the sequence 3, 7, 1, 3, 7, 1, 3, 7 and add the results
# the largest multiple of 10 of the sum calculated above must be equal to the 9th digit (checkDigit)
import math
def validateABA(aba):
checkDigit=int(a... | true |
084af05776f7ae422b74a67e08f68046b7acbd8c | AhirraoShubham/ML-with-Python | /variables.py | 1,771 | 4.65625 | 5 | ##########################################################################
# Variabels in Python
#
# * Variables are used to store information to be referenced and
# manipulated in computer program. They also provide a way of labeling
# data with a decriptive name, so our progams can be understood more
# cle... | true |
cf6db1cfb7ba5ebff8bf62f9d55eb93071f03e5f | noserider/school_files | /speed2.py | 539 | 4.125 | 4 | #speed program
speed = int(input("Enter speed: "))
#if is always the first statement
if speed >= 100:
print ("You are driving dangerously and will be banned")
elif speed >= 90:
print ("way too fast: £250 fine + 6 Points")
elif speed >= 80:
print ("too fast: £125 + 3 Points")
elif speed >= 70:
prin... | true |
8dcdef576c7fb51962fc4c2537742c92f51976f5 | noserider/school_files | /sleep.py | 580 | 4.125 | 4 | #int = interger
#we have two variable defined hourspernight & hoursperweek
hourspernight = input("How many hours per night do you sleep? ")
hoursperweek = int(hourspernight) * 7
print ("You sleep",hoursperweek,"hours per week")
#round gives a whole number answer or a specific number of decimal points
hourspermo... | true |
a3b6246985aa7ea86a440da73a96cefdd4eb6dc3 | noserider/school_files | /sleep1.py | 291 | 4.1875 | 4 | hourspernight = input("How many hours per night do you sleep? ")
hoursperweek = int(hourspernight) * 7
print ("You sleep",hoursperweek,"hours per week")
hourspermonth = float(hoursperweek) * 4.35
hourspermonth = round(hourspermonth)
print ("You sleep",hourspermonth,"hours per month")
| true |
1fb48b796d55cd2988bfb74060178f327b6b549e | helectron/holbertonschool-higher_level_programming | /0x0B-python-input_output/2-append_write.py | 282 | 4.28125 | 4 | #!/usr/bin/python3
'''module 2-append_write
Function:
append_write(filename="", text="")
'''
def append_write(filename="", text=""):
'''Function to append a text in a file'''
with open(filename, mode="a", encoding="utf-8") as myFile:
return myFile.write(text)
| true |
89f6aaf3951880cbacbf717942940359860c5cc7 | bdsh-14/Leetcode | /max_sum_subarray.py | 615 | 4.21875 | 4 | '''
Given an array of positive numbers and a positive number ‘k,’ find the maximum sum of any contiguous subarray of size ‘k’
Input: [2, 1, 5, 1, 3, 2], k=3
Output: 9
Explanation: Subarray with maximum sum is [5, 1, 3]
educative.io
'''
def max_sum(k, nums):
windowStart = 0
windowSum = 0
max_sum = 0
... | true |
0fa2259f7b692512ccfd9fc074ffd8640762853a | racer97/ds-class-intro | /python_basics/class02/exercise_6.py | 2,246 | 4.25 | 4 | '''
Edit this file to complete Exercise 6
'''
def calculation(a, b):
'''
Write a function calculation() such that it can accept two variables
and calculate the addition and subtraction of it.
It must return both addition and subtraction in a single return call
Expected output:
res = calculation(40, 10)
print... | true |
30132cd72458b94cd244412d9dcdc108a5674c6f | yatikaarora/turtle_coding | /drawing.py | 282 | 4.28125 | 4 | #to draw an octagon and a nested loop within.
import turtle
turtle= turtle.Turtle()
sides = 8
for steps in range(sides):
turtle.forward(100)
turtle.right(360/sides)
for moresteps in range(sides):
turtle.forward(50)
turtle.right(360/sides)
| true |
f0962e44eee61bfcb7524c68c346c7fb620269ec | EllipticBike38/PyAccademyMazzini21 | /es_ffi_01.py | 1,128 | 4.34375 | 4 | # Write a function insert_dash(num) / insertDash(num) / InsertDash(int num) that will insert dashes ('-') between each two odd numbers
# in num. For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number.
# Note that the number will always be non-negative (>= 0).
def insertDash(... | true |
ba6e0574e900be6eed7368ef339d1c1407ea1450 | noahmarble/Ch.05_Looping | /5.0_Take_Home_Test.py | 2,949 | 4.28125 | 4 | '''
HONOR CODE: I solemnly promise that while taking this test I will only use PyCharm or the Internet,
but I will definitely not ask another person except the instructor. Signed: ______________________
1. Make the following program work.
'''
print("This program takes three numbers and returns the sum.")
total = 0
... | true |
c83665d8eb9bcff974737e4705bb285b8b3384cf | FFFgrid/some-programs | /单向链表/队列的实现.py | 1,528 | 4.125 | 4 | class _node:
__slots__ = '_element','_next'#用__slots__可以提升内存应用效率
def __init__(self,element,next):
self._element = element #该node处的值
self._next = next #下一个node的引用
class LinkedQueue:
"""First In First Out"""
def __init__(self):
"""create an empty queue"""
self._hea... | true |
3081b981b3c1cc909ea8a84005bb3a47150af8db | Kelsi-Wolter/practice_and_play | /interview_cake/superbalanced.py | 2,487 | 4.1875 | 4 | # write a function to see if a tree is superbalanced(if the depths of any 2 leaf nodes
# is <= 1)
class BinaryTreeNode(object):
'''sample tree class from interview cake'''
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_left(self, value... | true |
d7955a29d3177efa8b6f558a9a26bd3a7c5f2c61 | mulualem04/ISD-practical-4 | /ISD practical4Q8.py | 282 | 4.15625 | 4 | # ask the user to input their name and
# asign it with variable name
name=input("your name is: ")
# ask the user to input their age and
# asign it with variable age
age=int(input("your age is: "))
age+=1 # age= age + 1
print("Hello",name,"next year you will be",age,"years old")
| true |
25405511319bff04521132f09d027eb1bedc6e7a | MahidharMannuru5/DSA-with-python | /dictionaryfunctions.py | 1,826 | 4.5625 | 5 | 1. str(dic) :- This method is used to return the string, denoting all the dictionary keys with their values.
2. items() :- This method is used to return the list with all dictionary keys with values.
# Python code to demonstrate working of
# str() and items()
# Initializing dictionary
dic = { 'Name' : 'Nandini', 'Ag... | true |
0bfff01de4d4b739f08c6d5499734d9039df55fc | octavian-stoch/Practice-Repository | /Daily Problems/July 21 Google Question [Easy] [Matrix].py | 1,618 | 4.15625 | 4 | #Author: Octavian Stoch
#Date: July 21, 2019
#You are given an M by N matrix consisting of booleans that
#represents a board. Each True boolean represents a wall. Each False boolean
#represents a tile you can walk on.
#Given this matrix, a start coordinate, and an end coordinate,
#return the minimum number... | true |
8ed67ae3d95f7ab983bd9b4d2374ac60bf1d44cb | tonycao/CodeSnippets | /python/1064python/test.py | 1,882 | 4.125 | 4 | import string
swapstr = "Hello World!"
result = ""
for c in swapstr:
if c.islower():
result += c.upper()
elif c.isupper():
result += c.lower()
else:
result += c
print(result)
string1 = input("Enter a string: ")
string2 = input("Enter a string: ")
string1_changed ... | true |
d7f42953edff49b748c99be05a79759fa6b994fc | zk18051/ORS-PA-18-Homework02 | /task2.py | 361 | 4.125 | 4 | print('Convert Kilometers To Miles')
def main():
user_value = input('Enter kilometers:')
try:
float(user_value)
print(float(user_value),'km')
except:
print(user_value, 'is not a number. Try again.')
return main()
user_miles = float(user_value) * 0.62137
print(user_val... | true |
b49a8155088c794799e763a3d43d12bd5fba57d6 | alokjani/project-euler | /e4.py | 845 | 4.3125 | 4 | # A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
#
# Find the largest palindrome made from the product of two 3-digit numbers.
def reverse(num):
return int(str(num)[::-1])
def isPalindrome(num):
if num == reverse(num):
... | true |
ee3f43d9120efc1037d5de4aefe93bcd4ea9fcad | DomfeLacre/zyBooksPython_CS200 | /module3/AutoServiceInvoice/AutoServiceInvoice1_with_dict.py | 2,232 | 4.25 | 4 | # Output a menu of automotive services and the corresponding cost of each service.
print('Davy\'s auto shop services')
# Creat dict() to store services : prices
servicePrices = {
'Oil change' : 35,
'Tire rotation' : 19,
'Car wash' : 7,
'Car wax' : 12
}
print('Oil change -- $35')
print('Tire rotation -... | true |
0a17bfb11cdda597d527c25d658ee78bf727ad90 | DomfeLacre/zyBooksPython_CS200 | /module7/MasterPractice_List_Dicts.py | 670 | 4.125 | 4 | ##### LISTS #####
# Accessing an Index of a List based on user input of a number: Enter 1 -5
ageList = [117, 115, 99, 88, 122]
# Ways to to get INDEX value of a LIST:
print(ageList.index(99)) # --> 2
# Use ENUMERATE to get INDEX and VALUE of LIST:
for index, value in enumerate(ageList):
print(index)
print('... | true |
3b3c1110fd920f34e35dbc55beb38d9b3ecb16cc | calvinjlzhai/Mini_quiz | /Mini_quiz.py | 2,737 | 4.28125 | 4 | #Setting score count
score = 0
#Introducation for user taking the quiz
print("Welcome to the quiz! Canadian Edition!\n")
#First question with selected answers provided
answer1 = input("Q1. What is the capital of Canada?"
"\na. Toronto\nb. Ottawa\nc. Montreal\nd.Vancouver\nAnswer: ")
# Account for... | true |
256990003e5d17856435c73e2faac0e495a2001f | DavidQiuUCSD/CSE-107 | /Discussions/Week1/OTP.py | 2,104 | 4.375 | 4 | import random #importing functions from Lib/random
"""
Author: David Qiu
The purpose of this program is to implement Shannon's One-Time Pad (OTP)
and to illustrate the correctness of the encryption scheme.
OTP is an example of a private-key encryption as the encryption key (K_e)
is equal to the decrypti... | true |
15f91012d9614d46fe03d9b4ff7b83dd53ad31b5 | vihahuynh/CompletePythonDeveloper2021 | /break-the-ice-with-python/question81.py | 321 | 4.21875 | 4 | """
By using list comprehension, please write a program to print the list
after removing numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].
"""
my_lst = [12,24,35,70,88,120,155]
# using filter
print(list(filter(lambda i: i % 35, my_lst)))
# using comprehensive
print([i for i in my_lst if i % 35])... | true |
9cc284d8bb87873882c68440c1ee19f0d4bcf094 | vihahuynh/CompletePythonDeveloper2021 | /break-the-ice-with-python/question4.py | 336 | 4.1875 | 4 | """
Input:
Write a program which accepts a sequence of comma-separated numbers from console
Output:
generate a list and a tuple which contains every number.Suppose the following input is supplied to the program
"""
seq = input('Please in out a sequence of comma-separated numbers\n')
print(seq.split(","))
print(tuple(s... | true |
154f1639865eb98d55ea566ccb0894b949ad14d3 | vihahuynh/CompletePythonDeveloper2021 | /break-the-ice-with-python/question28.py | 291 | 4.15625 | 4 | """
Define a function that can receive two integer numbers in string form and compute their sum and then print it in console.
"""
def sum_2_num():
num1 = input('Input the first number: \n')
num2 = input('Input the second number: \n')
print(int(num1) + int(num2))
sum_2_num()
| true |
0800b959b8ff2a1687b1c883135a06d5cec4776c | Pritheeev/Practice-ML | /matrix.py | 1,665 | 4.1875 | 4 | #getting dimension of matrix
print "enter n for nxn matrix"
n = input()
matrix1 = []
matrix2 = []
#taking elements of first matrix
print "Enter elements of first matrix"
for i in range(0,n):
#taking elements of first column
print "Enter elements of ",i,"column, seperated by space"
#raw_input().split() will... | true |
a586bcfe643f3d205136714172bf386a7b8c0e1f | wmaxlloyd/CodingQuestions | /Strings/validAnagram.py | 1,380 | 4.125 | 4 | # Given two strings s and t, write a function to determine if t is an anagram of s.
# For example,
# s = "anagram", t = "nagaram", return true.
# s = "rat", t = "car", return false.
# Note:
# You may assume the string contains only lowercase alphabets.
# Follow up:
# What if the inputs contain unicode characters? Ho... | true |
54f9eee09ecc211fc0cc378746ceb92c6ca76c8b | wdlsvnit/SMP-2017-Python | /smp2017-Python-maulik/extra/lesson8/madLibs.py | 909 | 4.40625 | 4 | #! python3
#To read from text files and let user add their own text anywhere the word-
#ADJECTIVE, NOUN, ADVERB or VERB
import re,sys
try:
fileAddress=input("Enter path of file :")
file = open(fileAddress)
except FileNotFoundError:
print("Please enter an existing path.")
sys.exit(1)
fileContent = file... | true |
b18cb0ad7ea82d7658bfb957eec60bb047c55971 | darkknight161/crash_course_projects | /pizza_toppings_while.py | 513 | 4.21875 | 4 | prompt = "Welcome to Zingo Pizza! Let's start with Toppings!"
prompt += "\nType quit at any time when you're done with your pizza masterpiece!"
prompt += "\nWhat's your name? "
name = input(prompt)
print(f'Hello {name}!')
toppings = []
topping = ""
while topping != 'quit':
topping = input('Name a toppi... | true |
640c1b68233d7fe7ee1cdc0a44b30dd0afce9c1b | umangag07/Python_Array | /array manipulation/changing shape.py | 1,019 | 4.625 | 5 | """
Changing shapes
1)reshape() -:gives a new shape without changing its data.
2)flat() -:return the element given in the flat index
3)flatten() -:return the copied array in 1-d.
4)ravel() -:returns a contiguous flatten array.
"""
import numpy as np
#1 array_variable.reshape(newshape)
a=np.arange(... | true |
31050593b4252bf94fb491e37e0a0628017d2b69 | 90-shalini/python-edification | /collections/tuples.py | 785 | 4.59375 | 5 | # Tuples: group of items
num = (1,2,3,4)
# IMUTABLE: you can't update them like a list
print(3 in num)
# num[1] = 'changed' # will throw error
# Faster than list, for the data which we know we will not change use TUPLE
# tuple can be a key on dictionary
# creating/accessing -> () or tuple
xyz = tuple(('a', 'b'))
print(... | true |
3aa3292bad982d13aa181250c738804b14af68ca | ssenthil-nathan/DSA | /linkedlistdelwithkey.py | 1,628 | 4.21875 | 4 | class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
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
def Delete(se... | true |
61739837cf983d73229378376144c6465d798813 | sevresbabylone/python-practice | /quicksort.py | 744 | 4.34375 | 4 | """Quicksort"""
def quicksort(array, left, right):
"""A method to perform quicksort on an array"""
if left < right:
pivot = partition(array, left, right)
quicksort(array, left, pivot-1)
quicksort(array, pivot+1, right)
def partition(array, left, right):
"""Returns new pivot after ... | true |
f853cecddcac4e12ec8d8d2f60e01e80ad840f98 | mclavan/Work-Maya-Folder | /2014-x64/prefs/1402/if_01_notes.py | 1,239 | 4.5625 | 5 | '''
Lesson - if statements
'''
'''
Basic if statement
if condition:
print 'The condition is True.'
'''
if True:
print 'The condition is True.'
if False:
print 'The condition is True'
'''
What is the condition?
2 == 2
2 == 3
'''
'''
Operators
== Equals
!= Not Equals
> Greater Than
>= Greater Than or equal... | true |
4560ae75b9c66bbb4cf36973f48db46b620e10a8 | pedronora/exercism-python | /prime-factors/prime_factors.py | 458 | 4.125 | 4 | def factors(value):
factors_list = []
# Divisible by 2:
while value % 2 == 0:
factors_list.append(2)
value = value / 2
# Divisible by other primes numbers:
sqrt = int(value**0.5)
for i in range(3, sqrt + 1, 2):
while value % i == 0:
factors_list.appen... | true |
fd7a963ec1bbba262d7f0cb3348995198a805674 | isobelyoung/Week4_PythonExercises | /Saturday_Submission/exercise_loops.py | 2,201 | 4.15625 | 4 | # Q1
print("***QUESTION 1***")
# Sorry Hayley - I had already written this bit before our class on Tuesday so didn't use the same method you did!
all_nums = []
while True:
try:
if len(all_nums) == 0:
num = int(input("Enter a number! "))
all_nums.append(num)
else:
... | true |
e6e3fe4c8e42ba41bfdabdc0df75ef1d40584fb8 | rigzinangdu/python | /practice/and_or_condition.py | 984 | 4.3125 | 4 | # We have to see [and] [or] conditions in pythons :
#[and] remember if both the conditions true than output will be true !!! if it's one of condition wrong than it's cames false ----> !!
#[or] remember one of the condition if it's true than its will be came true conditions -----> !!
#<-----[and]------>
name = "python... | true |
ca6f741a9a9300c892550aa72f17e1bcbb8197cf | Marwan-Mashaly/ICS3U-Weekly-Assignment-02-python | /hexagon_perimeter_calculator.py | 461 | 4.3125 | 4 | #!/usr/bin/env python3
# Created by Marwan Mashaly
# Created on September 2019
# This program calculates the perimeter of a hexagon
# with user input
def main():
# this function calculates perimeter of a hexagon
# input
sidelength = int(input("Enter sidelength of the rectangle (cm): "))
# proces... | true |
269fa0433fc048b50a8f24cc449a278c8b0b959c | kyumiouchi/python-basic-to-advanced | /11.73. Commun Errors.py | 2,023 | 4.25 | 4 | """
Common Errors
It is important to understand the error code
SyntaxError - Syntax error- not part of Python language
"""
# printf('Geek University') # NameError: name 'printf' is not defined
# print('Geek University')
# 1) Syntax Error
# 1
# def function: # SyntaxError: invalid syntax
# print('Geek Univers... | true |
631632c5fd1c857d8ec88288d114f5ca499a6a46 | elgun87/Dictionary | /main.py | 1,211 | 4.25 | 4 | # Created empty dictionary to add word and then to check if the word in the dictionary
# If yes print the meaning of the word
'''
dictionary = {}
while True:
word = input("Enter the word : ")
if word in dictionary: #checking if the word in the list
print(f'I have this word in my dictionary : {dictiona... | true |
704045f6eaaa5c51d088b11ceb7877a7cf69b2d3 | hannahmclarke/python | /dice_roll.py | 1,199 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue May 21 21:02:54 2019
@author: Hannah
"""
"""
Program will roll a pair of dice (number of sides will be randomly determined)
and ask the user to guess the total value, to determine who wins
Author: Hannah
"""
from random import randint
from time import sleep
def get_sides... | true |
18440ad27f90f49a1c08f5df08ffe73d743d6967 | Lanottez/IC_BA_2020 | /1st Term/Data_Structure_and_Algorithms/Codes/Exercises/ses02/ses02_extra.py | 2,174 | 4.4375 | 4 | def middle_of_three(a, b, c):
"""
Returns the middle one of three numbers a,b,c
Examples:
>>> middle_of_three(5, 3, 4)
4
>>> middle_of_three(1, 1, 2)
1
"""
# DON'T CHANGE ANYTHING ABOVE
# YOUR CODE BELOW
return ...
def sum_up_to(n):
"""
Returns the sum of integers ... | true |
8ee4f7214d13842468a03b05f7fdd25e3947c7fc | Lanottez/IC_BA_2020 | /1st Term/Data_Structure_and_Algorithms/Codes/Exercises/ses02/ses02.py | 1,057 | 4.375 | 4 | def sum_of_squares(x, y):
"""
Returns the sum of squares of x and y
Examples:
>>> sum_of_squares(1, 2)
5
>>> sum_of_squares(100, 3)
10009
>>> sum_of_squares(-1, 0)
1
>>> x = sum_of_squares(2, 3)
>>> x + 1
14
"""
# DON'T CHANGE ANYTHING ABOVE
# YOUR CODE BELOW... | true |
0c143e6c44d259294ada8ee2cda95c37f74a15ff | Lanottez/IC_BA_2020 | /1st Term/Data_Structure_and_Algorithms/Codes/Exercises/ses06/ses06_extra.py | 1,525 | 4.5625 | 5 | def caesar_cipher_encrypt(str_to_encrypt, n):
"""
Encrypt string using Caesar cipher by n positions
This function builds one of the most widely known encryption
techniques, _Caesar's cipher_. This works as follows:
you should be given a string str_to_encrypt and an encoding
integer n, wh... | true |
a858fbfb5b2570d28a04edf7ef7d99fae6cd1038 | mcwiseman97/Programming-Building-Blocks | /adventure_game.py | 1,829 | 4.1875 | 4 | print("You started a new game! Congratulations!")
print()
print("You have just had a very important phone call with a potential employer.")
print("You have been in search of a new job that would treat you better than you had been at your last place of emplyement.")
print("John, the employer, asked you to submit to him ... | true |
26eeca2fda332e7113887da66b91edf8ad362a2c | nerminkekic/Guessing-Game | /guess_the_number.py | 912 | 4.4375 | 4 | # Write a programme where the computer randomly generates a number between 0 and 20.
# The user needs to guess what the number is.
# If the user guesses wrong, tell them their guess is either too high, or too low.
import random
# Take input from user
guess = int(input("Guess a number between 0 and 20! "))
# Number of... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.