blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
ae35bfc0d8c5057a7d70cf79a272a353a0f15cf4 | pwgraham91/Python-Exercises | /shortest_word.py | 918 | 4.34375 | 4 | """
Given a string of words, return the length of the shortest word(s).
String will never be empty and you do not need to account for different data types.
"""
def find_short_first_attempt(string):
shortest_word_length = None
for word in string.split(' '):
len_word = len(word)
if shortest_word_length is None or len_word < shortest_word_length:
shortest_word_length = len_word
return shortest_word_length
def find_short(string):
return min(len(word) for word in string.split(' '))
assert find_short("bitcoin take over the world maybe who knows perhaps") == 3
assert find_short("turns out random test cases are easier than writing out basic ones") == 3
assert find_short("lets talk about javascript the best language") == 3
assert find_short("i want to travel the world writing code one day") == 1
assert find_short("Lets all go on holiday somewhere very cold") == 2
| true |
dc9a10c8f8f1cd1c46f78c475ed1ca57cc381ee1 | pwgraham91/Python-Exercises | /process_binary.py | 494 | 4.15625 | 4 | """
Given an array of one's and zero's convert the equivalent binary value to an integer.
Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1
"""
def binary_array_to_number(array):
output = ''
for i in array:
output += str(i)
return int(output, 2)
assert binary_array_to_number([0, 0, 0, 1]) == 1
assert binary_array_to_number([0, 0, 1, 0]) == 2
assert binary_array_to_number([1, 1, 1, 1]) == 15
assert binary_array_to_number([0, 1, 1, 0]) == 6
| true |
9b8ee1df25e986a9ad3abd9134abda3f6d3970f5 | pwgraham91/Python-Exercises | /sock_merchant.py | 990 | 4.71875 | 5 | """
John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.
For example, there are socks with colors . There is one pair of color and one of color . There are three odd socks left, one of each color. The number of pairs is .
Function Description
Complete the sockMerchant function in the editor below. It must return an integer representing the number of matching pairs of socks that are available.
Input:
9
10 20 20 10 10 30 50 10 20
Output:
3
"""
def get_num_match_socks(socks):
unmatched_socks = {}
num_matched_socks = 0
for i in socks:
if unmatched_socks.get(i):
del unmatched_socks[i]
num_matched_socks += 1
else:
unmatched_socks[i] = 1
return num_matched_socks
assert get_num_match_socks([10, 20, 20, 10, 10, 30, 50, 10, 20]) == 3
| true |
7c9c234858d6903b255c291661ae61787f7c8a4f | victorcwyu/python-playground | /learn-python/functions.py | 1,273 | 4.375 | 4 | # divide code into useful blocks
# allows us to order code, make it more readable, reuse it and save time
# a key way to define interfaces to share code
# defined using the block keyword "def", followed by the function name as the block name
def my_function():
print("Yolo")
# may receive arguments (variables passed from the caller to the function)
def my_function_args(name, greeting):
print("Yolo %s %s!" % (name, greeting))
my_function_args("Jolo", "Dolo")
# may also return a value to the caller
def sum_nums(a, b):
return a + b
print(sum_nums(2, 4))
# use an existing function, while adding own to create a program
# Modify this function to return a list of strings as defined above
def list_benefits():
return ["More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"]
# Modify this function to concatenate to each benefit - " is a benefit of functions!"
def build_sentence(benefit):
# return benefit + " is a benefit of functions!"
return "%s is a benefit of functions!" % benefit
def name_the_benefits_of_functions():
list_of_benefits = list_benefits()
for benefit in list_of_benefits:
print(build_sentence(benefit))
name_the_benefits_of_functions() | true |
f515c806b5240f92a077dd7ded268eaa19e8edd2 | victorcwyu/python-playground | /python-crash-course/string-replacement.py | 512 | 4.125 | 4 | # exercise: use Python's string replace method to fix this string up and print the new version out to the console
journey = """Just a small tone girl
Leaving in a lonely whirl
She took the midnight tray going anywhere
Just a seedy boy
Bored and raised in South Detroit or something
He took the midnight tray going anywhere"""
# solution 1
properLyrics = journey.replace("tone", "town").replace("whirl", "world").replace("tray", "train").replace("seedy", "city").replace(" or something", "")
print(properLyrics) | true |
84bd0d4db2706319680706e1cd0621ed313fa034 | Utkarshkakadey/Assignment-solutions | /Assignment 1.py | 1,053 | 4.40625 | 4 | # solution 1
# Python program to find largest
# number in a list
# list of numbers
list1 = [10, 20, 4, 45, 99]
# sorting the list
list1.sort()
# printing the last element
print("Largest element is:", list1[-1])
#solution 2
a=[]
c=[]
n1=int(input("Enter number of elements:"))
for i in range(1,n1+1):
b=int(input("Enter element:"))
a.append(b)
n2=int(input("Enter number of elements:"))
for i in range(1,n2+1):
d=int(input("Enter element:"))
c.append(d)
new=a+c
new.sort()
print("Sorted list is:",new)
#solution 3
# Python program to find second largest
# number in a list
# list of numbers
list1 = [10, 20, 4, 45, 99]
# sorting the list
list1.sort()
# printing the second last element
print("Second largest element is:", )
#solution 4
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(newList):
newList[0], newList[-1] = newList[-1], newList[0]
return newList
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
| true |
36ca26358ff16d783d4b7bc0b24e2768879ef9b4 | NadezhdaBzhilyanskaya/PythonProjects | /Quadratic/src/Bzhilyanskaya_Nadja_Qudratic.py | 2,751 | 4.125 | 4 | import math
class Qudratic:
def __init__(self, a,b,c):
"""Creates a qudratic using the formula: ax^2+bx+c=0"""
self.a = a
self.b = b
self.c = c
self.d = (b**2)-(4*a*c)
def __str__(self):
a = str(self.a) + "x^2 + " + str(self.b) + "x + " + str(self.c)
return a;
def displayFormula(self):
"""Prints out the formula of the qudratic"""
print (self)
def getDiscriminant(self):
"""Finds and returns the discriminant: b^2-4ac"""
return self.d
def getNumberOfRoots(self):
"""Determines how many roots the qudratic has using the discriminant"""
if self.d > 0:
return 2
elif self.d < 0:
return 0
else:
return 1
def isRealRoot(self):
"""Determines if root/roots are real or imaginary"""
if self.d < 0:
return False
else:
return True
def getRoot1(self) :
"""Gets first root:
If 2 real roots exists finds and returns the root in which the radical is subtracted.
If 1 real root exists finds and returns that 1 root.
If no real roots exist returns None"""
a = self.a
b = self.b
num = self.getNumberOfRoots()
if num == 0 :
return None
elif num == 0 :
answer= ((-1)*b) /(2*a)
else :
answer = ((-1)*b + math.sqrt(self.d))/(2*a)
return answer
def getRoot2(self) :
"""Gets second root:
If 2 real roots exists finds and returns the root in which the radical is added.
If 1 real root exists returns None.
If no real roots exist returns None"""
a = self.a
b = self.b
num = self.getNumberOfRoots()
if num < 2 :
return None
else :
answer = ((-1)*b - math.sqrt(self.d))/(2*a)
return answer
if __name__ == "__main__":
print("Welcome to the qudratic formula Program")
print(" Formula: ax^2+bx+c=0")
print("\n")
aIN=int(input("Value for a: "))
bIN=int(input("Value for b: "))
cIN=int(input("Value for c: "))
print("\n")
qud1= Qudratic(aIN,bIN,cIN)
print(qud1)
d = qud1.getDiscriminant()
num = qud1.getNumberOfRoots()
print("\n")
print("Discrimanent: ",d)
print("\n")
print("# of Roots: ",num)
print("\n")
print("Is root real: ",qud1.isRealRoot())
print("\n")
print("Root 1: ",qud1.getRoot1())
print("\n")
print("Root 2: ",qud1.getRoot2())
| true |
68202e160654a74f879656915b632679e51ccb89 | lmaywy/Examples | /Examples/Examples.PythonApplication/listDemo.py | 1,041 | 4.25 | 4 | lst=[1,2,3,4,5,6,7]
# 1.access element by index in order
print 'access element by index in order';
print lst[0];
print 'traverse element by index in order '
for x in lst:
print x;
# 2.access element by index in inverse order
print 'access element by index in inverse order'
print lst[-1];
length=len(lst);
i=length-1;
print 'traverse element by index in inverse order'
while i>=0:
print lst[i];
i=i-1;
# 3.add element
lst.append(8);
lst.insert(0,0);
print lst;
# 4.remove an element
lst.remove(3);
lst.pop(-1);
print lst;
# 5.replace an element from list
lst[-1]=5;
print lst;
# 6.sort list
lst.sort();
print lst;
# 7.reverse list
lst.append(3)
print lst;
lst.reverse();
print lst;
# 8.count given an value in the list
times=lst.count(5);
print times;
# 9.extend list with given list/tuple
lst.extend([10,11])
print lst;
# 10. generate list using while,also call sum to calculate total value
L = [];
x=1;
while x<=100:
L.append(x*x);
x=x+1;
print sum(L) | true |
62d8c229f14671d1ffacfcd65a667a1bce570b9b | aguynamedryan/challenge_solutions | /set1/prob4.py | 2,219 | 4.28125 | 4 | # -*- coding: utf-8 -*-
"""
Question:
Complete the function getEqualSumSubstring, which takes a single argument. The single argument is a string s, which contains only non-zero digits.
This function should print the length of longest contiguous substring of s, such that the length of the substring is2*N digits and the sum of the leftmost N digits is equal to the sum of the rightmost N digits.If there is no such string, your function should print 0.
Sample Test Cases:
Input #00:
123231
Output #00:
6
Explanation:
1 + 2 + 3 = 2 + 3 + 1.
The length of the longest substring = 6 where the sum of 1st half = 2nd half
Input #01:
986561517416921217551395112859219257312
Output #01:
36
"""
""" Solution """
def firstHalfOfString(s):
return s[0:len(s) / 2]
def secondHalfOfString(s):
return s[len(s) / 2:len(s)]
def sumString(string):
someSum = 0
for num in string:
someSum += int(num)
return someSum
def isEqualSumSubstring(string):
if (len(string) % 2 == 1):
return 0
if (sumString(firstHalfOfString(string)) == sumString(secondHalfOfString(string))):
return 1
return 0
def getEqualSumSubstring(string):
from collections import deque
# The queue will store all the strings we need to check
# We start by checking the entire string
queue = deque([string])
while len(queue) != 0:
s = queue.popleft();
# The first string that matches our criteria is,
# by design, the longest so we're done.
# Return the length!
if (isEqualSumSubstring(s)):
return len(s)
# If the current string isn't our winner we'll add
# to the queue two new substrings of the current string
# We trim a character off either end of the current string
# and feed it into the queue
#
# In this way, the queue will get filled
# with all possible substrings of the initial string
# until either a string matches our criteria,
# or the string becomes the empty string, meaning
# there is no match
if (len(s) - 1 > 0):
queue.append(s[0:len(s) - 1])
queue.append(s[1:len(s)])
return 0
if __name__ == "__main__":
print getEqualSumSubstring('986561517416921217551395112859219257312')
| true |
e443a8469abd8dd648d3919ba5122505f9ae0ee7 | ozturkaslii/GuessNumber | /Py_GuessNumber/Py_GuessNumber/Py_GuessNumber.py | 1,214 | 4.25 | 4 | low = 0;
high =100;
isGuessed = False
print('Please think of a number between 0 and 100!');
#loop till guess is true.
while not isGuessed:
#Checking your answer with Bisection Search Algorithm. It allows you to divide the search space in half at each step.
ans = (low + high)/2;
print('Is your secret number '+ str(ans) +'?');
#explanation allows to user to write her/his own input
explanation = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ");
#c represents correct answer. isGuessed will be true and game over.
if(explanation == 'c'):
isGuessed = True
#h is used for that computer's guess is higher than user's secret answer. this means high should be limited by guess.
elif(explanation == 'h'):
high = ans
#c is used for that computer's guess is lower than user's secret answer. this means low should be limited by guess.
elif(explanation == 'l'):
low = ans
#this condition allows us to limit user's input by h, l, or c.
else:
print("Sorry, I did not understand your input.")
print('Game over. Your secret number was: ' + str(ans))
| true |
3b72cf3f9878c6a37ba0274f31df18f4f3a5ad69 | khusheimeda/Big-Data | /Assignment1 - Map Reduce/reducer.py | 789 | 4.125 | 4 | #!/usr/bin/python3
import sys
# current_word will be used to keep track of either recognized or unrecognized tuples
current_word = None
# current_count will contain the number of tuples of word = current_word seen till now
current_count = 0
word = None
for line in sys.stdin:
line = line.strip()
word,count = line.split("\t")
count = int(count)
# If the seen word is equal to the one we're counting, update count
if (current_word == word):
current_count += count
else:
if current_word:
print(current_count)
# This is a new word, so initialise current_word and current_count variables
current_count = count
current_word = word
if current_word == word:
print(current_count)
| true |
9ce6d36ed817b6029a056e3dbd9e6581a00853e5 | KirthanaRamesh/MyPythonPrograms | /decimal_To_Binary.py | 1,577 | 4.53125 | 5 |
# Function for separating the integer and fraction part from the input decimal number.
def separation_of_integer_and_fraction():
global decimal_number, decimal_integer, decimal_fraction
decimal_integer = int(decimal_number)
decimal_fraction = decimal_integer - decimal_number
# Function to convert integer part to binary.
def integral_to_binary_calculation():
global decimal_number, decimal_integer, decimal_fraction
global binary_integral
while decimal_integer >= 1:
remainder = decimal_integer % 2
decimal_integer = decimal_integer // 2
binary_integral.append(remainder)
binary_integral.reverse()
# Function to convert fraction part to binary
def fraction_to_binary_conversion():
global decimal_fraction, temp1, temp2
global binary_fraction
i = 0
temp1 = decimal_fraction * 2
while i < precision :
temp2 = int(temp1)
temp1 = temp2 - temp1
#temp1 = temp1 - temp2
#temp1 = temp1 - int(temp1)
binary_fraction.append(abs(temp2))
temp1 = temp1 * 2
i = i + 1
# Getting input from the user
print("\nConversion of decimal number N into equivalent binary number up-to K precision after decimal point. ")
decimal_number = float(input("\nEnter decimal number, N: "))
precision = int(input("Enter K: "))
binary_integral = []
binary_fraction = ["."]
separation_of_integer_and_fraction()
integral_to_binary_calculation()
fraction_to_binary_conversion()
print("The equivalent binary number is ", *binary_integral, *binary_fraction, sep = "")
| true |
6b8bf1fd5506f086a1367c35f416315b8cc8b8bb | jeffder/legends | /main/utils/misc.py | 621 | 4.3125 | 4 | # Miscellaneous utilities
from itertools import zip_longest
def chunks(values, size=2, fill=None):
"""
Split a list of values into chunks of equal size.
For example chunks([1, 2, 3, 4]) returns [(1, 2), (3, 4)].
The default size is 2.
:param values: the iterable to be split into chunks
:param size: the size of the chunks. Must be an integer.
:param fill: fill missing values in with fill value
"""
if not isinstance(size, int):
raise TypeError('Size must be an integer')
if size <= 0:
size = 2
return zip_longest(*(iter(values),) * size, fillvalue=fill)
| true |
0649d4edfd70e8836a98437b1860c7f7709adaae | mihaivalentistoica/Algorithms_Data_Structures | /01-recursion/example-01.py | 319 | 4.34375 | 4 | def factorial(n):
"""Factorial of a number is the product of multiplication of
all integers from 1 to that number. Factorial of 0 equals 1.
e.g. 6! = 1 * 2 * 3 * 4 * 5 * 6
"""
print(f"Calculating {n}!")
if n == 0:
return 1
return n * factorial(n - 1)
print(f"6! = {factorial(6)}")
| true |
187269a9d58a66513d8bdda626b909f8c62ef928 | mosesokemwa/bank-code | /darts.py | 1,113 | 4.375 | 4 | OUTER_CIRCLE_RADIUS = 10
MIDDLE_CIRCLE_RADIUS = 5
INNER_CIRCLE_RADIUS = 1
CENTRE = (0, 0)
def score(x: float, y: float):
"""Returns the points earned given location (x, y) by
finding the distance to the centre defined at (0, 0).
Parameters
----------
x : float,
The cartesian x-coordinate on the target
y : float,
The cartesian y-coordinate on the target
"""
try:
x = abs(float(x))
y = abs(float(y))
except ValueError:
print('ValueError: The function score only accepts floats as inputs')
return
distance_to_centre = ( (x - CENTRE[0])**2 + (y - CENTRE[1])**2 ) ** (0.5)
if distance_to_centre > OUTER_CIRCLE_RADIUS:
return 0
elif MIDDLE_CIRCLE_RADIUS < distance_to_centre <= OUTER_CIRCLE_RADIUS:
return 1
elif INNER_CIRCLE_RADIUS < distance_to_centre <= MIDDLE_CIRCLE_RADIUS:
return 5
elif 0 <= distance_to_centre <= INNER_CIRCLE_RADIUS:
return 10
if __name__ == '__main__':
x, y = input('score ').split(',')
s = score(x, y)
print(f'Player earns: {s} points') | true |
e52d775f79831414f58c5ceeef965f1306b27293 | OsamaOracle/python | /Class/Players V1.0 .py | 1,294 | 4.3125 | 4 | '''
In the third exercise we make one final adjustment to the class by adding initialization data and a docstring. First add a docstring "Player-class: stores data on team colors and points.". After this, add an initializing method __init__ to the class, and make it prompt the user for a new player color with the message"What color do I get?: ".
Edit the main function to first create two player objects from the class, player1 and player2. After this, make the program call player1's method "goal" twice and player2's goal once. After this, call both objects with the method "tellscore". If everything went correctly, the program should print something like this:
'''
class Player:
teamcolor = "Blue"
points = 0
def __init__(self):
self.teamcolor = input("What color do I get?: ")
def tellscore(self):
print ("I am", self.teamcolor,",", " we have ", self.points, " Points!")
def goal(self):
self.points += 1
def printscore(self):
print("The", self.teamcolor, "contender has", self.__points, "points!")
def fucntion_main():
player1 = Player ()
player2 = Player ()
player1.goal()
player1.goal()
player2.goal()
player1.tellscore()
player2.tellscore()
if __name__ == '__main__':
fucntion_main()
| true |
87c6013053de3c1b0cdddff68e64ea6b76e5040f | lihaoranharry/INFO-W18 | /week 2/Unit 2/sq.py | 316 | 4.25 | 4 | x = int(input("Enter an integer: "))
ans = 0
while ans ** 2 <= x:
if ans **2 != x:
print(ans, "is not the square root of" ,x)
ans = ans + 1
else:
print("the square root is ", ans)
break
if ans **2 == x:
print("we found the answer")
else:
print("no answer discovered")
| true |
055abc0aa8a0fe307d3b1dda6ec697c908e61e44 | RelayAstro/Python | /ejercicio29.py | 962 | 4.5625 | 5 | #The is_palindrome function checks if a string is a palindrome. A palindrome is a string that can be equally read from left to right or right to left, omitting blank spaces, and ignoring capitalization. Examples of palindromes are words like kayak and radar, and phrases like "Never Odd or Even". Fill in the blanks in this function to return True if the passed string is a palindrome, False if not.
def is_palindrome(input_string):
# Replacing spaces with nothing
single_word = input_string.replace(" ", "")
# Converting the word to lower case
single_word = single_word.lower()
# Checking the first element with the last elements and so on
for i in range(len(single_word)):
if single_word[i] != single_word[len(single_word) - 1 - i]:
return False
return True
print(is_palindrome("Never Odd or Even")) # Should be True
print(is_palindrome("abc")) # Should be False
print(is_palindrome("kayak")) # Should be True | true |
5c84f84a9e1816751630c17bb1acb9b3301459a3 | dbrooks83/PythonBasics | /Grades.py | 711 | 4.5 | 4 | #Write a program to prompt for a score between 0.0 and 1.0.
#If the score is out of range, print an error. If the score is between
#0.0 and 1.0, print a grade using the following table:
#Score Grade
#>= 0.9 A
#>= 0.8 B
#>= 0.7 C
#>= 0.6 D
#< 0.6 F
#If the user enters a value out of range, print a suitable error message
#and exit. For the test, enter a score of 0.85.
grades = raw_input("Enter your score:")
try:
grade = float(grades)
except:
grade = -1
if grade>1.0:
print 'Enter your score as a decimal'
elif grade>=.9:
print 'A'
elif grade>=.8:
print 'B'
elif grade>=.7:
print 'C'
elif grade>=.6:
print 'D'
elif grade<.6:
print 'F'
elif grade==-1:
print 'Not a number' | true |
91fa15b2c4ae7d49ff66f69e13a921aed349f63e | TranshumanSoft/Repeat-a-word | /repeataword.py | 205 | 4.1875 | 4 | word = str(input("What word do you want to repeat?"))
times = int(input(f"How many times do you want to repeat '{word}'?"))
counter = 0
while counter < times:
counter = counter + 1
print(word) | true |
8c855c41046f03888b12b957cfb66ac866144ca7 | fandres70/Python1 | /functiondefaults.py | 575 | 4.34375 | 4 | # Learning how Python deals with default values of
# function parameters
def f(a, L=[]):
'''This function appends new values to the list'''
L.append(a)
return L
# not specifying a list input
print(f(1))
print(f(2))
print(f(3))
# specifying a list input
print(f(1, []))
print(f(2, []))
print(f(3, []))
def g(a, L=None):
if L is None:
L = []
L.append(a)
return(L)
# not specifying a list input
print(g(1))
print(g(2))
print(g(3))
# specifying a list input
print(g(1, []))
print(g(2, []))
print(g(3, []))
| true |
39b12a36d1c809b5b64250ac4543c95d26f5912b | fandres70/Python1 | /factorial.py | 426 | 4.34375 | 4 | #!/usr/bin/env python
# Returns the factorial of the argument "number"
def factorial(number):
if number <= 1: #base case
return 1
else:
return number*factorial(number-1)
# product = 1
# for i in range(number):
# product = product * (i+1)
# return product
user_input = int(raw_input("Enter a non-negative integer: "))
factorial_result = factorial(user_input)
print factorial_result
| true |
a4034f4c5a30994a6b8568eb369a8a4df8610c46 | Saskia-vB/eng-57-pyodbc | /error_file.py | 1,338 | 4.5 | 4 | # Reading a text file
# f = open ('text_file.txt', 'r')
#
# print(f.name)
#
# f.close()
# to use a text within a block of code without worrying about closing it:
# read and print out contents of txt file
# with open('text_file.txt', 'r') as f:
# f_contents = f.read()
# print(f_contents)
# reading a txt file and print each line using a loop
# with open('text_file.txt', 'r') as f:
# for line in f:
# print(line, end='')
# I can write to a file
# if the file does exist it will override it so if you want to write to an existing file you write with a for appending
# with open('test_file.txt', 'w') as f:
# f.write('Test')
# append
# with open('text_file.txt', 'a') as f:
# f.write('it worked again!')
# write on a new line
# with open('text_file.txt', 'a') as f:
# f.write('this time on a new line!\n')
# created a function that can open any txt file and print out each line
# def read_text(text_file):
# with open(text_file, 'r') as f:
# for line in f:
# print(line, end = '')
#
# print(read_text('test_file.txt'))
# create a function that writes a new line in a file
# user_input = str(input("Enter your new line: "))
# def new_line(user_input):
# with open('test_file.txt', 'a') as f:
# f.write("'" + user_input + "'" + '\n')
#
# print(new_line(user_input))
| true |
5f62cb78547b5a4152223c2a9c55789768d87b21 | bhumphris/Chapter-Practice-Tuples | /Chapter Practice Tuples.py | 2,234 | 4.46875 | 4 | # 12.1
# Create a tuple filled with 5 numbers assign it to the variable n
n = (3,5,15,6,12)
# the ( ) are optional
# Create a tuple named tup using the tuple function
tup = tuple()
# Create a tuple named first and pass it your first name
first = tuple("Ben")
# print the first letter of the first tuple by using an index
print first[0]
print "\n"
# print the last two letters of the first tuple by using the slice operator (remember last letters means use
# a negative number)
print first[-2:]
print "\n"
# 12.2
# Given the following code, swap the variables then print the variables
var1 = tuple("Good")
var2 = tuple("Afternoon")
var1, var2 = var2, var1
print var1, var2
print "\n"
# Split the following into month, day, year, then print the month, day and year
date = 'Jan 15 2016'
month, day, year = date.split()
print month
print day
print year
print "\n"
# 12.3
# pass the function divmod two values and store the result in the var answer, print answer
answer = divmod(19,2)
print answer
print "\n"
# 12.4
# create a tuple t4 that has the values 7 and 5 in it, then use the scatter parameter to pass
# t4 into divmod and print the results
t4 = (7,5)
print divmod(*t4)
print "\n"
# 12.5
# zip together your first and last names and store in the variable zipped
# print the result
zipped = zip("Ben", "Humphris")
print zipped
print "\n"
# 12.6
# Store a list of tuples in pairs for six months and their order (name the var months): [('Jan', 1), ('Feb', 2), etc
months = [("Jan", 1), ("Feb", 2), ("March", 3), ("April", 4), ("May", 5), ("June", 6)]
print months
print "\n"
# create a dictionary from months, name the dictionary month_dict then print it
month_dict = dict(months)
print month_dict
print "\n"
# 12.7
# From your book:
def sort_by_length(words):
t = []
for word in words:
t.append((len(word), word))
t.sort(reverse=True)
res = []
for length, word in t:
res.append(word)
return res
# Create a list of words named my_words that includes at least 5 words and test the code above
# Print your result
my_words = ("ashamed", "wonderful", "Spectacular", "Hyper", "Democracy")
print sort_by_length(my_words)
| true |
03ef1ea5a2c991e7a597f40b06aac37890dde380 | knobay/jempython | /exercise08/h01.py | 593 | 4.1875 | 4 | """Uniit 8 H01, week2"""
# Gets an input from the user works
# out if it is an Armstrong number
def armstrong_check():
"Works out if the user has entered an Armstrong number"
userinput = input("Enter a 3 digit number")
evaluation = int(userinput[0])**3 + int(userinput[1])**3 + int(userinput[2])**3
if len(userinput) > 3:
result = 'invalid input'
elif int(userinput) == evaluation:
result = 'that was an armstrong number'
else:
result = 'that was not an armstrong number'
print(result)
return
# call the funciton
armstrong_check()
| true |
688fa627915adf73bf41bc04d0636d41fb0d349d | knobay/jempython | /exercise08/e03.py | 581 | 4.125 | 4 |
"""Uniit 8 E03, week2"""
# Gets an input from the user works
# out if it contains a voul
PI = [3.14, 2]
def voul_or_not():
"Works out if the user has entered a voul or consonant"
userinput = input("Enter a letter")
if (userinput == 'a' or userinput == 'e'
or userinput == 'i' or userinput == 'o' or userinput == 'u'):
result = 'that was a voul'
elif len(userinput) > 1 or userinput.isdigit():
result = 'invalid input'
else:
result = 'that was a consonant'
print(result)
return
# call the funciton
voul_or_not()
| true |
2d766aea3921242f98860cc272bbfda43fb38efe | knobay/jempython | /exercise08/e02.py | 720 | 4.28125 | 4 | import math
#
print("\n--------------------------------------------------------------")
print("------------------------ E02 -------------------------")
x = True
while x:
numStr = input("Please enter a whole number:- ")
if numStr.isdigit():
num = int(numStr)
break
elif numStr.replace("-","").isdigit():
num = int(numStr)
break
else:
print("Sorry, it had to be a positive or negative integer, please try again")
if num > 0:
print("The number you entered was:- {} and it is greater than zero.".format(num))
elif num < 0:
print("The number you entered was:- {} and it is less than zero.".format(num))
else:
print("The number you entered was zero") | true |
378e0b3f129230aae31b144ab00fe46aa123b537 | Habits11/Python-Programs | /name_order.py | 953 | 4.15625 | 4 | # name_order.py
# A program to reorder a person's name
# Author: Tyler McCreary
def main():
name = input("Input the name to be reordered: ")
spaces = name.find(" ")
if spaces <= 0:
print("invalid name")
else:
first = name[:spaces]
name = name[spaces + 1:]
spaces = name.find(" ")
if spaces == -1:
print("invalid name")
else:
second = name[:spaces]
name = name[spaces + 1:]
spaces = name.find(" ")
if spaces != -1:
print("invalid name")
else:
third = name
comma = first.find(",")
if comma == -1:
transformed = third + ', ' + first + ' ' + second
print(transformed)
else:
transformed = second + ' ' + third + ' ' + first[:-1]
print(transformed)
main()
| true |
4be0db806d1d5c32ec0cd72121bf8cc9d7244de2 | jlh040/Python-data-structures-exercise | /25_sum_pairs/sum_pairs.py | 1,221 | 4.1875 | 4 | def sum_pairs(nums, goal):
"""Return tuple of first pair of nums that sum to goal.
For example:
>>> sum_pairs([1, 2, 2, 10], 4)
(2, 2)
(4, 2) sum to 6, and come before (5, 1):
>>> sum_pairs([4, 2, 10, 5, 1], 6) # (4, 2)
(4, 2)
(4, 3) sum to 7, and finish before (5, 2):
>>> sum_pairs([5, 1, 4, 8, 3, 2], 7)
(4, 3)
No pairs sum to 100, so return empty tuple:
>>> sum_pairs([11, 20, 4, 2, 1, 5], 100)
()
"""
# Make a new list, make a reversed copy of nums
l1 = []
nums_copy = nums.copy()
nums_copy.reverse()
# Loop through the reversed copy of nums and append each pair of sums to l1
for i in range(len(nums_copy)-1):
for j in range(i+1,len(nums_copy)):
l1.append((nums_copy[i], nums_copy[j], nums_copy[i] + nums_copy[j]))
# filter out any sums that are not equal to goal
goal_list = [tup for tup in l1 if tup[2] == goal]
# if there was no pair that summed to goal, return an empty tuple, otherwise return the
# first pair of numbers that summed to goal
if goal_list == []:
return ()
else:
return (goal_list[-1][1], goal_list[-1][0])
| true |
31a7fa16633f116e153c16ac3c4f588786976335 | annjose/LearningPython | /intro/user_inputs.py | 1,072 | 4.15625 | 4 |
students = []
def add_student(name, age=15):
student = {
"name": name,
"age": age
}
students.append(student)
print(f"Added new student with name '{name}' and age '{age}'")
def my_print(name, age, *args):
print("name =", name, "age =", age)
print(args)
my_print("Liza", 14, "a", 12, "bd")
name = "ann catherine"
print(name.title())
student_name = input("Enter student's name: ")
student_age = input("Enter student's age: ")
add_student(student_name, student_age)
print(students)
print("------------------")
def ask_user_input():
return input("Do you want to add a student? Answer yes or no: ")
add_student = ask_user_input()
while add_student.lower() == "yes" or add_student.lower() == "y":
# ask the user for student name and age
student_name = input("Enter student name: ")
student_age = input("Enter student age: ")
student = {
"name": student_name.title(),
"age": student_age
}
students.append(student)
add_student = ask_user_input()
print("Students ....\n", students)
| true |
30d6f3239d45955065ac72e17493067cd6bae523 | KilnDR/Python-2021 | /hello.py | 1,170 | 4.625 | 5 | #################################
# Learn Python Coding in 2021
# By Dave Roberts
# Codemy.com
#################################
import os
os.system('clear')
# Print Hello World to screen comment note hashtag to identity comment
#print ("Hello World!") # This is another comment
''' 3 single quotation marks allows multiple line comments
line 2 of comment
line 3 of comment
'''
# Variables in python
'''full_name = "Dave Roberts" # declare variable and assigned string value
print(full_name)
'''
#ata types in python
#Strings - test (wrapped in quotation marks can be single or double quotes)
#Numbers
#Lists
#Tuples - constant, can't be changed use parenthese instead of bracket
#Dictionaries - more complicated list use curly brackets and they have key and value pair
#Boolean
'''age = 41
print(age)
names = [full_name,age]
print(names[0]) #print single item
print(names) #print full list
'''
'''quote_test = 'We "Welcome" you'
print(quote_test)
'''
'''fav_pizza = {
"Dave": "Cheese",
"Bob": "Anchovy",
"Mary": "Pepporoni",
#"Bob": "Hawiian" #note last item in dictionary list is returned!
}
print(fav_pizza["Bob"])
'''
'''
switch = True
print(switch)
'''
| true |
1d5317da7e87f3e9b4a1241a532b1d04ea932ac7 | nathanlo99/dmoj_archive | /done/ccc12j1.py | 342 | 4.15625 | 4 | limit = int(input())
speed = int(input())
if speed - limit >= 31:
print("You are speeding and your fine is $500.")
elif speed - limit >= 21:
print("You are speeding and your fine is $270.")
elif speed - limit >= 1:
print("You are speeding and your fine is $100.")
else:
print("Congratulations, you are within the speed limit!") | true |
81f79215a0eb1e822e2bec641c6f5603e0e75dcc | kwakinator/DojoAssignments | /Python/Basic_Python/multsumavg.py | 684 | 4.4375 | 4 | ##Multiples
##Part I - Write code that prints all the odd numbers from 1 to 1000. Use the for loop and don't use a list to do this exercise.
for num in range(0,1001):
if num %2 != 0:
print num
num +=1
##Part II - Create another program that prints all the multiples of 5 from 5 to 1,000,000.
for num1 in range(5, 1000001,5):
##if num1 %5 == 0:
print num1
## num1 +=1
##Sum List
##Create a program that prints the sum of all the values in the list: a = [1, 2, 5, 10, 255, 3]
a = [1, 2, 5, 10, 255, 3]
print sum(a)
##Average List
##Create a program that prints the average of the values in the list: a = [1, 2, 5, 10, 255, 3]
print sum(a)/len(a)
| true |
5652e61cf8c50f36e5361ac5c87d0b466aea7f4c | kuljotbiring/Python | /pythonlearn/nameCases.py | 202 | 4.15625 | 4 | # Use a variable to represent a person’s name, and then print
# that person’s name in lowercase, uppercase, and title case.
name = "kuljot biring"
print(f"{name.lower()}\n{name.upper()}\n{name.title()}")
| true |
d49bace7590233647b762d83d4e9da6ef4f38296 | kuljotbiring/Python | /pythonlearn/dice_import.py | 899 | 4.125 | 4 | # Make a class Die with one attribute called sides, which has a default
# value of 6. Write a method called roll_die() that prints a random number
# between 1 and the number of sides the die has. Make a 6-sided die and roll it
# 10 times.
from random import randint
class Dice:
""" create a dice object and instantiate"""
def __init__(self, sides=6):
self.sides = sides
def roll_die(self):
return randint(1, self.sides)
# this function rolls the die passed in 10 times
def roll_dice(dice_type):
print(f"\nYou are rolling a {dice_type.sides} sided die!")
for die_roll in range(10):
print(f"You rolled a: {dice_type.roll_die()}")
# create and roll six sided die
hex_die = Dice()
roll_dice(hex_die)
# Make a 10-sided die and a 20-sided die. Roll each die 10 times.
deca_die = Dice(10)
roll_dice(deca_die)
poly_die = Dice(20)
roll_dice(poly_die)
| true |
28c139b9c1d115115ed01f6395abc373b672051b | kuljotbiring/Python | /pythonlearn/gradeWithFunction.py | 886 | 4.59375 | 5 | # Rewrite the grade program from the previous chapter using
# a function called computegrade that takes a score as its parameter and
# returns a grade as a string.
# Write a program to prompt for a score between 0.0 and
# 1.0. If the score is out of range, print an error message. If the score is
# between 0.0 and 1.0, print a grade using the following table:
# >= 0.9 A
# >= 0.8 B
# >= 0.7 C
# >= 0.6 D
# < 0.6 F
userGrade = input('Enter a score: ')
userGrade = float(userGrade)
def compute_grade(grade):
if userGrade > 1.0 or userGrade < 0.0:
score = 'Bad score'
elif userGrade >= .9:
score = 'A'
elif float(userGrade) >= .8:
score = 'B'
elif userGrade >= .7:
score = 'C'
elif userGrade >= .6:
score = 'D'
else:
score = 'F'
return score
your_grade = compute_grade(userGrade)
print(your_grade)
| true |
a8ce3b82c6b689f58ad53a7fe9b73569b81745fa | kuljotbiring/Python | /pythonlearn/whilesandwich.py | 805 | 4.34375 | 4 | # Make a list called sandwich_orders and fill it with the names of various
# sandwiches.
sandwich_orders = ['BLT', 'chicken', 'pastrami', 'veggie', 'tuna', 'california', 'turkey']
# Then make an empty list called finished_sandwiches.
finished_sandwiches = []
# Loop through the list of sandwich orders and print a message for each order, such
# as I made your tuna sandwich. As each sandwich is made, move it to the list
# of finished sandwiches.
while sandwich_orders:
sandwich = sandwich_orders.pop()
print(f"I have made your {sandwich} sandwich")
finished_sandwiches.append(sandwich)
print("\n")
# After all the sandwiches have been made, print a
# message listing each sandwich that was made.
for sandwich in finished_sandwiches:
print(f"Your {sandwich} sandwich is ready to eat")
| true |
5cced076bde9478592432ad305fa6ea00bda7797 | csduarte/FunPy | /kboparai1/ex15/sd01.py | 594 | 4.15625 | 4 | # Importing module argv from sys
from sys import argv
# Taking in script name and file name for argv
script, filename = argv
# Opening filename, which was named when invoking the script.
txt = open(filename)
# Printing filename through format variable.
print "Here's your file %r:" % filename
# prints the content of the file being read.
print txt.read()
# Collects name of file from user, aka stdin.
print "Type the filename again:"
file_again = raw_input("> ")
# Opens the filename input above.
txt_again = open(file_again)
# Prints the contents of the file being read.
print txt_again.read() | true |
8c240b4602fbdd0d064af941dc3ced8441d169cf | csduarte/FunPy | /kboparai1/ex03/sd05.py | 750 | 4.375 | 4 | print "I will now count my chickens:"
# dividing two numbers then adding 25
print "Hens", float(25+30/6)
# 100 - percentage
print "Roosters", float(100 - 25 * 3 % 4)
print "Now I will count the eggs:"
# Addition subtraction percentage division addition.
print float(3+2+1-5+4%2-1/4+6)
print "Is it true that 3+2<5-7?"
# Running thru 5 < -2
print float(3+2<5-7)
# Adding
print "What is 3+2?", float(3+2)
# Subtraction
print "what is 5 - 7?", float(5-7)
print "Oh, that's why it's False."
print "How about some more."
# Greater than problem
print "Is it greater?", float(5 > -2)
# Greater than or equal to problem
print "Is it greater or equal?", float(5>=-2)
# Less than or equal to problem
print "Is it less or equal?", float(5 <= -2)
| true |
1a9e42255b8574ce236cf67c14769d7e8245830c | csduarte/FunPy | /kboparai1/ex03/sd01.py | 686 | 4.15625 | 4 | print "I will now count my chickens:"
# dividing two numbers then adding 25
print "Hens", 25+30/6
# 100 - percentage
print "Roosters", 100 - 25 * 3 % 4
print "Now I will count the eggs:"
# Addition subtraction percentage division addition.
print 3+2+1-5+4%2-1/4+6
print "Is it true that 3+2<5-7?"
# Running thru 5 < -2
print 3+2<5-7
# Adding
print "What is 3+2?", 3+2
# Subtraction
print "what is 5 - 7?", 5-7
print "Oh, that's why it's False."
print "How about some more."
# Greater than problem
print "Is it greater?", 5 > -2
# Greater than or equal to problem
print "Is it greater or equal?", 5>=-2
# Less than or equal to problem
print "Is it less or equal?", 5 <= -2
| true |
9fd4dd421b659260bdd30f0934880c2c1996898f | tomilashy/using-lists-in-python | /list comprehension.py | 552 | 4.15625 | 4 |
name = [1,2,3,4,5,6,7,8,9];
odd=[x for x in name if x%2!=0 ];
even=[x for x in name if x%2==0 ];
print (odd,even);
edit=[x if x%2==0 else x*2 for x in name ];
print (edit);
mixed="This is jesutomi";
vowels=', '.join(v for v in mixed if v in "aeiou");
print (vowels);
nested_list=[[1,2,3],[4,5,6],[7,8,9]];
print(nested_list[0][-1]);
for first in nested_list:
for second in first:
print (second)
#printing odd values with nested list comprehension
[[print (second) for second in first if second%2 != 0] for first in nested_list ] | true |
8119a571523a8cf2bb146033c274677ad94e2311 | malhotraguy/Finding-the-specific-letter | /Code.py | 435 | 4.1875 | 4 | cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
search_letter = input("Enter the letter you want to search: ")
total = 0
for city_name in cities:
total += city_name.lower().count(search_letter)
print("In",city_name,"there are:",city_name.lower().count(search_letter),"no. of",search_letter)
print("The total # of \"" + search_letter + "\" found in the list is", total)
| true |
34f3214dbc2f0e0c38b5a46972a9832782ee7b1f | Mat4wrk/Object-Oriented-Programming-in-Python-Datacamp | /1.OOP Fundamentals/Create your first class.py | 785 | 4.46875 | 4 | # Create an empty class Employee
class Employee:
pass
# Create an object emp of class Employee
emp = Employee()
# Include a set_name method
class Employee:
def set_name(self, new_name):
self.name = new_name
# Create an object emp of class Employee
emp = Employee()
# Use set_name() on emp to set the name of emp to 'Korel Rossi'
emp.set_name('Korel Rossi')
# Print the name of emp
print(emp.name)
class Employee:
def set_name(self, new_name):
self.name = new_name
# Add set_salary() method
def set_salary(self, new_salary):
self.salary = new_salary
# Create an object emp of class Employee
emp = Employee()
# Use set_name to set the name of emp to 'Korel Rossi'
emp.set_name('Korel Rossi')
# Set the salary of emp to 50000
emp.set_salary(50000)
| true |
e0504710ea499bd394004095ba27d8b0a24b5c46 | ajay0006/madPythonLabs | /Lab5/verticalDisplay.py | 815 | 4.15625 | 4 | # this code displays a vertical line across the gfx hat screen
from gfxhat import lcd
lcd.clear()
lcd.show()
# this is a function that takes the user input for the X coordinate and validates it, making sure it isnt above 127
# it also returns the users input
def verticalDisplayInput():
x = int(input("please enter a value less than 128: "))
if x > 127:
print("you have entered a number greater than 127")
x = int(input("please enter a value less than 128: "))
while x <= 128:
return x
# this function sets the coordinates for the y axis that prints the horizontal line
def verticalDisplay(x=verticalDisplayInput(), y=1):
while y <= 63:
lcd.set_pixel(x, y, 1)
y = y + 1
# the function is called and the line is displayed
verticalDisplay()
lcd.show()
| true |
4a10a7ac84a121e134505038b4c4dbf00b7df0e4 | ericzacharia/MarkovSpeakerRecognition | /map.py | 2,162 | 4.625 | 5 | from abc import ABC, ABCMeta, abstractmethod
class Map(ABC):
"""
Map is an Abstract Base class that represents an symbol table
"""
@abstractmethod
def __getitem__(self,key):
"""
Similar to the __getitem__ method for a Python dictionary, this will
return the value associated with key in the map.
"""
pass
@abstractmethod
def __setitem__(self,key,value):
"""
Similar to the __setitem__ method for a Python dictionary, this will
add or update the key-value pairing inside the map.
"""
pass
@abstractmethod
def __delitem__(self,key):
"""
Similar to the __delitem__ method for a Python dictionary, this will
remove the key-value pairing inside the map.
"""
pass
@abstractmethod
def __contains__(self, key):
"""
Similar to the __contains__ method for a Python dictionary, this will
return true if the key-value pairing is inside the map; otherwise, if not
then return false.
"""
pass
@abstractmethod
def keys(self):
"""
Returns an iterable object (of your choosing) with all the keys inside
the map.
"""
pass
@abstractmethod
def values(self):
"""
Returns an iterable object (of your choosing) with all the values inside
the map.
"""
pass
@abstractmethod
def __len__(self):
"""
Returns the number items in the map.
It needs no parameters and returns an integer.
"""
pass
@abstractmethod
def __bool__(self):
"""
Returns whether the map is empty or not.
it needs no parameters and returns a bool.
"""
pass
@abstractmethod
def __iter__(self):
"""
Returns an iterator of the objects inside the map. The iterator returns
the key-value pair as tuple.
"""
pass
| true |
43d0a944eb575744d2010b5c7fba39af7e9d96c9 | Tiagosf00/sudoku-solver | /sudoku.py | 1,775 | 4.21875 | 4 | # Sudoku solver using backtrack recursion
# Example with an unique solution.
sudoku = [[5,3,0, 0,7,0, 0,0,0],
[6,0,0, 1,9,5, 0,0,0],
[0,9,8, 0,0,0, 0,6,0],
[8,0,0, 0,6,0, 0,0,3],
[4,0,0, 8,0,3, 0,0,1],
[7,0,0, 0,2,0, 0,0,6],
[0,6,0, 0,0,0, 2,8,0],
[0,0,0, 4,1,9, 0,0,5],
[0,0,0, 0,8,0, 0,7,9]]
# Check if a empty cell (x, y) can hold a certain number (value).
def check(x, y, value, board):
# Check vertical line
for i in range(9):
if(board[i][y] == value):
return False
# Check horizontal line
for j in range(9):
if(board[x][j] == value):
return False
# Check box
x0 = 3*(x//3)
y0 = 3*(y//3)
for i in range(3):
for j in range(3):
if(board[x0+i][y0+j] == value):
return False
return True
# Find all the possible solutions recursively.
def solve(board):
# We could do some pruning, maybe pass the last cell changed,
# so we can iterate starting from it.
for i in range(9):
for j in range(9):
if(board[i][j] == 0): # if cell is empty
for k in range(1, 10): # try every possible value
if(check(i, j, k, board)): # solve it recursively
board[i][j] = k
solve(board)
board[i][j] = 0
return
show(board)
input()
# Show the sudoku board.
def show(board):
for i in range(9):
for j in range(9):
print(f'{board[i][j]} ', end='')
if((j+1)%3==0):
print(' ', end='')
print('\n', end='')
if((i+1)%3==0 and i!=8):
print('\n', end='')
solve(sudoku)
| true |
c3928c896f07c49824ff603f33c236ce4be212da | nsridatta/SeleniumFrameworks | /DinoBot/src/test/stringfunctions.py | 871 | 4.40625 | 4 | from string import capwords
course = "Python for Programmers"
# capitalize method will capitalize only first letter in the sentence
print(course.capitalize())
for word in course.split():
print(word.capitalize(), sep=" ")
# capwords method of string library will capitalize first letter of the words in the sentence
print("\n" + capwords(course))
print(course.__len__())
print(course.replace("Programmers", "Coders"))
print(len(course))
# Upper case method
print("Upper case of this string is "+course.upper())
# Lower case method
print("Lower case of this string is "+course.lower())
# find the location of string python in the given variable
print(course.find("Python"))
# return a boolean if the given expression is present in the given string
print("for" in course)
# RFind method returns the last index of the string occurrence
print(course.rfind("for"))
| true |
51f1b6efac3506ef4a9e4eaf5555f1074b1f21a9 | Fatmahmh/100daysofCodewithPython | /Day058.py | 563 | 4.40625 | 4 | #Python RegEx 2
#The findall() function returns a list containing all matches.
import re
txt = "the rain in spain"
x = re.findall("ai",txt)
print(x)
txt = "the rain in spain"
x = re.findall("pro",txt)
print(x)
if (x):
print("yes we have match")
else:
print("no match")
#The search() function searches the string for a match, and returns a Match object if there is a match.
x = re.search("\s",txt)
print(x.start())
#The split() function returns a list where the string has been split at each match:
x = re.split("\s",txt)
print(x)
| true |
f2e342a56bb38695f1c3ce963a021259a0afe425 | Fatmahmh/100daysofCodewithPython | /Day017.py | 701 | 4.59375 | 5 | thistuple = ('apple ', 'bannana', 'orange', 'cherry')
print(thistuple)
#Check if Item Exists
if "orange" in thistuple:
print('yes , apple in this tuple')
#repeat an item in a tuple, use the * operator.
thistuple = ('python' , )*3
print(thistuple)
#+ Operator in Tuple uesd To add 2 tuples or more into one tuple.
#example
x = (3,4,5,6)
x = x + (1,2,3)
print(x)
#determine how many items a tuple has, use the len() method
print(len(x))
#It is also possible to use the tuple() constructor to make a tuple.
#Using the tuple() method to make a tuple.
thistuple = tuple((1,2,3,4,5,6,4,4))
print(thistuple)
print(thistuple.count(4))
print(thistuple.index(1))
| true |
1a91c62922e98e6333eeff93d4202125096d7117 | Fatmahmh/100daysofCodewithPython | /Day011.py | 516 | 4.25 | 4 | # Logical Operators
x = 5
print(x > 5 or x < 4)
print(x > 5 and x < 4)
print(not x < 4)
#Identity Operators
''' if they are actually the same object, with the same memory location.'''
x = 5
y = 5
z = x
print(" ")
print(x is z )
print(x is not z )
print(x is y)
print(x != z )
print(x == z )
print(z == y )
# Membership Operators
x = ['apple' , 'orange']
print('orange' in x)
print('orange' not in x)
print('banana' in x)
print('banana' not in x)
#Bitwise Operators
| true |
4c99f91d6c7d84f01d4428665924c7c1c61d9697 | Fatmahmh/100daysofCodewithPython | /Day022.py | 732 | 4.71875 | 5 | #Dictionary
#Empty dictionary.
thisdict = {}
thisdict = {
"brand" : 'ford',
"model": "mustang",
"year" : 1996
}
print(thisdict)
print(thisdict["model"])
#Get the value of the key.
print(thisdict.get('model'))
#You can change the value of a specific item by referring to its key name.
thisdict["year"] = 2019
print(thisdict)
#Loop Through a Dictionary
#print keys
for n in thisdict:
print(n)
#print values
for n in thisdict:
print(thisdict[n])
print(thisdict.values())
print(thisdict.keys())
#the items() function.
print(thisdict.items())
#Loop through both keys and values, by using the items() function
for x,y in thisdict.items():
print(x,y)
| true |
eda1d6ef2c68ead27256742ce59d27fef1d71673 | Fatmahmh/100daysofCodewithPython | /Day020.py | 372 | 4.4375 | 4 | thisset = {}
print(thisset)
#Create a Set.
thisset = {'apple', 'cherry', ' banana'}
print(thisset)
#//
thisset = {'apple',1,2,1,5}
print(thisset)
for x in thisset:
print(x)
print("apple" in thisset)
#Add an item to a set, using the add() method.
thisset.add("orange")
print(thisset)
thisset.update(['cherry','banana'])
print(thisset)
| true |
c6f5f3657072bbdce3289326fc9d1b50031e8f8e | Fatmahmh/100daysofCodewithPython | /Day030.py | 1,338 | 4.9375 | 5 | #Python Loops3 For Loop
'''The range() Function To loop through a set of code a specified number of times, we can use the range() function,
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.'''
for x in range(6):
print(x)
'''The range() function defaults to 0 t is possible to specify the starting value by adding a parameter: range(2, 6), which means values from 2 to 6
(but not including 6)'''
for x in range(2,6):
print(x)
'''The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3)'''
for x in range(2,30,3):
print(x)
#Else in For Loop The else keyword in a for loop specifies a block of code to be executed when loop is finished
#Print all numbers from 0 to 5, and print a message when the loop has ended
for x in range(2,6):
print(x)
else:
print("finally finished")
'''Nested Loops
A nested loop is a loop inside a loop.
The "inner loop" will be executed one time for each iteration of the "outer loop'''
#print each adjective for every fruit.
adj = ['red','big','testy']
fruites = ['apple','cherry','bannana']
for x in adj:
for y in fruites:
print(x,y)
| true |
b09b258af455cf1bb4113e47b35de12055951f72 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_235.py | 673 | 4.1875 | 4 | def main():
temp = int(input("Please enter in the temperature: "))
scale = input("Please enter what the temperature is measured in (use K or C): ")
if scale == "K":
if temp >= 373:
print("At this temperature, water is a gas")
elif temp <= 273:
print("At this temperature, water is a solid")
else:
print("At this temperature, water is a liquid")
else:
if temp >= 100:
print("At this temperature, water is a gas")
elif temp <= 0:
print("At this temperature, water is a solid")
else:
print("At this temperature, water is a liquid")
main()
| true |
a3b656dbacb035a707afa9a4c917bc40f13f3275 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_440.py | 674 | 4.125 | 4 | def main():
temp = float(input("please enter the temperature: "))
form = input("please enter 'C' for celsius or 'K' for kelvin: ")
if(temp > 0) and ( temp < 100) and (form == "C"):
print("the water is a liquid.")
if(temp <= 0) and (form == "C"):
print("the water is frozen solid.")
if(temp >=100) and (form == "C"):
print("the water is a gas.")
if(temp > 273) and (temp < 373) and (form == "K"):
print("the water is a liquid")
if(temp <= 273) and (form == "K"):
print("the water is frozen solid")
if(temp >= 373) and (form == "K"):
print("the water is a gas.")
main()
| true |
25d878c1cd851bdaaddcf45b486b01685b0034b9 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_149.py | 312 | 4.15625 | 4 | def main():
height= int(input("Please enter the starting height of the hailstone "))
while height >1:
if height % 2==0:
height = height//2
else:
height=(height*3) +1
print("Hail is currently at height", height)
print("Hail is stopped a height 1")
main()
| true |
6cca26f7f33f8153a78c53e83a1a578a02d1f37c | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_345.py | 717 | 4.125 | 4 | def main():
temp = float(input("Please enter the temperature: "))
tempType = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
if (tempType == 'C'):
if (temp >= 100):
print("The water is gas at this temperature")
elif (temp >= 0):
print("The water is liquid at this temperature")
else:
print("The water is frozen solid at this temperature")
elif (tempType == 'K'):
if (temp >= 373.16):
print("The water is gas at this temperature")
elif (temp >= 273.16):
print("The water is liquid at this temperature")
else:
print("The water is frozen solid at this temperature")
main()
| true |
863f0fe84be66041fef6e6038fbc8a3b2a64c85a | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_379.py | 584 | 4.25 | 4 | def main():
STOP = 1
height = int(input("Please enter the starting height of the hailstone: "))
while (height <=0):
print("The starting height must be a positive number greater than 0")
height = int(input(" Please enter the starting height of the hailstone: "))
while (height != STOP):
print ("Hail is currently at height", height)
heightMOD = height % 2
if (heightMOD == 0):
height = height // 2
elif (heightMOD == 1):
height = (height * 3) + 1
print ("Hail stopped at height", STOP)
main()
| true |
d01b3b97b6cb07c3332001b023c128da8a1452c6 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_229.py | 518 | 4.15625 | 4 | def main():
width = input("Please enter the width of the box: ")
width = int(width)
height = input("Please enter the height of the box: ")
height = int(height)
outline = input("Please enter a symbol for the box outline: ")
fill = input("Please enter symbol for the box to be filled with: ")
print(outline*width)
if(height > 1):
if(height > 2):
for i in range(height-2):
print(outline + (fill*(width-2)) + outline)
print(outline*width)
main()
| true |
ebc0aed659e66bcee2937d0655a6102d87e680c8 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_288.py | 665 | 4.125 | 4 | def main():
temp=float(input("Please enter the temperature: "))
unit=input("Please enter 'C' for Celcius, or 'K' for Kelvin: ")
if unit=="C":
if temp<=0:
print("At this temperature, water is a solid.")
elif temp>=100:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liguid.")
elif unit=="K":
if temp<=273.15:
print("At this temperature, water is a solid.")
elif temp>=373.15:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liguid.")
main()
| true |
c13e7fa212cadac8a9e8490e02947e335a3efb80 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_267.py | 396 | 4.1875 | 4 | def main():
width = int(input("Please enter a width: "))
height = int(input("Please enter a height: "))
symbol1 = input("Please enter a symbol: ")
symbol2 = input("Please enter a different symbol: ")
length = 0
print(symbol1*width)
for n in range(height - 2):
print(symbol1+(symbol2*(width - 2))+symbol1)
if height > 1:
print(symbol1*width)
main()
| true |
8d66c21863dca0efbba1981f8958b208c0830359 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_010.py | 1,039 | 4.125 | 4 | def main():
temp = float(input("Pleas enter the temperature:"))
scale = input("Please enter 'C' for Celsius, or 'K' for Kelvin:")
if scale == "C":
if temp <= 0:
print("At this temperature, water is a(frozen) solid.")
elif temp >= 100:
print("At this temperature, water is a gas.")
elif temp > 0 and tem < 100:
print("At this temperature, water is a liquid.")
elif scale == "K":
if temp <= 273.15 and temp >= 0:
print("At this temperature, water is a(frozen) solid.")
elif temp >= 373.15:
print("At this temperature, water is a gas.")
elif temp > 273.15 and tem < 373.15:
print("At this temperature, water is a liquid.")
elif temp < 0:
print("You cannot have a temperature below 0 Kelvin,it is the abosulte zero.But you can think this as a solid.")
elif scale != "C" or "K":
print("The answer you type in is invalid, make sure you type in capitalized 'C'or 'K'.")
main()
| true |
de0e4572ab2d9a4c45f884d3f7fa1dca8f71308c | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_016.py | 431 | 4.15625 | 4 | def main():
width = int(input("enter width of box "))
height = int(input("enter height of box "))
outline = input("enter a symbol for the outline of the box ")
fill = input("enter a symbol for the fill of the bod")
top = outline * width
print(top)
for i in range (0, height -2):
inside = (width -2)*fill
print(outline, inside, outline)
if height >= 2:
print(top)
main()
| true |
04023bc7cb609f7b7f9078ebadae64321c80ed97 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_264.py | 604 | 4.1875 | 4 | def main():
temp = float(input("What temperature would you like to test:"))
tempMode = input("Is this temperature in Kelvin or Celcius? Enter K or C:")
if temp <= 0 and tempMode == "C" or temp <= 273 and tempMode == "K":
print("At", str(temp) + tempMode, "water would be freezing.")
if 0 < temp < 100 and tempMode =="C" or 273 < temp < 373 and tempMode == "K":
print("At", str(temp) + tempMode, "water would be liquid.")
if temp >= 100 and tempMode == "C" or temp >= 373 and tempMode == "K":
print("At", str(temp) + tempMode, "water would be boiling.")
main()
| true |
90f7d12687698cfdd78085f0324bcca630cba0dc | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_119.py | 570 | 4.125 | 4 | temp = float(input("Please enter the temperature: "))
SI = input("Please enter 'C' for Celcius, or 'K' for Kelvin: ")
if SI == 'C' and temp > 100:
print("At this temperature, water is gas. ")
elif SI == 'C' and temp > 0:
print("At this temperature, water is liquid")
elif SI == 'C' and temp <= 0:
print("At this temperature, water is ice")
elif SI == 'K' and temp > 373.15:
print("At this temperature, water is gas")
elif SI == 'K' and temp > 273.15:
print("At this temperature, water is liquid")
else:
print("At this temperature, water is ice")
| true |
32d08976d85268fcfeda8cc6bab3279a51445ef0 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_019.py | 542 | 4.28125 | 4 | def main():
height=int(input("Please enter the height of the hail: "))
if height <= 1:
print("OOPS! You quit the program, gotta be greater than 1")
while height > 1:
even = height % 2
if even == 0:
if height >= 1:
print("The current height is ",height)
height=height//2
elif even != 0:
if height >= 1:
print("The current height is ", height)
height=height*3+1
print("The hail stopped at " ,height)
main()
| true |
eb7164e404106b0f9526a171840a92b9b4d52743 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_379.py | 621 | 4.1875 | 4 | def main():
temp = float(input("What is the temperature? "))
scale = input("Enter C for Celsius or K for Kelvin: ")
if scale == "K" and temp <= 273:
print("The water is frozen solid")
elif scale == "K" and temp >= 273 and temp <=373:
print("The water is a liquid")
elif scale == "K" and temp > 373:
print("The water is a gas")
if scale == "C" and temp <= 0:
print("The water is frozen solid")
elif scale == "C" and temp >= 0 and temp <=100:
print("The water is a liquid")
elif scale == "C" and temp > 100:
print("The water is a gas")
main()
| true |
8130491334db1ab5f6248f14e76e943fe204d846 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_357.py | 882 | 4.125 | 4 | def main():
FREEZE_C = 0
BOIL_C = 100
FREEZE_K = 273
BOIL_K = 373
tempNum = float(input("Please enter the temperature: "))
tempMes = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
if tempMes == "C" or tempMes == "c":
if tempNum <= FREEZE_C:
print("At this temperature, water is a solid.")
elif tempNum >= BOIL_C:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liquid.")
elif tempMes == "K" or tempMes == "k":
if tempNum <= FREEZE_K:
print("At this temperature, water is a solid.")
elif tempNum >= BOIL_K:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liquid.")
else:
print("Please enter a valid measurement.")
main()
| true |
f67cca03dedd3fabb5a608307249f2c99fbdde95 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_065.py | 397 | 4.25 | 4 | def main():
startingHeight = int(input("Please enter the starting height of the hailstone:"))
while startingHeight != 1 :
if startingHeight % 2 == 0 :
startingHeight = startingHeight / 2
else :
startingHeight = (startingHeight * 3) + 1
print("Hail is currently at", startingHeight)
print("Hail stopped at height", startingHeight)
main()
| true |
b4a99812a7f88d70e240e4b0e8d0b5e7d1c1fdf5 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_182.py | 748 | 4.15625 | 4 | def main():
userTemp = float(input("Please enter the temperature:"))
userScale = input("Please enter 'C' for Celsius, or 'K' for Kelvin:")
a = userTemp
if userScale == "C":
if a > 0 and a < 100:
print("At this temperature, water is a liquid.")
elif a <= 0:
print("At this temperature, water is a (frozen) solid.")
elif a >= 100:
print("At this temperature, water is a gas.")
if userScale == "K":
if a > 273 and a < 373:
print("At this temperature, water is a liquid")
elif a <= 273:
print("At this temperature, water is a (frozen) solid.")
elif a>= 373:
print("At this temperature, water is a gas.")
main()
| true |
7fb3c53caf031fb4a7580440acbfc8f8811d65b7 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_246.py | 581 | 4.375 | 4 | def main ():
inpTemp=float(input("What is the temperature?"))
unit=input("What is the unit? (you may either enter C for Celcius or K for Kelvin)")
if unit == "C":
temp=inpTemp
elif unit == "K":
temp=inpTemp-273
else:
print ("You did not enter a correct unit. Please either enter C for Celcius or K for Kelvin.")
if temp >= 100:
print ("Water is a gas at this temperature.")
elif temp < 0:
print ("Water is a solid at this temperature.")
else:
print ("Water is a liquid at this temperature.")
main ()
| true |
c443537f08867bc6ac762e6794ed4f2d6158635b | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_287.py | 479 | 4.15625 | 4 | def main():
width = int(input("Please enter the width of the box:"))
height= int(input("Please enter the height of the box:"))
outline_symbol = input("Please enter a symbol for the box outline:")
box_fill_symbol= input("Please enter a symbol for the box fill:")
print(outline_symbol* width)
for i in range(height-2):
print(outline_symbol + box_fill_symbol*(width-2) + outline_symbol)
if height > 1:
print (outline_symbol* width)
main()
| true |
82b5935a8d2440bff62d12a0e950755951b034c8 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_025.py | 404 | 4.21875 | 4 | def main():
hail=float(input("Please enter the starting height of the hailstone:"))
while hail!=1:
if (hail % 2)== 0:
hail= int(hail/2)
print("Hail is currently at height", hail)
elif (hail % 2)!=0:
hail= (hail*3)+1
print("Hail is currently at height",hail)
if (hail)==1:
print("Hail stopped at height 1")
main()
| true |
9b6c849522778de47640b1e71dc28f13a81a6176 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_356.py | 504 | 4.125 | 4 | def main():
width = int(input("Pease enter the width of the box: "))
height = int(input("Please enter the height of the box: "))
outline = input("Please enter the symbol for the box outline: ")
fill = input("Pease enter a symbol for the box fill: ")
if height != 1:
print(width *outline)
for i in range(0, height -2):
print(outline + fill*(width-2) + outline)
print(width * outline)
if width == 1 and height == 1:
print(outline)
main()
| true |
5bafe79e853a4f1faf96a70b31f85709b0c3eba9 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_391.py | 449 | 4.15625 | 4 | def main():
print()
temp = float(input("Please enter the temperature: "))
scale = input("Please enter the scale, C for Celsius or K for Kelvin: ")
if scale == "K":
temp = temp - 273.15
if temp <= 0:
print("At this temperature, water is frozen solid.")
elif temp < 100:
print("At this temperature, water is a liquid")
else:
print("At this temperature, water is a gas.")
print()
main()
| true |
0d8bec79312aa7cd3f9d43f5c607d0ab256f53d4 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_290.py | 532 | 4.1875 | 4 | def main ():
width = int(input("What is the width of the box: "))
height = int(input("What is the height of the box: "))
boxOutline = input("What symbol do you want to use for the box's outline: ")
boxFill = input("What symbol do you want to use to fill the box: ")
upperLimit = height - 1
fillWidth = width - 2
for x in range (height):
if x == 0 or x == upperLimit:
print (boxOutline * width)
else:
print (boxOutline + (boxFill * fillWidth) + boxOutline)
main ()
| true |
9164491697c9054aa77cd4dbc5b848897cfb1ef3 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_111.py | 466 | 4.125 | 4 | def main():
width = int(input("Please enter the width of the box: "))
height = int(input("Please enter the height of the box: "))
symbolOut = input("Please enter the symbol for the box outline: ")
symbolIn = input("Please enter a symbol for the box fill: ")
width2 = (width - 2)
symbol1 = (width * symbolOut)
print(symbol1)
for i in range(1, height):
print(symbolOut + symbolIn * width2 + symbolOut)
print(symbol1)
main()
| true |
09c091612e8ff7d2f1abcfa9f0f2cbac911ef224 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_109.py | 740 | 4.25 | 4 | def main():
startingHeight = (int(input("Please enter the starting height of the hailstone:")))
if (startingHeight == 1):
print ("Hail stopped at height",startingHeight)
else:
print("Hail is currently at height",startingHeight)
while (startingHeight != 1):
if (startingHeight % 2) != 0:
startingHeight = int(((startingHeight * 3) + 1))
print("Hail is currently at height",startingHeight)
if (startingHeight % 2) == 0:
startingHeight = int((startingHeight / 2))
if (startingHeight == 1):
print ("Hail stopped at height",startingHeight)
else:
print("Hail is currently at height",startingHeight)
main()
| true |
b3a9e187faac24d060d635a3cf5601e11c1a95bf | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_237.py | 1,010 | 4.15625 | 4 | def main():
temperature = float(input("Please enter the temperature: "))
scaleType = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
C_FROZEN = 0
C_BOIL = 100
K_FROZEN = 273
K_BOIL = 373
if scaleType == 'C':
if temperature <= C_FROZEN:
print("At this temperature, water is a (frozen) solid.")
print(" ")
elif (temperature > C_FROZEN) and (temperature < C_BOIL):
print("At this temperature, water is a liquid.")
print(" ")
else:
print("At this temperature, water is a gas.")
print(" ")
else:
if temperature <= K_BOIL:
print("At this temperature, water is a (frozen) solid.")
print(" ")
elif (temperature > K_FROZEN) and (temperature < K_BOIL):
print("At this temperature, water is a liquid.")
print(" ")
else:
print("At this temperature, water is a gas.")
print(" ")
main()
| true |
cdaf91d26893dc124174bc5b9e919c9065f1f593 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_315.py | 538 | 4.21875 | 4 | def main():
starting_height = int(input("Please enter the starting height of the hailstone: "))
print("Hail is currently at height",starting_height)
while starting_height != 1:
if starting_height % 2 == 0:
starting_height = int(starting_height / 2)
if starting_height != 1:
print("Hail is currently at height",starting_height)
else:
starting_height = int((starting_height * 3) +1)
if starting_height != 1:
print("Hail is currently at height",starting_height)
print("Hail is stopped at",starting_height)
main()
| true |
a114f24c69db097c663703ae32a90c51ac5b6d14 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_196.py | 747 | 4.125 | 4 | def main():
user_temp = float(input("Please enter the temperature: "))
user_scale = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
if user_scale == 'K':
if user_temp < 273.15:
print("At this temperature, water is a (frozen) solid.")
elif user_temp > 373.15:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liquid.")
if user_scale == 'C':
if user_temp < 0:
print("At this temperature, water is a (frozen) solid.")
elif user_temp > 100:
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liquid.")
main()
| true |
c4df35c8a0b8dab68815c048f3487c7f243e7d75 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_415.py | 452 | 4.1875 | 4 | def main():
Temp = float(input("Enter the temperature: "))
Type = input("Enter 'C' for Celsius, or 'K' for Kelvin: ")
if Temp <= 273.15 and Type == "K" or Temp <= 0 and Type == "C":
print("At this temperature, water is a solid.")
elif Temp >= 373.15 and Type == "K" or Temp >= 100 and Type == "C":
print("At this temperature, water is a gas.")
else:
print("At this temperature, water is a liquid.")
main()
| true |
987cdb70436033ed5d8253f83c2ca4286aee9d73 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_290.py | 288 | 4.125 | 4 | def main():
a = int(input("Please enter the starting height of the hailstone: "))
while a !=1:
print("Hail is currently at height",int(a))
if a %2== 0:
a/=2
else:
a = a*3+1
print("Hail stopped at height 1")
main()
| true |
f3fc99aa58bb857b66fe794eb9da3bcc09e62253 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_254.py | 462 | 4.125 | 4 | def main():
width = int(float(input("Please enter the width of the box: ")))
height = int(float(input("Please enter the hieght of the box: ")))
outline = input("Please enter a symbol for the box outline: ")
fill = input("Please enter a symbol for the box fill: ")
EDGE = 2
height=height-EDGE
print(width*outline)
while height > 0:
print(outline,(width-EDGE)*fill,outline)
height-=1
print(width*outline)
main()
| true |
41669cf282bd4afa08e42abaef9651e42d94f6dc | MAPLE-Robot-Subgoaling/IPT | /src/web/hw3_69.py | 573 | 4.15625 | 4 |
def main():
FREEZE = 0
BOIL = 100
CONVERT = 273.15
temp = float(input("Please enter the temperature: "))
print("Please enter the units...")
units = str(input("Either 'K' for Kelvin or 'C' for Celcius: "))
if units == 'K' :
tempCel = temp - CONVERT
else :
tempCel = temp
if tempCel <= FREEZE :
print("At this temperature, water is a (frozen) solid.")
elif tempCel < BOIL :
print("At this temperature, water is a liquid.")
else :
print("At this temperature, water is a gas.")
main()
| true |
e8fae662feeb6aa590fe33becf210da929c7a8ad | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_348.py | 460 | 4.15625 | 4 | def main():
width = int(input("Please enter the width of the box: "))
height = int(input("Please enter the height of the box: "))
symb1 = input("Please enter a symbol for the box outline: ")
symb2 = input("Please enter a symbol for the box fill: ")
width1 = width - 2
fill = symb2 *width1
outer = symb1 * width
print(symb1 * width)
for a in range(0,height-1):
print(symb1+fill+symb1)
print(symb1 * width)
main()
| true |
afeafa3b4267e96a9be0539abfaa626da21f9455 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_174.py | 558 | 4.3125 | 4 | def main():
userHeight = int(input("Please enter a positive integer that will serve as the starting height for the hailstone: "))
print("Hail height starts at", userHeight)
while userHeight != 1:
if userHeight % 2 == 1:
userHeight = int((userHeight * 3) + 1)
print("Hail height: " + str(userHeight))
elif userHeight % 2 == 0:
userHeight = int(userHeight / 2)
print("Hail height: " + str(userHeight))
if userHeight == 1:
print("Hail has reached the height of 1!")
main()
| true |
83dfbf3cbd2f80f48c06dd7763f886026f23ac2d | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_135.py | 794 | 4.125 | 4 | def main():
width = int(input("What do you want the width of the box to be? "))
height = int(input("What do you want the height of the box to be? "))
outline = str(input("Enter the symbol you want the outline to be: "))
fill = str(input("Enter the symbol you want the filling of the box to be: "))
print(outline * width)
if width > 2 and height != 1:
filling = outline + fill *(width - 2) + outline
for i in range(0, height - 2):
print(filling)
if width > 1 and height != 1:
if width == 2:
for i in range (0, height - 1):
print(outline * width)
else:
print(outline * width)
if width == 1 and height != 1:
for i in range(0, height - 1):
print(outline)
main()
| true |
8a4dfd706d16db0a3a5d148d11ba2399def19641 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_118.py | 940 | 4.1875 | 4 | def main():
SOLID_TEMP_CELSIUS = 0
GAS_TEMP_CELSIUS = 100
SOLID_TEMP_KELVIN = 273.15
GAS_TEMP_KELVIN = 373.15
tempNum = float(input("Please enter the temperature: "))
degreeType = input("Please enter 'C' for Celsius or 'K' for Kelvin: ")
if (degreeType == "C"):
if (tempNum <= SOLID_TEMP_CELSIUS):
print("At this temperature, water is a (frozen) solid.")
elif (tempNum > SOLID_TEMP_CELSIUS and tempNum < GAS_TEMP_CELSIUS):
print("At this temperature, water is a liquid.")
else:
print("At this temperature, water is a gas.")
else:
if (tempNum <= SOLID_TEMP_KELVIN):
print("At this temperature, water is a (frozen) solid.")
elif (tempNum > SOLID_TEMP_KELVIN and tempNum < GAS_TEMP_KELVIN):
print("At this temperature, water is a liquid.")
else:
print("At this temperature, water is a gas.")
main()
| true |
31c4258373d73681e8d1021fb4fac4d42105c0ca | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_421.py | 743 | 4.15625 | 4 | def main():
temp=float(input("Please enter the temperature: "))
scale=input("Please enter 'C' for Celcius, or 'K' for Kelvin: ")
if temp <= 0 and scale == "C":
print("At this temperature, water is a solid.")
elif temp > 0 and temp < 100 and scale == "C":
print("At this temperature, water is a liquid.")
elif temp >= 100 and scale == "C":
print("At this temperature, water is a gas.")
if temp <= 273.16 and scale == "K":
print("At this temperature, water is a solid")
elif temp > 273.16 and temp < 373.16 and scale == "K":
print("At this temperature, water is a liquid.")
elif temp >= 373.16 and scale == "K":
print("At this temperature, water is a gas.")
main()
| true |
6dfe0293e894534bf993ae70f3a1f3a78e7e9d15 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_222.py | 399 | 4.3125 | 4 | def main():
height = input("Please enter the current height of the hailstone: ")
height = int(height)
while(height > 1):
height = int(height)
print("The hailstone is at height",height)
if(height % 2 == 0):
height /= 2
elif(height % 2 != 0):
height *= 3
height += 1
print("The hailstone stopped at height 1")
main()
| true |
dae3c37bca2ad430eabd80d5f763b520b214ab5e | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_158.py | 679 | 4.125 | 4 | def main():
temp =float(input("please enter a temperature "))
unit = input("please enter 'C' for celsius or 'K' for kelvin ")
if unit=="C":
if temp <0:
print("At this temperature, water is a solid")
elif temp >100:
print("At this temperature, water is a gas")
elif temp >0 and temp <100:
print("At this temperature, water is a liquid")
elif unit=="K":
if temp <273.16:
print("At this temperature, water is a solid")
elif temp >373.16:
print("At this temperature, water is a gas")
elif temp >273.16 and temp <373.16:
print("At this temperature, water is a liquid")
main()
| true |
71bc91e8c4ed40169539728b97f99fc0b18170d1 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_062.py | 516 | 4.28125 | 4 | def main():
hailStormNum = int(input("Please insert a positive integer, which is the starting height of the hailstorm: "))
while hailStormNum != 1:
if hailStormNum % 2 == 0:
hailStormNum = hailStormNum / 2
hailStormNum = int(hailStormNum)
print (hailStormNum)
else:
hailStormNum = hailStormNum * 3 + 1
hailStormNum = int(hailStormNum)
print (hailStormNum)
print ("This is the final height of the hailstorm.")
main()
| true |
c2865ffd41f13fe9025094fdf6b7a0de4b384e04 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_207.py | 697 | 4.125 | 4 | def main():
userTemp = float(input("Please enter the temperature: "))
unitScale = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
if unitScale == "C":
if userTemp <= 0:
print("At this temperature, water is a solid.")
elif userTemp >= 100:
print("At this temperature, water is a gas.")
else:
print("At this temperature, waster is a liquid.")
else:
if userTemp <= 273.2:
print("At this temperature, water is a solid.")
elif userTemp >= 373.2:
print("At this temperature, water is a gas.")
else:
print("At this temperature, waster is a liquid.")
main()
| true |
6d99ddfa0e550e40ed5332c54493d4f5a6dc49b4 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_337.py | 807 | 4.125 | 4 | def main():
temperature = float(input('Please enter the temperature: '))
scale = input('Please enter C for Celsius, or K for Kelvin: ')
if (temperature <= 0) and (scale == 'C'):
print ('At this tmeperature, water is a (frozen) solid.')
elif (temperature >= 100) and (scale == 'C'):
print ('At this temperature, water is a gas.')
elif (0<temperature<100) and (scale== 'C'):
print ('At this temperature, water is a liquid.')
elif (temperature <= 273) and (scale == 'K'):
print ('At this temperature, water is a (frozen) solid.')
elif (temperature >=373) and (scale == 'K'):
print ('At this temperature, water is a gas.')
elif (273<temperature<373) and (scale == 'K'):
print ('At this temperature, water is a liquid.')
main()
| true |
60050fbfe1d39a9e0ad38e9908a0f8fcba491fe1 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_233.py | 834 | 4.15625 | 4 | FREEZING_POINT_OF_CELSIUS= 0
BOILING_POINT_OF_CELSIUS = 100
FREEZING_POINT_KELVIN = 373.16
BOILING_POINT_KELVIN= 273.16
def main():
temp= float(input("Please enter the temperature:"))
temp1= (input("Please enter 'C' for Celsius, or 'K' for Kelvin:"))
if temp1 =="C":
if temp > 0 and temp < 100:
print("At this temperature, water is a liquid.")
elif temp <=100:
print("At this temperature, water is a (frozen) solid.")
else:
print("At this temperature, water is a gas.")
else:
if temp > 273.16 and temp < 373.16:
print("At this temperature, water is a liquid.")
elif temp <= 273.16:
print("At this temperature, water is a (frozen) solid.")
else:
print("At this temperature, water is a gas.")
main()
| true |
2c92980b2b3d805d6227c49c796507ce79b88b81 | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_374.py | 486 | 4.125 | 4 | def main():
width = int(input("Please enter the width of the box: "))
height = int(input("Please enter the height of the box: "))
symbol = input("Please enter the symbol for the box outline: ")
filling = input("Please enter the symbol for the box filling: ")
fillWidth = width - 2
for box in range(1,height):
if box == 1:
print (symbol*width)
else:
print (symbol+(fillWidth*filling)+symbol)
print(symbol*width)
main()
| true |
fdf6fbdf2f21fe305e544a367b705a2eead1d2dc | MAPLE-Robot-Subgoaling/IPT | /data/HW5/hw5_123.py | 598 | 4.125 | 4 | def main():
index = 0
widthPrompt = int(input("What is the width of the box? "))
heightPrompt = int(input("What is the height of the box? "))
outsideSymbol = str(input("What character is the outside of the box made of? "))
insideSymbol = str(input("What character is the inside of the box made of? "))
print(outsideSymbol * widthPrompt)
if heightPrompt > 2:
for index in list(range(heightPrompt - 2)):
print(outsideSymbol + insideSymbol * (widthPrompt - 2) + outsideSymbol)
if heightPrompt != 1:
print(outsideSymbol * widthPrompt)
main()
| true |
fa2c9b4e50d08505b1992c319c2fff86781a5d26 | MAPLE-Robot-Subgoaling/IPT | /data/HW3/hw3_179.py | 756 | 4.15625 | 4 | def main():
GAS_C = 100
LIQUID_C = 60
GAS_K = 373.15
LIQUID_K = 333.15
temp = float(input("Please enter the temperature "))
unit = input("Please enter 'C' for Celsius, or 'K' for Kelvin: ")
if unit == 'C':
if temp > GAS_C:
print("At this temperature, water is a gas")
elif temp >= LIQUID_C:
print("At this temperature, water is a liquid")
else:
print("At this temperature, water is a solid")
elif unit == 'K':
if temp >= GAS_K:
print("At this temperature, water is a gas")
elif temp >= LIQUID_K:
print("At this temperature, water is a liquid")
else:
print("At this temperature, water is a solid")
main()
| true |
95d8cc3d61617d2bdae5c8339d0963acac2bc1b8 | MAPLE-Robot-Subgoaling/IPT | /data/HW4/hw4_447.py | 417 | 4.25 | 4 | def main():
startingHeight=int(input("Please enter the starting height of the hailstone:"))
while startingHeight>1:
print("Hail is currently at Height",startingHeight)
if startingHeight % 2==0:
startingHeight=startingHeight/2
elif startingHeight % 2==1:
startingHeight= (startingHeight*3)+1
print("Hail stopped at height",startingHeight)
main()
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.