blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
01d9fb6b2beaaf0ec20b04968465667abf6e7a42 | ivan-yosifov88/python_basics | /Nested Conditional Statements/03. Flowers.py | 954 | 4.125 | 4 | numbers_of_chrysanthemums = int(input())
number_of_roses = int(input())
number_of_tulips = int(input())
season = input()
is_day_is_holiday = input()
chrysanthemums_price = 0
roses_price = 0
tulips_price = 0
bouquet_price = 0
if season == "Spring" or season == "Summer":
chrysanthemums_price = 2
roses_price = 4.1... | true |
bc1e774ca217588ba4a73263971168008f430fe0 | ivan-yosifov88/python_basics | /Exams -Training/05. Movie Ratings.py | 706 | 4.15625 | 4 | import sys
number_of_films = int(input())
max_rating = 0
movie_with_max_rating = ""
min_rating = sys.maxsize
movie_with_min_rating = ""
total_sum = 0
for films in range(number_of_films):
movie_title = input()
rating = float(input())
total_sum += rating
if rating > max_rating:
max_rating = rating... | true |
c61bb81014dba0334bb13516bd8044cc520bde54 | Williano/Solved-Practice-Questions | /MaleFemalePercentage.py | 1,308 | 4.1875 | 4 | # Script: MaleFemalePercentage.py
# Description: This program ask the user for the number of males and females
# registered in a class. The program displays the percentage of
# males and females in the class.
# Programmer: William Kpabitey Kwabla
# Date: 11.03.17
# Declaring the percentage v... | true |
2582a618219a2e0d3d43d30273d576a824303311 | Williano/Solved-Practice-Questions | /mass_and_weight.py | 1,791 | 4.71875 | 5 | # Scripts : mass_and_weight
# Description : This program asks the user to enter an object’s mass,
# and then calculates its weight using
# weight = mass * acceleration due to gravity.
# If the object weighs more than 1,000 newtons,
# it displays a message indicati... | true |
5086ee66505c76e27be7738c6022065c451771bb | Williano/Solved-Practice-Questions | /MultiplicationTable.py | 2,041 | 4.3125 | 4 | # Script: MultiplicationTable.py
# Description: This program ask for a number and limit and generates
# multiplication table for it.
# Programmer: William Kpabitey Kwabla
# Date: 20.07.16
# Defines the main function.
def main():
# Calls the intro function
intro()
# Declares variable for rep... | true |
596e39993129339fa272c671b82d43c35ccaf17e | Akarshit7/Python-Codes | /Coding Ninjas/Conditionals and Loops/Sum of even & odd.py | 284 | 4.15625 | 4 | # Write a program to input an integer N
# and print the sum of all its even
# digits and sum of all its odd digits separately.
N = input()
total = 0
evens = 0
for c in N:
c = int(c)
total += c
if c % 2 == 0:
evens += c
odds = total - evens
print(evens, odds)
| true |
4dfe380f00ab58f5741096abaf9493e869792cef | kelvDp/CC_python-crash_course | /chapter_5/toppings.py | 2,546 | 4.4375 | 4 | requested_topping = 'mushrooms'
# checks inequality: so if the req_topping is NOT equal to anchovies, then it will print the message
if requested_topping != 'anchovies':
print("Hold the anchovies!")
# you can check whether a certain value is in a list, if it is the output will be true, and if not --> false:
more... | true |
630e926f49514037051c98cded41250dc8c12f11 | kelvDp/CC_python-crash_course | /chapter_10/word_count.py | 929 | 4.4375 | 4 | def count_words(file):
"""Counts the approx number of words in a file"""
try:
with open(file,encoding="utf-8") as f:
contents = f.read()
except FileNotFoundError:
print(f"Sorry, but this file {file} does not exist here...")
else:
words = contents.split()
num_... | true |
fcefa167431b4e2efd08e9f95b43fb57cf3bd37b | kelvDp/CC_python-crash_course | /chapter_2/hello_world.py | 469 | 4.5 | 4 | #can simply print out a string without adding it to a variable:
#print("Hello Python World!")
#or can assign it to a variable and then print the var:
message= "Hello Python world!"
print(message)
#can print more lines:
message_2="Hello Python crash course world!!"
print(message_2)
#code that generates an error :
... | true |
59cdb01876a7669b21e7d9f71920850a2a88091c | kelvDp/CC_python-crash_course | /chapter_3/cars.py | 919 | 4.75 | 5 | cars = ['bmw', 'audi', 'toyota', 'subaru']
#this will sort the list in alphabetical order but permanently, so you won't be able to sort it back:
cars.sort()
print(cars)
# You can also sort this list in reverse alphabetical order by passing the
# argument reverse=True to the sort() method. The following example sorts... | true |
9a6c01e73c78e5c039f7b4af55924e22b1d4ca85 | kelvDp/CC_python-crash_course | /chapter_4/dimensions.py | 542 | 4.21875 | 4 | dimensions = (200, 50)
#tuples are basically same as lists but they are immutable which means you can't change them without re-assigning the whole thing
print(dimensions[0])
print(dimensions[1])
print("\n")
#!!! cant do this : dimensions[0] = 250 !!!
#you can loop through them just like a list
#this is how to chan... | true |
906a57cb5b9813652c9d66960ab30f157c769421 | kelvDp/CC_python-crash_course | /chapter_10/write_message.py | 1,615 | 4.84375 | 5 | # To write text to a file, you need to call open() with a second argument telling
# Python that you want to write to the file.
filename = "programming.txt"
with open(filename,"w") as file_object:
file_object.write("I love programming!")
# The second
# argument, 'w', tells Python that we want to open the file in ... | true |
8f732d671d158a32dfa7e691f588bef489b74ae8 | beffiom/Learn-Python-The-Hard-Way | /ex6.py | 1,204 | 4.71875 | 5 | # initializing a variable 'types_of_people' as an integer
types_of_people = 10
# initializing a variable 'x' as a formatted string with an embedded variable
x = f"There are {types_of_people} types of people."
# initializing a variable 'binary' as a string
binary = "binary"
# initializing a variable 'do_not' as a strin... | true |
cd1e137d53325fcd2f7084654877b0c10646ae40 | sitaramsawant2712/Assessment | /python-script/problem_1_solution_code.py | 926 | 4.34375 | 4 | """
1. 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.
(Answer: 233168) (solution code attached: problem_1_solution_code.py)
"""
def natural_number_multi_three_and_five(low... | true |
cc7a50c93dded63e648a1e0f3c627cf0e490b207 | OngZhenHui/Sandbox_Prac3 | /ascii_table.py | 1,054 | 4.1875 | 4 | def main():
character = str(input("Enter a character: "))
print("The ASCII code for {} is {}".format(character, ord(character)))
lower_limit = 33
upper_limit = 127
number = get_number(lower_limit, upper_limit)
print("The character for {} is {}".format(number, chr(number)))
for i in range(... | true |
d9d43b943dd3dd38d8c0584f1fac139ad181b38c | aJns/cao19 | /E4/ex04_01.py | 1,970 | 4.21875 | 4 | """
This coding exercise involves checking the convexity of a piecewise linear function.
You task is to fill in the function "convex_check".
In the end, when the file is run with "python3 ex04_01.py" command, it should display the total number of convex functions.
"""
# basic numpy import
import num... | true |
ca00bc72743cb5168f449a4e7032d3cfdcb884c4 | mikeykh/prg105 | /13.1 Name and Address.py | 2,405 | 4.25 | 4 | # Write a GUI program that displays your name and address when a button is clicked (you can use the address of the school). The program’s window should appear as a sketch on the far left side of figure 13-26 when it runs. When the user clicks the Show Info button, the program should display your name and address as sho... | true |
a2f82639d7a3d84317e5d0c3bfe6e5d8b9ea91dc | mikeykh/prg105 | /Automobile Costs.py | 2,135 | 4.59375 | 5 | # Write a program that asks the user to enter the
# monthly costs for the following expenses incurred from operating
# his or her automobile: loan payment, insurance, gas, oil, tires and maintenance.
# The program should then display the total monthly cost of these expenses,
# and the total annual cost of these expense... | true |
f2b94660239c6fa96843a0d999ffe0c40b13bfa4 | shadiqurrahaman/python_DS | /tree/basic_tree.py | 1,644 | 4.15625 | 4 | from queue import Queue
class Node:
def __init__(self,data):
self.data = data
self.left = None
self.right = None
class Tree:
def __init__(self):
self.root = None
self.queue = Queue()
def push_tree(self,data):
new_node = Node(data)
if self.root ... | true |
2699742da7500f56858626be9c6369a58c96f0ed | jyoshnalakshmi/python_examples | /file_handling/file_write.py | 691 | 4.25 | 4 | #--------------------------------------------------------------------
#Description : Writing into the file
#Used Function : write()
#Mode : 'w'
#--------------------------------------------------------------------
with open('file1.py','w') as f:
print("write(This is write function using 'w')");
f.write("Hey this ... | true |
10b02c26c2f09f703ce16eab5d8a0183677d8fb2 | dhiraj1996-bot/Code-a-Thon | /list.py | 502 | 4.125 | 4 | #Question 2
list1 = ["aman","raj","ayush","gracie"]
list2 = ["akshay","rakesh","raj","ram"]
#creating a function to check for duplicate values and then removing them
#and creating list without the duplicate values
def find_common(list1,list2):
for x in list1:
for y in list2:
if x == y :
... | true |
dd52c000cd4d5d7a021449a7451de4fa84047042 | nkuhta/Python-Data-Structures | /2. Files/average_spam_confidence.py | 938 | 4.125 | 4 | ##############################################################
######### compute the average spam ############
##############################################################
# X-DSPAM-Confidence:0.8475
# Prompt for user input filename then search for the number and average
fname=input('Enter file... | true |
b4846a2a1d6db0d4cbc3bb5a9097c509af4484a5 | nitschmann/python-lessons | /04_list_manipulations/exc_18.py | 374 | 4.25 | 4 | # list manipulations - exercise 18
cities = ["St. Petersburg", "Moscow", "Buenos Aires", "New York", "Stockholm",
"Amsterdam"]
print(cities)
print(sorted(cities))
print(cities)
print(sorted(cities, reverse = True))
print(cities)
cities.reverse()
print(cities)
cities.reverse()
print(cities)
cities.sort()
pri... | true |
c3e5bce720be7b1d73cdc72befdaf18f9e6c27da | dipikarpawarr/TQ_Python_Programming | /PythonPracticePrograms/String/Remove_Occurrances_Of_Specific_Character.py | 257 | 4.28125 | 4 | # WAP to remove all occurences of given char from String
strInput = input("\nEnter the string = ")
charRemove = input("Which character you have to remove = ")
result = strInput.replace(charRemove,"")
print("\nBefore = ", strInput)
print("After = ",result) | true |
06970f054e1768bc231abc16a32fff9286e053f6 | dipikarpawarr/TQ_Python_Programming | /PythonPracticePrograms/String/Anagram_String.py | 456 | 4.15625 | 4 | # WAP to accept 2 string and check whether they are anagram or not eg) MARY ARMY
strInput1 = input("Enter the first string = ")
strInput2 = input("Enter the second string = ")
if len(strInput1) == len(strInput2):
sorted1 = sorted(strInput1)
s1 = "".join(sorted1)
sorted2=sorted(strInput2)
s2 = "".join... | true |
77bd1bf62927f89fbbfc01fd300a2d5ca7677dc3 | dipikarpawarr/TQ_Python_Programming | /PythonPracticePrograms/Flow Control - Loops/Count_Digits_In_Given_Number.py | 247 | 4.28125 | 4 | # Write a Python program to count number of digits in any number
num = int(input("Enter the number = "))
numHold = num
count = 0
while(num>0):
digit = num %10
count += 1
num //= 10
print("Total digits in the ",numHold," is = ", count) | true |
85bd50a7ef08b61082969d3a7a8b5a9a7efc04e9 | dipikarpawarr/TQ_Python_Programming | /PythonPracticePrograms/Flow Control - Loops/Pallindrome_Number.py | 576 | 4.125 | 4 | # WAP to check given no is palindrome or not. Original =Reverse
# Eg 1221, 141, 12321, etc
num = input("Enter the number = ")
print("\n---- Solution 1 ----")
reverse = num[::-1]
if num == reverse:
print(num," is palindrome")
else:
print(num, " is not palindrome")
# OR
print("\n---- Solution 2 ----")
num1 = ... | true |
55c986710dc439d7818700236233a042e3ca1a76 | jerome1232/datastruct-tut | /src/2-topic-starter.py | 1,629 | 4.34375 | 4 | class Queue:
'''
This represents a queue implemented by a doubly
linked list.
'''
class Node:
'''
An individual node inside a linked list
'''
def __init__(self, data):
'''Initialize with provided data and no links.'''
self.data = data
self.previous = N... | true |
47f966adae31358284fc408907a2eea4a60f5c23 | kensekense/unige-fall-2019 | /metaheuristics/example_for_kevin.py | 2,864 | 4.4375 | 4 | '''
When you're coding, you want to be doing your "actions" inside of functions.
You are usually using your "global" space to put in very specific values.
Here's an example.
'''
import random
def modifier_function (input1, input2):
'''
For simplicity, I've named the inputs to this function input1 an... | true |
1eafc06083e85e6fff87c4a0c26b0c7a759844f9 | deleks-technology/myproject | /simpleCal.py | 1,493 | 4.21875 | 4 | print("Welcome to our simple Calculator... ")
print("====================================================================")
# Prompt User for first number
# to convert a string to a number with use the int()/ float()
first_number = float(input("Please input your first number: "))
print("=========================... | true |
24dccadfc40fb85d20305d92ba298bc511a6ea64 | niranjan2822/PythonLearn | /src/Boolean_.py | 804 | 4.375 | 4 | # Boolean represent one of two values :
# True or False
print(10 > 9) # --> True
print(10 == 9) # --> False
print(10 < 9) # --> False
# Ex :
a = 200
b = 300
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
# Output --> b is greater than a
# bool() --> The bool() function all... | true |
223bf6f986a50959f1f6f61520204ad384e2daec | sachdevavaibhav/CFC-PYDSA-TEST01 | /Test-01-Py/Ans-03.py | 281 | 4.1875 | 4 | # 3. Write a Python program to sum of two given integers. However, if the sum
# is between 15 to 20 it will return 20.
num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
ans = num1 + num2
if 15 <= ans <= 20:
print(20)
else:
print(ans) | true |
17eec4b963a4a7fb27a29279261a1df059be22e3 | amaria-a/secu2002_2017 | /lab03/code/hangman.py | 2,022 | 4.15625 | 4 |
# load secret phrase from file
f = open('secret_phrase.txt','r')
# ignore last character as it's a newline
secret_phrase = f.read()[:-1]
# get letters to guess, characters to keep, initialize ones that are guessed
to_guess = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
to_keep = " ,'-"
guessed = []
# creat... | true |
42e1b76389b3f6dd99e36f7d8f4d3f89fe3af8c0 | mguid73/basic_stats | /basic_stats/basic_stats.py | 788 | 4.40625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Basic stats module
"""
def mean(a):
"""
input is the list of numbers you want to take the mean
"""
# computing amount
ctlist= []
for n in a:
n=1 # changing every value in the list to 1
ctlist.append(n) # creating a new list made up... | true |
43e2dccabe35905571ca61822de501fd25906b79 | AlexanderHurst/CrackingVigenereCypher | /vigenere.py | 2,009 | 4.1875 | 4 | from sys import argv
import string_tools
from sanitization import sanitize
# takes a secret message and key and returns
# vigenere ciphertext
# note secret message and key must be a list of numbers
# use string tools to convert
def encrypt(secret_message, secret_key):
cipher_text = []
# encrypting adds the k... | true |
eb8f13ba8ef2c9a7adad8dcc94081a8aa24cb93e | hsinhuibiga/Python | /insertion sort.py | 1,419 | 4.34375 | 4 |
# sorts the list in an ascending order using insertion sort
def insertion_sort(the_list):
# obtain the length of the list
n = len(the_list)
# begin with the first item of the list
# treat it as the only item in the sorted sublist
for i in range(1, n):
# indicate the current item to be p... | true |
d70613eaa55ed3f52e384a4f97e3a751d0723e87 | grimmi/learnpython | /linkedlist1.py | 1,132 | 4.125 | 4 | '''
Linked Lists - Push & BuildOneTwoThree
Write push() and buildOneTwoThree() functions to easily update and
initialize linked lists. Try to use the push() function within your
buildOneTwoThree() function.
Here's an example of push() usage:
var chained = null
chained = push(chained, 3)
chained = push(chained, 2)
ch... | true |
d3e25805b601aff974c730abd85b4368724d09d4 | grimmi/learnpython | /reversebytes.py | 810 | 4.125 | 4 | '''
A stream of data is received and needs to be reversed.
Each segment is 8 bits meaning the order of these segments need to be reversed:
11111111 00000000 00001111 10101010
(byte1) (byte2) (byte3) (byte4)
10101010 00001111 00000000 11111111
(byte4) (byte3) (byte2) (byte1)
Total number of bits will always be a mu... | true |
b813a38631d35d6ccc84b871fade7dc9ccbde14c | ll0816/My-Python-Code | /decorator/decorator_maker_with_arguments.py | 1,084 | 4.1875 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# decorator maker with arguments
# Liu L.
# 12-05-15
def decorator_maker_with_args(d_arg1, d_arg2):
print "I make decorators! And I accept arguments:{} {}".format(d_arg1, d_arg2)
def decorator(func):
print "I am the decorator. Somehow you passed me arguments:... | true |
295ace8f90f7303eba831493003cdd7289a4c3c9 | ll0816/My-Python-Code | /decorator/dive_in_decorator.py | 1,094 | 4.21875 | 4 | # !/usr/bin/python
# -*- coding: utf-8 -*-
# dive in decorator
# Liu L.
# 12-05-15
def decorator_maker():
print "I make decorators! I am executed only once:"+\
"when you make me create a decorator"
def my_decorator(func):
print "I am a decorator! I am executed"+\
"only when you decorate a... | true |
b8fdbfa602d0928217d6fa18a3dee3bdfaf6890d | AnanthaVamshi/PySpark_Tutorials | /code/chap02/word_count_driver_with_filter.py | 2,672 | 4.21875 | 4 | #!/usr/bin/python
#-----------------------------------------------------
# This is a word count in PySpark.
# The goal is to show how "word count" works.
# Here we write transformations in a shorthand!
#
# RULES:
#
# RULE-1:
# Here I introduce the RDD.filter() transformation
# to ignore the words if the... | true |
aa60328ddf11240a19c9aa1360b49ae37777aee9 | shreya-trivedi/PythonLearn | /q03lenght.py | 515 | 4.21875 | 4 | #!/usr/bin/python3.5
'''
Problem Statement
Define a function that computes the length of a given list or string.
(It is true that Python has the len() function built in,
but writing it yourself is nevertheless a good exercise.)
'''
import sys
def get_lenght(word):
''' Function to get lenght of a string
Args... | true |
43ea03ea1d693d03366841964a2808e64626c414 | MihaiRr/Python | /lab11/Recursion.py | 1,335 | 4.46875 | 4 | # The main function that prints all
# combinations of size r in arr[] of
# size n. This function mainly uses
# combinationUtil()
def printCombination(arr, n, r):
# A temporary array to store
# all combination one by one
data = [""] * r
# Print all combination using
# te... | true |
86b6be121a3af8171cf502278d6a7cd974db0533 | jshubh19/pythonapps | /bankaccount.py | 2,486 | 4.15625 | 4 | # bank account
class BankAccount:
''' this is Janta ka Bank'''
def __init__(self,accountname='BankAccount',balance=20000): #for making class method we use __init__ const
self.accountname=accountname
self.balance=baalance
def deposite (self,value):
self.balance=self.balance+val... | true |
6c562dadd0b180b5357b4ce57c73b440cb7c06a3 | Mariam-Hemdan/ICS3U-Unit-4-01-Python | /while_loop.py | 470 | 4.1875 | 4 | #!/usr/bin/env python3
# Created by : Mariam Hemdan
# Created on : October 2019
# This program uses while loop
def main():
# this program uses While loop
sum = 0
loop_counter = 0
# input
positive_integer = int(input("Enter an integer: "))
print("")
# process & output
while loop_coun... | true |
78eebbec669e95bedd57fb74714c56a8a3705178 | Pyabecedarian/Algorithms-and-Data-Structures-using-Python | /Stage_1/Task5_Sorting/bubble_sort.py | 729 | 4.28125 | 4 | """
Bubble Sort
Compare adjacent items and exchange those are out of order. Each pass through the list places the next
largest value in its proper place.
If not exchanges during a pass, then the list has been sorted.
[5, 1, 3, 2] ---- 1st pass ----> [1, 3, 2, 5]
Complexity: O(n^2)
"""
def bub... | true |
5e3a27d7f44acfc40517e889015a6bc778855ade | EarthBeLost/Learning.Python | /Exercise 3: Numbers and Math.py | 1,051 | 4.59375 | 5 | # This is the 3rd exercise!
# This is to demonstrate maths within Python.
# This will print out the line "I will now count my chickens:"
print "I will now count my chickens:"
# These 2 lines will print out their lines and the result of the maths used.
print "Hens", 25 + 30 / 6
print "Roosters", 100 - 25 * 3 % 4
# Th... | true |
a3ee6737bc9880a213034cfc71ffd34b3f4d1215 | JakeGads/Python-tests | /Prime.py | 888 | 4.1875 | 4 | """
Ask the user for a number and determine whether the number is prime or not.
(For those who have forgotten, a prime number is a number that has no divisors.).
You can (and should!) use your answer to Exercise 4 to help you.
Take this opportunity to practice using functions, described below.
"""
def main():
run ... | true |
54c8d3a2094f4f575acd6ea4ecac7a4dc1746ec8 | green-fox-academy/wenjing-liu | /week-01/day-03/data_structure.py/product_db_2.py | 1,472 | 4.53125 | 5 | product_db = {
'milk': 200,
'eggs': 200,
'fish': 400,
'apples': 150,
'bread': 50,
'chicken': 550
}
def search_db(db):
print('Which products cost less than 201?')
smaller_keys = []
for key, value in product_db.items():
if value < 201:
smaller_keys.append(key)
if smaller_keys:
print(f... | true |
c874fd86801315b98f608f9011a54ef8299a8b54 | green-fox-academy/wenjing-liu | /week-01/day-05/matrix/matrix_rotation.py | 952 | 4.1875 | 4 | """
# Matrix rotation
Create a program that can rotate a matrix by 90 degree.
Extend your program to work with any multiplication of 90 degree.
"""
import math
def rotate_matrix(matrix, degree):
rotate_times = degree//90%4
print(rotate_times)
for rotate_time in range(rotate_times):
tmp_matrix = []
... | true |
75194eb550340de1c1ab9a31adc510fec7ef771b | green-fox-academy/wenjing-liu | /week-02/day-01/encapsulation-constructor/counter.py | 947 | 4.125 | 4 | class Counter:
def __init__(self, num = 0):
self.num = int(num)
self._initial_num = self.num
def add(self, number = 1):
if isinstance(number, (int, float)):
self.num += int(number)
else:
raise Exception('You must input number')
def get(self):
return self.num
def reset(se... | true |
12c1001a8ec9759c913683af89a5f8db183d87a7 | green-fox-academy/wenjing-liu | /week-02/day-02/decryption/reversed_order.py | 510 | 4.15625 | 4 | # Create a method that decrypts reversed-order.txt
def decrypt(file_name, result_file_name):
try:
with open(file_name, 'r') as source_file:
with open(result_file_name, 'a') as result_file:
line_list = source_file.readlines()
result_file.write(''.join(reverse_order(line_list)))
except Exce... | true |
6f8fa5537d1c905be5afa97b890f334fb16fcd43 | green-fox-academy/wenjing-liu | /week-01/day-02/loops/guess_the_number.py | 634 | 4.21875 | 4 | # Write a program that stores a number, and the user has to figure it out.
# The user can input guesses, after each guess the program would tell one
# of the following:
#
# The stored number is higher
# The stried number is lower
# You found the number: 8
magic_num = 5
print('Guess the number!')
is_found = False
whil... | true |
01e271b2fd0fbdd4b16f96d6171e294982bd0674 | green-fox-academy/wenjing-liu | /week-01/day-05/matrix/transposition.py | 465 | 4.15625 | 4 | """
# Transposition
Create a program that calculates the transposition of a matrix.
"""
def transposition_matrix(matrix):
result = []
for col_num in range(len(matrix[0])):
result.append([None]*len(matrix))
print(result)
for row_num in range(len(result)):
for col_num in range(len(result[row_num])):
... | true |
29031610a8bc863cea296a89d3bc058715762bf3 | green-fox-academy/wenjing-liu | /week-01/day-03/functions/bubble.py | 575 | 4.34375 | 4 | # Create a function that takes a list of numbers as parameter
# Returns a list where the elements are sorted in ascending numerical order
# Make a second boolean parameter, if it's `True` sort that list descending
def bubble(arr):
return sorted(arr)
def advanced_bubble(arr, is_descending = False):
sorted_a... | true |
6eeb0463f0b42acc6fde7d5b61449e790949897b | dylan-hanna/ICS3U-Unit-5-05-Python | /address.py | 816 | 4.125 | 4 | #!/usr/bin/env python3
# Created by: Dylan Hanna
# Created on: Nov 2019
# This program accepts user address information
def mailing(name_one, address_one, city_one, province_one, postal_code_one):
print(name_one)
print(address_one)
print(city_one, province_one, postal_code_one)
def main():
while Tru... | true |
870d8536737e98f5e09e6475cea90552b8ae1aaf | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 4 - Style and Structure/73-multi-line-strings.py | 2,669 | 4.125 | 4 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 4. Style & Structure > Section 3:
# Multi-line strings (1/2)
'''
Sometimes we end up wanting to use very long strings, and this can
cause some problems.
If you run pycodestyle on this, you'll get the following message:
some_script.py: E501 line too l... | true |
861a628085be4eea68e5e32c6cab55f2d0f36838 | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 2 - Strings and Lists, Part 1/29-f-strings.py | 1,068 | 4.3125 | 4 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 2. Strings & Lists Part 1 > Section 16: f-strings
# Do it in the terminal:
'''
f-strings is something that was added to Python in version 3.6—
so in order for this to work on your own computer, you must be sure
to have Python 3.6 or later. As a remin... | true |
8eafc4cab7035114ead9e844e3f5a57c3c489e01 | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 2 - Strings and Lists, Part 1/24-slicing-word-triangle-exercise.py | 977 | 4.1875 | 4 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 2. Strings & Lists Part 1 > Section 12: Slicing(1/2)
'''
Exercise: Word triangle
find a partially completed for loop.
Goal is to finish the loop so that it prints out the following:
d
de
def
defi
defin
defini
definit
definite
definitel
definitely
'''... | true |
95e54eacc1da6c8c5b8724634c686b56b1ae1e41 | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 3 - Strings and Lists, Part 2/43-mutable-vs-immutable.py | 905 | 4.3125 | 4 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 3. Strings & Lists Part 2 > Section 3:
# Mutable vs. immutable
'''
List are mutable (can be modified)
Strings are immutable (cannot be modified)
'''
# Exercise 1 - Mutable
print('\nExercise 1 - Mutable:\n')
breakfast = ['toast', 'bacon', 'eggs']
pri... | true |
f9ca6dad8f3dc6f8363fe1b8a49072604bb770ab | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 3 - Strings and Lists, Part 2/66-convert-string-into-list.py | 800 | 4.5625 | 5 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 3. Strings & Lists Part 2 > Section 17:
# Find and replace (1/2)
# Convert a string into a list
# Approach 1 (without using split method)
def list_conversion(string):
list = []
for index in string:
list.append(index)
return list
... | true |
46b0b93e3d86c6cc425459be309bd3bd15ed3d1c | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 2 - Strings and Lists, Part 1/19-range-function.py | 1,245 | 4.71875 | 5 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 2. Strings & Lists Part 1 > Section 9:
# The range function, revisited
'''
Earlier, we used the range function with for loops.
We saw that instead of using a list like this:
'''
print()
for side in [0, 1, 2, 3]:
print(side)
print()
# Range can ... | true |
9580691741d7e3c606279cd91512724f8c087993 | vamshi-krishna-prime/Programming_Nanodegree | /6. Python, Part 2/Lesson 3 - Strings and Lists, Part 2/56-break-exercise-no-repeating-words.py | 686 | 4.21875 | 4 | # Udacity > Intro to the Programming Nanodegree >
# Python part 2 > 3. Strings & Lists Part 2 > Section 10:
# Infinite loops and breaking out
# Exercise - Repeated words:
'''
Write an function to store the words input by the user
and exit the while loop when a word is repeated.
There's another way to exit from an in... | true |
612dbf123309396abbe8755f327c1e0eed8d5303 | divineBayuo/NumberGuessingGameWithPython | /Number_Guessing_GameExe.py | 1,959 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jun 3 10:52:42 2021
@author: Divine
"""
#putting both programs together
#importing required libs
import tkinter as tk
import random
import math
root = tk.Tk()
canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()
#making the game cod... | true |
cca6ea9561c63a741e72107d537b70054a4220c2 | goateater/MyCode | /learn_python/basic_string_operations.py | 785 | 4.5 | 4 | #!/usr/bin/env python
bso = """
Basic String Operations
----------------------
Strings are bits of text. They can be defined as anything between quotes:
As you can see, the first thing you learned was printing a simple sentence. This sentence was stored by Python as a string.
However, instead of immediately printin... | true |
78b6c9150a4804af6f60d62d040fc09c9f86d0a1 | nfbarrett/CCIS-1505-02 | /Session11/Test2-Q28.py | 549 | 4.21875 | 4 | blnDone = False # sets Boolean to false
while blnDone == False: # checks Boolean is still false
try: # repeats this until Boolean is true
num = int(input( "Enter your age" )) # asks for number, converts input into integer
blnDone = True # sets Boolean to true
except (ValueError): # if input is n... | true |
ba771d7f4f312d4276781c88642d7aae08baaf7d | nfbarrett/CCIS-1505-02 | /Session11/Test2-Q27.py | 837 | 4.46875 | 4 | def maximumValue( x, y, z ): # calls the function for maximumvalue
maximum = x # if position 1 is max this will be displayed
if y > maximum: # checks if position 2 is larger that position 1
maximum = y # if position 2 is larger, position 2 will be displayed
if z > maximum: # checks if position 3 is... | true |
15b5733f80fddc8c8a22522ae0653f1de90546bf | liujiantao007/Perform-Object-Detection-With-YOLOv3-in-Keras | /Draw_rectangle/single_rectangle_cv2.py | 911 | 4.3125 | 4 | # Python program to explain cv2.rectangle() method
# importing cv2
import cv2
from matplotlib import pyplot as plt
path ='2.jpg'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
# Start coordinate, here (5, 5)
# represents the top ... | true |
5d9b8983b5652dc449658873bfd8b237fdc57b64 | jsheridanwells/Python-Intro | /7_dates.py | 955 | 4.375 | 4 | #
# Example file for working with date information
#
from datetime import date
from datetime import time
from datetime import datetime # imports standard modules
def main():
## DATE OBJECTS
# Get today's date from the simple today() method from the date class
today = date.today()
print('la fecha es ', today... | true |
a1a92e7de2c597aaa4d1a6443bc2354216c9f1f5 | pavan1126/python-1-09 | /L3 8-09 Reverse order.py | 379 | 4.25 | 4 | #copying elements from one array to another array in reverse order
a=[1,2,3,4,5]
b=[None]*len(a)
length=len(a)
#logic starts here
for i in range(0,length):
b[i]=a[length-i-1]
#printing output
print("the elements of first array is")
for i in range(0,length):
print(a[i])
print("the elements of reversed... | true |
84eb0afd3ad225fc0e23eb56292b845ed1d4e4ec | eessm01/100-days-of-code | /python_for_everybody_p3/files_exercise1.py | 348 | 4.375 | 4 | """Python for everybody.
Exercise 1: Write a program to read through a
file and print the contents of the file (line
by line) all in upper case. Executing the
program will look as follows:
"""
fname = input('Enter a file name: ')
try:
fhand = open(fname)
except:
print('File not found')
exit()
for line... | true |
b01c74c82073bf2a8cfdbbba7ac08bfd433a4560 | eessm01/100-days-of-code | /platzi_OOP_python/insertion_sort.py | 799 | 4.21875 | 4 | from random import randint
def insertion_sort(one_list):
# iterate over one_list from 1 to list's length
for i in range(1, len(one_list)):
current_element = one_list[i]
# iterate over all elements in the left side (from i-1 to 0)
for j in range(i-1,-1,-1):
# compare cur... | true |
3869deac3ad24925a63d2cdaeb4db9431e08a8af | eessm01/100-days-of-code | /real_python/day10_11_dear_pythonic_santa_claus.py | 1,732 | 4.28125 | 4 | #!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""
Exercises from https://realpython.com/python-thinking-recursively/
The algorithm for interative present delivery implemented in Python
Now that we have some intuition about recursion, let's introduce the formal
definition of a recursive function. A recursive function ... | true |
c2cde7223eafaf4d2c98b3bdef23a6653511f93e | BitPunchZ/Leetcode-in-python-50-Algorithms-Coding-Interview-Questions | /Algorithms and data structures implementation/binary search/index.py | 678 | 4.34375 | 4 |
def binarySearch(arr, target):
left = 0
right = len(arr)-1
while left <= right:
mid = (left+right)//2
# Check if x is present at mid
if arr[mid] == target:
return mid
# If x is greater, ignore left half
elif arr[mid] < target:
left = mid + ... | true |
efd43f194e740f108d25a1a7a8e3fce39e208d5a | DhananjayNarayan/Programming-in-Python | /Google IT Automation with Python/01. Crash Course on Python/GuestList.py | 815 | 4.5 | 4 | """
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 print out:
Ken is 30 years... | true |
1bf31d944d5650e5c3c2bd35a75dbef782f24ec7 | ReDi-school-Berlin/lesson-6-exercises | /6-dictionaries/dictionaries.py | 1,298 | 4.5 | 4 | # What are some differences between dictionaries and lists?
# dict is not indexable
# lists are ordered and dictionaries aren't
# dictionaries cannot have duplicate keys
# --------------------
# How to create an empty dictionary
person = {}
# --------------------
# add values for this person, like name, phon... | true |
9a27ab3cacd389a2bd69066a4241542185256072 | tomdefeo/Self_Taught_Examples | /python_ex284.py | 419 | 4.3125 | 4 | # I changed the variable in this example from
#
text in older versions of the book to t
# so the example fits on smaller devices. If you have an older
# version of the book, you can email me at cory@theselftaughtprogrammer.io
# and I will send you the newest version. Thank you so much for purchasing my book!
impor... | true |
d6c7cd46e60e6aa74cdd28de4f94aa45a65eb861 | GarrisonParrish/binary-calculator | /decimal_conversions.py | 1,823 | 4.1875 | 4 | """Handle conversions from decimal (as integer/float) to other forms."""
# NOTE: A lot of this code is just plain bad
def dec_to_bin(dec: int, N: int = 32):
"""Converts decimal integer to N-bit unsigned binary as a list. N defaults to 32 bits."""
# take dec, use algorithm to display as a string of 1's and 0... | true |
2726d03db151046c1091b93d14a5593c2d368e52 | vrillusions/python-snippets | /ip2int/ip2int_py3.py | 963 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Asks for an IPv4 address and convert to integer.
In Python v3.3 the ipaddress module was added so this is much simpler
"""
import sys
import ipaddress
__version__ = '0.1.0-dev'
def main(argv=None):
"""The main function.
:param list argv: List of arguments ... | true |
30d6d86bbcdcfee563d26985ccfaae90c8480397 | Splufic-Automation-Systems-Ltd/Python-Training-Online-Cohort-One | /Week Three/Day 2/temp.py | 340 | 4.375 | 4 |
import math
# a python program that converts temperature from Farenheit to Celcius
# get the user input
fahrenheit = input('Enter the temperature in degrees Fahrenheit: ')
# calculate the result
result = (5/9 * (int(fahrenheit) - 32))
result = math.trunc(result)
# print the result
print(f'The temperature in degrees C... | true |
d1d792d85b93fcb95cfc3183cf05541dd8579d84 | rotus/the-python-bible | /tuple_examples.py | 248 | 4.125 | 4 | # Tuples, like lists, hold values - Except tuple data CANNOT be changed
# Useful for storing data/values that never need updated or modified
our_tuple = (1,2,3,"a","b")
print(our_tuple)
# Pull data out of individual elements
print(our_tuple[3])
| true |
9cf228ee2b0cd2fa8899ce07b5ccc5738d729e92 | rotus/the-python-bible | /dictionary_basics.py | 394 | 4.5625 | 5 | # Used to store values with "keys" and then can retreive values based on those keys
students = {"Alice":25, "Bob":27, "Claire":17, "Dan":21, "Emma":25}
print(students)
# extract Dan's value from dict
print(students["Dan"])
# Update Alice's age
print(students["Alice"])
students["Alice"] = 26
print(students["Alice"])... | true |
ba5f177e8ed7dff0164f72206401d5dd35ab690a | johnnymcodes/cs131b_python_programming | /4_functions/w10exhand.py | 1,504 | 4.21875 | 4 | # Write a program that expects numeric command line arguments and calls
# functions to print descriptive statistics such as the mean, median,
# mode, and midpoint.
# Week 9 : Severance 4
import sys #expects numeric command line arguments
cmarg = sys.argv[1:] #returns a list of cmd arguments
numlist = list(... | true |
87f7b24055a392eb6a29a2a72b8b9395b4c083fe | johnnymcodes/cs131b_python_programming | /6_strings/sortuserinput.py | 944 | 4.5625 | 5 | #intro to python
#sort user input
#write a program that prints out the unique command line arguments
#it receives, in alphabetical order
import sys
cmdarg = sys.argv[1:]
cmdarg.sort()
delimiter = ' '
if len(cmdarg) > 1:
joinstring = delimiter.join(sys.argv[1:])
print('this is your command argument '... | true |
8d88e73998d7d8bdfb3d323a963369c44aee27db | aliyakm/ICT_task1 | /3.py | 521 | 4.28125 | 4 | print("Please, choose the appropriate unit: feet = 1, meter = 2.")
unit = int(input())
print("Please, enter width and length of the room, respectively")
width = float(input())
length = float(input())
if unit == 1:
area = width*length
result = "The area of the room is {0} feets"
print(result.fo... | true |
2f91d697437a7ae3ffb51c07443634f68505566b | androidgilbert/python-test | /ex33.py | 514 | 4.1875 | 4 |
def test_while(a,b):
numbers=[]
i=0
while i<a:
print "At the top is %d"%i
numbers.append(i)
i=i+b
print "numbers now:",numbers
print "at the bottom i is %d"%i
return numbers
def test_for(a):
numbers=[]
for i in range(0,a,3):
print "at the top is %d"%i
numbers.append(i)
print "numbe... | true |
00cf375c449164d643f12c421ffc3fbbde8a789e | androidgilbert/python-test | /ex30.py | 410 | 4.15625 | 4 | people=30
cars=40
buses=15
if cars>people:
print "we should take the cars"
elif cars<people:
print "we should not take the cars"
else:
print "we can't decide"
if buses>cars:
print "that is too many buses"
elif buses<cars:
print "maybe we could take the buses"
else:
print "we still can not decide"
if people>buse... | true |
3391a8aed49e4335f75ad4b18ac26639b9752b6e | JenySadadia/MIT-assignments-Python | /Assignment2/list_comprehension(OPT.2).py | 714 | 4.125 | 4 | print 'Exercise OPT.2 : List comprehension Challenges(tricky!)'
print '(1)'
print 'find integer number from list:'
def int_element(lists):
return [element for element in lists if isinstance(element, int)]
lists = [52,53.5,"grp4",65,42,35]
print int_element(lists)
print '(2)'
print 'Here the y = x*x + ... | true |
860251764c96cccf6db12d1695ae1774d9332dc4 | Tanner0397/LightUp | /src/chromosome.py | 2,288 | 4.125 | 4 | """
Tanner Wendland
9/7/18
CS5401
Missouri University of Science and Technology
"""
from orderedset import OrderedSet
"""
This is the class defintion of a chromosome. A chromosome has genetic code that ddetermines the phenotype of the population member (the placement of the bulbs).
The genetic code is a li... | true |
a221f1dd62fc93c85c1329c670fe4d330df35caa | imthefrizzlefry/PythonPractice | /DailyCodingChallenge/Hard_Problem004.py | 1,069 | 4.125 | 4 | import logging
'''This problem was asked by Stripe.
Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well.
For example, the ... | true |
79dacd2b79eb76486bfcb0ad860b01eced6ff016 | imthefrizzlefry/PythonPractice | /DailyCodingChallenge/Hard_Problem012.py | 1,032 | 4.53125 | 5 | '''This problem was asked by Amazon.
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, ... | true |
b075eaa1eb0118a9f0fd0e112b91f318e4a98a20 | Aifedayo/Logic | /palindrome.py | 346 | 4.375 | 4 | def palindrome(string):
'''
Python function that checks whether a word
or phrase is palindrome or not
'''
new_string = string.replace(' ','')
if new_string == new_string[::-1]:
print(f'{string} is a palindrome')
else:
print(f'{string} is not a palindrome')
palindrome(input(... | true |
2b288e37ceb0c00528623ce6c863597d09aebfb8 | ish-suarez/afs-200 | /week5/function/function.py | 481 | 4.1875 | 4 | def step1():
user_input = []
print(f'I will be asking you for 3 numbers')
for i in range(3):
num = int(input(f'Give me a number: '))
user_input.append(num)
input_max = max(num for num in user_input)
input_min = min(num for num in user_input)
print(f'Your Numbers are: {user... | true |
affa4eda6861fe0c5a2e31f232d3714fa15d84e8 | ish-suarez/afs-200 | /week2/evenOrOdd/evenOrOdd.py | 1,078 | 4.28125 | 4 | # Getting input to determine if numbers are even or odd
def user_input_eve_or_odd():
number = int(input('Give me a number and I will tell you if it is even or odd? '))
check_if_even_or_odd = number % 2
if check_if_even_or_odd == 0:
print(f"{number} is Even")
else:
print(f"{number} is Od... | true |
1ee69b4669c48ad85dd511ae57d7d4125cf6f645 | VimleshS/python-design-pattern | /Strategy pattern/solution_1.py | 2,021 | 4.125 | 4 | """
All the classes must in a seperate file.
Problems in this approch.
Order Class
It is not adhering to S of solid principles
There is no reason for order class to know about shipper.
Shipping Cost
Uses a default contructor.
Uses the shipper type stored in a shipper class to ca... | true |
3947858a10bb6fe6e1f0549d39c60f70de70a696 | UmberShadow/PigLatin | /UmberShadow_Pig Latin.py | 989 | 4.5 | 4 | #CJ Malson
#March 6th, 2021
#Intro to Python Programming
#Professor Wright
#I don't understand pig latin at all. What is this??
#Program requests a word (in lowercase letters) as input and translates the word into Pig Latin.
#If the word begins with a group of consonants, move them to the end of the word and ... | true |
693aa7a983a83814395518f00d68d6345502694b | luqiang21/Hackerrank.com | /Cracking the Coding Interview/Davis'_Staricase.py | 1,891 | 4.1875 | 4 | '''
Davis' staircase, climb by 1, 2 or 3 steps when given n stairs
in a staircase
'''
import numpy as np
def staircase(n):
# this function is written based on discussion of this problem on
# the website
A = [1,2,4]
A.append(sum(A))
A.append(A[1] + A[2] + A[3])
M = np.array([[1,1,0],[1,0,1],[1,0,0]])
An = np.arr... | true |
321cb60befeebd95889763e272177d7cdfd9f1a0 | sureshrmdec/algorithms | /app/dp/knapsack.py | 1,105 | 4.1875 | 4 | """
Given a weight limit for a knapsack, and a list of items with weights and benefits, find the optimal knapsack
which maximizes the benefit, whilee the total weight being less than the weight limit
https://www.youtube.com/watch?v=ipRGyCcbrGs
eg -
item 0 1 2 3
wt 5 2 8 6
benefit 9 3 1 4
wt limit = 10
soln: ... | true |
28d24e0531c3f15a5f79fd0501f8f58662452f0b | joaolrsarmento/university | /courses/CT-213/lab3_ct213_2020/hill_climbing.py | 1,841 | 4.1875 | 4 | from math import inf
import numpy as np
def hill_climbing(cost_function, neighbors, theta0, epsilon, max_iterations):
"""
Executes the Hill Climbing (HC) algorithm to minimize (optimize) a cost function.
:param cost_function: function to be minimized.
:type cost_function: function.
:param... | true |
95bf38eccb1a70731cc9cc4602a440fdb98043dd | ranjanlamsal/Python_Revision | /file_handling_write.py | 1,891 | 4.625 | 5 | '''In write mode we have attributes such as :
To create a new file in Python, use the open() method, with one of the following parameters:
"x" - Create - will create a file, returns an error if the file exist
"a" - Append - will create a file if the specified file does not exist
"w" - Write - will create a f... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.