blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
f17a75008eec374d65910efd49a1b74dc56df089 | danahagist/self_taught_programmer | /chap6_challenge.py | 2,252 | 4.3125 | 4 | # 1. Print every charater in the string 'Camus.'
for i in 'Camus':
print(i)
# 2. Write a program that collects two strings from a user,
# inserts them into the string
# 'Yesterday I wrote a [response_one]. I sent it to [response_two]!"
#response_one = input("What did you write?")
#response_two = input("Who d... | true |
55833c5f34370c541b63de42ef21a1b3d053515b | danahagist/self_taught_programmer | /chap11_challenge.py | 1,125 | 4.25 | 4 | # Chapter 11 Challenges
# 1. add a square_list calss variable to a class called Square so that every time you create
# a new Square object, the new object gets added to the list
class Square:
sq_list = []
def __init__(self,s):
self.side = s
self.sq_list.append(self.side)
sq1 = Square(4)
sq2 = ... | true |
12e873ca5c5b7ebecee4697f8dcf967fc47d1c19 | danahagist/self_taught_programmer | /chap13_challenge.py | 2,272 | 4.375 | 4 | # Chapter 13 Challenges
# 1. Create Rectangle and Square classes with a method called calculate_perimeter
# that calculates the perimeter of the shapes they represent.
# Create Rectangle and Square objects and call the method on both of them
class Rectangle:
def __init__(self,l,w):
self.length = l
... | true |
ea34cbbc1b97f0586ffa176dff9964b09f503581 | brandonhumphries/week-1-python-exercises | /n_to_m.py | 510 | 4.25 | 4 | starting_number = int(raw_input('Start from: '))
ending_number = int(raw_input('End on: '))
current_number = 0
while starting_number > ending_number:
print 'Please enter a number for "End on" that is less than the number for "Start from".'
starting_number = int(raw_input('Start from: '))
ending_number = in... | true |
ac00101ce4b3fb4084919631a615f899898bd9cb | camelk/python3test | /ex4-22.py | 403 | 4.3125 | 4 | #-*- coding: UTF-8 -*-
import math
x1, y1 = eval(input("Enter any point(x,y)(ex. x, y): "))
print("the point", x1, ",", y1)
# define the circle(x0, y0, radius)
x0 = 0
y0 = 0
radius = 10
length = math.sqrt((x0-x1)**2+(y0-y1)**2)
print("length", format(length, ".2f"))
if radius >= length:
print("the point is with... | true |
ffece2e2a99ac22cc1bdb3267e96369b45807873 | jblairkiel/UA-CS-150 | /Practice/functions/functions.py | 738 | 4.125 | 4 | def main():
x = float(input("Enter the first value:"))
y = float(input("Enter the second value:"))
op = input("Enter an operation (+, -, *, %, /): ")
if (op == '+'):
print("The answer is %.2" % addition(x,y))
elif (op == '-'):
print("The answer is", subtraction(x,y))
elif (op =... | true |
462d6b698cdc133ec3e3b0d995c19e3ae4c1d82e | mdimranansari/Python | /DateAndTime.py | 1,515 | 4.46875 | 4 | # to use Python functionality for Date and time, use import statements
# predefined classes to imported as follows
from datetime import date
from datetime import time
from datetime import datetime
class DateAndTime():
print("**Date and Time Class**")
def method1(self):
today=date.today()
p... | true |
c72a456a1488036122be55c5c513ea8371074a6f | mdimranansari/Python | /PrintLines.py | 552 | 4.125 | 4 | '''
Created on Nov 9, 2018
@author: mohammadimran
'''
#===================================================================
print('''my name is imran first line
This is second Line''')
# To Print in multiple lines ===================================================================
print("""my name is imran fir... | true |
79744e7008aec86914d58987932a0daa84dd0cb6 | Edacv2/hello-word | /code/multiplication_table.py | 558 | 4.21875 | 4 | while True:
"""This will create a mutiplication table starting with the given number + 10
until user enter stop"""
print("\nMultiplication Table\n")
num_r = input("Enter number or type \"stop\" to quit: ")
if num_r == "stop":
break
else:
print()
for num1 in r... | true |
ae567d98710fced6bf59b235e59ff4e7df6d9e62 | vincentchen1/python-quiz | /python quiz/quiz_step1.py | 663 | 4.1875 | 4 | import random
def random_key():
# find all the keys, 'keys' now in a SET data structure
keys = words.keys()
# convert 'keys' to LIST
keys = list(keys)
# randomly select a key from 'keys'
random_key = random.choice(keys)
return random_key
words = {
"red" : "rojo",
"blue... | true |
cd5005f68edfee692eae50ba5c0cdce414f1eefb | JobHoekstra/Afvinkopdracht-3 | /Python HS3 opdr 2.py | 621 | 4.3125 | 4 | length1 = float(input("What length does rectangle 1 have? "))
width1 = float(input("What width does rectangle 1 have? "))
length2 = float(input("What length does rectangle 2 have? "))
width2 = float(input("What width does rectangle 2 have? "))
area_rectangle1 = length1 * width1
area_rectangle2 = length2 * width2... | true |
7cb548fcdf25d5ab59bf5a6c3623a44b6ce4eaf6 | emilywitt/HW04 | /HW04_ex00.py | 1,872 | 4.28125 | 4 | #!/usr/bin/env python
# HW04_ex00
# Create a program that does the following:
# - creates a random integer from 1 - 25
# - asks the user to guess what the number is
# - validates input is a number
# - tells the user if they guess correctly
# - if not: tells them too high/low
# - only lets t... | true |
d7bddbe6439afe518d2a2c7e47ae341a2ae2729c | miaviles/Core-Python-From-Basics-to-Advanced | /Files/Statements/conditionalStatements.py | 655 | 4.34375 | 4 |
# simple if
name = input("Enter any language: ")
if name =="python":
print("You are learning python programming")
# if-else
name = input("enter any language: ")
if name =="python":
print("You are learning python programming")
else:
print("You are learning other programming language")
# if-elif-elif...els... | true |
ff5534427250b2cfe51a3b3677ad0a007789e547 | miaviles/Core-Python-From-Basics-to-Advanced | /Files/User Defined - Function/function.py | 683 | 4.25 | 4 | # convert tuple to list and change some elements to the list then convert back to tuple.
# This is because, tuple are immutable
tuple_nums = (10, 20, 30)
print("Old tuple =", tuple_nums)
list_nums = list(tuple_nums)
list_nums[0] = 1000
tuple_number = tuple(list_nums)
print("New tuple =", tuple_number)
# print range of... | true |
fa4ac13e544acac7abd798e67c4f574e46e18ec0 | rafidka/samples | /FullTextSearch/CreatingInvertedIndex/main.py | 1,998 | 4.15625 | 4 | import os
import sys
if sys.version_info < (3, 0):
input = raw_input
docs = []
prompt = 'Add a text document to index. When you are done with all documents, type "exit": '
while True:
doc = input(prompt)
if doc.lower() == 'exit':
break
docs.append(doc)
print(os.linesep)
print("Indexing the documents." + ... | true |
d96c83ee3b3459a504a9ae0110a366840bc52efa | Maksym-Gorbunov/python1 | /conditionals.py | 1,345 | 4.3125 | 4 | # CONDITIONALS
'''
x = 7
# Basic If
if x < 6:
print('This is true')
# If Else
if x < 6:
print('This is true')
else:
print('This is false')
# Elif
color = 'red'
if color == 'red':
print('Color is red')
elif color == 'blue':
print('Color is blue')
else:
print('Color is not red or blue')
... | true |
c073314030798d98dbe49460a3a9b27675fe72df | asarver/CSSI | /Strings/rotate.py | 783 | 4.125 | 4 | # return a string where each letter in original
# is shifted by a certain amount of places
#
def rotate_word(original, shift):
rot = ""
for c in original:
rot += rotate_letter(c, shift)
return rot
def rotate_letter(letter, shift):
decimal = ord(letter)
shifted = dec... | true |
cb4c81aae45bea2a6ee4f8e62ea9d74608465626 | MKerbleski/Intro-Python | /src/day-1-toy/fileio.py | 402 | 4.15625 | 4 | # Use open to open file "foo.txt" for reading
foo = open('foo.txt', 'r')
# Print all the lines in the file
lines = foo.read()
print(lines)
# Close the file
foo.close()
# Use open to open file "bar.txt" for writing
bar = open('bar.txt', 'w+')
# Use the write() method to write three lines to the file
bar.write('line uno... | true |
fd8a12fd5546327bc3591b05ac86e09b8d79ceb9 | d3athwarrior/LearningPython | /Loops.py | 1,123 | 4.34375 | 4 | secret = "fish"
password = ""
authorized = False
count = 0
max_Count = 5
while password != secret:
password = input("What's the password?")
else:
# The else block in case of a loop, be it for loop or while loop will always be executed with exception of the case when 'break' is used to come out of the loop
... | true |
74b801bd8ebb148b3fecce2eeb01b7c8182205d9 | d3athwarrior/LearningPython | /BooleanValuesAndOperators.py | 1,983 | 4.5 | 4 | # Python understands truthy values and falsy values instead of explicitly evaluating true and false only
random_dict = {'a': 1}
empty_dictionary = {}
empty_string = ''
if random_dict:
print("random_dict evaluated to true")
else:
print("random_dict evaluated to false")
if empty_string:
print('Empty string ... | true |
d3f25187b8b50755b8f3246883592074af02b381 | Arvind6353/python-basics-json-geocoding | /data-structures/set.py | 817 | 4.46875 | 4 | # allow only unique elements
# keyword set
set1 = set(['one', 'two', 'three', 'two'])
print('set1 -',set1)
set2 = set(['four', 'two'])
print('set2 -', set2)
# set operations
#add
set1.add('five')
print('after adding "five" to the set1 -', set1)
print('set2 -', set2)
#union
print('union of set1 and set2 -',s... | true |
2914428193f44c1c3c0ebb172f209e677fe3b5c4 | schlangens/learningPython | /splitting_and_joining.py | 407 | 4.34375 | 4 | # Iterable means can be looped through
# Split method by default breaks on white space
print('hello there students'.split())
# outputs 3 items into a list ['hello' , 'there' , 'students']
# we can tell it what to break on
print("red:blue:green".split(':'))
flavors = ['chocolate', 'mint', 'strawberry']
print("My ... | true |
bf5c502f78ceefd8b633b16cd23ac652c6cd478f | AlexGascon/Advent-of-Code | /2017/Day_4/part_2.py | 2,577 | 4.1875 | 4 | """--- Part Two ---
For added security, yet another system policy has been put in place. Now, a
valid passphrase must contain no two words that are anagrams of each other -
that is, a passphrase is invalid if any word's letters can be rearranged to
form any other word in the passphrase.
For example:
abcde fghij ... | true |
f78a0cc46b8b86eabf74c3bdeb3976488cc3194d | AlexGascon/Advent-of-Code | /2017/Day_2/part_1.py | 2,330 | 4.40625 | 4 | """
--- Day 2: Corruption Checksum ---
As you walk through the door, a glowing humanoid shape yells in your direction.
"You there! Your state appears to be idle. Come help us repair the corruption
in this spreadsheet - if we take another millisecond, we'll have to display an
hourglass cursor!"
The spreadsheet consist... | true |
2dace78d7153af1caf75eba791f74e133c6806a9 | Akhil-Suresh/pylearn | /topics/classMethod.py | 1,356 | 4.34375 | 4 | # Class Method
# ============
# A class method is a method that is bound to a class rather than its object. It doesn't require creation of a class instance, much like staticmethod.
# The difference between a static method and a class method is:
# - Static method knows nothing about the class and just deals ... | true |
0d955d2aed5acf2b145db03804049ea1b1fabf42 | xudaaaaan/Leetcode | /dan/Problems/Hard/LinkedList/23. Merge k Sorted Lists/solution.py | 1,302 | 4.125 | 4 | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
from Queue import PriorityQueue
class Solution(object):
#Time complexity: O(kN) where k is #of linkedlist and N is #of node.
def mergeKLists1(self, lists):
"""
... | true |
231187b3b104cd46493800bfa98a436688b94241 | aniaskudlarska/adventOfCode | /day3/day3.py | 1,743 | 4.375 | 4 | #Day 3
#Given a large list representing a map, where . represents empty space and # represents a tree
#each line has a pattern that repeats, and is 31 units long
#Traverse the map by moving RIGHT three spaces DOWN one space
#Map propagates infinitely in the X direction
#Objective 1: Count the number of trees encounter... | true |
9d5e1da037f67a05c8b64ab13df0678f82c2ccba | eugene01a/algorithms-practice | /problems/reverse_int.py | 1,297 | 4.1875 | 4 | '''
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the p... | true |
7d551270479f025f81a74b1fccdd890e72b3f837 | eugene01a/algorithms-practice | /problems/climbing_stairs.py | 1,293 | 4.15625 | 4 | from unittest import TestCase
import ddt
'''
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
Example 1:
Input: 2
Output: 2
Explanation: There are two ways... | true |
111616c1f50983eb300220b61e5c0574c5eb3466 | eugene01a/algorithms-practice | /problems/strstr.py | 1,521 | 4.1875 | 4 | from unittest import TestCase
import ddt
'''
Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1:
Input: haystack = "hello", needle = "ll"
Output: 2
Example 2:
Input: haystack = "aaaaa", needle = "bba"
Output: -1
Clarification:
Wh... | true |
5ee612c54c0336fce37ff51aa8f40a2350ff464f | fatalhalt/PythonPractice | /datatypes.py | 1,119 | 4.1875 | 4 | #!/usr/bin/env python
# below snippet demonstrates list datatype in python (akin to arrays)
# lists are ordered, mutable, hold arbitrary objects, expand dynamically
l = [21, 'foo', 13, True, 21, [0, 1.0]]
l.append({'ipv4': '8.8.8.8'})
l.extend(['12', '33'])
l.insert(0, '1st')
# len is 10, the list or dict count as 1 e... | true |
2b28d5c679d60ca6eb1eaa437078904d6b3dd367 | vishal-chillal/assignments | /new_tasks_23_june/46_solutions/17_modified_palindrome.py | 962 | 4.125 | 4 | #Write a version of a palindrome recognizer that also accepts phrase palindromes such as "Go hang a salami I'm a lasagna hog.", "Was it a rat I saw?", "Step on no pets", "Sit on a potato pan, Otis", "Lisa Bonet ate no basil", "Satan, oscillate my metallic sonatas", "I roamed under it as a tired nude Maori", "Rise to vo... | true |
d7cb9b3a841ee5afb8020372886f1e17f13e35e4 | Behroz-Arshad/Assignment | /Question no 1.py | 380 | 4.125 | 4 | #Question no 1
'''
Define a function max() that takes two numbers as arguments and
returns the largest of them.
Use the if-then-else construct available in Python.
(It is true that Python has the max()
function built in, but writing it yourself is nevertheless a good exercise ).
'''
#code
def max(num1,num2):
if n... | true |
07674a5c64bcb8a55d89165777ffefb89af393d9 | Behroz-Arshad/Assignment | /question no 9.py | 694 | 4.125 | 4 | #Question no 9
'''
Write a function is_member()
that takes a value ( i.e. a number, string, etc ) x and a list of values a,
and returns True if x is a member of a, False otherwise.
(Note that this is exactly what the in operator does, but for the sake of the
exercise you should pretend
Python did not have this o... | true |
cc7cb3ade4f24f00403711eea7f51794a6668ea4 | WajeehaJ/python_exercises | /ex_12.4.py | 906 | 4.28125 | 4 | """
Write a program that reads a word list from a file (see Section 9.1) and prints all the sets of words that are anagrams.
"""
def read_file(filename):
""" Return the contents of a file as a sring """
return open(filename).read()
def print_anagram_wordlist(word_list):
"""
Print all the anagram words... | true |
a2c10b00fabc0811fbd512091905790172c8f5d6 | KotatuBot/Pbit | /Pbit/pbit_negative.py | 1,587 | 4.375 | 4 | class Pbit_Negative():
"""
負の数に関する関数
"""
def __init__(self):
pass
def negative_number(self,plus_number):
"""
Function returning negative number
Args:
plus_number: Plus number
Return:
negative_numbers: negative number
... | true |
122fb4cdcc1861fe03d5740aedad1847ad149dc8 | yangyuxiang1996/leetcode | /out/production/leetcode/232.用栈实现队列.py | 1,492 | 4.125 | 4 | #
# @lc app=leetcode.cn id=232 lang=python
#
# [232] 用栈实现队列
#
# @lc code=start
class MyQueue(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.listA = []
self.listB = []
self.size = 0
def push(self, x):
"""
Push ele... | true |
6e4d5807c3ca9d49a3884c92efb97f5ebd463c68 | Anezeres/AprendizajeConPython | /Curso Introductorio/How+to+create+a+Function+in+Python.py | 1,263 | 4.21875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[10]:
def rectangle_area(width, length):
area = width * length
return area
rectangle_area(6, 9)
# In[9]:
rectangle_area(4, 15)
# In[4]:
def is_even(x):
if x % 2 == 0:
return True
else:
return False
# In[5]:
is... | true |
409988a6895183e8a636745cba558c671399913b | Anezeres/AprendizajeConPython | /Curso Introductorio/lower+and+upper+function+in+Python.py | 569 | 4.21875 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
print('This is User Car'.lower())
# In[2]:
print('This is User Car'.upper ())
# In[ ]:
#write a program in python contain a string
# message for an electrical instructional sign
# in the street warning the cars drivers that
# they don't to turn left.
#then ch... | true |
9880aaa12c57da01f5dfd2613605e80bdc86b15c | Urvashi-91/Urvashi_Git_Repo | /Interview/Rubrik/arrayPick.py | 1,153 | 4.25 | 4 | '''
You are given 2 array with non-repeating numbers
Pick any number from array1
You can place the number at the start or end of the array2
Find the min operations required to convert second array to first one.
Can someone suggest ways to do it.
array 1 = 4,2,3,5,1,6
array 2 = 3,6,5,4,1,2
now we need to find the min... | true |
347b9852bb95d7f2f677e24179f44fc17138e491 | Urvashi-91/Urvashi_Git_Repo | /Interview/Amazon/monthsProgram.py | 905 | 4.4375 | 4 | '''
Write the number of days in months program so that the program prompts the user for the file name and reads the dates from the file.
The dates in the file are written in the format dd.mm.yyyy. The program looks for the month in each line (hint: use split) and prints out the number of days in that month.
Rewrite t... | true |
726eaa16b9528b54206642dd73ae0d7f3c6fcba9 | Urvashi-91/Urvashi_Git_Repo | /Interview/Stripe/flatten_nested_dictionary.py | 978 | 4.3125 | 4 | '''
Write a function to flatten a nested dictionary. Namespace the keys with a period.
For example, given the following dictionary:
{
"key": 3,
"foo": {
"a": 5,
"bar": {
"baz": 8
}
}
}
it should become:
{
"key": 3,
"foo.a": 5,
"foo.bar.baz": 8
}
You can ass... | true |
b21a8ac34f7eca14b815bde3cb69208f3ca03964 | YakutovDmitriy/bio-python-course-2018 | /task8/materials/StackSingle.py | 716 | 4.25 | 4 |
class StackSingle:
""" Stack: Module implementation """
elements = []
@staticmethod
def push(elem):
""" Pushes 'elem' to stack """
StackSingle.elements.append(elem)
@staticmethod
def pop():
""" Removes head of stack and returns it """
elem = StackSingle.elemen... | true |
198062df64779f1544b65a0c53e880ac4e8e6091 | JARVVVIS/ds_algo_practice | /recursion/nth_tribonacci.py | 547 | 4.25 | 4 | # The Tribonacci sequence Tn is defined as follows:
# T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
# Given n, return the value of Tn.
def trib(num,vals):
if num in vals.keys():
return vals[num]
else:
m = num-3
ans = trib(m,vals)+trib(m+1,vals)+trib(m+2,vals)
... | true |
dbfcbf4ac89757c0d464878e1505674e3ee694b7 | CalvQ/Algorithms | /solutions/Power.py | 630 | 4.34375 | 4 | '''
Problem: Power Function
Statement: Write a Power Function that is O(log n)
Example:
pow(5,3)
-> 125
Note: A normal, simple power function is O(n), where
it simply loops n times, multiplying each loop
Assume power is non-negative
'''
... | true |
135d7d191af69971736e438a051a6266261ff0c6 | Alaarg/Python_Exercises | /Examples/day-5-examples.py | 2,333 | 4.25 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Nov 25 09:54:37 2019
@author: Ahmad ALaarg
"""
"""
class Person:
def say_hello(self):
print('Hello')
p = Person()
p.say_hello()
# -----------------------------
class Vehicle:
def __init__(self, name, color):
self.__name = name # __name is privat... | true |
812f00a5f48dfdb8564d2aad429d13e9a0970752 | Eblazecode/Algopy | /functions.py | 2,016 | 4.3125 | 4 | # infinite monkey theorem
"""
The theorem states that a monkey hitting keys
at random on a typewriter keyboard for an
infinite amount of time will almost surely type a
given text, such as the complete works
of William Shakespeare
Well, suppose we replace a monkey with a Python function.
How long do you think... | true |
324feb6c30f252e92b1a8028b0834068ab9aaee3 | ravi4all/PythonJune_Morning | /08-UserDefinedModules/main_calc.py | 999 | 4.21875 | 4 | # import calculator
from modules import calculator
num_1 = int(input("Enter first number : "))
num_2 = int(input("Enter second number : "))
addition = calculator.add(num_1,num_2)
subtraction = calculator.sub(num_1,num_2)
division = calculator.div(num_1,num_2)
multiply = calculator.mul(num_1,num_2)
# print("... | true |
9dac8d2c8df1b7bfb1bbbf90fe0102c05b50de88 | adityababar07/class12 | /python/code_4.py | 317 | 4.28125 | 4 | # write a program to find the area of a regular polygon.
from math import tan, pi
no_sides = int(input("enter the number of sides in your regular polygon :\t"))
length = int(input("enter the length of a side:\t"))
a = (length**2)*no_sides/(4 * tan(pi/no_sides))
print(f"the area of the regular polygon is {a} ")
| true |
e4e2fbcc82f697dfd6cc0aa7be5a29f5a65533ff | coingraham/codefights | /python/isDigit/isDigit.py | 514 | 4.28125 | 4 | """
Determine if the given character is a digit or not.
Example
For symbol = '0', the output should be
isDigit(symbol) = true;
For symbol = '-', the output should be
isDigit(symbol) = false.
Input/Output
[time limit] 4000ms (py)
[input] char symbol
A character which is either a digit or not.
[output] boolean
true... | true |
eb304048fbf707704e37ad426f2d7b211b04c6e3 | coingraham/codefights | /python/differentSquares/differentSquares.py | 1,164 | 4.125 | 4 | """
Given a rectangular matrix containing only digits, calculate the number of different 2 x 2 squares in it.
Example
For
matrix = [[1, 2, 1],
[2, 2, 2],
[2, 2, 2],
[1, 2, 3],
[2, 2, 1]]
the output should be
differentSquares(matrix) = 6.
Here are all 6 different 2 x 2 squares... | true |
69291455f012a59761d86759cc770146e5a843d2 | coingraham/codefights | /python/lineEncoding/lineEncoding.py | 1,351 | 4.15625 | 4 | """
Given a string, return its encoding defined as follows:
First, the string is divided into the least possible number of disjoint substrings consisting of identical characters
for example, "aabbbc" is divided into ["aa", "bbb", "c"]
Next, each substring with length greater than one is replaced with a concatenation o... | true |
dd704af1a01c75201ff7cac0a3bcb50a97a7e049 | Mananjot/Internship-at-Sabudh-2020 | /weekly-assignments/PythonAssessmentTest/q1(Swap Alternate).py | 1,300 | 4.28125 | 4 | """
Question1: Swap Alternate
You have been given an array/list of size N. You need to swap every pair of alternate elements in the array/list. You have to change the input array itself and print the result
Input Format:
First line of each test case or query contains an integer 'N' representing the size of the array... | true |
ce2b920bfbca1df915912736417a71c7df68ed2d | mb85/Python-2015 | /2015-08-07/solutions/exercise_10.py | 653 | 4.1875 | 4 | #!/usr/bin/env python3
# coding: utf-8
import random
types = {"r": "Rock", "p": "Paper", "s": "Scissors"}
computer = random.choice(("r", "p", "s"))
while True:
user = input("Please enter a choice from 'r', 'p' or 's': ").lower()
if user not in ("r", "p", "s"):
print("Invalid choice! Please choose 'r'... | true |
b33cd720d94c9d09006a09f595b55fefb20201c3 | mb85/Python-2015 | /2015-08-07/solutions/exercise_08.py | 403 | 4.21875 | 4 | #!/usr/bin/env python3
# coding: utf-8
import math
def get_height(distance, angle, height):
return (math.tan(angle) * distance) + height
d = float(input("How far are you from the base of the tree? "))
a = float(input("What angle is the top of the tree from your eyes? "))
h = float(input("How tall are you? "))
... | true |
4485449698a2df6c65ec76da8796b5cbf15cbc85 | SGrafik/python-fun-box | /compressString.py | 479 | 4.25 | 4 | def compress(string):
"""
return the string in chr-number of chr format if it's shorter than the original string.
e.g. "helloooo" will become "h1e1l2o4", but "helo" is stil "helo"
"""
result = ""
i = 0
strLen = len(string)
while i < (strLen-1):
count = 1
while string[i] == string[i+1]:
count += 1
i ... | true |
7c8a854c1077c5a0d33d0126cb4d2c5f75daaaef | dcastro2021/BasicChallenges2021 | /Codechallenge#2_Cargo.py | 637 | 4.21875 | 4 | #Here is a solution to the Code Challenge#2
print ("Identifying Incoming Cargo Services")
alist = ["International", "Domestic", "Over the Road", "LTL", "Reefers"]
if "International" in alist:
print("True")
for elem in alist:
if "Int" in elem:
print(elem)
#Here is our function
def Test_If_Substring... | true |
9928f6a1779e489abd5728afb0f2f2f535ff97ea | wellingi/arena-fighter | /old-arena/artobjects.py | 1,410 | 4.15625 | 4 | #!usr/bin/env
#The purpose of the program is to examine object-oriented programming and its features, like classes.
class SVG:
def __init__(self):
Name="woeijf"
# HAVE A WRITE FILE
def createfile(self, filename):
svgfile = open(filename, "w")
svgfile.write("<svg xmlns=\"http://www.w3.org/2000/svg\" version=... | true |
dd1002cb842b898297204057d59a5a588071f062 | linbearababy/python-learning | /python projects/project 001/proj001.py | 1,116 | 4.4375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 2018
@author: linbearbaby
#############
#computer project 01
#Algorithm
# Input a number
# translate it to float
# convet its unit by math
# print them
##########
num_1=input("Input rods: ") #input a number as your distance
n=float(num_1)#tran... | true |
8f63f1edf04536a20e0a7b2bb83d70f7fad3f099 | imcallister/theo | /exercises/letters in name.py | 311 | 4.25 | 4 | # write a program to ask user for his name and then
# tell him if the letter T is in his name
player_name = input ("what's you're name?")
print ("hello", player_name)
if 't' in player_name or 'T' in player_name:
print("there is a T in your name!")
else:
print("i'm sorry there is not a T in your name") | true |
3a62d484f15c3d6d50227d2949b6d1ab3e5a32e3 | codingdhsdm/project | /project.py | 1,626 | 4.28125 | 4 | from PIL import Image
# RGB values for recoloring.
darkBlue = (0, 51, 76)
red = (217, 26, 33)
lightBlue = (112, 150, 158)
yellow = (252, 227, 166)
# Import image.
#User can input an image they want to recolor, or put a filter on
print("Find an image you would like to put a filter on. Save it on... | true |
d55bc10eba02e672f3cae18fe3428941f1d4238f | nsmedira/python-for-everybody | /Data Structures/7_files/assignment_7_1.py | 399 | 4.375 | 4 | # Write a program that prompts for a file name
# Use the file words.txt and convert to upppercase
# You can download the sample data at http://www.py4e.com/code3/words.txt
filename = input("Enter file name: ")
# then opens that file
filehandle = open(filename)
# reads through the file
for line in filehandle :
# ... | true |
bd78b030b8fa51b97257a4f880d17ce2db556537 | Galadirith/my-project-2 | /dadownloader/progressbar.py | 1,122 | 4.1875 | 4 | import sys
def progressBar(label, current, total):
"""
A simple progress bar for the terminal
This will print a progress bar to the terminal that looks like:
<label> [|||| ] 40%
It is designed to be used for a discrete finite set of tasks to complete.
You should call progressBar aft... | true |
21b6804cb6ddf80ec5983a2bc2f9943107a9607c | spark0517/Control-Flow-Labs | /exercise-1.py | 816 | 4.28125 | 4 | # exercise-01 Vowel or Consonant
# Write the code that:
# 1. Prompts the user to enter a letter in the alphabet:
# Please enter a letter from the alphabet (a-z or A-Z):
# 2. Write the code that determines whether the letter entered is a vowel
# 3. Print one of following messages (substituting the letter for x):
... | true |
0a694b68967b29cc71ecc871d4c45c3da158dc61 | alejandroxag/python_learning | /DataCamp/Introduction-to-Python/basics.py | 359 | 4.25 | 4 | # DataCamp
# Introduction to Python
# Python Basics
# Ex 1
# Definition of pi_string
pi_string = "3.1415926"
# Convert pi_string into float: pi_float
pi_float = float(pi_string)
print(type(pi_string))
print(type(pi_float))
# Ex 2
print("I can add integers, like " + str(5) + " to strings.")
print("I said " + ("Hey... | true |
033c2679b38a7752dd97f4ea3fa686d3db2de811 | A00354888/hello-world | /Lab6/findWords.py | 1,632 | 4.25 | 4 | import sys
from os import path
def countWordsInText(text):
wordDict = {}
for wordInText in text.split():
wordDict[wordInText] = int(wordDict.get(wordInText, 0)) + 1
return wordDict
def createUserWordList():
userInput = "Y"
wordList = []
while userInput.upper() == "Y":
... | true |
83b727a2fd2e3cf6ddd138bb8a559e5bc14f61ad | amloewi/reviewerator | /multisort.py | 1,896 | 4.15625 | 4 | from pprint import pprint
def multisort(x, fxns, reverse):
"""Recursively sorts simultaneously on multiple, prioritized criteria.
This function sorts the whole list 'x' by the first criterion (i.e., the 'key' function 0 passed in 'fxns'), then for each subset of elements with the same sorting value, it sorts THAT ... | true |
175f0063675761ac7a8647783f0765c3edef46ee | barbarer/Diss2-Win21 | /flower.py | 1,615 | 4.625 | 5 | from turtle import *
def drawPetal(turtle, width):
"""
Write a function to draw the petal shape for the flower head. It
can be a square, triangle, etc.
"""
pass
def drawHead(turtle):
"""
Write a function to draw a spirograph like pattern as the flower head.
It should call drawPeta... | true |
3530b43814f9b57e34d80995752e17369a154968 | amr3k/Leetcode-hard | /Lists/sudoku-solver/__main__.py | 853 | 4.125 | 4 | """
URL: https://leetcode.com/problems/sudoku-solver/
Problem description:
Write a program to solve a Sudoku puzzle by filling the empty cells.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row.
Each of the digits 1-9 must occur exactly once in each ... | true |
47379ca1f2896a4d2200f635376d1b0ac7177711 | subhashiniperni-test/python | /Tested programs code/Task6.py | 269 | 4.375 | 4 | num1 = int(input("Please enter your number --- > "))
# Print table of given number but only display number where multiple is not divisible of 3, 5, 7
for i in range(1, 11):
num = num1 * i
if (num % 3 != 0 and num % 5 != 0 and num % 7 != 0):
print(num) | true |
7e415892169f6ba97f196319e866c57cb72f8f7d | leiurus17/py_test | /py_test/Elementary009.py | 524 | 4.34375 | 4 | '''
Created on Dec 3, 2016
@author: Marlon_2
'''
# Write a guessing game where the user has to guess a secret number.
# After every guess the program tells the user whether their number was too large or too small.
# At the end the number of tries needed should be printed.
# I counts only as one try if they inp... | true |
cc279a261b7387d78c749b69cfbaede9191e7f8e | VikasOO7/Python | /Nptel python programs/matched.py | 1,042 | 4.1875 | 4 | '''
Write a function matched(s) that takes as input a string s and checks if the brackets "(" and ")" in s are matched: that is, every "(" has a matching ")" after it and every ")" has a matching "(" before it. Your function should ignore all other symbols that appear in s. Your function should return True if s has mat... | true |
904bfcc5b26e728960e8963fa8ab8880a7ce0bec | VikasOO7/Python | /Nptel python programs/matrixflip.py | 1,700 | 4.34375 | 4 | '''
A two dimensional matrix can be represented in Python row-wise, as a list of lists: each inner list represents one row of the matrix. For instance, the matrix
1 2 3
4 5 6
7 8 9
would be represented as [[1, 2, 3], [4, 5, 6], [7, 8, 9]].
A horizonatal flip reflects each row. For instance, if we flip the prev... | true |
5edac900cc65dc4b9abf28b4bb2a907486006d50 | VikasOO7/Python | /Nptel python programs/primepartition.py | 889 | 4.125 | 4 | '''
A positive integer m can be partitioned as primes if it can be written as p + q where p > 0, q > 0 and both p and q are prime numbers.
Write a Python function primepartition(m) that takes an integer m as input and returns True if m can be partitioned as primes and False otherwise. (If m is not positive, your funct... | true |
de4f95ad0e2aad46987d3bae748000aecc2a7aa1 | hafizaj/Dropbox | /Python Materials/CS97/hw3_turtle_soln.py | 706 | 4.21875 | 4 | from turtle import *
def tree( trunkLength, angle, levels ):
left(90)
sidewaysTree(trunkLength, angle, levels)
def sidewaysTree( trunkLength, angle, levels ):
""" draws a sideways tree
trunklength = the length of the first line drawn ("the trunk")
angle = the angle to turn before drawing a... | true |
ec253df1bddaf3b46d6ba419a5e77b09103d8743 | AronIS98/Basic | /Forritun/Aron_verkefni/Ekki_mitt/populationbjarki.py | 1,611 | 4.125 | 4 | def open_file(filename):
'''comment'''
try:
txt_file = open(filename)
return txt_file
except FileNotFoundError:
print('Filename {} not found!'.format(filename))
def population():
population_list = []
for line in filename:
line = line.strip()
line_list = line... | true |
cf8ef1fb006a8f8e0c19c4a63e030fa2733b2e54 | JLodha/PythonTutorial | /Variables.py | 369 | 4.125 | 4 | character_name = "Tom"
character_age = 19
is_male = False
print("There was a character named " + character_name + ".")
print("He was "+ str(character_age) +" years old.")
character_name = "Jerry"
print("He did not liked his name "+character_name)
print("But he liked his age "+str(character_age))
if is_male==True:
... | true |
81ca00c42644d1b1040819668a8e81802bb374f1 | JLodha/PythonTutorial | /2DList_NestedLoops.py | 513 | 4.25 | 4 | #2D Lists
number_lists = [
[1,2,3],
[4,5,6],
[7,8,9],
[0]
]
print(number_lists[1][1])
print(len(number_lists))
print(len(number_lists[1]))
#Nested For Loops
print("Printing the elements line by line of 2D List: ")
for index_row in range(len(number_lists)):
for index_column in range(len(number_li... | true |
51b02667e4e6fc25dbb6cbbe5bff371bf592c1b1 | JLodha/PythonTutorial | /ExponentFunction.py | 242 | 4.15625 | 4 | def power_f(base,exponent):
result =1
for index in range(exponent):
result = result * base
return result
base = int(input("Enter Base: "))
exponent = int(input("Enter Exponent: "))
ans = power_f(base,exponent)
print(ans)
| true |
78b4bffa40a83a30ec944793b005fa466ace64f3 | zoomjuice/CodeCademy_CompSci | /Unit_06-LinearDataStructures/06_04_01-NodeImplementation.py | 722 | 4.375 | 4 | """
Let’s implement a linked list in Python. As you might recall, each linked list is a sequential chain of nodes. So
before we start building out the LinkedList itself, we want to build up a Node class in Python that we can use to
build our data containers.
Remember that a node contains two elements:
data
... | true |
b87c05816b034cf6f5f009458c99a0e7fb71e7c7 | zoomjuice/CodeCademy_CompSci | /Unit_06-LinearDataStructures/06_06_01-StackIntro.py | 716 | 4.1875 | 4 | """
Stacks Python Introduction
You have an understanding of how stacks work in theory, so now let’s see how they can be useful out in the wild!
Remember that there are three main methods that we want our stacks to have:
Push - adds data to the “top” of the stack
Pop - provides and removes data from the “top”... | true |
f7236e0d27ea8d55c0d50597ddfbe96ba27062c2 | zoomjuice/CodeCademy_CompSci | /Unit_06-LinearDataStructures/06_02_01-PythonNodesIntro.py | 667 | 4.34375 | 4 | """
Nodes Python Introduction
Now that you have an understanding of what nodes are, let’s see one way they can be implemented using Python.
We will use a basic node that contains data and one link to another node. The node’s data will be specified when
creating the node and immutable (can’t be updated). The link wil... | true |
fa17da5f051500515fe7deb727a8d56ac0eed875 | JaynaBhatt/Python-Program-Week1 | /stringlongcount.py | 226 | 4.40625 | 4 | strng = input("Please Enter string = ")
longest = 0
for x in strng.split() :
if len(x) > longest:
longest = len(x)
longest_word = x
print("The longest word is", longest_word, "with length", len(longest_word))
| true |
918ed5feb0b63027c178443d21668435b1434790 | muneebzafarqureshi/AMAZON_Web_Scarping | /Task 2.py | 1,313 | 4.3125 | 4 | import pandas as pd #Using Pandas library to show the selected category
dviz = pd.read_excel("DVIZ Test.xls") #reading the excel file, you can change the location of the excel as in my case the python file and excel file both are in same location
#all the categories under COMPUTER section
print('Computer Access... | true |
60a588a3d9795d1d86bcb546da5a17b29927af86 | agampreet2209/PythonClasses | /daily_class/2021-02-22/stringmethods.py | 1,415 | 4.375 | 4 | s = "My Name Is Agam,i am 21 years old."
print(s.capitalize()) # only converts the first letter into capital by default
print(s.center(100)) # to align the text in the center
print(s.count("a")) # total repitation
print(s.expandtabs(2)) # it customizes tab size. It takes optional parameter as a int
print(s.find("name... | true |
e16869eb1d2e3c5ea20764a372068620276850c6 | RCoon/CodingBat | /Python/List_1/rotate_left3.py | 402 | 4.28125 | 4 | # Given an array of ints length 3, return an array with the elements "rotated
# left" so {1, 2, 3} yields {2, 3, 1}.
# rotate_left3([1, 2, 3]) --> [2, 3, 1]
# rotate_left3([5, 11, 9]) --> [11, 9, 5]
# rotate_left3([7, 0, 0]) --> [0, 0, 7]
def rotate_left3(nums):
nums.append(nums.pop(0))
return nums
print(rotate... | true |
ecb0b92b4dd82c22ed432b58a5decac36d84447a | RCoon/CodingBat | /Python/Logic_1/caught_speeding.py | 875 | 4.1875 | 4 | # You are driving a little too fast, and a police officer stops you. Write code
# to compute the result, encoded as an int value: 0=no ticket, 1=small ticket,
# 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61
# and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2.
# U... | true |
61dd7f580094a771b9cd4796e7f409ae61f2addc | BipinGhule/Bipin | /HW/Print count of characters, words in the given statement.py | 675 | 4.21875 | 4 | #Take a string from the user and store it in a variable.
#Initialize the character count variable to 0 and the word count variable to 1.
#Use a for loop to traverse through the characters in the string and increment the character count variable each time.
#Increment the word count variable only if a space is encountere... | true |
c0e2bbf262240cf07810f150a2aa43cd219c54c1 | ads2100/100code | /day17.py | 947 | 4.5 | 4 | #week 3 __ day17
#to check if ilems is exist or not :
tuple_info=("orange","apple","cherry")
if 'apple' in tuple_info :
print("yes, apple is in the fruits tuple")
#+++++++++++++++++++++++++++
# to raplecate the items we will use * opreators:
thistuple =("muteb",)*3
print(thistuple)
thistuple =("muteb")*3
print(... | true |
1ffbcc74bb9f1cfe8df98dd90565418b2dbbf1f5 | ads2100/100code | /day10.py | 377 | 4.1875 | 4 | #week 2 --- day10
#python operators
x=5 ;y=6
print(x+y)
print(x-y)
print(x*y)
print(x/y)
print(x/2)
#######################
x=10
x+=2
print(x)
x=5
x**=2
print(x)
x=15
x^=2
print(x)
##################################
# python comparison operators
#using to comparing bertoween two variable and the resuls is true or fal... | true |
26d3506962dc3cee307bc105cbebb9f9ee96a61f | ironsketch/pythonSeattleCentral | /HW2/finished/06MichelleBerginHW2triangleposs.py | 491 | 4.1875 | 4 | # Creating a definition that takes in 3 parameters
def isTriangle(a,b,c):
# Creating an if/else statement
# If any of these conditions are met then print
if a >= b + c or b >= a + c or c >= a + b:
print('This triangle is not possible, you FOOL!')
# Otherwise all others print this
else:
... | true |
2ffbc71dff52a8b4f5fee80b9828d617d30cdf73 | ironsketch/pythonSeattleCentral | /Chapter 1/forrange07.py | 586 | 4.3125 | 4 | # Below is looping through 'i' 7 times, when you use the keyword range
# it will iterate upwards. Although as it stands it will only print 0 - 6
for i in range (7):
print (i)
# To seperate each iteration
print ("Done")
print('')
# Below is looping through 'i' 7 times, when you use the keyword range
# it will iter... | true |
0e44011c5e88ba2feaec69668aab3475dc8f2cc9 | ironsketch/pythonSeattleCentral | /Turtle/kokorosquareforemore.py | 2,967 | 4.34375 | 4 | # Importing the turtle library
import turtle
# Setting up my window
wn = turtle.Screen()
# Setting the color of my window
wn.bgcolor('Dark Slate Gray')
# Setting the title of my windpw
wn.title('Kokoro saves your heart')
# Setting up my turtle a kokoro which stores library information
# from turtle into the variabl... | true |
33be18dd56b7feb678373a455101c04ae121b92d | ironsketch/pythonSeattleCentral | /Chapter 1/chaosrows.py | 1,166 | 4.40625 | 4 | # Start the main definition
def main():
threeNine = 3.9
twoZero = 2.0
x = .5
y = .5
def chaos(num, num2):
x = num * x * (1 - x)
y = num2 * y * (1 - y)
# Just a message printed out that explains to the user
print ("A chaotic function")
# Asking and getting user input on how... | true |
09e5d94e5ce774549d0cedd8015b4292fa556c86 | ironsketch/pythonSeattleCentral | /HW3/is_anagram.py | 1,154 | 4.34375 | 4 | def is_anagram(s1,s2):
'''
Downey Exercise 10.7. Two words are anagrams
if you can rearrange the letters from one to
spell the other. Write a function called is_anagram
that takes two strings and returns
True if they are anagrams.Sort each string
If the sorted strings are equal, they are anagrams
Otherwise,... | true |
1612501a623cfee5e34084036ba8a187d03abb84 | ironsketch/pythonSeattleCentral | /HW4/finished/MichelleBerginHW4_001.py | 1,537 | 4.28125 | 4 | '''Write definitions for the following two functions:
sumN(n) returns the sum of the first n natural numbers.
sumNCubes(n) returns the sum of the cubes of the first
n natural numbers. Then use these functions in a program
that prompts a user for n and prints out the sum of
the first n natural numbers and the sum of the... | true |
f0bbb0b911d57951fcf2de40c37dd7c16822d3ed | ironsketch/pythonSeattleCentral | /Chapter 1/Ch1ZelleEx_Worksheet.py | 962 | 4.25 | 4 | # Zelle Ch 1 examples
print('Hello World!')
print(2+3)
print('2 + 3 =',2+3)
def hello():
print('Hello')
print('Computers are fun!')
def greet(person):
'''Simple function with 1 parameter.'''
print("Hello", person)
print("How are you?")
greet('John')
greet("Emily")
greet
g... | true |
70d826ef68867e13831c85f9607eb7c62626bbf9 | ironsketch/pythonSeattleCentral | /HW4/finished/MichelleBerginHW4_004.py | 1,343 | 4.21875 | 4 | '''Write and test a function to meet this specification.
toNumbers(strList) strList is a list of strings, each of
which represents a number. Modifies each entry in the
list by converting it to a number.'''
#04
################################################
## Zelle 6.13 - toNumbers ##
###########... | true |
588abfe1ddd985d65bb5582b9af8a030b0d2377c | ironsketch/pythonSeattleCentral | /HW5/finished/MichelleBerginHW5_007.py | 2,362 | 4.375 | 4 | '''Write a program that accepts a date in the form month/day/year and
outputs whether or not the date is valid. For example 5/24/1962 is
valid, but 9/31/2000 is not. (September has only 30 days.)'''
#07
################################################
## Zelle 7.11 – determines valid ##
##################... | true |
9fbf96b37be3935f1ffb50c6827a3558fad5e0b9 | subsekhar/PythonExample | /New_Exercises/exercise2.py | 253 | 4.125 | 4 | # This program generates a 6 digit random number
# It combines 6 randomly generated numbers each in the range 0 to 9
import random
output = ""
for i in range(0,6):
output+=str(random.randint(0,9))
print("The winning lottery ticket is:", output)
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.