blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
6169a5437d4ea11923d0857763dbc8c26ab8fc10 | lonely7yk/LeetCode_py | /LeetCode484FindPermutation.py | 2,821 | 4.21875 | 4 | """
By now, you are given a secret signature consisting of character 'D' and 'I'. 'D' represents a
decreasing relationship between two numbers, 'I' represents an increasing relationship between
two numbers. And our secret signature was constructed by a special integer array, which contains
uniquely all the different... | true |
1ffd9e7ad58b95c2cc0ea50932209de8ce1218c2 | lonely7yk/LeetCode_py | /LeetCode425WordSquares.py | 2,901 | 4.15625 | 4 | """
Given a set of words (without duplicates), find all word squares you can build from them.
A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns).
For example, the word sequence ["ball","area","lead","lady"] forms a word square bec... | true |
b336e49c34dff2b02b7fd80f3f1ef8ab12513ec5 | lonely7yk/LeetCode_py | /LeetCode401BinaryWatch.py | 2,155 | 4.1875 | 4 | """
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom
represent the minutes (0-59).
Each LED represents a zero or one, with the least significant bit on the right.
For example, the above binary watch reads "3:25".
Given a non-negative integer n which represents the... | true |
8c36c1856f7a002736f85d36d5b6af586b613faf | lonely7yk/LeetCode_py | /LeetCode1000/LeetCode1363LargestMultipleofThree.py | 2,572 | 4.25 | 4 | """
Given an integer array of digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order.
Since the answer may not fit in an integer data type, return the answer as a string.
If there is no answer return an empty string.
Example 1:
Input: digits = [8,1,9]
... | true |
07f16a7a3c94ffb901cfa58800c1ea6d43c01ba2 | lonely7yk/LeetCode_py | /LeetCode080RemoveDuplicatesfromSortedArrayII.py | 2,097 | 4.125 | 4 | """
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most
twice and return the new length.
Do not allocate extra space for another array; you must do this by modifying the input array
in-place with O(1) extra memory.
Clarification:
Confused why the returned value is an int... | true |
5e6d19174f78688d3bf5abc2d9b7c1cf8e2233b0 | lonely7yk/LeetCode_py | /MergeSort.py | 866 | 4.15625 | 4 | def mergeSort(nums):
sort(nums, 0, len(nums) - 1)
def sort(nums, left, right):
if left < right:
mid = (left + right) // 2
sort(nums, left, mid)
sort(nums, mid + 1, right)
merge(nums, left, mid, right)
def merge(nums, left, mid, right):
tmp = [0 for i in range(right - left +... | false |
2ad306d0b108ae285a558caf7a29d762f3a2caee | devendrapansare21/Python-with-Lets-Upgrage | /Assignment_Day-4.py | 693 | 4.1875 | 4 | '''Program to find number of 'we' in given string and their positions in string '''
str1="what we think we become ; we are Python pragrammers"
print("Total number of 'we' in given string are ", str1.count("we"))
print("position of first 'we'--> ",str1.find("we"))
print("position of last 'we'--> ",str1.rfind("we... | true |
48021044a11b7c223777765d4586f343212bc0ac | dasszer/sudoki | /sudoki.py | 2,445 | 4.15625 | 4 | import pprint
# sudoki.py : solves a sudoku board by a backtracking method
def solve(board):
"""
Solves a sudoku board using backtracking
:param board: 2d list of ints
:return: solution
"""
find = find_empty(board)
if find:
row, col = find
else:
return True
for i i... | true |
a1f9631072c3e8da6a46de97db2cb0a3b9bcdb99 | priyatharshini23/2 | /power.py | 217 | 4.4375 | 4 | # 2
num=int(input("Enter the positive integer:"))
exponent=int(input("Enter exponent value:"))
power=1
i=1
while(i<=exponent):
power=power*num
i=i+1
print("The Result of{0}power{1}={2}".format(num,exponent,power)
| true |
6730b03c1a640ce24dcca9a2a335906295209339 | rajasekaran36/GE8151-PSPP-2020-Examples | /unit2/practice-newton-squareroot.py | 362 | 4.3125 | 4 | print("Newton Method to find sq_root")
num = int(input("Enter number: "))
guess = 1
while(True):
x = guess
f_x = (x**2) - num
f_d_x = 2*x
actual = x - (f_x/f_d_x)
actual = round(actual,6)
if(guess == actual):
break
else:
print("guess=",guess,"actual=",actual)
guess = ... | true |
70d0f8c4cc2fc8bb64513fa5b4350501a0812ad7 | Aamir-Meman/BoringStuffWithPython | /sequences/reduce-transforming-list.py | 646 | 4.15625 | 4 | """
The reduce function is the one iterative function which can be use
to implement all of the other iterative functions.
The basic idea of reduce is that it reduces the list to a single value.
The single value could be sum as shown below, or any kind of object including a new list
"""
from _functools import reduce... | true |
067c7fea36ae0de1ac94277db2f3215270a1040d | Tiger-a11y/PythonProjects | /dict Exercise.py | 479 | 4.21875 | 4 | # Apni Dictionary
dict = { "Set" : "Sets are used to store multiple items in a single variable.",
"Tuples" : "Tuples are used to store multiple items in a single variable.",
"List" : "Lists are used to store multiple items in a single variable.",
"String" : "Strings in python are surrounded b... | true |
e6dd483cc36f30e58d629cb0936ce4ef10c7e840 | zachariahsharma/learning-python | /numbers/6.py | 1,313 | 4.40625 | 4 | #this is telling python to remmember the types of people
types_of_people=10
#this is showng us a sentance that tells us how many types of people
x=f"there are {types_of_people} types of people"
#this is telling python to remmember the word binary under the word binary
binary='binary'
#this is telling python to remmemb... | false |
0d19edda62a7a9a5d74f0cd59405eb82cbaa924f | sankalpg10/GAN_Even_Num_Generator | /dataset.py | 1,240 | 4.125 | 4 | import math
import numpy as np
def int_to_bin(number: int) -> int:
# if number is negative or not an integer raise an error
if number < 0 or type(number) is not int:
raise ValueError("only positive integers are allowed")
# converts binary number into a list and returns it
return [... | true |
75764f96681592643f63082b017aa4c1a64d5e56 | justawho/Python | /TablePrinter.py | 620 | 4.25 | 4 | ## A function named printTable() that rakes a list of lists of strings and
## displays it in a well-organized table
def printTable(someTable):
colWidths = [0] * len(someTable)
for j in range (len(someTable[0])):
for i in range(len(someTable)):
colWidths[i] = len(max(someTable[i], key=len))
... | true |
92f7400e1ffa24879e1626c42e1e5c21c2e4eda8 | eshthakkar/coding_challenges | /bit_manipulation.py | 1,108 | 4.125 | 4 | # O(n^2 + T) runtime where n is the total number of words and T is the total number of letters.
def max_product(words):
"""Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters.
You may assume that each word will contain only l... | true |
3e6f61f56ba8f3973be04896b5827c9bf99f664b | eshthakkar/coding_challenges | /rectangle_overlap.py | 1,895 | 4.1875 | 4 | # Overlapping rectangle problem, O(1) space and time complexity
def find_rectangular_overlap(rect1, rect2):
""" Find and return the overlapping rectangle between given 2 rectangles"""
x_overlap_start_pt , overlap_width = find_range_overlap(rect1["x_left"], rect1["width"], rect2["x_left"], rect2["width"])
y... | true |
49421b3c6d6cd17108c8a9ef1c58130c2c531d3e | eshthakkar/coding_challenges | /kth_largest_from_sorted_subarrays.py | 676 | 4.125 | 4 | # O(k) time complexity and O(1) space complexity
def kth_largest(list1,list2,k):
""" Find the kth largest element from 2 sorted subarrays
>>> print kth_largest([2, 5, 7, 8], [3, 5, 5, 6], 3)
6
"""
i = len(list1) - 1
j = len(list2) - 1
count = 0
while count < k:
if list1... | true |
2dfff17f70a01dcaf4d742352055b160fbc06669 | jimibarra/cn_python_programming | /miniprojects/trip_cost_calculator.py | 396 | 4.375 | 4 | print("This script will calculate the cost of a trip")
distance = int(input("Please type the distance to drive in kilometers: "))
usage = float(input("Please type the fuel usage of your car in liters/kilometer: "))
cost_per_liter = float(input("Please type the cost of a liter of fuel: "))
total_cost = cost_per_liter *... | true |
a9cfee9934cc75445451574cfc4878cb11d39f4d | jimibarra/cn_python_programming | /07_classes_objects_methods/07_02_shapes.py | 1,539 | 4.625 | 5 | '''
Create two classes that model a rectangle and a circle. The rectangle class should
be constructed by length and width while the circle class should be constructed by
radius.
Write methods in the appropriate class so that you can calculate the area (of the rectangle and circle),
perimeter (of the rectangle) and cir... | true |
b1b191321e4f71bf57f4052aaa91cb01c8d60501 | jimibarra/cn_python_programming | /07_classes_objects_methods/07_01_car.py | 1,075 | 4.53125 | 5 | '''
Write a class to model a car. The class should:
1. Set the attributes model, year, and max_speed in the __init__() method.
2. Have a method that increases the max_speed of the car by 5 when called.
3. Have a method that prints the details of the car.
Create at least two different objects of this Car class and dem... | true |
8c1053a3d6092c244c89f36e11d60cc63b1d9090 | jimibarra/cn_python_programming | /03_more_datatypes/2_lists/03_11_split.py | 540 | 4.40625 | 4 | '''
Write a script that takes in a string from the user. Using the split() method,
create a list of all the words in the string and print the word with the most
occurrences.
'''
user_string = input("Please enter a string: ")
my_list = user_string.split(" ")
print(my_list)
my_dict = {}
my_set = set(my_list)
for item ... | true |
900c1185f0af45dd797ce33c0e0ce11fb759a449 | jimibarra/cn_python_programming | /02_basic_datatypes/2_strings/02_09_vowel.py | 991 | 4.4375 | 4 | '''
Write a script that prints the total number of vowels that are used in a user-inputted string.
CHALLENGE: Can you change the script so that it counts the occurrence of each individual vowel
in the string and print a count for each of them?
'''
#Total Vowel Count
vowel = ['a', 'e', 'i', 'o', 'u']
stri... | true |
1c551d5fdea25beebc8b9c566d17fc4c23a1c3b1 | jimibarra/cn_python_programming | /04_conditionals_loops/04_10_squares.py | 237 | 4.34375 | 4 | '''
Write a script that prints out all the squares of numbers from 1- 50
Use a for loop that demonstrates the use of the range function.
'''
for num in range(1,51):
square = num ** 2
print(f'The square of {num} is {square} ')
| true |
6bfee747928fa37a7cbcf03d73fd118133f6c930 | jimibarra/cn_python_programming | /01_python_fundamentals/01_07_area_perimeter.py | 277 | 4.1875 | 4 | '''
Write the necessary code to display the area and perimeter of a rectangle that has a width of 2.4 and a height of 6.4.
'''
area = 6.4 * 2.4
perimeter = 2 * (6.4 + 2.4)
print(f"The area of the rectangle is {area}")
print(f"The perimeter of the rectangle is {perimeter}")
| true |
f884581a74b2fa33ba0754284fac126e5e7e9bd6 | namnamgit/pythonProjects | /emprestimo_bancario.py | 949 | 4.125 | 4 | # rodrigo, may0313
# escreva um programa para aprovar o empréstimo bancário para compra de uma casa.
# o programa deve perguntar o valor da casa a comprar, o salário e a quantidade de anos a pagar.
# o valor da presta;ão mensal não pode ser superior a 30% do salário.
# calcule o valor da presta;ão como sendo o valor da... | false |
d8dfdd0ab64c2408a82be5fcbbd1b37fddbe0fee | namnamgit/pythonProjects | /maior_e_menor_numero.py | 810 | 4.125 | 4 | # rodrigo, apr1013
# escreva um programa que leia três números e que imprima o maior e o menor
while True:
numero1 = int(input('Digite o primeiro número: '))
numero2 = int(input('Digite o segundo número: '))
numero3 = int(input('Digite o terceiro número: '))
if numero1 > numero2 and numero1 > numero3:
print('%d... | false |
d0e9358885e01dee964f826d9302180cb7d3ab90 | AmyShackles/LearnPython3TheHardWay | /ex7.py | 1,396 | 4.28125 | 4 | # prints the string 'Mary had a little lamb'
print("Mary had a little lamb.")
# prints 'Its fleece was white as snow', the {} indicated replacement and 'snow' was the replacement text
print("Its fleece was white as {}.".format('snow'))
# prints 'And everywhere that Mary went'
print("And everywhere that Mary went.")
# p... | true |
7d9600f2d3b44ba69232a20d4586c61dc48fb8b6 | shkyler/gmit-cta-problems | /G00364753/Q2d.py | 957 | 4.375 | 4 | # Patrick Moore 2019-03-05
# This is a script to create a function that finds the max value in a list
# using an iterative approach, as directed by Question 2(d) of the
# Computational Thinking with Algorithms problem sheet
# define a function that takes a list as an argument
def max_iter(data):
# set the maximum v... | true |
9d6e2e6e6d8c55965fe4206b140c78b2ee145772 | michaelobr/gamble | /Gamble.py | 1,667 | 4.3125 | 4 | #Short introduction of the purpose of this program
print("This short little program will help determine the probability of profitability and ROI from playing 50/50 raffles.")
#The number of tickets the user will purchase
num_user_tickets = int(input("How many tickets will you purchase? "))
#The total amount of... | true |
bca2eb0df154973cc48900b3493b812846429288 | Izabela17/Programming | /max_int.py | 727 | 4.25 | 4 | """If users enters x number of positive integers.
Program goes through those integers and finds the maximum positive
and updates the code. If a negative integer is inputed the progam stops the execution
"""
"""
num_int = int(input("Input a number: ")) # Do not change this line
max_int = num_int
while num_int >= 0:
... | true |
62f9cca5ef39e633b5a20ffd6afb27772a5291fc | NikolaosPanagiotopoulos/python-examples-1 | /Addition.py | 225 | 4.21875 | 4 | #this program adds two numbers
num1=input('Enter first number: ')
num2=input('Enter second number: ')
#Add two numbers
sum=float(num1)+float(num2)
#display the sum
print('The sum of {0} and {1} is {2}'.format(num1,num2,sum))
| true |
14765ce398a35e4730122fb867cd45d386d19c7f | allysonvasquez/Python-Projects | /2-Automating Tasks/PhoneAndEmail.py | 852 | 4.15625 | 4 | # author: Allyson Vasquez
# version: May.15.2020
# Practice Exercises: Regular Expressions
# https://www.w3resource.com/python-exercises/re/index.php
import re
# TODO: check that a string contains only a certain set of characters(a-z, A-Z and 0-9)
charRegex = re.compile(r'\d')
test_str = str('My name is Allyson and ... | true |
c36172a0a429a3b3fb4a47464f7516ea21f3aac3 | OscarDani/EjerciciosUnidad3 | /03 Creational Patterns/AbstractFactory.py | 1,684 | 4.15625 | 4 | # AbstractFactory.py
class Dog:
"""A simple dog class"""
def speak(self):
return "Woof!"
def __str__(self):
return "Dog"
class Cat:
"""A simple cat class"""
def speak(self):
return "Maow!"
def __str__(self):
return "Ca... | false |
a9842c9896f227bb707b36906ec06f6fe93c0fc2 | talrab/python_excercises | /fibonacci.py | 707 | 4.3125 | 4 |
run_loop = True
num_elements = int(input("Please enter the number of elements: "))
if num_elements < 0:
run_loop = False
while (run_loop):
answer = []
for x in range(num_elements):
print( "X=" + str(x))
if (x+1==1):
answer.append(1)
elif (x+1==2):
answer.ap... | true |
5ecc9a206a36401a31124acf585a4a121a98291b | Pectin-eng/Lesson-6-Python | /lesson_6_task_4.py | 2,301 | 4.3125 | 4 | print('Задача 4.')
# Пользователь вводит атрибуты всего класса:
class Car:
speed = int(input('Введите вашу скорость: '))
color = input('Введите цвет машины: ')
name = input('Введите марку машины: ')
is_police = input('У вас полицейская машина? да/нет ')
def go(self, color, name):
print(f'... | false |
51a4bcb49223b93ebc60b0cce21f4cbde2c5b8da | yankwong/python_quiz_3 | /question_1.py | 506 | 4.25 | 4 | # create a list of number from 1 to 10
one_to_ten = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# using list comprehension, generate a new list with only even numbers
even_from_one_to_ten = [num for num in one_to_ten if (num % 2 == 0)]
# using list comprehension, generate a new list with only odd numbers
odd_from_one_to_ten = [num... | true |
421ce0dabf326248c65348bd3506e5596570730a | pnthairu/module7_Arrays | /sort_and_search_array.py | 2,039 | 4.3125 | 4 | from array import array as arr
from filecmp import cmp
# Start Program
"""
Program: sort_and_Search_array.py
Author: Paul Thairu
Last date modified: 06/23/2020
You can make a new files test_sort_and_search_array.py and sort_and_search_array.py.
In the appropriate directories. For this assignment,
you can... | true |
0d7b86cad05e0a7391f3eb150175446a58f20c6b | ratneshgujarathi/Encryptor-GUI- | /encrypt_try.py | 1,299 | 4.4375 | 4 | #ceasor cipher method encryption
#this is trial module to easy encrypyt the message
#c=(x-n)%26 we are ging to follow this equation for encrytion
#c is encryted text x is the char n is the shifting key that should be in numbers % is modulus 26 is total alphabets
#function for encrytion
def encryption(string... | true |
a7ca5c75d43d8fbdb082f89d549b1db9959e101a | praveendareddy21/ProjectEulerSolutions | /src/project_euler/problem4/problem4.py | 2,395 | 4.21875 | 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.
Created on Feb 18, 2012
@author: aparkin
'''
from project_euler.timing import timeruns, format... | true |
1ff64de9934c840e397cc2a3b07690cae8566481 | Diksha-11/OOPM-C-Notes | /python all sheets (Saurabh Shukla)/python ass 2/ass2.7.py | 485 | 4.1875 | 4 | print("Form of Quadratic Equation is :- ax^2+bx+c")
a=int(input("Enter 'a' of an quadratic question: "))
b=int(input("Enter 'b' of an quadratic question: "))
c=int(input("Enter 'c' of an quadratic question: "))
D=(b*b)-(4*a*c)
if (D<0):
print("Nature is unequal and imaginary")
elif(D==0):
print("Nat... | false |
eea1a67f02c852cd6ca7b2997c9bb7ffdff4e7ba | coomanky/game-v1 | /main.py | 2,848 | 4.3125 | 4 | #user information
print("hello and welcome to (game v2) , in this game you will be answering a series of questions to help inprove your knowledge of global warming ")
print (" ")
name = input ("What is your name? ")
print ("Hello " + name)
print(" ")
# tutorial
def yes_no(question):
valid = False
while no... | true |
52dad76686a481f7218cc435f240c3086897bc37 | DesignisOrion/DIO-Tkinter-Notes | /grid.py | 467 | 4.40625 | 4 | from tkinter import *
root = Tk()
# Creating Labels
label1 = Label(root, text="Firstname")
label2 = Label(root, text="Lastname")
# Creating Text fields
entry1 = Entry(root)
entry2 = Entry(root)
# Arrange in the grid format
label1.grid(row=0, column=0)
label2.grid(row=1, column=0)
# Want to have... | true |
fa5cdbad427a59b56aedf23a00a36b3dfc8dee2e | hubbm-bbm101/lab5-exercise-solution-b2200765016 | /Exercise 1.py | 307 | 4.21875 | 4 |
number = int(input("Welcome, enter a number: " ))
sum = 0
if number % 2 == 0 :
for i in range(1, number + 1):
sum = sum +i
print("the sum is: ", sum)
else:
for i in range(1, number + 1, 2):
sum = sum +i
average = sum / number
print("The average is: ", average)
| false |
39d2367ba2910304e1e50724783ffbd3ece60b0f | divyakelaskar/Guess-the-number | /Guess the number .py | 1,862 | 4.25 | 4 | import random
while True:
print("\nN U M B E R G U E S S I N G G A M E")
print("\nYou have 10 chances to guess the number.")
# randint function to generate the random number between 1 to 100
number = random.randint(1, 100)
""" number of chances to be given to the user t... | true |
356ad2bf5d602c408dd3c44c2e475c5a8379da0a | emorycs130r/Spring-2021 | /class_8/lists_intro.py | 454 | 4.25 | 4 | fruits = ['Apple', 'Strawberry', 'Orange']
# Index = Position - 1
# print(fruits[3])
print(type(fruits))
vegetables = []
print(f"Before adding value: {vegetables}")
vegetables.append('Brocolli')
print(f"After adding value: {vegetables}")
# print(vegetables)
fruits.append('Kiwi')
print(f"Fruits are: {fruits}")
f... | true |
9af404e0faeff67ace5589e05ecb3fdc9c680104 | emorycs130r/Spring-2021 | /class_6/temperature_conversion.py | 662 | 4.40625 | 4 | '''
Step 1: Write 2 functions that converts celsius to farenheit, celsius to kelvin.
Step 2: Get an input from user for the celsius value, and f/k for the value to convert it to.
Step 3: Based on the input call the right function.
'''
def c_to_f(temp):
return (9/5) * temp + 32
def c_to_k(temp):
return te... | true |
90653fca5369a36f393db2f49b30322080d0a944 | emorycs130r/Spring-2021 | /class_11/pop_quiz_1.py | 458 | 4.1875 | 4 | '''
Create a dictionary from the following list of students with grade:
bob - A
alice - B+
luke - B
eric - C
Get input of name from user using the "input()" and use it to display grade. If the name isn't present, display "Student not found"
'''
def working_numbers_set(input_list):
return list(dict.fromkeys(in... | true |
c0cb66d637c94a99eb4255c5991a2fcc0aae122c | vparjunmohan/Python | /Basics-Part-II/program30.py | 513 | 4.125 | 4 | '''Write a Python program to reverse the digits of a given number and add it to the original, If the sum is not a palindrome repeat this procedure.
Note: A palindrome is a word, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar.'''
def rev_number(n):
while ... | true |
6da942919c4afcaf3e6a219f42c642b4a34761c3 | vparjunmohan/Python | /Basics-Part-I/program19.py | 334 | 4.40625 | 4 | 'Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchanged.'
str = input('Enter a string ')
if str[:2] != 'Is':
newstr = 'Is' + str
print('New string is',newstr)
else:
print('String un... | true |
a73d72582cc340a3c517b4f5ecde7a396175b7cc | vparjunmohan/Python | /Basics-Part-I/program150.py | 241 | 4.1875 | 4 | 'Python Program for sum of squares of first n natural numbers.'
def squaresum() :
sm = 0
for i in range(1, n+1):
sm = sm + (i * i)
return sm
n = int(input('Enter a number '))
print('Sum of squares is',squaresum())
| true |
55e157e4a5c65734f28ef1a72c3c987732ca8ebc | vparjunmohan/Python | /Basics-Part-I/program7.py | 375 | 4.46875 | 4 | ''' Write a Python program to accept a filename from the user and print the extension of that.
Sample filename : abc.java
Output : java'''
filename = input('Enter file name: ')
extension = filename.split('.')
#split() method returns a list of strings after breaking the given string by the specified separator.
print(... | true |
5ba74fcc46711f7c2ce61a3e700579dc8323f775 | vparjunmohan/Python | /Basics-Part-I/program24.py | 244 | 4.125 | 4 | 'Write a Python program to test whether a passed letter is a vowel or not.'
def vowel():
if n in ['a','e','i','o','u']:
print(n,'is a vowel')
else:
print(n,'is not a vowel')
n = input('Enter a letter ')
vowel() | false |
b07684fbb0a42f18683a21a8fc4d08abe25c5712 | vparjunmohan/Python | /String/program1.py | 215 | 4.15625 | 4 | 'Write a Python program to calculate the length of a string.'
def strlen(string):
length = len(string)
print('Length of {} is {}'.format(string, length))
string = input('Enter a string ')
strlen(string)
| true |
b206558992aed8a4b4711787dff8f4933ad1d2ec | vparjunmohan/Python | /Basics-Part-II/program45.py | 671 | 4.15625 | 4 | '''Write a Python program to that reads a date (from 2016/1/1 to 2016/12/31) and prints the day of the date. Jan. 1, 2016, is Friday. Note that 2016 is a leap year.
Input:
Two integers m and d separated by a single space in a line, m ,d represent the month and the day.
Input month and date (separated by a single space)... | true |
26e6febc3d8ee93be39496e3c05ef6e62def8bac | mandeeppunia2020/python2020 | /Day8.py | 1,477 | 4.46875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[ ]:
Intronduction to tuple datatype:
# In[ ]:
defination: an immutable list is called tuple:
classfication: tuple is classified as an immutable datatype:
how to define the tuple:------>()
# In[1]:
student=('mandeep','punia','muskan','ravi','rohit','prince'... | false |
97cc5bf2f5ebc0790d157a8ad00a2006aa53ca64 | AbhishekKunwar17/pythonexamples | /11 if_elif_else condition/unsolved02.py | 236 | 4.21875 | 4 | Write Python code that asks a user how many pizza slices they want.
The pizzeria charges Rs 123.00 a slice
if user order even number of slices, price per slice is Rs 120.00
Print the total price depending on how many slices user orders. | true |
194a7d2d1d862cfda300d7e94bc7b8398af7be5b | icydee/python-examples | /fibonacci.py | 1,151 | 4.1875 | 4 | #!/usr/local/bin/python3
# Python 2.6 script to calculate fibonacci number
# Raises exception if invalid input is given
class fib_exception(Exception):
pass
def fib_recursive(input):
n = int(input)
if n <= 0 or n != input :
raise fib_exception()
elif n==1 :
# first in series
r... | false |
1ac7a9e8d9ee10eeb8e571d3dd6e5698356a1a47 | NitinSingh2020/Computational-Data-Science | /week3/fingerExc3.py | 1,503 | 4.28125 | 4 | def stdDevOfLengths(L):
"""
L: a list of strings
returns: float, the standard deviation of the lengths of the strings,
or NaN if L is empty.
"""
if len(L) == 0:
return float('NaN')
stdDev = 0
avgL = 0
lenList = [len(string) for string in L]
for a in lenList:
av... | true |
80d674fa13606ccecb4943feb34ea9878cf45cca | AutumnColeman/python_basics | /python-strings/caesar_cipher.py | 688 | 4.5625 | 5 | #Given a string, print the Caesar Cipher (or ROT13) of that string. Convert ! to ? and visa versa.
string = raw_input("Please give a string to convert: ").lower()
cipher_list = "nopqrstuvwxyzabcdefghijklm"
alpha_list = "abcdefghijklmnopqrstuvwxyz"
new_string = ""
for letter in string:
if letter == "m":
ne... | true |
3bac6dcded9f050f8c3d8aff2e2f9f5083310d00 | nishesh19/CTCI | /educative/rotateLinkedList.py | 1,146 | 4.1875 | 4 | from __future__ import print_function
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
def print_list(self):
temp = self
while temp is not None:
print(temp.value, end=" ")
temp = temp.next
print()
def rotate(head, rotations):
# TODO: Write ... | true |
9c091e4e3c4090e276eaad3b8ae15ea5e8fb6654 | nishesh19/CTCI | /Arrays and Strings/Urlify.py | 721 | 4.28125 | 4 | # Write a method to replace all spaces in a string with '%20: You may assume that the string
# has sufficient space at the end to hold the additional characters, and that you are given the "true"
# length of the string. (Note: If implementing in Java, please use a character array so that you can
# perform this operatio... | true |
6e58c3d2c52524ae138b55a4d4dbaf57512d363b | nishesh19/CTCI | /LinkedList/deletemiddlenode.py | 1,892 | 4.125 | 4 | '''
2.3 Delete Middle Node: Implement an algorithm to delete a node in the middle (i.e., any node but
the first and last node, not necessarily the exact middle) of a singly linked list, given only access to
that node.
EXAMPLE
Input: the node c from the linked list a->b->c->d->e->f
Result: nothing is returned, but the n... | true |
e94f1f07150945766804cb28a1e831429bc880de | L0GI0/Python | /Codes/functions_with_lists.py | 919 | 4.25 | 4 | #!/usr/bin/python3
lucky_numbers = [32, 8, 15, 16, 23, 42]
friends = ["Kevin", "Karen", "Jim", "Oscar", "Tom"]
print(friends)
#append another lists at the end of a list
friends.extend(lucky_numbers)
print(friends)
#adding indivitual elements at the end of given list
friends.append("Creed")
#adding individual elements... | true |
7255e858a67f1640b7f82972435b916b1dc4f301 | L0GI0/Python | /Codes/if_statement_and_comparistion.py | 245 | 4.3125 | 4 | #!/usr/bin/python3
#comparison operators eg. >=, <. <=, ==, !=
def max_num(num1, num2, num3):
if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3
print (max_num(3, 4, 5))
| false |
e4434cfa2ff0b2b53664dd678bb0d6c9490e8e67 | ibnahmadCoded/how_to_think_like_a_computer_scientist_Chapter_5 | /palindrom_checker.py | 248 | 4.21875 | 4 | def is_palindrome(word):
"""Reverses word given as argument"""
new_word = ""
step = len(word) + 1
count = 1
while step - count != 0:
new_word += word[count * -1]
count += 1
return new_word == word
| true |
0ff0a238da2e48a751d66401f303090375a03ed1 | Sandbox4KidsTM/Python_Basics | /Supplemental_Material/PythonProjects/14. ALGEBRA/ALGEBRA/StringManipulation.py | 733 | 4.125 | 4 | # https://www.youtube.com/watch?v=k9TUPpGqYTo&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=2
# MATH FUNCTIONS in Python: https://docs.python.org/3.2/library/math.html
#all key methods related to string manipulation
message = "Hello World"
print(message[0:3]) #including lower limit, but not including upper li... | true |
111a4db76992a35f4590e21b69684d8f7d057b94 | SherMM/programming-interview-questions | /epi/sorting/selection_sort.py | 812 | 4.21875 | 4 | import sys
import random
def selection_sort(array):
"""
docstring
"""
def swap(arr, i, j):
arr[i], arr[j] = arr[j], arr[i]
for i in range(len(array)):
min_value = array[i]
min_index = i
for j in range(i+1, len(array)):
value = array[j]
if va... | false |
fa987c3d6e2c2e1dba192beee4cb430cb9d265ce | DZGoldman/Google-Foo-Bar | /problem22.py | 2,284 | 4.40625 | 4 | # things that are true:
"""
Peculiar balance
================
Can we save them? Beta Rabbit is trying to break into a lab that contains the
only known zombie cure - but there's an obstacle. The door will only open if a
challenge is solved correctly. The future of the zombified rabbit population is
at stake, so Beta ... | true |
3b0cf9d684b3b6c02b9fad9165f2df2904cdf20c | thomaswhyyou/python_examples | /indentation_behavior.py | 298 | 4.53125 | 5 | # Example 1.
numbers = [1, 2, 3]
letters = ["a", "b", "c"]
print("\nExample 1:")
for n in numbers:
print(n)
for l in letters:
print(l)
# Example 2.
numbers = [1, 2, 3]
letters = ["a", "b", "c"]
print("\nExample 2:")
for n in numbers:
print(n)
for l in letters:
print(l)
| false |
dd37dfdb73c77dc4cbacd57bf754b6b9b6c131ac | LucienVen/python_learning | /algorithm/insertionSort.py | 752 | 4.3125 | 4 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
# 插入排序
def insertion_sort(list):
for index in range(1, len(list)):
current_value = list[index]
position = index
while position > 0 and list[position - 1] > current_value:
print '比较项>>> list[position]: {} -- current_value: {}'.format(l... | false |
303dc61ab22c33d78817134b852e8f4826c0d97b | AneliyaPPetkova/Programming | /Python/2.StringsAndDataStructures/1.StringWith10Symbols.py | 342 | 4.125 | 4 | """Напишете програма, която взима текст от потребителя
използвайки input() и ограничава текста до 10 символа и добавя ... накрая
"""
stringInput = input()
if len(stringInput) >= 10:
print(stringInput[:10] + "...")
else:
print(stringInput)
| false |
79a7c011b0ed82c278939fef81f60c4be7c88320 | ashutoshfolane/PreCourse_1 | /Exercise_2.py | 2,030 | 4.34375 | 4 | # Exercise_2 : Implement Stack using Linked List.
class Node:
# Node of a Linked List
def __init__(self, data=0, next=None):
self.data = data
self.next = next
class Stack:
def __init__(self):
# Head is Null by default
self.head = None
# Check if stack is empty
def ... | true |
3c0133cdc322e6dd514e693f319baa869857ee73 | amandineldc/git | /exo python.py | 1,340 | 4.25 | 4 | #exo1 : Write a Python program to convert temperatures to and from celsius, fahrenheit.
#[ Formula : c/5 = f-32/9 [ where c = temperature in celsius and f = temperature in fahrenheit ]
print("---MENU---\n1) °C en °F\n2) °F en °C\nPour quitter tape 0")
menu=int(input("Fais un choix :"))
if menu == 1:
C = int(in... | false |
6686ad3efa4b2036988196c50b0ab6f56c1903f7 | debajyoti-ghosh/Learn_Python_The_Hard_Way | /Exe8.py | 527 | 4.125 | 4 | formatter = "{} {} {} {}"
#format can take int as argument
print(formatter.format(1, 2, 3, 4))
#.format can take string as argument
print(formatter.format('one', 'two', 'three', 'four'))
#.format can take boolean as argument
print(formatter.format(True, False, True, False))
#.format can take variable as argument
pr... | true |
72301ec7c64df86bd3500a01d59262d2037866dd | Aditya-A-Pardeshi/Coding-Hands-On | /4 Python_Programs/1 Problems on numbers/10_EvenFactors/Demo.py | 411 | 4.125 | 4 | '''
Write a program which accept number from user and print even factors of that number
Input : 24
Output: 2 4 6 8 12
'''
def PrintEvenFactors(no):
if(no<0):
no = -no;
for i in range(2,int(no/2)+1):
if(no%i == 0):
print("{} ".format(i),end = " ");
def main():
no = int(... | true |
408babae6f2e8b73ff56eaab659d421628c46cab | Aditya-A-Pardeshi/Coding-Hands-On | /4 Python_Programs/6 Problems on characters/2_CheckCapital/Demo.py | 408 | 4.15625 | 4 | '''
Accept Character from user and check whether it is capital or not
(A-Z).
Input : F
Output : TRUE
Input : d
Output : FALSE
'''
def CheckCapital(ch):
if((ch >= 'A') and (ch <= 'Z')):
return True;
else:
return False;
def main():
ch = input("Enter character:");
result = False... | true |
c3c59745e3de6f17d1f404221048e9ce92aed2e3 | Aditya-A-Pardeshi/Coding-Hands-On | /4 Python_Programs/1 Problems on numbers/22_DisplayTable/Demo.py | 348 | 4.125 | 4 | '''
Write a program which accept number from user and display its table.
Input : 2
Output : 2 4 6 8 10 12 14 16 18 20
'''
def PrintTable(num):
if(num == 0):
return;
for i in range(1,11):
print(num*i,end = " ");
def main():
no = int(input("Enter number: "));
PrintTable(no);
if __name_... | true |
f31b354b73c09c00f6c797bbefd5e89017b93fe2 | Aditya-A-Pardeshi/Coding-Hands-On | /4 Python_Programs/1 Problems on numbers/3_Print_Numbers_ReverseOrder/Demo.py | 356 | 4.15625 | 4 | #Accept a positive number from user and print numbers starting from that number till 1
def DisplayNumbers(no1):
if(no1 < 0):
print("Number is not positive");
else:
for i in range(no1,0,-1):
print(i);
def main():
no1 = int(input("Enter number: "));
DisplayNumbers(no1);
if... | true |
c40119ce76ad55a08ee28a35e120940d643a2b49 | DMSstudios/Introduction-to-python | /input.py | 726 | 4.28125 | 4 | #first_name = input('enter your first name: ')
#second_name = input('enter your first name: ')
#print( f'My name is:' first_name, second_name')
#print(f"My name is,{first_name},{second_name}")
#print("My name is {} {}" .format(first_name,second_name))
taskList = [23, "Jane", ["Lesson 23", 560, {"currency": "KES"}]... | true |
7a1ae6018cb2d4f2eba4296c4a1e928de77f9089 | Watersilver/cs50 | /workspace/pset6/mario/less/mario.py | 390 | 4.125 | 4 | # Draws hash steps from left to right. Last step is double as wide as others
from cs50 import get_int
# Gets height by user
height = -1
while height < 0 or height > 23:
height = get_int("Height: ")
# Prints half pyramid
# Iterate rows
for i in range(height):
# Iterate collumns
for j in range(height + 1):... | true |
78cc32c777d2be27d9a280fd1b8478b02d2d78d2 | thakopian/100-DAYS-OF-PYTHON-PROJECT | /BEGIN/DAY_03/005.2-pizza-order-nested-conditional.py | 1,149 | 4.25 | 4 | # 🚨 Don't change the code below 👇
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ")
add_pepperoni = input("Do you want pepperoni? Y or N ")
extra_cheese = input("Do you want extra cheese? Y or N ")
# 🚨 Don't change the code above 👆
# Write your code below this li... | true |
70c1be0fa061a29d265589d2fc8390769d219330 | thakopian/100-DAYS-OF-PYTHON-PROJECT | /BEGIN/DAY_03/001.flow-if-else-conditional.py | 277 | 4.28125 | 4 | print("Can you the rollercoaster!?")
height = int(input("What is your height in cm? "))
'''
#pseudo code
if condition:
do this
else:
do this
'''
if height >= 125:
print("Get on board and ridet he rollercoaster!!!")
else:
print("sorry not good enough kid!")
| true |
a8d94cc1c75e67f5f965b11f2ae74973f4147c6a | thakopian/100-DAYS-OF-PYTHON-PROJECT | /BEGIN/DAY_04/04.1-day-4-2-exercise-solution.py | 1,817 | 4.3125 | 4 | # https://repl.it/@thakopian/day-4-2-exercise#main.py
# write a program which will select a random name from a list of names
# name selected will pay for everyone's bill
# cannot use choice() function
# inputs for the names - Angela, Ben, Jenny, Michael, Chloe
# import modules
import random
# set varialbles for in... | true |
3c77f361ce4c9e5622fce0236a73fff1cfedd73b | thakopian/100-DAYS-OF-PYTHON-PROJECT | /BEGIN/DAY_04/03-lists.py | 1,199 | 4.25 | 4 | # list exercise replit https://repl.it/@thakopian/day-4-list-practice#main.py
states_of_america = ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut", "Massachusetts", "Maryland", "South Carolina", "New Hampshire", "Virginia", "New York", "North Carolina", "Rhode Island", "Vermont", "Kentucky", "Tennes... | false |
71ed0dcfdfe584e915b41a7bbbc197c3609d97e6 | chupin10/KodeKonnectPyClass | /rockpaperscissors.py | 812 | 4.125 | 4 | import random
computerchoice = random.randint(0, 2)
if computerchoice == 0:
computerchoice = 'rock'
if computerchoice == 1:
computerchoice = 'paper'
if computerchoice == 2:
computerchoice = 'scissors'
print(computerchoice)
yourchoice = input('Enter rock, paper, or scissors: ')
if yourchoice == computerch... | false |
ae31c6cde30707ffccaf9bc0ed9eb70756f11514 | xc13AK/python_sample | /week_v2.0.py | 655 | 4.46875 | 4 | #!/usr/bin/python3.4
#-*- coding:UTF-8 -*-
import datetime
#get the feature day from input
year=int(input("enter the year:"))
month=int(input("enter the month:"))
day=int(input("enter the day:"))
new=datetime.date(year,month,day)
print("the day is %s-%s-%s"%(new.year,new.month,new.day))
weekday=int(new.weekday())
... | true |
586b29249cd0af8bad4d2622fca3846faa5626d1 | RandomStudentA/cp1404_prac | /prac_05/hex_colours.py | 446 | 4.34375 | 4 | COLOR_TO_NAME = {"AliceBlue": "#f0f8ff", "AntiqueWhite": "#faebd7", "aquamarine1": "#7fffd4", "azure1": "#f0ffff",
"beige": "#f5f5dc", "bisque1": " #ffe4c4", "black": "#000000"}
color_name = input("Enter color name: ")
while color_name != "":
if color_name in COLOR_TO_NAME:
print(color_nam... | false |
3b105b43f202b9ca5f35fe8a65a3e5ce7ca4815c | RandomStudentA/cp1404_prac | /prac_04/lists_warmup.py | 984 | 4.34375 | 4 | numbers = [3, 1, 4, 1, 5, 9, 2]
# What I thought it would print: 3
# What it printed: 3
print(numbers[0])
# What I thought it would print: 2
# What it printed: 2
print(numbers[-1])
# What I thought it would print: 1
# What it printed: 1
print(numbers[3])
# What I thought it would print: 2
# What it printed: [3, 1, ... | true |
c67eee77631f9ef0d3a325eadeaab4039f3d8b1b | Systematiik/Python-The-Hard-Way | /ex15_1.py | 429 | 4.21875 | 4 | # reading textfiles by user input
# open() opens file when in same directory
# read() reads file
from sys import argv
# takes argument and puts under variable txt and function open, opens filename
filename = input("Give me a text file to read (.txt): ")
txt = open(filename)
print(f"Here's your file {filenam... | true |
ad8927d675907b661391b785026adaae2f33d3bd | Systematiik/Python-The-Hard-Way | /ex15.py | 702 | 4.15625 | 4 | #reading textfiles by passing args and user input
#open() opens file when in same directory
#read() reads file
from sys import argv
script, filename = argv
#takes argument and puts under variable txt and function open, opens filename
txt = open(filename)
print(f"Here's your file {filename}: ")
print(txt.... | true |
ea77221764e592bae48f42e9a6b5d512744f505c | Systematiik/Python-The-Hard-Way | /ex29.py | 654 | 4.1875 | 4 | people = 20
cats = 30
dogs = 15
#20 < 30
#print
if people < cats:
print("Too many cats! The world is doomed!")
#20 !> 30
#no print
if people > cats:
print("Not many cats! The world is saved!")
#20 !< 15
#no print
if people < dogs:
print("The world is drooled on!")
#20 > 15
#print
i... | false |
107b0bb56f9a83d4f3ef6bb8c0d218b85757c96f | tranxuanduc1501/Homework-16-7-2019 | /Bài 4 ngày 16-7-2019.py | 704 | 4.25 | 4 | a= float(input("Input a to solve equation: ax^2+bx+c=0 "))
b= float(input("Input b to solve equation: ax^2+bx+c=0 "))
c= float(input("Input c to solve equation: ax^2+bx+c=0 "))
if a==0 and b==0 and c==0:
print('This equation has infinity solution')
elif a==0 and b==0 and c!=0:
print('This equation has no ... | false |
9c738875350bec148a14096eec94605fe89c99b0 | vibhorsingh11/hackerrank-python | /04_Sets/02_SymmetricDifference.py | 467 | 4.3125 | 4 | # Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates
# those values that exist in either M or N but do not exist in both.
# Enter your code here. Read input from STDIN. Print output to STDOUT
a, b = (int(input()), input().split())
c, d = (int... | true |
7276c10f1e342e0f6ca8170a299fc4471cd955a6 | menasheep/CodingDojo | /Python/compare_arrays.py | 1,165 | 4.15625 | 4 | list_one = [1,2,5,6,2]
list_two = [1,2,5,6,2]
if list_one == list_two:
print True
print "These arrays are the same!"
else:
print False
print "These arrays are different. Womp womp."
# *****
list_one = [1,2,5,6,5]
list_two = [1,2,5,6,5,3]
if list_one == list_two:
print True
print "These array... | true |
0dfe39b515dc391753d29b540d6af13abefd8269 | yshshadow/Leetcode | /201-250/211.py | 2,515 | 4.1875 | 4 | # Design a data structure that supports the following two operations:
#
# void addWord(word)
# bool search(word)
# search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter.
#
# Example:
#
# addWord("bad")
# addWord("dad")
# addWord... | true |
9137c399473cded62f26e36e512433eb4faaa00f | yshshadow/Leetcode | /1-50/48.py | 1,614 | 4.125 | 4 | # You are given an n x n 2D matrix representing an image.
#
# Rotate the image by 90 degrees (clockwise).
#
# Note:
#
# You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
#
# Example 1:
#
# Given input matrix =
# [
#... | true |
b99592d95dcd3f2ce168808da0f08c2b5a83da5d | yshshadow/Leetcode | /51-100/94.py | 1,376 | 4.125 | 4 | # Given a binary tree, return the inorder traversal of its nodes' values.
#
# For example:
# Given binary tree [1,null,2,3],
# 1
# \
# 2
# /
# 3
# return [1,3,2].
#
# Note: Recursive solution is trivial, could you do it iteratively?
# Definition for a binary tree node.
class TreeNode(object):
de... | true |
c73e65896ce89c0ae540e9330a0214a0a5ba5a93 | yshshadow/Leetcode | /51-100/88.py | 1,074 | 4.21875 | 4 | # Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
#
# Note:
# You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.
#
class... | true |
310b99e9b68a2f81323c619977371e3638fc66b1 | yshshadow/Leetcode | /300-/572.py | 1,583 | 4.21875 | 4 | # Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself.
#
# Example 1:
# Given tree s:
#
# 3
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.