blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
230e1d2846f4b608c3f541d5d089655ca97f9efe | kmrsimkhada/Python_Basics | /loop/while_with_endingCriteria.py | 968 | 4.25 | 4 | #While-structure with ending criteria
'''
The second exercise tries to elaborates on the first task.
The idea is to create an iteration where the user is able to define when the loop ends by testing the input which the user gave.
Create a program which, for every loop, prompts the user for input, and then prints it... | true |
e1dca0956dc0547a3090e508787df989034b0eaf | kmrsimkhada/Python_Basics | /type_conversion.py | 702 | 4.5 | 4 | #Type Conversions
'''
In this exercise the aim is to try out different datatypes.
Start by defining two variables, and assign the first variable the float value 10.6411.
The second variable gets a string "Stringline!" as a value.
Convert the first variable to an integer, and multiply the variable with the string by... | true |
26a5ce912495c032939b4b912868374a6d8f83c7 | kmrsimkhada/Python_Basics | /lists/using_the_list.py | 2,397 | 4.84375 | 5 | #Using the list
'''
n the second exercise the idea is to create a small grocery shopping list with the list datastructure.
In short, create a program that allows the user to (1) add products to the list, (2) remove items and (3) print the list and quit.
If the user adds something to the list, the program asks "What... | true |
8a49bad35b7b1877abf081adc13ed6b9b63d0de8 | suhanapradhan/IW-Python | /functions/6.py | 319 | 4.28125 | 4 | string = input("enter anything consisting of uppercase and lowercase")
def count_case(string):
x = 0
y = 0
for i in string:
if i.isupper():
x += 1
else:
y += 1
print('Upper case count: %s' % str(x))
print('Lower case count: %s' % str(y))
count_case(string)
| true |
35a98e4bf5b1abcd7d6dd9c6ff64d53d07f8788e | BinyaminCohen/MoreCodeQuestions | /ex2.py | 2,795 | 4.1875 | 4 | def sum_list(items):
"""returns the sum of items in a list. Assumes the list contains numeric values.
An empty list returns 0"""
sum = 0
if not items: # this is one way to check if list is empty we have more like if items is None or if items is []
return 0
else:
for x in items:
... | true |
a9cb243ebc4a52d46e6d214a17e011c293cde3ff | s16323/MyPythonTutorial1 | /EnumerateFormatBreak.py | 1,464 | 4.34375 | 4 |
fruits = ["apple", "orange", "pear", "banana", "apple"]
for i, fruit in enumerate(fruits):
print(i, fruit)
print("--------------Enumerate---------------")
# Enumerate - adds counter to an iterable and returns it
# reach 3 fruit and omit the rest using 'enumerate' (iterator)
for i, fruit in enumerate(fruits): ... | true |
4cb726601b5dda4443b8fe3b388cbd6f598013a8 | varnagysz/Automate-the-Boring-Stuff-with-Python | /Chapter_05-Dictionaries_and_Structuring_Data/list_to_dictionary_function_for_fantasy_game_inventory.py | 1,640 | 4.21875 | 4 | '''Imagine that a vanquished dragon’s loot is represented as a list of strings
like this:
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
Write a function named addToInventory(inventory, addedItems), where the
inventory parameter is a dictionary representing the player’s inventory
(like in... | true |
71db3ebdbd3bbcac09c385947f6b327f9d7c3d73 | harshit-sh/python_games | /matq.py | 743 | 4.25 | 4 | # matq.py
# Multiplication Quiz program
# Created by : Harshit Sharma
from random import randint
print "Welcome to Maths Multiplication Quiz!"
print "--------------------------------"
ques = int(raw_input("How many questions do you wish to answer? "))
print "--------------------------------"
limit = int(raw_input("Ti... | true |
cdaa647a527a20cf851f65ce4df554a3185b920a | annkon22/ex_book-chapter3 | /linked_list_queue(ex20).py | 1,835 | 4.1875 | 4 | # Implement a stack using a linked list
class Node:
def __init__(self, init_data):
self.data = init_data
self.next = None
def get_data(self):
return self.data
def get_next(self):
return self.next
def set_data(self, new_data):
self.data = new_data... | true |
32662139be2cd03f427faaa5a1255fb8fd24b1cd | annkon22/ex_book-chapter3 | /queue_reverse(ex5).py | 457 | 4.25 | 4 | #Implement the Queue ADT, using a list such that the rear of the queue
#is at he end of the list
class Queue():
def __init__(self):
self.items = []
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
return self.items.pop(0)
my_q = Queu... | true |
061acf150e2bea1ec8acbc7ce8d2a4550c408e0e | ChristianDzul/ChristianDzul | /Exam_Evaluation/Question_06.py | 506 | 4.15625 | 4 | ##Start##
print ("Welcome to the area calculator")
##Variables##
length = 0
width = 0
area_square = 0
area_rectangle = 0
##Getting the values##
length = int( input("Insert a value for the lenght \n"))
width = int( input("Insert a value for the width \n"))
##Process##
if (length == width):
area_square = length * wi... | true |
8bf756db6183232e427214af5df6d0d67b19b98c | meraj-kashi/Acit4420 | /lab-1/task-1.py | 286 | 4.125 | 4 | # This script ask user to enter a name and number of cookies
# script will print the name with cookies
name=input("Please enter your name: ")
number=int(input("Please enetr number of your cookies: "))
print(f'Hi {name}! welcome to my script. Here are your cookies:', number*'cookies ') | true |
9b80a85e7d931de6d78aeddeeccc2c154897a88b | vikrampruthvi5/pycharm-projects | /code_practice/04_json_experimenter_requestsLib.py | 1,217 | 4.125 | 4 |
"""
Target of this program is to experiment with urllib.request library and understand GET and POST methods
Tasks:
1. Create json server locally
2. retrieve json file using url
3. process json data and perform some actions
4. Try POST method
"""
"""
1. Create json server locally
a. From... | true |
aa322e4df062956a185267130057767ad450dc6e | JRose31/Binary-Lib | /binary.py | 937 | 4.34375 | 4 | ''' converting a number into binary:
-Divide intial number by 2
-If no remainder results from previous operation, binary = 0,
else if remainder exists, round quotient down and binary = 1
-Repeat operation on remaining rounded-down quotient
-Operations complete when quotient(rounded down or not) == 0... | true |
5b17c79d9830601e3ca3f21b2d1aa8f334e93f13 | piumallick/Python-Codes | /LeetCode/Problems/0104_maxDepthBinaryTree.py | 1,405 | 4.15625 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 20:12:03 2020
@author: piumallick
"""
# Problem 104: Maximum Depth of a Binary Tree
'''
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the
longest path from the root node down to the farthest leaf n... | true |
c5f5581f816bd354b3ee78d660c58aab13bb3906 | piumallick/Python-Codes | /LeetCode/Leetcode 30 day Challenge/April 2020 - 30 Day LeetCode Challenge/02_isHappyNumber.py | 1,406 | 4.125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 25 22:49:19 2020
@author: piumallick
"""
# Day 2 Challenge
"""
Write an algorithm to determine if a number n is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum... | true |
48a6871dba994b1244835a8fcc2a5edf9b206ca1 | piumallick/Python-Codes | /LeetCode/Problems/0977_sortedSquares.py | 909 | 4.1875 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 7 15:01:17 2020
@author: piumallick
"""
# Problem 977: Squares of a Sorted Array
'''
Given an array of integers A sorted in non-decreasing order,
return an array of the squares of each number,
also in sorted non-decreasing order.
Example 1:
Inp... | true |
3da3dfcf8bdba08539c1a0ecb23f7a908a8718f6 | piumallick/Python-Codes | /LeetCode/Problems/0009_isPalindrome.py | 973 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 15:46:03 2020
@author: piumallick
"""
# Problem 9: Palindrome Number
"""
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
Input:... | true |
a4b659635bbc3dbafabce7f53ea2f2387281daa3 | piumallick/Python-Codes | /Misc/largestNumber.py | 613 | 4.5625 | 5 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 27 10:59:35 2019
@author: piumallick
"""
# Python Program to find out the largest number in the array
# Function to find out the maximum number in the array
def largestNumber(arr, n):
# Initialize the maximum element
max = arr[0]
... | true |
78784eb5050732e41908bbb136a0bac6881bc29b | phenom11218/python_concordia_course | /Class 2/escape_characters.py | 399 | 4.25 | 4 | my_text = "this is a quote symbol"
my_text2 = 'this is a quote " symbol' #Bad Way
my_text3 = "this is a quote \" symbol"
my_text4 = "this is a \' \n quote \n symbol" #extra line
print(my_text)
print(my_text2)
print(my_text3)
print(my_text4)
print("*" * 10)
line_length = input("What length is the line?" >)
chara... | true |
5ce0153e690d86edc4b835656d290cda02caa2c7 | plee-lmco/python-algorithm-and-data-structure | /leetcode/23_Merge_k_Sorted_Lists.py | 1,584 | 4.15625 | 4 | # 23. Merge k Sorted Lists hard Hard
#
# Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
#
# Example:
#
# Input:
# [
# 1->4->5,
# 1->3->4,
# 2->6
# ]
# Output: 1->1->2->3->4->4->5->6
def __init__(self):
self.counter = itertools.count()
def mergeKLists(self,... | true |
cec13d4024f52f100c8075e5f1b43408790377bb | aquatiger/misc.-exercises | /random word game.py | 1,175 | 4.5625 | 5 | # does not do what I want it to do; not sure why
# user chooses random word from a tuple
# computer prints out all words in jumbled form
# user is told how many letters are in the chosen word
# user gets only 5 guesses
import random
# creates the tuple to choose from
WORDS = ("python", "jumble", "easy", "difficult"... | true |
30be4f414ed675c15f39ccf62e33924c7eb9db3b | Deepanshudangi/MLH-INIT-2022 | /Day 2/Sort list.py | 348 | 4.46875 | 4 | # Python Program to Sort List in Ascending Order
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort()
print("Element After Sorting List in Asce... | true |
34028b34420e05f24493049df0c8b5b0391eb9b9 | sammaurya/python_training | /Assignment6/Ques4.py | 879 | 4.4375 | 4 | '''
We have a function named calculate_sum(list) which is calculating the sum of the list.
Someone wants to modify the behaviour in a way such that:
1. It should calculate only sum of even numbers from the given list.
2. Obtained sum should always be odd. If the sum is even, make it odd by adding +1 and
if the sum... | true |
44f4b11f6819b285c3698ab59571f03591ad72b8 | sahilsehgal81/python3 | /computesquareroot.py | 308 | 4.125 | 4 | #!/usr/bin/python
value = eval(input('Enter the number to find square root: '))
root = 1.0;
diff = root*root - value
while diff > 0.00000001 or diff < -0.00000001:
root = (root + value/root) / 2
print(root, 'squared is', root*root)
diff = root*root - value
print('Square root of', value, "=", root)
| true |
cfcd0baa03e8b3534f59607103dfec97f760ea28 | zoeang/pythoncourse2018 | /day03/exercise03.py | 699 | 4.40625 | 4 | ## Write a function that counts how many vowels are in a word
## Raise a TypeError with an informative message if 'word' is passed as an integer
## When done, run the test file in the terminal and see your results.
def count_vowels(word):
if (type(word)==str)==False:
raise TypeError, "Enter a string."
else:
vowel... | true |
bb7941ec61dab5e4798f20fb78222c933efdcfe4 | Quantum-Anomaly/codecademy | /intensive-python3/unit3w4d6project.py | 757 | 4.5 | 4 | #!/usr/bin/env python3
toppings = ['pepperoni', 'pineapple', 'cheese', 'sausage', 'olives', 'anchovies', 'mushrooms']
prices = [2,6,1,3,2,7,2]
num_pizzas = len(toppings)
#figure out how many pizzas you sell
print("we sell " + str(num_pizzas) + " different kinds of pizza!")
#combine into one list with the prices attache... | true |
544c379a54a69a59d25a1241727d02f9414d6d1b | Murrkeys/pattern-search | /calculate_similarity.py | 1,633 | 4.25 | 4 | """
Purpose : Define a function that calculates the similarity between one
data segment and a given pattern.
Created on 15/4/2020
@author: Murray Keogh
Program description:
Write a function that calculates the similarity between a data segment
and a given pattern. If the segment is shorter than the pat... | true |
13593ebd81e6210edd3981895623975c820a72bc | MurrayLisa/pands-problem-set | /Solution-2.py | 367 | 4.4375 | 4 | # Solution-2 - Lisa Murray
#Import Library
import datetime
#Assigning todays date and time from datetime to variable day
day = datetime.datetime.today().weekday()
# Tuesday is day 1 and thursday is day 3 in the weekday method in the datetime library
if day == 1 or day == 3:
print ("Yes - today begins with a T")
... | true |
c0babd8461d2df8c5c3fe535b4fcc9ae15464adf | dcassells/Project-Euler | /project_euler001.py | 565 | 4.46875 | 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.
"""
def three_multiple(x):
if x%3 == 0:
return 1
else:
return 0
def five_multiple(x):
if x%5 == 0:
return 1
else... | true |
5af9348c7a72d67d0985911be231eb92519c8610 | elagina/Codility | /lessons/lesson_1.py | 580 | 4.15625 | 4 | """
Codility
Lesson 1 - Iterations
BinaryGap - Find longest sequence of zeros in binary representation of an integer.
"""
def solution(N):
bin_N = str("{0:b}".format(N))
max_counter = 0
counter = 0
for ch in bin_N:
if ch == '1':
if max_counter < counter:
max_coun... | true |
b3bd54dd4116a00744311a671f01040d70799f98 | josemigueldev/algoritmos | /07_factorial.py | 442 | 4.21875 | 4 | # Factorial de un número
def factorial(num):
result = 1
if num < 0:
return "Sorry, factorial does not exist for negative numbers"
elif num == 0:
return "The factorial of 0 is 1"
else:
for i in range(1, num + 1):
result = result * i
return f"The factorial of ... | true |
c5cdfbda5e8cb293bb7773ef345ddb5c8157313e | udhay1415/Python | /oop.py | 861 | 4.46875 | 4 | # Example 1
class Dog():
# Class object attribute
species = "mammal"
def __init__(self, breed):
self.breed = breed
# Instantation
myDog = Dog('pug');
print(myDog.species);
# Example 2
class Circle():
pi = 2.14
def __init__(self, radius):
self.radius = radius
... | true |
f7ba7fbb5be395558e1d8451e6904279db95952d | Nour833/MultiCalculator | /equation.py | 2,637 | 4.125 | 4 | from termcolor import colored
import string
def equation():
print(colored("----------------------------------------------------------------", "magenta"))
print(colored("1 ", "green"), colored(".", "red"), colored("1 dgree", "yellow"))
print(colored("2 ", "green"), colored(".", "red"), colored("2 degree... | true |
f9d07c3b4fbdc162b266613270fb975eac8e097d | lidongdongbuaa/leetcode2.0 | /位运算/汉明距离/461. Hamming Distance.py | 1,551 | 4.28125 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/1/16 20:33
# @Author : LI Dongdong
# @FileName: 461. Hamming Distance.py
''''''
'''
题目分析
1.要求:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Input: x = 1, y = 4 Output: 2 Explanation:
1 (... | true |
e88f7472da1d78f89cd3a23e98c97c3bc054fba7 | lidongdongbuaa/leetcode2.0 | /二叉树/二叉树的遍历/DFS/145. Binary Tree Postorder Traversal.py | 1,978 | 4.15625 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/2/19 20:15
# @Author : LI Dongdong
# @FileName: 145. Binary Tree Postorder Traversal.py
''''''
'''
题目分析
1.要求:
Given a binary tree, return the postorder traversal of its nodes' values.
Example:
Input: [1,null,2,3]
1
\
... | true |
8a4ccf34efe6041af0f3d69dae882df49b30d0e8 | lidongdongbuaa/leetcode2.0 | /二分搜索/有明确的target/33. Search in Rotated Sorted Array.py | 2,283 | 4.21875 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/3/12 15:24
# @Author : LI Dongdong
# @FileName: 33. Search in Rotated Sorted 数组.py
''''''
'''
题目分析 - 本题重点看
find the target value in the sorted rotated array, return its index, else return -1
O(logN)
binary search problem
input: nums:list[int], repeated valu... | true |
01aeba94e37e74be60c0b9232b80b18edcdf251e | lidongdongbuaa/leetcode2.0 | /二叉树/路径和/257. Binary Tree Paths.py | 2,842 | 4.1875 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/2/26 16:16
# @Author : LI Dongdong
# @FileName: 257. Binary Tree Paths.py
''''''
'''
题目分析
1.要求:Given a binary tree, return all root-to-leaf paths.
Note: A leaf is a node with no children.
Example:
Input:
1
/ \
2 ... | true |
7fab504e2bf2fbdf95ba142fb630b38fb34b4ab4 | lidongdongbuaa/leetcode2.0 | /二分搜索/有明确的target/367. Valid Perfect Square.py | 2,926 | 4.34375 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/3/12 11:19
# @Author : LI Dongdong
# @FileName: 367. Valid Perfect Square.py
''''''
'''
题目分析
1.要求:Given a positive integer num, write a function which returns True if num is a perfect square else False.
Note: Do not use any built-in library function suc... | true |
c7c49fdd8806c4b5e06b0502cb892511d82cec67 | lidongdongbuaa/leetcode2.0 | /数据结构与算法基础/leetcode周赛/200301/How Many Numbers Are Smaller Than the Current Number.py | 1,974 | 4.125 | 4 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/3/1 11:32
# @Author : LI Dongdong
# @FileName: How Many Numbers Are Smaller Than the Current Number.py
''''''
'''
题目分析
1.要求:
2.理解:in a arr, count how many elem in this list < list[i], output
3.类型:array
4.确认输入输出及边界条件:
input: list, length? 2<= <= 500; valu... | true |
51a7a056f3efed50e627e4e07e0b63053e4f499e | masskro0/test_generator_drivebuild | /utils/plotter.py | 1,910 | 4.5625 | 5 | """This file offers several plotting methods to visualize functions or roads."""
import matplotlib.pyplot as plt
import numpy as np
def plotter(control_points):
"""Plots every point and lines between them. Used to visualize a road.
:param control_points: List of points as dict type.
:return: Void.
""... | true |
7265ea38cd157f595842c3ef9b309107ce72703a | FalseFelix/pythoncalc | /Mood.py | 381 | 4.1875 | 4 | operation=input("what mood are you in? ")
if operation=="happy":
print("It is great to see you happy!")
elif operation=="nervous":
print("Take a deep breath 3 times.")
elif operation=="sad":
print("kill yourself")
elif operation == "excited":
print("cool down")
elif operation == "relaxed":
print("dr... | true |
20b4b1e4590ec30986cd951656926c9777e9b35b | kingdayx/pythonTreehouse | /hello.py | 1,232 | 4.21875 | 4 | SERVICE_CHARGE = 2
TICKET_PRICE =10
tickets_remaining = 100
# create calculate_price function. It takes tickets and returns TICKET_PRICE * tickets
def calculate_price(number_of_tickets):
# add the service charge to our result
return TICKET_PRICE * number_of_tickets + SERVICE_CHARGE
while tickets_remaining:
... | true |
6bb6ae0cb5373c6619deda59adfbf5a33263419e | darshikasingh/tathastu_week_of_code | /day 3/program3.py | 271 | 4.34375 | 4 | def duplicate(string):
duplicateString = ""
for x in string:
if x not in duplicateString:
duplicateString += x
return duplicateString
string = input("ENTER THE STRING")
print("STRING AFTER REMOVING DUPLICATION IS", duplicate(string))
| true |
b15f207ad94ebec1fd8365a66a54563c1589e958 | vrashi/python-coding-practice | /upsidedowndigit.py | 228 | 4.25 | 4 | # to print the usside-down triangle of digits
row = int(input("Enter number of rows"))
a = row
for i in range(row+1, 0, -1):
for j in range(i+1, 2, -1):
print(a, end = " ")
a = a - 1
print()
a = row
| true |
394e5870361f046e78b91c28e4a0b9584e2cb158 | os-utep-master/python-intro-Jroman5 | /wordCount.py | 1,513 | 4.125 | 4 | import sys
import string
import re
import os
textInput =""
textOutput =""
def fileFinder():
global textInput
global textOutput
if len(sys.argv) is not 3:
print("Correct usage: wordCount.py <input text file> <output file>")
exit()
textInput = sys.argv[1]
textOutput = sys.argv[2]
if not os.path.exists(textInp... | true |
0008d5d1d0598ec37b494351fe76f7d0fd49011b | AdityanBaskaran/AdityanInterviewSolutions | /Python scripts/evenumbers.py | 371 | 4.125 | 4 | listlength = int(input('Enter the length of the list ... '))
numlist = []
for x in range(listlength):
number = int(input('Please enter a number: '))
numlist.append(number)
numlist.sort()
def is_even_num(l):
enum = []
for n in l:
if n % 2 == 0:
enum.append(n)
return enum
print (... | true |
4914e373050abc2fc202a357d4e8a82ee7bd87c7 | laurakressin/PythonProjects | /TheHardWay/ex20.py | 920 | 4.1875 | 4 | from sys import argv
script, input_file = argv
# reads off the lines in a file
def print_all(f):
print f.read()
# sets reference point to the beginning of the file
def rewind(f):
f.seek(0)
# prints the line number before reading out each line in the file
def print_a_line(line_count, f):
print line_count... | true |
c9f68086ab8f97bad4b3b1c1961a0216f655f14c | cscoder99/CS.Martin | /codenow9.py | 275 | 4.125 | 4 | import random
lang = ['Konichiwa', 'Hola', 'Bonjour']
user1 = raw_input("Say hello in English so the computer can say it back in a foreign langauge: ")
if (user1 == 'Hello') or (user1 == 'hello'):
print random.choice(lang)
else:
print "That is not hello in English" | true |
2052521302b0654c70fc5e7065f4a2cd6ff71fb1 | martinfoakes/word-counter-python | /wordcount/count__words.py | 1,035 | 4.21875 | 4 | #!/usr/bin/python
file = open('word_test.txt', 'r')
data = file.read()
file.close()
words = data.split(" ")
# Split the file contents by spaces, to get every word in it, then print
print('The words in this file are: ' + str(words))
num_words = len(words)
# Use the len() function to return the length of a list (words... | true |
fbc2c2b14924d71905b9ad9097f2e9d7c9e541fc | davidobrien1/Programming-and-Scripting-Exercises | /collatz.py | 1,533 | 4.78125 | 5 | # David O'Brien, 2018-02-09
# Collatz: https://en.wikipedia.org/wiki/Collatz_conjecture
# Exercise Description: In the video lectures we discussed the Collatz conjecture.
# Complete the exercise discussed in the Collatz conjecture video by writing a
# single Python script that starts with an integer and repeatedly a... | true |
d31bfb61f8e01688b186e6ccf860c12f8b1184de | j-kincaid/LC101-practice-files | /LC101Practice/Ch13_Practice/Ch13_fractions.py | 543 | 4.21875 | 4 | class Fraction:
""" An example of a class for creating fractions """
def __init__(self, top, bottom): # defining numerator and denominator
self.num = top
self.den = bottom
def __repr__(self):
return str(self.num) + "/" + str(self.den)
def get_numerator(self):
return... | true |
878934e0c30544f1b8c659ed41f789f20d9ac809 | j-kincaid/LC101-practice-files | /LC101Practice/Ch10_Practice/Ch10Assign.py | 1,008 | 4.15625 | 4 | def get_country_codes(prices):
# your code here
""" Return a string of country codes from a string of prices """
#_________________# 1. Break the string into a list.
prices = prices.split('$') # breaks the list into a list of elements.
#_________________# 2. Manipulate the individual element... | true |
01c29535868a34895b949fa842ba41393251e622 | j-kincaid/LC101-practice-files | /LC101Practice/Ch9_Practice/Ch_9_Str_Methods.py | 880 | 4.28125 | 4 | #___________________STRING METHODS
# Strings are objects and they have their own methods.
# Some methods are ord and chr.
# Two more:
ss = "Hello, Kitty"
print(ss + " Original string")
ss = ss.upper()
print(ss + " .upper")
tt = ss.lower()
print(tt + " .lower")
cap = ss.capitalize() # Capitalizes the first chara... | true |
c2570e4c6ef6f4d83565952d783fa681eed14981 | lunaxtasy/school_work | /primes/prime.py | 670 | 4.34375 | 4 | """
Assignment 3 - Prime Factors
prime.py -- Write the application code here
"""
def generate_prime_factors(unprime):
"""
This function will generate the prime factors of a provided integer
Hopefully
"""
if isinstance(unprime, int) is False:
raise ValueError
factors = []
#for c... | true |
b241bbd11590407332240b8254c911742e4382cc | TangMartin/CS50x-Introduction-to-Computer-Science | /PythonPractice/oddoreven.py | 264 | 4.28125 | 4 | number = -1
while(number <= 0):
number = int(input("Number: "))
if(number % 2 == 0 and number % 4 != 0):
print("Number is Even")
elif(number % 2 == 0 and number % 4 == 0):
print("Number is a multiple of four")
else:
print("Number is Odd")
| true |
36020e1b3eaa7ce3cfd732813f6f86b0948245e3 | Kartavya-verma/Competitive-Pratice | /Linked List/insert_new_node_between_2_nodes.py | 1,888 | 4.125 | 4 | class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def inserthead(self, newnode):
tempnode = self.head
self.head = newnode
self.head.next = tempnode
del tempnode
def li... | true |
34e7f7e3d1b5c3688c8091c12c360da3f4563c45 | PoojaKushwah1402/Python_Basics | /Sets/join.py | 1,642 | 4.8125 | 5 | # join Two Sets
# There are several ways to join two or more sets in Python.
# You can use the union() method that returns a new set containing all items from both sets,
# or the update() method that inserts all the items from one set into another:
# The union() method returns a new set with all items from both sets:
... | true |
52355dd175d820141ce23ace508c0c73501a74b0 | PoojaKushwah1402/Python_Basics | /variable.py | 809 | 4.34375 | 4 | price =10;#this value in the memory is going to convert into binary and then save it
price = 30
print(price,'price');
name = input('whats your name ?')
print('thats your name '+ name)
x, y, z = "Orange", "Banana", "Cherry" # Make sure the number of variables matches the number of values, or else you will get an error.... | true |
692f1ef93f6b188a9a3244d45c73239e18ded92c | PoojaKushwah1402/Python_Basics | /Sets/sets.py | 999 | 4.15625 | 4 | # Set is one of 4 built-in data types in Python used to store collections of data.
# A set is a collection which is both unordered and unindexed.
# Sets are written with curly brackets.
# Set items are unordered, unchangeable, and do not allow duplicate values.
# Set items can appear in a different order every time you... | true |
9df5a51bffcc602bc34b04de97ef2b65e1a7759f | PoojaKushwah1402/Python_Basics | /List/list.py | 1,906 | 4.4375 | 4 | #Unpack a Collection
# If you have a collection of values in a list, tuple etc. Python allows you extract the
#values into variables. This is called unpacking.
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x,'x')
print(y,'y')
print(z,'z')
# Lists are one of 4 built-in data types in Python used to sto... | true |
6811f8a6667506b20213934697e0b3207ace1520 | tskiranmayee/Python | /5. Set&Tuples&Dictionary/AccessingItems.py | 393 | 4.21875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue May 18 15:49:01 2021
@author: tskir
"""
""" Accessing Items in Dictionary """
dictEx={1:"a",2:"b",3:"c",4:"d"}
i=dictEx[1]
print("Value of the key 1 is: {}".format(i))
"""Another way of Accessing Items in Dictionary"""
j=dictEx.get(1)
print("Another way to get value for key... | true |
c2e88d79e03904bc41c849691d12962c9165c683 | Marlon-Poddalgoda/ICS3U-Assignment5-B-Python | /times_table.py | 1,287 | 4.1875 | 4 | #!/usr/bin/env python3
# Created by Marlon Poddalgoda
# Created on December 2020
# This program calculates the times table of a user input
import constants
def main():
# this function will calculate the times table of a user input
print("This program displays the multiplication table of a user input.")
... | true |
ad841fe2c7b77c9f500e9a1962d9460b3dfc0425 | sweetmentor/try-python | /.~c9_invoke_74p4L.py | 2,562 | 4.3125 | 4 | # print('Hello World')
# print('Welcome To Python')
# response = input("what's your name? ")
# print('Hello' + response)
#
# print('please enter two numbers')
# a = int(input('enter number 1:'))
# b = int(input('enter number 2:'))
# print(a + b)
# num1 = int(input("Enter First Number: "))
# num2 = int(input("Enter S... | true |
88a00a55774274724298e6641d778fc1ef0e77d7 | pavelgolikov/Python-Code | /Data_Structures/Linked_List_Circular.py | 1,978 | 4.15625 | 4 | """Circular Linked List."""
class _Node(object):
def __init__(self, item, next_=None):
self.item = item
self.next = next_
class CircularLinkedList:
"""
Circular collection of LinkedListNodes
=== Attributes ==
:param: back: the lastly appended node of this CircularLinkedList
... | true |
dbaa1a417e12832ee0865031534e3d04de7e6d04 | pavelgolikov/Python-Code | /Old/Guessing game.py | 808 | 4.15625 | 4 | import random
number = random.randint (1,20)
i=0
print ('I am thinking about a number between 1 and 20. Can you guess what it is?')
guess = int(input ()) #input is a string, need to convert it to int
while number != guess:
if number > guess:
i=i+1
print ('Your guess is too low. You used ... | true |
9d841232854343600926341d118f977d258536be | pavelgolikov/Python-Code | /Old/Dictionary practice.py | 1,576 | 4.1875 | 4 | """Some functions to practice with lists and dictionaries."""
def count_lists(list_):
"""Count the number of lists in a possibly nested list list_."""
if not isinstance(list_, list):
result = 0
else:
result = 1
for i in list_:
print(i)
result = re... | true |
3e43132819bc8bae1eb277d76ca981b9827fcde4 | enrique95ae/Python | /Project 01/test007.py | 391 | 4.1875 | 4 | monday_temperatures = [9.1, 8.8, 7.5, 6.6, 8.9]
##printing the number of items in the list
print(len(monday_temperatures))
##printing the item with index 3
print(monday_temperatures[3])
##printing the items between index 1 and 4
print(monday_temperatures[1:4])
##printing all the items after index 1
print(monday_tem... | true |
835bbc207ec0ffb49e6a0edcf82dc3aeb3b28504 | fbakalar/pythonTheHardWay | /exercises/ex26.py | 2,999 | 4.25 | 4 | #---------------------------------------------------------|
#
# Exercise 26
# Find and correct mistakes in someone else's
# code
#
# TODO: go back and review ex25
# compare to functions below
# make sure this can be run by importing ex25
#
#-----------------------------------------... | true |
1832a289dececef43f9f2e08eaf902bc5ced7016 | fbakalar/pythonTheHardWay | /exercises/ex22.py | 1,248 | 4.1875 | 4 | #####################################################
#
# Exercise 22 from Python The Hard Way
#
#
# C:\Users\berni\Documents\Source\pythonTheHardWay\exercises
#
#
# What do you know so far?
#
# TODO:
# add some write up for each of these
#
#####################################################
'''
thi... | true |
d8feb89430783948201453c395aa1d4a3c1ab9d2 | meet-projects/TEAMB1 | /test.py | 305 | 4.15625 | 4 |
words=["ssd","dsds","aaina","sasasdd"]
e_word = raw_input("search for a word in the list 'words': ")
check = False
for word in words:
if e_word in word or word in e_word:
if check==False:
check=True
print "Results: "
print " :" + word
if check==False:
print "Sorry, no results found."
| true |
63f15390b441813b85bfa8c35efa0a06db9be552 | lachlanpepperdene/CP1404_Practicals | /Prac02/asciiTable.py | 434 | 4.3125 | 4 | value = (input("Enter character: "))
print("The ASCII code for",value, "is",ord(value),)
number = int(input("Enter number between 33 and 127: "))
while number > 32 and number < 128:
print("The character for", number, "is", chr(number))
else:
print("Invalid Number")
# Enter a character:g
# The A... | true |
ecee3c7834b468cec5f437d173b91fc9665f63d1 | Git-Pierce/Week8 | /MovieList.py | 1,487 | 4.21875 | 4 | def display_menu():
print("MOVIE LIST MENU")
print("list - List all movies")
print("add - Add a movie")
print("del - Delete a movie")
print("exit - Exit program")
print()
def list(movie_list):
i = 1
for movie in movie_list:
print(str(i) + "- " + movie)
i += 1
print()... | true |
1d66b04c774e3346197d17c4ca559a4c5642f3e9 | green-fox-academy/Chiflado | /week-03/day-03/horizontal_lines.py | 528 | 4.40625 | 4 | from tkinter import *
root = Tk()
canvas = Canvas(root, width='300', height='300')
canvas.pack()
# create a line drawing function that takes 2 parameters:
# the x and y coordinates of the line's starting point
# and draws a 50 long horizontal line from that point.
# draw 3 lines with that function.
def drawing_hori... | true |
95908f7ea38b97f342408bbdeac0b56f276d74d5 | green-fox-academy/Chiflado | /week-02/day-02/matrix.py | 539 | 4.125 | 4 |
# - Create (dynamically) a two dimensional list
# with the following matrix. Use a loop!
#
# 1 0 0 0
# 0 1 0 0
# 0 0 1 0
# 0 0 0 1
#
# - Print this two dimensional list to the output
def matrix2d(x, y):
matrix = []
for i in range(x):
row = []
for j in range(y):
if i == j:... | true |
eccb62bc74d79af4e65142572fdb175ff1ca479d | green-fox-academy/Chiflado | /week-02/day-05/anagram.py | 395 | 4.21875 | 4 | first_string = input('Your first word: ')
sorted_first = sorted(first_string)
second_string = input('Aaaaand your second word: ')
sorted_second = sorted(second_string)
def anagram_finder(sorted_first, sorted_second):
if sorted_first == sorted_second:
return 'There are anagrams!'
else:
return 'T... | true |
6f52eeb81dedf18d2dc0b356e818818a953fcad5 | alessandraburckhalter/python-rpg-game | /rpg-1.py | 2,163 | 4.15625 | 4 | """In this simple RPG game, the hero fights the goblin. He has the options to:
1. fight goblin
2. do nothing - in which case the goblin will attack him anyway
3. flee"""
print("=-=" * 20)
print(" GAME TIME")
print("=-=" * 20)
print("\nRemember: YOU are the hero here.")
# create a main class to ... | true |
88561d8cc5a2b0a3778877fbf87a05d0a378d21d | gssasank/UdacityDS | /DataStructures/LinkedLists/maxSumSubArray.py | 805 | 4.25 | 4 | def max_sum_subarray(arr):
current_sum = arr[0] # `current_sum` denotes the sum of a subarray
max_sum = arr[0] # `max_sum` denotes the maximum value of `current_sum` ever
# Loop from VALUE at index position 1 till the end of the array
for element in arr[1:]:
'''
# ... | true |
562547cb28e651432ca6be189ebd212e0ba50d31 | gssasank/UdacityDS | /PythonBasics/conditionals/listComprehensions.py | 784 | 4.125 | 4 | squares = [x**2 for x in range(9)]
print(squares)
#if we wanna use an if statement
squares = [x**2 for x in range(9) if x % 2 == 0]
print(squares)
#if we wanna use an if..else statement, it goes in the middle
squares = [x**2 if x % 2 == 0 else x + 3 for x in range(9)]
print(squares)
# QUESTIONS BASED ON THE CONCEPT
... | true |
e6908a1fede2583910d752dec6b6af8ddf2a0460 | gssasank/UdacityDS | /PythonBasics/functions/scope.py | 483 | 4.1875 | 4 | egg_count = 0
def buy_eggs():
egg_count += 12 # purchase a dozen eggs
buy_eggs()
#In the last video, you saw that within a function, we can print a global variable's value successfully without an error.
# This worked because we were simply accessing the value of the variable.
# If we try to change or reassign ... | true |
188bd91cfa5302a8cc99c2f09e4aa376c35895b7 | gredenis/-MITx-6.00.1x-Introduction-to-Computer-Science-and-Programming-Using-Python | /ProblemSet1/Problem3.py | 1,187 | 4.25 | 4 | # Assume s is a string of lower case characters.
# Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example,
# if s = 'azcbobobegghakl', then your program should print
# Longest substring in alphabetical order is: beggh
# In the case of ties, print the first... | true |
ec72975409e3eda6707fcb67778244299c00431e | Rhotimie/ZSSN | /lib/util_sort.py | 1,361 | 4.125 | 4 | import itertools
def sort_tuple_list(tuple_list, pos, slice_from=None):
"""
Return a List of tuples
Example usage:
sort_tuple_list([('a', 1), ('b', 3), ('c', 2)])
:param status: list of tuples
:type status: List
:param list:
:param int:
:return: sorted list of tuples e.g [('a', ... | true |
b445be9fa502014837bbc795a20d74940eb7d72d | NotBobTheBuilder/conways-game-of-life | /conways.py | 2,242 | 4.125 | 4 | from itertools import product
from random import choice
def cells_3x3(row, col):
"""Set of the cells around (and including) the given one"""
return set(product(range(row-1, row+2), range(col-1, col+2)))
def neighbours(row, col):
"""Set of cells that directly border the given one"""
return cells_3x3(ro... | true |
2355ee5a02dcbc66d33649b618d1c57e356e9ada | jamj2000/Programming-Classes | /Math You Will Actually Use/Week6_Sympy.py | 725 | 4.3125 | 4 | ' "pip install sympy" before you do any of this '
import sympy # import the calculator with variable buttons :)
from sympy import Symbol
# -------------------------- first, solve the simple equation 2*x=2
x = Symbol('x') # create a "symoblic variable" x
equation = 2*x - 2 # define the equation 2*x = 2
solution =... | true |
0b6dae16fec055ad0eccb3d651b02f5643540e81 | jamj2000/Programming-Classes | /Intro To Python/semester1/Week10_Challenge0.py | 1,798 | 4.34375 | 4 | '''
This is a deep dive into FUNCTIONS
What is a function?
A function is a bunch of commands bundled into a group
How do you write a function?
Look below!
CHALLENGES: (in order of HEAT = difficulty)
Siberian Winter: Change the link of the Philly function
Canada in Spring: Make the link an inp... | true |
ad291e7fa25471945efc95465a4589cd89a44e7a | mihir-liverpool/RockPaperScissor | /rockpaperscissor.py | 841 | 4.125 | 4 | import random
while True:
moves = ['rock', 'paper', 'scissor']
player_wins = ['paperrock', 'scissorpaper', 'rockscissor']
player_move = input('please choose between rock paper or scissor: ')
computer_move = random.choice(moves)
if player_move not in moves:
print('please choose an option betw... | true |
1dbd6a073c1fbdae4bdc435d7a678e49e8709ab3 | sombra721/Python-Exercises | /Regular Expression_ex.py | 1,503 | 4.125 | 4 | '''
The script will detect if the regular expression pattern is contained in the files in the directory and it's sub-directory.
Suppose the directory structure is shown as below:
test
|---sub1
| |---1.txt (contains)
| |---2.txt (does not contain)
| |---3.txt (contains)
|---sub2
| |... | true |
8ae7109db20182e8e0367a39c03fa9e4dd04dba5 | ryanthemanr0x/Python | /Giraffe/Lists.py | 561 | 4.25 | 4 | # Working with lists
# Lists can include integers and boolean
# friends = ["Kevin", 2, False]
friends = ["Kevin", "Karen", "Jim"]
print(friends)
# Using index
friends = ["Kevin", "Karen", "Jim"]
# 0 1/-2 2/-1
print(friends[0])
print(friends[2])
print(friends[-1])
print(friends[-2])
print(fri... | true |
6b82f94e0a3149bcb55199f4d3d3d860732aa475 | ryanthemanr0x/Python | /Giraffe/if_statements.py | 631 | 4.40625 | 4 | # If Statements
is_male = False
is_tall = False
if is_male or is_tall:
print("You are a male or tall or both")
else:
print("You are neither male nor tall")
is_male1 = True
is_tall1 = True
if is_male1 and is_tall1:
print("You are a tall male")
else:
print("You are either not male or tall or both")
i... | true |
9e0a944f2100cab01f4e4cad3921c8786998681b | ikramsalim/DataCamp | /02-intermediate-python/4-loops/loop-over-lists-of-lists.py | 446 | 4.25 | 4 | """Write a for loop that goes through each sublist of house and prints out the x is y sqm, where x is the name of the room
and y is the area of the room."""
# house list of lists
house = [["hallway", 11.25],
["kitchen", 18.0],
["living room", 20.0],
["bedroom", 10.75],
["bathroom", ... | true |
dcf1b439aa3db2947653f9197e961d4969f92095 | ycayir/python-for-everybody | /course2/week5/ex_09_05.py | 782 | 4.25 | 4 | # Exercise 5: This program records the domain name (instead of the
# address) where the message was sent from instead of who the mail came
# from (i.e., the whole email address). At the end of the program, print
# out the contents of your dictionary.
# python schoolcount.py
#
# Enter a file name: mbox-short.txt
# {'med... | true |
c3c1bf04376f728f6470a055e56c878ceec2d3b3 | mjdall/leet | /spiral_matrix.py | 2,106 | 4.1875 | 4 | def spiral_order(self, matrix):
"""
Returns the spiral order of the input matrix.
I.e. [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
becomes [1, 2, 3, 6, 9, 8, 7, 4, 5].
:type matrix: List[List[int]]
:rtype: List[int]
"""
if not matrix or matrix is None:
return ... | true |
3dd6609f9805f7c8bbf9949b56584a2c044475a3 | mjdall/leet | /count_elements.py | 668 | 4.28125 | 4 | def count_elements(arr):
"""
Given an integer array arr, count element x such that x + 1 is also in arr.
If there're duplicates in arr, count them seperately.
:type arr: List[int]
:rtype: int
"""
if arr is None or len(arr) == 0:
return 0
... | true |
334da6ffae18a403cc33ae03c1600238a6a45ddd | denemorhun/Python-Problems | /Hackerrank/Strings/MatchParanthesis-easy.py | 1,891 | 4.40625 | 4 | # Python3 code to Check for balanced parentheses in an expression
# EASY
'''
Given a string containing just the characters '(', ')', '{', '}', '[' and ']',
determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in... | true |
bb708c316a2f7041f23c61036ff825153ad424a2 | denemorhun/Python-Problems | /Grokking the Python Interview/Data Structures/Stacks and Queues/q_using_stack.py | 1,149 | 4.21875 | 4 | from typing import Deque
from stack import MyStack
# Push Function => stack.push(int) //Inserts the element at top
# Pop Function => stack.pop() //Removes and returns the element at top
# Top/Peek Function => stack.get_top() //Returns top element
# Helper Functions => stack.is_empty() & stack.isFull() //returns... | true |
a34383ee463d3c9749caf0e52c10e3e114fe02a7 | denemorhun/Python-Problems | /AlgoExperts/LinkedList/remove_duplicates_from_linked_list.py | 1,693 | 4.15625 | 4 | '''
A Node object has an integer data field, , and a Node instance pointer, , pointing to
another node (i.e.: the next node in a list).
A removeDuplicates function is declared in your editor, which takes a pointer to the
node of a linked list as a parameter. Complete removeDuplicates so that it deletes
any duplic... | true |
07bab891b92ca248e39056da104d2a9afdff953c | denemorhun/Python-Problems | /Hackerrank/Arrays/validate_pattern.py | 1,708 | 4.34375 | 4 | '''Validate Pattern from array 1 to array b
Given a string sequence of words and a string sequence pattern, return true if the sequence of words matches the pattern otherwise false.
Definition of match: A word that is substituted for a variable must always follow that substitution. For example, if "f" is substituted ... | true |
7ff5903c490ef8c34099db9252ec42918f2e850b | tcano2003/ucsc-python-for-programmers | /code/lab_03_Functions/lab03_5(3)_TC.py | 1,028 | 4.46875 | 4 | #!/usr/bin/env python3
"""This is a function that returns heads or tails like the flip of a coin"""
import random
def FlipCoin():
if random.randrange(0, 2) == 0:
return ("tails")
return ("heads")
def GetHeads(target):
"""Flips coins until it gets target heads in a row."""
heads = count = ... | true |
3b1315a4ffacc91f29a75daa3993a1cb2aab4133 | tcano2003/ucsc-python-for-programmers | /code/lab_03_Functions/lab03_6(3).py | 2,442 | 4.46875 | 4 | #!/usr/bin/env python3
"""Introspect the random module, and particularly the randrange()
function it provides. Use this module to write a "Flashcard"
function. Your function should ask the user:
What is 9 times 3
where 9 and 3 are any numbers from 0 to 12, randomly chosen.
If the user gets the answer right, your f... | true |
008fa26d54dc77f783b3b60f5e2f85c83535a3fd | tcano2003/ucsc-python-for-programmers | /code/lab_14_Magic/circle_defpy3.py | 1,823 | 4.1875 | 4 | #!/usr/bin/env python3
"""A Circle class, acheived by overriding __getitem__
which provides the behavior for indexing, i.e., [].
This also provides the correct cyclical behavior whenever
an iterator is used, i.e., for, enumerate() and sorted().
reversed() needs __reversed__ defined.
"""
#need to have def __getitem__(<... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.