blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
b9b22be77a2ec061bba9dea6a8967e6f18e1da3c | cumtqiangqiang/leetcode | /top100LinkedQuestions/5_longest_palindromic_sub.py | 783 | 4.125 | 4 | '''
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
Input: "babad"
Output: "bab"
Note: "aba" is also a valid answer.
Example 2:
Input: "cbbd"
Output: "bb"
'''
def longestPalindrome(s: str) -> str:
start = 0
end = 0
for i in range(len(s... | true |
f1386a1b5ff8705938dbdd96f11c954fdf1dfd3c | diceitoga/regularW3PythonExercise | /Exercise8.py | 339 | 4.125 | 4 | #Exerciese 8: 8. Write a Python program to display the first and last colors from the following list. Go to the editor
#color_list = ["Red","Green","White" ,"Black"]
color_list = ["Red","Green","White" ,"Black"]
lengthof=len(color_list)
print("First Item: {}".format(color_list[0]))
print("Last Item: {}".format(color_... | true |
cf2a4e7217f251ae3b854f5c5c44eaa3ea3f140b | diceitoga/regularW3PythonExercise | /Ex19_is.py | 413 | 4.21875 | 4 | #Ex 19: 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
print("test")
sentence_string = input("Please enter a short sentence and I will add something: ")
first_l = sentence_string.spli... | true |
84fee185f3fbf9a59cf1efe89ca7ff5472e97691 | diceitoga/regularW3PythonExercise | /Ex21even_odd.py | 388 | 4.46875 | 4 | #Ex21. Write a Python program to find whether a given number (accept from the user) is even or odd,
#print out an appropriate message to the user.
def even_odd(num):
even_odd = ''
if num%2==0:
even_odd = 'even'
else:
even_odd = 'odd'
return even_odd
what_isit =even_odd(int(input("Please enter an integer betw... | true |
d83882634e4db5e59edfbb1c760ef0483010fd3b | joqhuang/si | /lecture_exercises/gradepredict.py | 2,003 | 4.40625 | 4 | # discussion sections: 13, drop 2
# homeworks: 14, drop 2
# lecture exercise: 26, drop 4
# midterms: 2
# projects: 3
# final project: 1
# get the data into program
# extract information from a CSV file with all the assignment types and scores
# return a data dictionary, where the keys are assignment groups and values ... | true |
0abe0e63e9cd588267c456a87ea6ce6068e3da15 | Tonyqu123/data-structure-algorithm | /Valid Palindrome.py | 720 | 4.3125 | 4 | # Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
#
# For example,
# "A man, a plan, a canal: Panama" is a palindrome.
# "race a car" is not a palindrome.
#
# Note:
# Have you consider that the string might be empty? This is a good question to ask dur... | true |
8c7569bf644859b9a51d0a6b06935c0dcbbfd509 | chococigar/Cracking_the_code_interview | /3_Stacks_and_Queues/queue.py | 598 | 4.1875 | 4 | #alternative method : use lists as stack
class Queue(object) :
def __init__(self):
self.items = []
def isEmpty(self):
return (self.items==[])
def enqueue(self, item):
self.items.insert(0, item)
def dequeue(self):
self.items.pop() #first in first out. last item is first.
... | true |
93b706571c7b3451f5c677cc7d9ddb1dffa67f13 | blkbrd/python_practice | /helloWorld.py | 2,330 | 4.15625 | 4 | print ("hello World")
'''
#print('Yay! Printing.')
#print("I'd much rather you 'not'.")
#print('I "said" do not touch this.')
print ( "counting is fun")
print ("hens", 25 + 30 / 6)
print ("Is it greater?", 5 > -2)
#variables
cars = 100
space_in_a_car = 4
drivers = 30
passengers = 90
cars_not_driven = c... | true |
64f31b62c4a464b495cf051d73c26b67b37cc8bb | padma67/guvi | /looping/sum_of_first_and_last_digit_of_number.py | 342 | 4.15625 | 4 | # Program to find First Digit and last digit of a Number
def fldigit():
number = int(input("Enter the Number: "))
firstdigit = number
while (firstdigit >= 10):
firstdigit = firstdigit // 10
lastdigit = number % 10
print("sum of first and last digit of number is {0}".format(firstdigit+l... | true |
df2c4134cb5454aac257dcb270cc651595b3a8c4 | padma67/guvi | /looping/Calculator.py | 865 | 4.1875 | 4 | #Calculator
#get the input value from user
num1=float(input("Enter the number 1:"))
num2=float(input("Enter the number 2:"))
print("1.Add")
print("2.Sub")
print("3.Div")
print("4.Mod")
print("5.Mul")
print("6.Expo")
#get the function operator from uuer
ch=float(input("Enter your choice:"))
c=round(ch)
if(c==1):
pr... | true |
451744ff93bd4ee503af5d2f28e1bf8d89f16517 | padma67/guvi | /looping/Print_even_numbers_from_1_to_100.py | 264 | 4.1875 | 4 | #To print all even numbers between 1 to 100
def Even():
#declare the list for collect even numbers
even=[]
i=1
while(i<=100):
if(i%2==0):
even.append(i)
i=i+1
print("even numbers between 1 to n",even)
Even()
| true |
6e135b53bbde0cd65bdf7c36815195dd29e6ec66 | Nitin26-ck/Scripting-Languages-Lab | /Part B/Lab 5/Prg5_file_listcomprehension.py | 2,064 | 4.1875 | 4 | """
Python File Handling & List Comprehension
Write a python program to read contents of a file (filename as argument) and store the number of occurrences of each word in a dictionary.
Display the top 10 words with the most number of occurrences in descending order.
Store the length of each of these words... | true |
221fdeb75e2f6db401901b5755e991bdffdcee75 | Nitin26-ck/Scripting-Languages-Lab | /Part B/Lab 1/Prg1c_recursion_max.py | 809 | 4.15625 | 4 | """
Introduction to Python : Classes & Objects, Functions
c) Write a recursive python function that has a parameter representing a list of integers
#and returns the maximum stored in the list.
"""
#Hint: The maximum is either the first value in the list or the maximum of the rest of
#the list whichever is larger. If th... | true |
901e5ae13f821c2e3da9df9b46d9a1d7e7cc003c | KodingKurriculum/learn-to-code | /beginner/beginner_3.py | 1,789 | 4.78125 | 5 | # -*- coding: utf-8 -*-
"""
Beginner Script 3 - Lists, and Dictionaries
Functions allow you to group blocks of code and assign it a name. Functions
can be called over and over again to perform specific tasks and return values
back to the calling program.
"""
"""
1.) Lists (also known as an Array) are great for storin... | true |
0f882e8b74773b888de20be38564c13642cd306a | ijuarezb/InterviewBit | /04_LinkedList/K_reverse_linked_list.py | 2,527 | 4.125 | 4 | #!/usr/bin/env python3
import sys
#import LinkedList
# K reverse linked list
# https://www.interviewbit.com/problems/k-reverse-linked-list/
#
# Given a singly linked list and an integer K, reverses the nodes of the
#
# list K at a time and returns modified linked list.
#
# NOTE : The length of the list is divisibl... | true |
0e8330781cac465d3bae07379fa9d2435940d03e | Ekimkuznetsov/Lists_operations | /List_split.py | 309 | 4.25 | 4 | # LIsts operations
# For each line, split the line into a list of words using the split() method
fname = input("Enter file name: ")
fh = open(fname)
fst = list()
for line in fh:
x = line.split()
for word in x:
if word not in fst:
fst.append(word)
fst.sort()
print(fst) | true |
e6ecd5211b15b6cb201bdd2e716a7b4fec2db726 | markcurtis1970/education_etc | /timestable.py | 1,693 | 4.5 | 4 | # Simple example to show how to calculate a times table grid
# for a given times table for a given length.
#
# Note there's no input validation to check for valid numbers or
# data types etc, just to keep the example as simple. Plus I'm not
# a python developer :-)
# Ask user for multiplier and max range of times tab... | true |
1a024d3e345afbcc0b8cfa354e14416401f9c565 | dogac00/Python-General | /generators.py | 1,253 | 4.46875 | 4 | def square_numbers(nums):
result = []
for i in nums:
result.append(i*i)
return result
my_nums = square_numbers([1,2,3,4,5])
print(my_nums) # will print the list
# to convert it to a generator
def square_numbers_generator(nums):
for i in nums:
yield i*i
my_nums_generator = square_numbers_gener... | true |
f7eaadb3ee801b8011e2fddd03a055902f2da614 | sohanjs111/Python | /Week 3/For loop/Practice Quiz/question_2.py | 608 | 4.375 | 4 | # Question 2
# Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10 factorials (from 0 to 9) with
# the corresponding number. Remember that the factorial of a number is defined as the product of an integer and all
# integers before it. For example, the fac... | true |
7a22126b7d66730558314ad8295c087559ee4b41 | sohanjs111/Python | /Week 4/Graded Assessment/question_1.py | 1,463 | 4.5 | 4 | # Question 1
# The format_address function separates out parts of the address string into new strings: house_number and street_name,
# and returns: "house number X on street named Y". The format of the input string is: numeric house number, followed by the
# street name which may contain numbers, but never by themse... | true |
6adef0926886b9f6406f056fb9faef6640068338 | sohanjs111/Python | /Week 4/Lists/Practice Quiz/question_6.py | 957 | 4.40625 | 4 | # Question 6
# The guest_list function reads in a list of tuples with the name, age, and profession of each party guest, and prints the
# sentence "Guest is X years old and works as __." for each one. For example, guest_list(('Ken', 30, "Chef"), ("Pat", 35, 'Lawyer'),
# ('Amanda', 25, "Engineer")) should... | true |
3918f8ff48585ae65b1949cc709a8da345d26b93 | sohanjs111/Python | /Week 4/Strings/Practice Quiz/question_2.py | 593 | 4.3125 | 4 | # Question 2
# Using the format method, fill in the gaps in the convert_distance function so that it returns the phrase "X miles equals Y
# km", with Y having only 1 decimal place. For example, convert_distance(12) should return "12 miles equals 19.2km".
def convert_distance(miles):
km = miles * 1.6
... | true |
69fd417b735877ae844880c2f8ed10f80d33413a | khayes25/recursive_card_sorter | /merge_sort.py | 1,634 | 4.125 | 4 | """
Merge Sort Algorithm
"""
#Class Header
class Merge_Sort :
def merge_sort(list, left, right) :
if(left < right) :
middle = (left + right) / 2
merge_sort(list, left, middle)
merge_sort(list, middle + 1, right)
merge(list, left, middle, right)
de... | true |
b16802cea3e32892e7953167eb4932457c6e41bb | mr-akashjain/Basic-Python-Stuff-For-Fun | /pigLatin.py | 2,301 | 4.125 | 4 | from time import sleep
sentence = input("Hi, They call me latin pig translator. Enter a sentence to have fun with me:")
sleep(4)
print("Thanks for the input!! Fasten your seatbelt as you are about to enter into my world")
sleep(3)
print("I know my world is small, but it is mine!")
sleep(2)
say_something = inpu... | true |
2bc6e15c932be59832de9e40960dc14c4de17c4f | AidaQ27/python_katas_training | /loops/vowel_count.py | 777 | 4.21875 | 4 | """
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, and u as vowels for this Kata.
The input string will only consist of lower case letters and/or spaces.
---
We are starting with exercises that require iteration through
the elements of a structure, so it will be good to dedica... | true |
42b2eac7097ededd9d87d2746afaeb5f8fc9b240 | Nalinswarup123/python | /class 6/bio.py | 658 | 4.125 | 4 | '''biologists use seq of letter ACTC to model a genome. A gene is a substring
of gnome that starts after triplet ATG and ends before triplet TAG , TAA and
TGA.
the length of Gene string is mul of 3 and Gene doesnot contain any of the triple
TAG , TAA and TGA.
wap to ask user to enter a genone and display all genes... | true |
470cd5e72d7a9147a6d2fc4835040fb3446f1dcc | Nalinswarup123/python | /calss 1/distance between two points.py | 275 | 4.125 | 4 | #distance between two points
print('enter first point')
x,y=int(input()),int(input())
print('enter second point')
a,b=int(input()),int(input())
x=((x-a)**2+(y-b)**2)**0.5
print('distance between the given points=',x)
#print('{} is the required distance'.format(x))
| true |
6692daa627b01842e018d078fac7b64354d9a968 | smritta10/PythonTraining_Smritta | /Task3/Task3_all_answers.py | 1,906 | 4.125 | 4 | Task -3
#Question 1
diff_list= [10,'Smritta', 10.5,'1+2j', 20,'Singh', 113.0, '3+4j', 100, 'Python_learning']
print(diff_list)
-----------------------------------------------------
#Question 2
list1= [10,20,30,40,50]
s1= list1[ :5] #actual list
s2= list1[ : :-1] # lists items in reverse order
s3= list1[1:5:2] # lis... | true |
c91f0044d88593f20382a5dd1122504d9fbf8c1d | sindhupaluri/Python | /count_string_characters.py | 425 | 4.34375 | 4 | # Please write a program which counts and returns the numbers of each character in a string input.
# count_characters( "abcdegabc" )
# { 'a':2, 'c':2, 'b':2, 'e':1, 'd':1, 'g':1 }
def count_characters(string):
char_count = {}
for char in string:
if char in char_count:
char_count[char] +=... | true |
05b0deda5e25686a6082b289b46594a1b57e7ea3 | RAmruthaVignesh/PythonHacks | /Foundation/example_*args_**kwargs.py | 845 | 4.53125 | 5 | #When the number of arguments is unknown while defining the functions *args and **kwargs are used
import numpy as np
def mean_of_numbers(*args):
'''This function takes any number of numerical inputs and returns the mean'''
args = np.array(args)
mean = np.mean(args)
return mean
print "The mean of the n... | true |
f24bcde3c27bf62a63df4e2e2d6d76925ac51352 | RAmruthaVignesh/PythonHacks | /Foundation/example_list_comprehension.py | 651 | 4.71875 | 5 | #Example 1 : To make a list of letters in the string
print "This example makes a list of letters in a string"
print [letter for letter in "hello , _world!"]
#Example 2: Add an exclamation point to every letter
print "\nExample 2: Add an exclamation point to every letter"
print [letter+"!" for letter in "hello , world... | true |
9095e434cabe1afd4d287c4db9885bbf0d7b4515 | RAmruthaVignesh/PythonHacks | /OOPS/class_inheritance_super()_polygons.py | 1,891 | 4.78125 | 5 | #This example explains the super method and inheritance concept
class polygons(object):
'''This class has functions that has the functionalities of a polygon'''
def __init__(self,number_of_sides):#constructor
self.n = number_of_sides
print "The total number of sides is" , self.n
def interi... | true |
7e06219cc161ddfb37e3f72d261c9c256ea20414 | RAmruthaVignesh/PythonHacks | /MiscPrograms/number_of_letters_in_word.py | 354 | 4.3125 | 4 | #get the word to be counted
word_to_count = 'hello_world!'
print ("the word is" , word_to_count)
# iniliatize the letter count
letter_count = 0
#loop through the word
for letter in word_to_count:
print("the letter", letter, "#number" , letter_count)
letter_count = letter_count+1
print ("there are", letter_co... | true |
0fff4ced9ebbb6852543fb009386e49bee3c352a | AlanDTD/Programming-Statistics | /Week 2/Week 2 exercises - 2.py | 909 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jul 29 20:05:57 2021
@author: aland
"""
#Loops and input Processing
nums = tuple(input("Enter at least 5 numbers separated by commas!"))
print(len(nums))
print(nums)
sum_num = 0
count = 0
if type(nums) == tuple: #Checks if ithe value is a tuple
while len(nums) < 5: ... | true |
ed04c33b0bd58feb0e53c7970ee6ec5de1511481 | mvessey/comp110-21f-workspace | /lessons/for_in.py | 382 | 4.46875 | 4 | """An example of for in syntax."""
names: list[str] = ["Madeline", "Emma", "Nia", "Ahmad"]
# example of iterating through names using a while loop
print("While output:")
i: int = 0
while i < len(names):
name: str = names[i]
print(name)
i += 1
print("for ... in output")
# the following for ... in loops is... | true |
78f53c4a130daf34adc2ef48ec7e37be90c0a3b1 | klcysn/free_time | /climb_staircase.py | 452 | 4.3125 | 4 | # There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters.
# For example, if N is 4, then there are 5 unique ways:
# 1, 1, 1, 1
# 2, 1, 1
# 1, 2, 1
# 1, 1, 2
# ... | true |
94ebe7be385aa68e463c7cdc89bd1e257b9ecdbe | klcysn/free_time | /fizzbuzz.py | 799 | 4.71875 | 5 | # Create a function that takes a number as an argument and returns "Fizz", "Buzz" or "FizzBuzz".
# If the number is a multiple of 3 the output should be "Fizz".
# If the number given is a multiple of 5, the output should be "Buzz".
# If the number given is a multiple of both 3 and 5, the output should be "FizzBuzz".
#... | true |
f82a0f9537ee9ec944bdf9e95ea691a5f06e1bf3 | Chetancv19/Python-code-Exp1-55 | /Lab2_5.py | 701 | 4.125 | 4 | #Python Program to Check Prime Number
#chetan velonde 3019155
a = int(input("Enter the number for checking whether it is prime or not:"))
if a > 1:
for x in range(2, a):
if a % x == 0:
print(str(a) + " is not a prime number.")
break
else:
print(str(a) + " is a ... | true |
56987b36b796816bbf61315b11be60fc6bed2aee | ljkhpiou/test_2 | /ee202/draw.py | 642 | 4.1875 | 4 | import turtle
myPen = turtle.Turtle()
myPen.shape("arrow")
myPen.color("red")
#myPen.delay(5) #Set the speed of the turtle
#A Procedue to draw any regular polygon with 3 or more sides.
def drawPolygon(numberOfsides):
exteriorAngle=360/numberOfsides
length=2400/numberOfsides
myPen.penup()
m... | true |
08435281ef189434c121be0f66540830b0e2f006 | NectariosK/email-sender | /email_sender.py | 2,438 | 4.375 | 4 | #This piece of code enables one to send emails with python
#Useful links below
'''
https://www.geeksforgeeks.org/simple-mail-transfer-protocol-smtp/
https://docs.python.org/3/library/email.html#module-email
https://docs.python.org/3/library/email.examples.html
'''
'''
import smtplib #simple mail transfe... | true |
8d64c60833a9b781e2b4e1243e1e987f08030c41 | dwbelliston/python_structures | /generators/example.py | 683 | 4.4375 | 4 | # Remember, an Iterable is just an object capable of returning its members one at a time.
# generators are used to generate a series of values
# yield is like the return of generator functions
# The only other thing yield does is save the "state" of a generator function
# A generator is just a special type of iterator... | true |
24d69d7df270af8673070ef7079cbcd3254d9bd7 | valakkapeddi/enough_python | /comprehensions_and_generators.py | 1,353 | 4.6875 | 5 | # Comprehension syntax is a readable way of applying transforms to collection - i.e., creating new collections
# that are modified versions of the original. This doesn't change the original collection.
# For instance, given an original list like the below that contains both ints and strings:
a_list = [1, 2, 3, 4, 'a',... | true |
861db59c044985dc0b8e4d71dbff92d480b40ef1 | Jones-Nick-93/Class-Work | /Binary Search Python.py | 1,284 | 4.25 | 4 | #Nick Jones
#DSC 430 Assignment 7 Time Complexity/Binary Search
#I have not given or received any unauthorized assistance on this assignment
#YouTube Link
import random
'''function to do a binary search to see if 2 #s from a given list sum to n'''
def binary_search(array, to_search, left, right):
# termina... | true |
e41b72f54d45718b0680fbbb7f61a3d0761f527f | Ameen-Samad/number_guesser | /number_ guesser.py | 1,426 | 4.15625 | 4 | import random
while True:
secret_number = random.randrange(1, 10, 1)
limit = 3
tries = 0
has_guessed_correctly = False
while not has_guessed_correctly:
user_guess = int(input("Guess a number: "))
print(f"You have guessed {user_guess}")
limit = limit - 1
tries = trie... | true |
307e85576dc78d29ecf9077c70776c3498e1a60c | LizaPersonal/personal_exercises | /Programiz/sumOfNaturalNumbers.py | 684 | 4.3125 | 4 | # Python program to find the sum of natural numbers up to n where n is provided by user
def loop_2_find_sum():
num = int(input("Enter a number: "))
if num < 0:
num = int(input("Enter a positive number"))
else:
sum = 0
# use while loop to iterate until zero
while num > 0:
... | true |
35ab0ae28ae798f5fd4317432d082e164b5815ef | zenthiccc/CS5-ELECTIVE | /coding-activities/2ndQ/2.5-recursive-binary-search.py | 1,311 | 4.15625 | 4 | # needle - the item to search for in the collection
# haystack - the collection of items
# NOTE: assume the haystack is ALWAYS sorted, no need to sort it yourself
# the binary search function to be exposed publicly
# returns the index if needle is found, returns None if not found
def binary_search(needle, haystack):
... | true |
e3b267c428b62ae5e579a8d9b2446a85443ba889 | hyerynn0521/CodePath-SE101 | /Week 1/fizzbuzz.py | 683 | 4.46875 | 4 | #
# Complete the 'FizzBuzz' function below.
#
# This function takes in integer n as a parameter
# and prints out its value, fizz if n is divisible
# by 3, buzz if n divisible by 5, and fizzbuzz
# if n is divisible by 3 and 5.
#
"""
Given an input, print all numbers up to and including that input, unless they are divisi... | true |
52673f2e5435fb7d724b5028a3f64c61398d3c47 | hyerynn0521/CodePath-SE101 | /Week 5/longest_word.py | 816 | 4.4375 | 4 | #!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'longestWord' function below.
#
# The function is expected to return a STRING.
# The function accepts STRING_ARRAY words as parameter.
# This function will go through an array of strings,
# identify the largest word, and retur... | true |
48108b1d24bc92d1d52af57f50fed1f7e06b45a9 | brivalmar/Project_Euler | /Python/Euler1.py | 202 | 4.125 | 4 | total = 0
endRange = 1000
for x in range(0, endRange):
if x % 3 == 0 or x % 5 == 0:
total = total + x
print "The sum of numbers divisible by 3 and 5 that are less than 1000 is: %d " % total
| true |
96d1013baf191fdc17c8e134d7e68886803aa689 | Vagelis-Prokopiou/python-challenges | /codingbat.com/String-2/end_other.py | 719 | 4.125 | 4 | #!/usr/bin/python3
# @Author: Vagelis Prokopiou
# @Email: drz4007@gmail.com
# @Date: 2016-04-02 17:33:14
# @Last Modified time: 2016-04-02 17:55:41
# Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the comput... | true |
dc0aaec53f5565f1396c8cb1907070f4b1f9527d | divyaprakashdp/DSA-with-Python | /merge_sort.py | 1,422 | 4.3125 | 4 | def merge_sort(listToSort):
"""
sorts a list in descending order
Returns a new sordted list
"""
if len(listToSort) <= 1:
return listToSort
leftHalf, rightHalf = split(listToSort)
left = merge_sort(leftHalf)
right = merge_sort(rightHalf)
return merge(left, right)
def split... | true |
27e6c78de9ae2f6ff0c91d470bbf175bd9b7e7cc | mashpolo/leetcode_ans | /700/leetcode706/ans.py | 1,235 | 4.125 | 4 | #!/usr/bin/env python
# coding=utf-8
"""
@desc:
@author: Luo.lu
@date: 2019-01-09
"""
class MyHashMap:
def __init__(self):
"""
Initialize your data structure here.
"""
self.key = []
self.value = []
def put(self, key, value):
"""
value will always be... | true |
36a29f204892487912c3e60c6766a68a3a23a7b5 | iQaiserAbbas/artificial-intelligence | /Lab-01/Lab-01.py | 921 | 4.125 | 4 | __author__ = "Qaiser Abbas"
__copyright__ = "Copyright 2020, Artificial Intelligence lab-01"
__email__ = "qaiserabbas889@yahoo.com"
# Python Program - Calculate Grade of Student
print("Please enter 'x' for exit.");
print("Enter marks obtained in 5 subjects: ");
subject1 = input();
if subject1 == 'x':
exit();
else... | true |
f2c41e4f2cbef4b9d331b423a27dd93e259b0329 | cardigansquare/codecademy | /learning_python/reverse.py | 221 | 4.1875 | 4 | #codeacademy create function the returns reversed string without using reversed or [::-1]
def reverse(text):
new_text = ""
for c in text:
new_text = c + new_text
return new_text
print reverse("abcd!") | true |
556e83e3f35ac103b07d064083e1288293ebc1f9 | roseORG/GirlsWhoCode2017 | /GWC 2017/story.py | 1,154 | 4.25 | 4 | start = '''
Rihanna is in town for her concert. Help her get to her concert...
'''
print(start)
done = False
left= False
right= False
while not done:
print("She's walking out of the building. Should she take a left or right?")
print("Type 'left' to go left or 'right' to go right.")
use... | true |
17dccb7a8621b306bbae0dd58f64c23e17c746c8 | shamramchandani/Code | /Python/chapter 3.py | 410 | 4.15625 | 4 | def collatz(num):
if num%2 == 0:
print(num / 2)
return (num / 2)
else:
print((num *3) +1)
return (num *3) +1
try:
number = int(input("Please enter a number"))
print(number)
if number <= 1:
print('Please input a number greater than 1')
else:
while number > 1:
number... | true |
771aafb570437f9bdbd5bc60ea6b4106b22c2541 | hperry711/dev-challenge | /chapter2_exercises.py | 1,534 | 4.21875 | 4 | # Exercises for chapter 2:
# Name: Hunter Perry
# Exercise 2.1.
# zipcode = 02492 generates a SyntaxError message because "9" is not within the octal number system. When an integer is lead with a zero in Python it generates the Octal representation for that number. >>> zipcode = 02132 only contains numbers between 0... | true |
b98fb37acb9ed1b4cbf2d57f516cf650bc515332 | Airbomb707/StructuredProgramming2A | /UNIT1/Evaluacion/eval02.py | 304 | 4.15625 | 4 | #Evaluation - Question 7
#Empty array
#A length variable could be added for flexible user inputs
lst=[]
#Storing Values
for n in range(3):
print("Enter value number ", n+1)
num=int(input("> "))
lst.append(num)
#Built-in Max() Function in Python
print("The largest number was: ", max(lst))
| true |
d9fad0b9f0dda940f073f6f461fd01c145eb5ba1 | ZammadGill/python-practice-tasks | /task8.py | 319 | 4.21875 | 4 | """ Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers """
def squareOddNumber(numbers_list):
odd_numbers_square = [n * n for n in numbers_list if n % 2 != 0]
print(odd_numbers_square)
numbers = [1,2,3,4,5,6,7,8,9]
squareOddNumber(numbers)
| true |
cb611e5efb7fe55ca6e79a43a2eccfffd86b4834 | Hrishikeshbele/Competitive-Programming_Python | /minimum swaps 2.py | 1,891 | 4.34375 | 4 | '''
You are given an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. You are allowed to swap any two elements.
You need to find the minimum number of swaps required to sort the array in ascending order.
Sample Input 0
4
4 3 1 2
Sample Output 0
3
Explanation 0
Given arra... | true |
2e3998204f8cf62aeb969ff28cd45b217b480bf0 | Hrishikeshbele/Competitive-Programming_Python | /merge2binarytree.py | 1,623 | 4.125 | 4 | '''
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.
You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node.
Otherwise... | true |
224e2c2e3835534e75d9816249aaf06625e70ada | Hrishikeshbele/Competitive-Programming_Python | /Letter Case Permutation.py | 1,326 | 4.1875 | 4 | '''
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.
Return a list of all possible strings we could create. You can return the output in any order.
Example 1:
Input: S = "a1b2"
Output: ["a1b2","a1B2","A1b2","A1B2"]
approach:
let's see recursion ... | true |
afab2fe8f815cda591267691c0667a75a6182296 | Hrishikeshbele/Competitive-Programming_Python | /Leaf-Similar Trees.py | 767 | 4.25 | 4 | '''
Two binary trees are considered leaf-similar if their leaf value sequence is the same.
Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.
Input: root1 = [1,2], root2 = [2,2]
Output: true
approach : we find root nodes of both tree and compare them
'''
class Solutio... | true |
34b090968b06ee05bd9ebfb94547b9ba63e32b2b | Hrishikeshbele/Competitive-Programming_Python | /Invert the Binary Tree.py | 1,079 | 4.3125 | 4 | '''
Given a binary tree, invert the binary tree and return it.
Look at the example for more details.
Example :
Given binary tree
1
/ \
2 3
/ \ / \
4 5 6 7
invert and return
1
/ \
3 2
/ \ / \
7 6 5 4
'''
### we exchange the left and right child recursively
# Definition f... | true |
9af9bc53e43238029d5c791bbc1cd37d26920e7a | Hrishikeshbele/Competitive-Programming_Python | /Jewels and Stones.py | 1,027 | 4.125 | 4 | '''
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a
type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. ... | true |
23275fede27675ba37f35a8e9117af1395c3aa72 | nirajkvinit/pyprac | /recursiveBinarySearch.py | 472 | 4.15625 | 4 | # Binary search using recursion
def binarySearchRecursive(arr, low, high, value):
mid = low + int((high + low) / 2)
if arr[mid] == value:
return mid
elif arr[mid] < value:
return binarySearchRecursive(arr, mid + 1, high, value)
else:
return binarySearchRecursive(arr, low, mid - 1, value)
def binarySearch(... | true |
a4c94ed077075a01ef12f176fbccff19ef24a0fc | nirajkvinit/pyprac | /100skills/dictgen.py | 386 | 4.3125 | 4 | '''
With a given number n, write a program to generate a dictionary that
contains (i, i*i) such that i is an number between 1 and n (both included). and
then the program should print the dictionary.
'''
def dictgen():
n = int(input("Enter a number: "))
d = dict()
for i in range(1, n+1):
d[i] = i**... | true |
606fe3d50350078588bbbf2a1f07e3c46b9c66e9 | Padma-1/100_days-coding | /Abundant_number.py | 332 | 4.1875 | 4 | #A number is abundant if sum of the proper factors of the number is greater than the given number eg:12-->1+2+3+4+6=16-->16>12 i.e., 12 is Abundant number
n=int(input())
sum=0
for i in range(1,n//2+1):
if n%i==0:
sum+=i
if sum>n:
print("Abundant number")
else:
print("not Abundant number")... | true |
b63c5ad4a138de403ef34297f1e05d4668c20339 | Padma-1/100_days-coding | /sastry_and_zukerman.py | 674 | 4.15625 | 4 | ###Sastry number:A number N is a Sastry Number if N concatenated with N + 1 gives a perfect square.eg:183
##from math import sqrt
##def is_sastry(n):
## m=n+1
## result=str(n)+str(m)
## result=int(result)
## if sqrt(result)==int(sqrt(result)):
## return True
## return False
##n=int(input... | true |
96af38fcaf676e67b50112b713af0b4d4fa08022 | aswanthkoleri/Competitive-codes | /Codeforces/Contests/Codeforces_Global_Round_3/Quicksort.py | 2,073 | 4.34375 | 4 | def partition(arr,low,high):
i = ( low-1 ) # index of smaller element
pivot = arr[high] # pivot
# print("Pivot 1 = ",pivot)
# What we are basically doing in the next few steps :
# 1. Whenever we find an element less than the pivot element we swap it with the element starting from the 0th inde... | true |
44e4a22c1318e44f75e74af86558246f9acecd83 | lavish205/hackerrank | /time_conversion.py | 913 | 4.3125 | 4 | """PROBLEM STATEMENT
Given a time in AM/PM format, convert it to military (24-hour) time.
Note: Midnight is 12:00:00AM on a 12-hour clock and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock and 12:00:00 on a 24-hour clock.
Input Format
A time in 12-hour clock format (i.e.: hh:mm:ssAM or hh:mm:ssPM... | true |
255a630ce8ac960c214b6758e771233d36f0a6bc | Mo-Shakib/DSA | /Data-Structures/Array/right_rotate.py | 565 | 4.53125 | 5 | # Python program to right rotate a list by n
# Returns the rotated list
def rightRotate(lists, num):
output_list = []
# Will add values from n to the new list
for item in range(len(lists) - num, len(lists)):
output_list.append(lists[item])
# Will add the values before
# n to... | true |
124bbb8ba9da101c72ffae44f897a2b8d71a4261 | G00398792/pforcs-problem-sheet | /bmi.py | 674 | 4.5625 | 5 | # bmi.py
# This program calculates your Body Mass Index (BMI).
# author: Barry Gardiner
#User is prompted to enter height and weight as a float
# (real number i.e. 1.0) number. The users weight is divided
# by the height in metres to the power of 2. The output
# is printed to the screen. The code "{:.2f}'.format(BMI)... | true |
f70c9a371369cb3ec1cd1f484c877704fa30b799 | mre9798/Python | /lab 9.1.py | 233 | 4.3125 | 4 | # lab 9.1
# Write a recursive function to find factorial of a number.
def fact(n):
if n==1:
return 1
else:
return n*fact(n-1)
n=int(input("Enter the nnumber : "))
print("Factorial is ",fact(n)) | true |
65abd6e3940706315542de8ba291bdd93b2c1dab | bajram-a/Basic-Programing-Examples | /Conditionals/Exercise2.4.py | 505 | 4.25 | 4 | """Write a program that requires from the user to input coordinates x and y for the circle center
and the radius of that circle, then another set of coordinates for point A.
The program then calculates whether A is within the circle"""
from math import sqrt
Cir_x = float(input())
Cir_y = float(input())
r = float(inp... | true |
c5ff2f18e9728e2e015be69bf7389b11c54f55ba | fantods/python-design-patterns | /creational/builder.py | 1,258 | 4.4375 | 4 | # decouples creation of a complex object and its representation
# helpful for abstractions
# Pros:
# code is more maintainable
# object creation is less error-prone
# increases robustness of application
# Cons:
# verbose and requires a lot of code duplication
# Abstract Building
class Building(object):
def __in... | true |
77f8837147e6516faa44883791fc94cfe6f4e02b | BloodiestChapel/Personal-Projects | /Python/HelloWorld.py | 461 | 4.1875 | 4 | # This is a standard HelloWorld program.
# It is meant for practice.
import datetime
print('Hello World!')
print('What is your name?')
myName = input()
myNameLen = len(myName)
print('It is good to meet you, ' + myName)
print('Your name is ' + str(myNameLen) + ' characters long.')
print('What is your age?')
date ... | true |
7d6e84349dcb9c8ca76a35192e1bbbc5a6301142 | TheRockStarDBA/PythonClass01 | /program/python_0050_flow_control_nested_for_loop.py | 1,158 | 4.1875 | 4 | '''
Requirement:
There are 4 numbers: 1/2/3/4.
List out all 3 digits numbers using these 4 numbers.
You cannot use the same number twice in the 3 digits numbers.
'''
#Step 1) How to generate 1 digit number?
for i in range(1,5):
print(i, end=' ')
print('\n-------------------------------------')
#Step 2) How to ge... | true |
ad3979824471e652f79e74cf93ca18366b922436 | TheRockStarDBA/PythonClass01 | /program/python_0020_flow_control_if.py | 1,262 | 4.28125 | 4 | # Every python program we've seen so far is sequential exection.
# Code is executed strictly line after line, from top to bottom.
# Flow Control can help you skip over some lines of the code.
# if statement
today = input("What day is today?")
print('I get up at 7 am.')
print('I have my breakfast at 8 am.')
# IMP... | true |
e9fcd04639d97eef36e0891c5a4e8ad7513bd9c1 | TheRockStarDBA/PythonClass01 | /program/python_0048_practice_number_guessing_name.py | 1,575 | 4.40625 | 4 | '''
Requirement:
Build a Number guessing game, in which the user selects a range, for example: 1, 100.
And your program will generate some random number in the range, for example: 42.
And the user needs to guess the number.
If his answer is 50, then you need to tell him. “Try Again! You guessed too high”
If his answer... | true |
45d32d880019054cbcc22f71c5cf0b62bc605ecf | TheRockStarDBA/PythonClass01 | /program/python_0006_data_type_str.py | 613 | 4.15625 | 4 |
# str - 字符串
str1 = "Hello Python!"
str2 = 'I am str value, "surrounded" by single quote.'
str3 = "I am another str value, 'surrounded' by doulbe quotes."
print('variable str1 type is:', type(str1), 'str1=', str1)
print('variable str2 type is:', type(str2), 'str2=', str2)
print('variable str3 type is:', type(str3), '... | true |
caf77761eb946bc292c8f0c9802bc0bfd75160a4 | TheRockStarDBA/PythonClass01 | /program/python_0031_practice_input_if_elif_else_bmi_calculator.py | 1,132 | 4.53125 | 5 | # Requirement: get input from the user about height in meters and weight in kg.
# Calculate his bmi based on this formula:
# bmi = weight / (height ** 2)
# Print information based on user's bmi value
# bmi in (0, 16) : You are severely underweight
# bmi in [16, 18.5) : You are underweight
# bmi in [18.5, 25) :... | true |
e9a945d21935f5bb2e66d9323eeb5e26b5a97ec6 | TheRockStarDBA/PythonClass01 | /program/python_0039_library_random.py | 1,221 | 4.5625 | 5 |
# IMPORTANT !!! ----------------------------------
# Import the random module into your python file
# ------------------------------------------------
import random
# IMPORTANT !!! ----------------------------------
# random.randint(1, 10) is composed of 4 parts.
#
# 1) random : module name
# 2) . ... | true |
587e9f60c46a7db78e6e1f78885eb0b405f16239 | Alamin11/JavaScript-and-Python | /lecture02/sequeces.py | 652 | 4.15625 | 4 | from typing import OrderedDict, Sequence
# Mutable and Ordered
# Mutable means can be changed the Sequence
# Orderd means can not be changed the sequence because order matters
#string = oredered
name = "Farjana"
print(name[0])
print(name[6])
print(name)
#Lists=mutable and ordered
listName = ["Farjana", "Toma", "Nuntu... | true |
71cdaa322abe4a1f266d5ce9704c11f3a759892c | alisaffak/GlobalAIHubPythonHomework | /proje.py | 2,720 | 4.1875 | 4 | student_name = "Ali".upper()
student_surname = "Şaffak".upper()
all_courses = ["Calculus","Lineer Algebra","Computer Science","DSP","Embeded Systems"]
selected_courses = set()
student_grades = {}
def select_courses():
j = 1
for i in all_courses:
print("{}-{}".format(j,i))
j +=1
... | true |
6a8f962aebd5ddd10742d907de30819d82ae5d1e | LaRenegaws/wiki_crawl | /lru_cache.py | 2,955 | 4.125 | 4 | import datetime
class Cache:
"""
Basic LRU cache that is made using a dictionary
The value stores a date field that is used to maintain the elements in the cache
Date field is used to compare expire an element in the cache
Persisted field is a boolean that determines whether it can be deleted
"""
def __... | true |
448aa1aead420c84febe08b1d5dcecff30b28d85 | canlasd/Python-Projects | /Assignment3.py | 450 | 4.1875 | 4 | wind=eval(input("Enter Wind Speed"))
if wind>=74 and wind <=95:
print ("This is a category 1 hurricane")
elif wind<=96 and wind <=110:
print ("This is a category 2 hurricane")
elif wind<=111 and wind <=130:
print ("This is a category 3 hurricane")
elif wind<=131 and wind <=155:
... | true |
1b25840045d4858f9eec3deeda08f2373376ee25 | osanseviero/Python-Notebook | /ex31.py | 626 | 4.375 | 4 | #Program 31. Using while loops
def create_list(size, increment):
"""Creates a list and prints it"""
i = 0
numbers = []
while i < size:
print "New run! "
print "At the top i is %d" % i
numbers.append(i)
i = i + increment
print "Numbers now: ", numbers
print "At the bottom i is %d\n \n" % i
prin... | true |
006a4070da536f4d42c65d93e0e5eb67db3b06b6 | mirgags/pear_shaped | /fruit_script.py | 1,896 | 4.21875 | 4 | # An interactive script that prompts the user to accept or reject fruit
# offerings and then asks if they want any other fruit that wasn't offered.
# Responses are stored in the fruitlist.txt file for later reading.
yeses = ['YES', 'OK', 'SURE', 'YEAH', 'OKAY', 'SI']
nos = ['NO', 'NOPE', 'NAH', 'UH-UH']
fruits = []
... | true |
1864a160dec53b2c9585bf05928daeafc23ff066 | andrewdaoust/project-euler | /problem004.py | 825 | 4.1875 | 4 | """
A palindromic number reads the same both ways. The largest palindrome made
from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
"""
def palindrome_check(n):
s = str(n)
length = len(s)
for i in range(int(len(s)/2)):
... | true |
c6ecdc710116054197d6d8f14f50f7af44700829 | andrewdaoust/project-euler | /problem001.py | 487 | 4.3125 | 4 | """
If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
import numpy as np
def run():
mult_3_5 = []
for i in range(1, 1000):
if i % 3 == 0:
mult_3_5.a... | true |
688b44387560371c3262dd115f377c87f06eabb5 | nickmallare/Leet-Code-Practice | /35-search-insert-position.py | 851 | 4.1875 | 4 | """
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You must write an algorithm with O(log n) runtime complexity.
"""
class Solution(object):
def searchInsert(self, nums, target):
... | true |
f911c2170e7dcb50d4d0eef0eebe550926af2c87 | Frank-LSY/Foundations-of-AI | /HW1/Puzzle8/bfs.py | 1,650 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 3 17:01:00 2019
vanilla breadth first search
- relies on Puzzle8.py module
@author: Milos Hauskrecht (milos)
"""
from Puzzle8 import *
#### ++++++++++++++++++++++++++++++++++++++++++++++++++++
#### breadth first search
def br... | true |
4ad120e7f53162c10541c354acd1a30bc30cbeae | Nihila/python_programs | /begginer/positiveornegative.py | 797 | 4.25 | 4 | #-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Administrator
#
# Created: 04/02/2018
# Copyright: (c) Administrator 2018
# Licence: <your licence>
#--------------------------------------------------------------------... | true |
327720b380ef7d2fa891f67c916ba51f91c74769 | pandey-ankur-au17/Python | /coding-challenges/week03/Assignment/AssignmentQ2while.py | 540 | 4.125 | 4 | def by_while_loop():
print("by using while loop ")
n = int(input("Enter the number of lines : "))
line = 1
while (line <= n):
print(" " * (n - line), end="")
digit = 1
while digit <= line:
print(digit, end="")
if line == digit:
rev_digi... | true |
158bdd6828bc4a720f962b5d329b5b8f8f5a045f | pandey-ankur-au17/Python | /coding-challenges/week04/day01/ccQ2.py | 366 | 4.46875 | 4 | # Write a function fibonacci(n) which returns the nth fibonacci number. This
# should be calcuated using the while loop. The default value of n should be 10.
def fibonacci(n=10):
n1=0
n2=1
count=0
while count<n:
print(n1)
nth=n1+n2
n1=n2
n2=nth
count=count+1
#n=... | true |
c830897d5aa2bd691af45ccb59f3bcaa22307d75 | pandey-ankur-au17/Python | /coding-challenges/week07/AssignmentQ1.py | 991 | 4.15625 | 4 | # Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
# Note:
# Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementati... | true |
58bfff25bede8b43e9e236d83d9326a8f0b4b125 | pandey-ankur-au17/Python | /coding-challenges/week07/day04/ccQ3.py | 591 | 4.25 | 4 | # Given an array with NO Duplicates . Write a program to find PEAK
# ELEMENT
# Return value corresponding to the element of the peak element.
# Example :
# Input : - arr = [2,5,3,7,9,13,8]
# Output : - 5 or 13 (anyone)
# HINT : - Peak element is the element which is greater than both
# neighhbours.
def Peak_value(arr)... | true |
632564d4d1d0ed5f9c4cc1a8d9a36b67ab263810 | alishalabi/binary-search-tree | /binary_search_tree.py | 2,888 | 4.25 | 4 | """
Step 1: Build a binary search tree, with add, remove and in methods.
Step 2: Perform DFS's and BFS
"""
class BinaryTreeNode:
def __init__(self, data, left_child=None, right_child=None):
self.data = data
self.left_child = left_child
self.right_child = right_child
self.is_leaf =... | true |
0bb123d4261f05d1c3b1654c10cff9300a408135 | pancakewaffles/Stuff-I-learnt | /Python Refresher/Python for Security Developers/Module 2 Apprentice Python/Activities/Apprentice_Final_Activity.py | 1,475 | 4.125 | 4 | import operator
saved_string = ''
def remove_letter(): #Remove a selected letter from a string
base_string = str(raw_input("Enter String: "));
letter = str(raw_input("Letter to remove: "));
i = len(base_string) -1 ;
while(i < len(base_string) and i >= 0):
if(base_string[i] == le... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.