This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. | |
# If there are two or more words that are the same length, return the first word from the string with that length. | |
# Ignore punctuation and assume sen will not be empty. | |
def LongestWord(sen): | |
import re | |
length_greatest = 0 | |
# Convert string to lowercase | |
sen = sen.lower() | |
# Only keep alphabet + numbers + white space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create pig latin based on string inputted | |
# Get sentence from user | |
sentence = input("Please type in a sentence to be converted into pig-latin: ").strip().lower() | |
# Split sentence into sentence | |
sentence = sentence.split() | |
# Loop through sentence and convert to pig-latin | |
new_sentence = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get user email address | |
email = input("What is your email address?: ").strip() | |
# Slice out the user name | |
user_name = email[:email.index("@")] | |
# Slice the domain name | |
domain_name = email[email.index("@")+1:] | |
# Format message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Have the function SimpleAdding(num) add up all the numbers from 1 to num. | |
# For example: if the input is 4 then your program should return 10 because 1 + 2 + 3 + 4 = 10. | |
def SimpleAdding(num): | |
sum = 0 | |
for x in range(1,num+1): | |
sum = sum + x | |
return sum | |
print(SimpleAdding(input())) | |
# print SimpleAdding(raw_input()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Have the function SimpleSymbols(str) take the str parameter being passed and | |
# determine if it is an acceptable sequence by either returning the string true or false. | |
# The str parameter will be composed of different symbols with several letters | |
# between them (ie. ++d+===+c++==a) and for the string to be true | |
# each letter must be surrounded by a + symbol. | |
# Examples: | |
# +t+a+b+ returns True | |
# +++a+s++++e+ returns True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# selection sort | |
def selection_sort(n): | |
moves = 0 | |
print("Unsorted list: {}".format(unsorted_list)) | |
length_of_list = len(unsorted_list) | |
for i in range(0,length_of_list-1): | |
# get min of list [i .... length_of_list] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PentagonalNumber(num) reads num which will be a positive integer and determine how many dots exist in a pentagonal shape | |
# around a center dot on the Nth iteration. | |
# For example, in the image below you can see that on the first iteration there is only a single dot, | |
# on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots. | |
# The formula for this sequence is (5(n-1)^2 + 5(n-1) + 2) / 2 | |
def PentagonalNumber(num): | |
num = num - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using the Python language, have the function KaprekarsConstant(num) take | |
# the num parameter being passed which will be a 4-digit number with at least | |
# two distinct digits. | |
# Your program should perform the following routine on the number: | |
# Arrange the digits in descending order and in ascending order | |
# subtract the smaller number from the bigger number. Then repeat the previous step. | |
# Performing this routine will always cause you to reach a fixed number: 6174. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function input is a string that are the coordinates of a space on a 8x8 | |
# chess board. The structure of str will be (x y)(a b) where (x y) is the | |
# current position and (a b) is the new position. | |
# a and b will be strictly greater than x and y respectively. | |
# Program will determine the number of ways there are of travelling from | |
# (x y) to (a b) by only travelling up and right. | |
def ChessboardTraveling(str): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bubble sort | |
def bubble_sort(n): | |
moves = 0 | |
print("Unsorted list: {}".format(unsorted_list)) | |
length_of_list = len(unsorted_list) | |
print("Number of numbers : {}".format(length_of_list)) |
NewerOlder