├── 1 Debugging practice ├── debug add 10.txt ├── debug do the brackets match.txt ├── debug fareheit to celcius.txt ├── debug guess secret number.txt └── debug with arguments.txt ├── 10. Extending data structures ├── 9.1.6 Checkerboard, v1.txt ├── 9.1.7 Checkerboard, v2.txt ├── 9.1.8 Checkerboard, v3.txt ├── 9.1.9 Tic Tac Toe.txt ├── 9.2.5 Divisible by 3.txt ├── 9.2.8 Last Names.txt ├── 9.2.9 Strings To Integers.txt ├── 9.3.6 Coordinate Pair.txt ├── 9.3.7 Slopes.txt ├── 9.3.9 Full Name & Citation.txt ├── 9.4.5 Phone Book.txt ├── 9.4.6 Word Counts.txt ├── 9.5.6 Swapping.txt └── 9.5.7 Word Counts, Part 2.txt ├── 11. Project Guess the word └── 10.1.5 Guess the word All parts.txt ├── 3. Introduction to programming with turtle graphics ├── 2.1.4 Stretched Slinky.txt ├── 2.10.4 Blubble Wrap 2.0.txt ├── 2.10.5 Sidewalk.txt ├── 2.11.4 Dartboard.txt ├── 2.11.5 Line of Increasing Blocks.txt ├── 2.12.4 Colored Dartboard.txt ├── 2.12.5 Four Corners.txt ├── 2.13.4 Colorful Caterpillar.txt ├── 2.13.5 Circle in a square.txt ├── 2.13.6 Snowman.txt ├── 2.14.4 Geometry 2.0.txt ├── 2.15.4 Dartboard using i.txt ├── 2.15.5 Phone Signal.txt ├── 2.16.4 Happy face.txt ├── 2.16.5 Black and white squares.txt ├── 2.17.4 Rating.txt ├── 2.17.5 Happy Sad face.txt ├── 2.18.4 Increasing squares.txt ├── 2.18.5 Guess a number.txt ├── 2.19.4 Guess a number 2.0.txt ├── 2.19.5 Circle pyramid 2.0.txt ├── 2.19.6 Checkerboard.txt ├── 2.2.4 Shorter Dashed Line.txt ├── 2.2.5 Caterpillar.txt ├── 2.3.5 Rectangle.txt ├── 2.3.5 Row of circles.txt ├── 2.3.6 Columns.txt ├── 2.4.6 Columns 2.0.txt ├── 2.5.5 Hexagon.txt ├── 2.5.6 'x' Marks the Spot.txt ├── 2.5.7 Circle Pyramid.txt ├── 2.6.4 Circle Pyramid.txt ├── 2.8.4 Beaded Bracelet.txt ├── 2.8.5 Shape stack.txt ├── 2.9.5 Four Colored triangles.txt ├── 2.9.6 Colorful Bracelet.txt └── 2.9.7 Kid's Shapes toy.txt ├── 4. Basic python and console interaction ├── 3.1.5 Introduce yourself.txt ├── 3.1.6 Fix this program.txt ├── 3.1.7 Vertical name.txt ├── 3.2.6 Make some variables.txt ├── 3.2.7 Undefined Variables.txt ├── 3.3.6 Hello name.txt ├── 3.3.7 Age.txt ├── 3.4.5 Add parentheses.txt ├── 3.4.7 Rectangle.txt ├── 3.5.4 Fix this program.txt ├── 3.5.6 Introduce yourself part 2.txt ├── 3.5.7 Rectangle part 2.txt ├── 3.5.8 Rectangle part 3.txt ├── 3.5.9 Recipe.txt └── 3.6.5 Add coments.txt ├── 5.Conditionals ├── 4.1.4 Fix this program.txt ├── 4.1.5 Plants.txt ├── 4.2.5 Fix this program.txt ├── 4.2.6 Is it raining.txt ├── 4.3.10 Transaction.txt ├── 4.3.6 Old enough to vote.txt ├── 4.3.7 Positive, zero or negative.txt ├── 4.3.9 Table Reservation.txt ├── 4.4.4 Administrators teachers and students.txt ├── 4.4.5 Presidential Eligibility.txt ├── 4.4.6 Presidential eligibility extended.txt └── 4.5.4 Correct portion.txt ├── 6. Looping ├── 5.1.6 2 through 20 even.txt ├── 5.1.7 Divisibility.txt ├── 5.2.5 Counting 10 to 100 by tens.txt ├── 5.2.8 Average Test Score.txt ├── 5.2.9 How many Names.txt ├── 5.3.7 Higher Lower.txt ├── 5.3.8 Higher Lower 2.txt ├── 5.4.6 Rolling dice.txt └── 5.4.7 Categories.txt ├── 7. Functions and exceptions ├── 6.1.5 Weather.txt ├── 6.2.5 Fix this program.txt ├── 6.2.6 Adding to a Value.txt ├── 6.2.7 Add subtract or multiply.txt ├── 6.3.5 Print product.txt ├── 6.3.6 Print multiple times.txt ├── 6.3.8 Area of a square with default parameters.txt ├── 6.4.4 Add one.txt ├── 6.4.8 Sum two numbers.txt ├── 6.4.9 Temperature Converter.txt ├── 6.5.5 Divisibility pt2.txt ├── 6.5.6 Temperature converter.txt └── 6.5.7 Enter a positive number.txt ├── 8. String ├── 7.1.4 Initials.txt ├── 7.1.5 Doghouse.txt ├── 7.2.6 First character.txt ├── 7.2.7 Part 1 replace a letter.txt ├── 7.2.8 part 2 replace a letter.txt ├── 7.3.4 Find the error.txt ├── 7.4.4 Length of users name.txt ├── 7.4.7 Spelling Bee.txt ├── 7.4.8 Count occurrences.txt ├── 7.5.5 Contains a Vowel.txt ├── 7.6.10 part 2 remove all from string.txt ├── 7.6.4 Enthusiasm.txt ├── 7.6.8 Vowels in first name.txt └── 7.6.9 Part 1 remove all from string.txt ├── 9 Creating and altering data structures ├── 8.1.10 Coordinate pairs.txt ├── 8.1.7 Fix this tuple.txt ├── 8.1.8 Citation.txt ├── 8.1.9 Cookout orders.txt ├── 8.2.5 Letters in name.txt ├── 8.2.7 Listed greeting.txt ├── 8.3.5 Max in list.txt ├── 8.3.6 Owls.txt ├── 8.3.7 Exclamation points.txt ├── 8.3.8 Word ladder.txt ├── 8.4.11 Fruits and Vegetables.txt ├── 8.4.12 Librarian, Part 2.txt ├── 8.4.13 Owls, Part 2.txt ├── 8.4.4 How Many Names.txt ├── 8.4.5 Five Numbers.txt └── 8.4.7 Librarian.txt └── README.md /1 Debugging practice/debug add 10.txt: -------------------------------------------------------------------------------- 1 | public class Add10 2 | { 3 | public static void main(String[] args) 4 | { 5 | add10(1); 6 | add10(100); 7 | add10(-50); 8 | } 9 | 10 | private static void add100(int num) 11 | { 12 | System.out.println(num + 10); 13 | } 14 | } -------------------------------------------------------------------------------- /1 Debugging practice/debug do the brackets match.txt: -------------------------------------------------------------------------------- 1 | public class BracketTest 2 | { 3 | public static void main(String[] args) 4 | { 5 | Method call would go here 6 | } 7 | 8 | public static boolean bracketsMatch(String brackets) 9 | { 10 | count = 0; 11 | for (int i = 0; i brackets.length()) 12 | { 13 | if (brackets.charAt(i) == '{') 14 | { 15 | count++; 16 | } 17 | else 18 | { 19 | count--; 20 | } 21 | if (count 0) 22 | { 23 | return false; 24 | } 25 | } 26 | return count == 0; 27 | } 28 | } -------------------------------------------------------------------------------- /1 Debugging practice/debug fareheit to celcius.txt: -------------------------------------------------------------------------------- 1 | public class DegreeConversion 2 | { 3 | public static void main(String[] args) 4 | { 5 | System.out.println(fahrenheitToCelsius(72)); 6 | System.out.println(fahrenheitToCelsius(100)); 7 | System.out.println(fahrenheitToCelsius(32)); 8 | System.out.println(fahrenheitToCelsius(-10)); 9 | } 10 | 11 | public static double fahrenheitToCelsius(double degrees) 12 | { 13 | return (5/9) * (degrees - 32); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /1 Debugging practice/debug guess secret number.txt: -------------------------------------------------------------------------------- 1 | SECRET_NUMBER = 37 2 | MAX_TRIES = 10 3 | 4 | 5 | print "Try to guess my number! It is between 0 and 100." 6 | print "You have " + str(MAX_TRIES) + " chances :)" 7 | print "" 8 | 9 | tries = 1 10 | guess = int(input("Enter your guess: ")) 11 | 12 | while tries < MAX_TRIES: 13 | if guess > SECRET_NUMBER: 14 | print "\tToo High!" 15 | elif guess < SECRET_NUMBER: 16 | print "\tToo Low!" 17 | else: 18 | print "\tRight!" 19 | break 20 | guess = int(input("Enter your guess: ")) 21 | tries += 1 -------------------------------------------------------------------------------- /1 Debugging practice/debug with arguments.txt: -------------------------------------------------------------------------------- 1 | def replace_at_index(text, position, replace): 2 | length = len(text) 3 | 4 | # If position to replace is an illegal 5 | # position, return without replacing 6 | if position >= length: 7 | return text 8 | 9 | # Iterate through text and replace letter 10 | # at position with new string 11 | result_str = "" 12 | for i in range(length): 13 | if i == position: 14 | result_str += replace 15 | else: 16 | result_str += text[i] 17 | 18 | return result_str 19 | 20 | 21 | print replace_at_index("karel", 0, "K") 22 | print replace_at_index("CA", 1, "ALIFORNIA") -------------------------------------------------------------------------------- /10. Extending data structures/9.1.6 Checkerboard, v1.txt: -------------------------------------------------------------------------------- 1 | 2 | # Pass this function a list of lists, and it will 3 | # print it such that it looks like the grids in 4 | # the exercise instructions. 5 | def print_board(board): 6 | for i in range(len(board)): 7 | 8 | # This line uses some Python you haven't 9 | # learned yet. You'll learn about this 10 | # part in a future lesson: 11 | # 12 | # [str(x) for x in board[i]] 13 | print " ".join([str(x) for x in board[i]]) 14 | 15 | # Your code here... 16 | 17 | board = [ 18 | [1,1,1,1,1,1,1,1], 19 | [1,1,1,1,1,1,1,1], 20 | [1,1,1,1,1,1,1,1], 21 | [0,0,0,0,0,0,0,0], 22 | [0,0,0,0,0,0,0,0], 23 | [1,1,1,1,1,1,1,1], 24 | [1,1,1,1,1,1,1,1], 25 | [1,1,1,1,1,1,1,1], 26 | ] 27 | 28 | print_board(board) -------------------------------------------------------------------------------- /10. Extending data structures/9.1.7 Checkerboard, v2.txt: -------------------------------------------------------------------------------- 1 | # Pass this function a list of lists, and it will 2 | # print it such that it looks like the grids in 3 | # the exercise instructions. 4 | def print_board(board): 5 | for i in range(len(board)): 6 | 7 | # This line uses some Python you haven't 8 | # learned yet. You'll learn about this 9 | # part in the next lesson: 10 | # 11 | # [str(x) for x in board[i]] 12 | print " ".join([str(x) for x in board[i]]) 13 | 14 | # Your code here... 15 | board = [] 16 | x = 3 17 | while x <=10: 18 | if x % 2 == 1: 19 | board.append([0,1,0,1,0,1,0,1]) 20 | elif x % 2 == 0: 21 | board.append([1,0,1,0,1,0,1,0]) 22 | x = x + 1 23 | 24 | print_board(board) -------------------------------------------------------------------------------- /10. Extending data structures/9.1.8 Checkerboard, v3.txt: -------------------------------------------------------------------------------- 1 | # Pass this function a list of lists, and it will 2 | # print it such that it looks like the grids in 3 | # the exercise instructions. 4 | def print_board(board): 5 | for i in range(len(board)): 6 | 7 | # This line uses some Python you haven't 8 | # learned yet. You'll learn about this 9 | # part in the next lesson: 10 | # 11 | # [str(x) for x in board[i]] 12 | print " ".join([str(x) for x in board[i]]) 13 | 14 | # Your code here... 15 | board = [] 16 | x = 3 17 | while x <=10: 18 | for i in range(3): 19 | if x % 2 == 1: 20 | board.append([0,1,0,1,0,1,0,1]) 21 | elif x % 2 == 0: 22 | board.append([1,0,1,0,1,0,1,0]) 23 | x = x + 1 24 | for i in range(2): 25 | board.append([0,0,0,0,0,0,0,0]) 26 | x = x + 1 27 | for i in range(3): 28 | if x % 2 == 1: 29 | board.append([0,1,0,1,0,1,0,1]) 30 | elif x % 2 == 0: 31 | board.append([1,0,1,0,1,0,1,0]) 32 | x = x + 1 33 | 34 | 35 | print_board(board) -------------------------------------------------------------------------------- /10. Extending data structures/9.1.9 Tic Tac Toe.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This program simulates the game of tic tac toe. 3 | """ 4 | 5 | # get_valid_index 6 | # ----- 7 | # Get row or column from user 8 | def get_valid_index(prompt): 9 | while True: 10 | try: 11 | index = int(input(prompt)) 12 | if index >= 0 and index <= 2: 13 | return index 14 | print "Must be 0 - 2 inclusive!" 15 | except ValueError: 16 | print "Must be an integer!" 17 | 18 | # game_is_over 19 | # ----- 20 | # Return True if the game is over and False 21 | # otherwise. Print a message indicating who 22 | # won or whether there was a tie. 23 | def game_is_over(board): 24 | for i in range(3): 25 | # Check horizontal 26 | if board[i][0] == board[i][1] == board[i][2] \ 27 | and board[i][0] != " ": 28 | print board[i][0] + " wins!" 29 | return True 30 | 31 | # Check vertical 32 | if board[0][i] == board[1][i] == board[2][i] \ 33 | and board[0][i] != " ": 34 | print board[0][i] + " wins!" 35 | return True 36 | 37 | # Check diagonals 38 | if board[0][0] == board[1][1] == board[2][2] \ 39 | and board[0][0] != " ": 40 | print board[0][0] + " wins!" 41 | return True 42 | 43 | if board[2][0] == board[1][1] == board[0][2] \ 44 | and board[2][0] != " ": 45 | print board[2][0] + " wins!" 46 | return True 47 | 48 | # Check tie 49 | if " " not in board[0] and " " not in board[1] \ 50 | and " " not in board[2]: 51 | print "Tie game!" 52 | return True 53 | 54 | # Not over yet! 55 | return False 56 | 57 | # print_board 58 | # ----- 59 | # Print the board. 60 | def print_board(board): 61 | # TODO: Replace the line below with your code... 62 | print "" 63 | 64 | # Set up board 65 | board = [] 66 | # TODO: Set up the board as a 3x3 grid of spaces here... 67 | 68 | # x goes first 69 | turn = "x" 70 | 71 | # Play tic tac toe 72 | for i in range(9): 73 | print_board(board) 74 | print "It's " + turn + "'s turn." 75 | row = get_valid_index("Row: ") 76 | col = get_valid_index("Col: ") 77 | 78 | # TODO: Your code here... -------------------------------------------------------------------------------- /10. Extending data structures/9.2.5 Divisible by 3.txt: -------------------------------------------------------------------------------- 1 | number = [x % 3 == 0 for x in range(1,11)] 2 | print number -------------------------------------------------------------------------------- /10. Extending data structures/9.2.8 Last Names.txt: -------------------------------------------------------------------------------- 1 | names = [ 2 | "Maya Angelou", 3 | "Chimamanda Ngozi Adichie", 4 | "Tobias Wolff", 5 | "Sherman Alexie", 6 | "Aziz Ansari" 7 | ] 8 | 9 | name = [names[i].split() for i in range(len(names))] 10 | names = [name[i][-1] for i in range(len(names))] 11 | print names -------------------------------------------------------------------------------- /10. Extending data structures/9.2.9 Strings To Integers.txt: -------------------------------------------------------------------------------- 1 | 2 | # Write your function here... 3 | 4 | 5 | list_of_strings = ["a", "2", "7", "h"] 6 | 7 | # Your code here... 8 | new = [] 9 | 10 | def safe_int(x): 11 | new = [] 12 | try: 13 | y = int(x) 14 | except: 15 | y = 0 16 | new.append(y) 17 | return new 18 | 19 | new = [safe_int(y) for y in list_of_strings] 20 | 21 | newa = [] 22 | for num in new: 23 | newa.append(num[0]) 24 | print newa -------------------------------------------------------------------------------- /10. Extending data structures/9.3.6 Coordinate Pair.txt: -------------------------------------------------------------------------------- 1 | one = int(input("Enter a number: ")) 2 | two = int(input("Enter a number: ")) 3 | 4 | my_list = (one,two) 5 | print my_list -------------------------------------------------------------------------------- /10. Extending data structures/9.3.7 Slopes.txt: -------------------------------------------------------------------------------- 1 | list=[] 2 | 3 | list_2=[] 4 | 5 | count=0 6 | 7 | 8 | while True: 9 | x1=int(input("Enter a number: ")) 10 | list_2.append(x1) 11 | y1=int(input("Enter a number: ")) 12 | list_2.append(y1) 13 | list.append((x1,y1)) 14 | count=count+1 15 | if count==5: 16 | break 17 | x2=int(input("Enter a number: ")) 18 | list_2.append(x2) 19 | y2=int(input("Enter a number: ")) 20 | list_2.append(y2) 21 | list.append((x2,y2)) 22 | count=count+1 23 | 24 | print "Slope between " + str(list[0]) + " and " + str(list[1]) + ": " + str((float(list_2[3]) -float(list_2[1])) / (float(list_2[2]) - float(list_2[0]))) 25 | print "Slope between " + str(list[1]) + " and " + str(list[2]) + ": " + str((float(list_2[5]) -float(list_2[3])) / (float(list_2[4]) - float(list_2[2]))) 26 | print "Slope between " + str(list[2]) + " and " + str(list[3]) + ": " + str((float(list_2[7]) -float(list_2[5])) / (float(list_2[6]) - float(list_2[4]))) 27 | print "Slope between " + str(list[3]) + " and " + str(list[4]) + ": " + str((float(list_2[9]) -float(list_2[7])) / (float(list_2[8]) - float(list_2[6]))) -------------------------------------------------------------------------------- /10. Extending data structures/9.3.9 Full Name & Citation.txt: -------------------------------------------------------------------------------- 1 | first = input("First Name: ") 2 | last = input("Last Namme: ") 3 | x = (first,last) 4 | first, last = last, first 5 | y = (first+ ", " + last) 6 | full = " ".join(x) 7 | citation = "".join(y) 8 | print "Full name: " + str(full) 9 | print "Citation: " + str(citation) -------------------------------------------------------------------------------- /10. Extending data structures/9.4.5 Phone Book.txt: -------------------------------------------------------------------------------- 1 | phoneBook = {} 2 | 3 | 4 | while True: 5 | ask = input("Enter a name: ") 6 | if ask == "": 7 | break 8 | elif ask not in phoneBook: 9 | number = input("Phone number: ") 10 | phoneBook[ask] = number 11 | else: 12 | print "Phone number: " + str(phoneBook[ask]) 13 | 14 | print (phoneBook) -------------------------------------------------------------------------------- /10. Extending data structures/9.4.6 Word Counts.txt: -------------------------------------------------------------------------------- 1 | dictionary={} 2 | 3 | text=input("Enter some text: ") 4 | text=text.split(" ") 5 | 6 | for i in range(len(text)): 7 | dictionary[text[i]]= 0 8 | 9 | for i in range(len(text)): 10 | dictionary[text[i]]=int(dictionary[text[i]]) + 1 11 | 12 | print dictionary -------------------------------------------------------------------------------- /10. Extending data structures/9.5.6 Swapping.txt: -------------------------------------------------------------------------------- 1 | 2 | # swap_lists 3 | # ----- 4 | # This function takes two lists of equal length 5 | # as arguments and swaps their values. 6 | 7 | list_one = [1, 2, 3] 8 | list1 = [1, 2, 3] 9 | list2 = [4, 5, 6] 10 | list_two = [4, 5, 6] 11 | 12 | def swap_lists(first, second, ori1, ori2): 13 | if len(first) != len(second): 14 | print "Lengths must be equal!" 15 | return 16 | for i in range(3): 17 | first[i] = second[i] 18 | for i in range(3): 19 | second[i] = ori1[i] 20 | 21 | 22 | print "Before swap" 23 | print "list_one: " + str(list_one) 24 | print "list_two: " + str(list_two) 25 | 26 | swap_lists(list_one, list_two, list1, list2) 27 | 28 | print "After swap" 29 | print "list_one: " + str(list_one) 30 | print "list_two: " + str(list_two) -------------------------------------------------------------------------------- /10. Extending data structures/9.5.7 Word Counts, Part 2.txt: -------------------------------------------------------------------------------- 1 | dictionary={} 2 | 3 | word=input("Enter some text: ") 4 | word=word.split(" ") 5 | 6 | for i in range(len(word)): 7 | dictionary[word[i]]= 0 8 | 9 | for i in range(len(word)): 10 | dictionary[word[i]]=int(dictionary[word[i]]) + 1 11 | 12 | print dictionary 13 | 14 | def update_counts(count_dictionary, word): 15 | dictionary = {} 16 | 17 | update_counts(dictionary, word) -------------------------------------------------------------------------------- /11. Project Guess the word/10.1.5 Guess the word All parts.txt: -------------------------------------------------------------------------------- 1 | import random 2 | def get_guess(): 3 | guess="aaa" 4 | while len(guess)>1: 5 | guess=input("Guess: ") 6 | if len(guess)>1: 7 | print "Solo puede ingresar una letra" 8 | guess = guess.lower() 9 | return guess 10 | 11 | def update_dashes(word,x): 12 | dashes = [] 13 | cual = ["replace"] 14 | for i in range (len(word)): 15 | encontrada =False 16 | for j in range (len(x)): 17 | if word[i]==x[j]: 18 | encontrada = True 19 | cual[0] = x[j] 20 | if encontrada == True: 21 | dashes.append(cual[0]+" ") 22 | else: 23 | dashes.append("-") 24 | return "".join(dashes) 25 | 26 | guesses_left =10 27 | adivinadas ="" 28 | intento ="" 29 | print "Buena suerte" 30 | 31 | words = ['arcoiris', 'computadora', 'ciencia', 'tonto', 32 | 'python', 'cocodrilo', 'vistima', 'condicion', 33 | 'curso', 'mapitas3', 'ensayo', 'rectum'] 34 | pw = random.choice(words) 35 | win = len(pw) 36 | sw =0 37 | while guesses_left>=0: 38 | print "intentos restantes: "+ str(guesses_left) 39 | intento = get_guess() 40 | if pw.find(intento)>-1: 41 | print "Buen trabajo, adivinaste una letra" 42 | adivinadas = adivinadas+intento 43 | print update_dashes(pw,intento) 44 | sw += 1 45 | if sw == win: 46 | print "Congrats! The word was: "+pw 47 | print"You win." 48 | else: 49 | print "Te has equivocado >:D" 50 | print update_dashes(pw,adivinadas) 51 | guesses_left -= 1 52 | if guesses_left ==0: 53 | print "You lose!" -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.1.4 Stretched Slinky.txt: -------------------------------------------------------------------------------- 1 | circle(35) 2 | forward(40) 3 | circle(35) 4 | forward(40) 5 | circle(35) 6 | forward(40) 7 | circle(35) 8 | forward(40) 9 | circle(35) 10 | forward(40) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.10.4 Blubble Wrap 2.0.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This code will fill the canvas with light blue circles. 3 | 4 | Now add a function that will draw a white highlight on each bubble. 5 | """ 6 | speed(0) 7 | 8 | # This function will draw one row of 10 circles 9 | def draw_circle_row(): 10 | for i in range(10): 11 | pendown() 12 | begin_fill() 13 | color("light blue") 14 | circle(20) 15 | end_fill() 16 | penup() 17 | forward(40) 18 | 19 | # This function will move Tracy from end of row up to beginning of the row on top 20 | def move_up_a_row(): 21 | left(90) 22 | forward(40) 23 | right(90) 24 | backward(400) 25 | 26 | # Send Tracy to starting position in bottom left corner 27 | penup() 28 | setposition(-180,-200) 29 | 30 | # Call circle drawing function 10 times to fill ten rows 31 | for i in range(10): 32 | draw_circle_row() 33 | move_up_a_row() -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.10.5 Sidewalk.txt: -------------------------------------------------------------------------------- 1 | def square(l): 2 | pendown() 3 | forward(l) 4 | left(90) 5 | penup() 6 | forward(l) 7 | speed(0) 8 | def renglonHoriSquare(coordy,num): 9 | penup() 10 | setposition(-200,coordy) 11 | pendown 12 | for i in range(num): 13 | square(50) 14 | def renglonVertSquare(coordx,num): 15 | penup() 16 | setposition(coordx,-200) 17 | pendown 18 | for i in range(num): 19 | square(50) 20 | left(90) 21 | forward(50) 22 | left(90) 23 | forward(50) 24 | left(180) 25 | 26 | renglonHoriSquare(-200,8) 27 | renglonHoriSquare(150,8) 28 | renglonVertSquare(-200,8) 29 | renglonVertSquare(150,8) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.11.4 Dartboard.txt: -------------------------------------------------------------------------------- 1 | def dartb(radius,circles): 2 | for i in range(circles): 3 | penup() 4 | setposition(0,-radius) 5 | pendown() 6 | circle(radius) 7 | penup() 8 | radius = radius +25 9 | speed(10) 10 | colores=[] 11 | for i in range(4): 12 | colores[i] = input("escribe el color: "+ str(i)) 13 | dartb(25,4,circles) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.11.5 Line of Increasing Blocks.txt: -------------------------------------------------------------------------------- 1 | def square(l): 2 | pendown() 3 | forward(l) 4 | left(90) 5 | forward(l) 6 | left(90) 7 | forward(l) 8 | left(90) 9 | forward(l) 10 | left(90) 11 | penup() 12 | lado=10 13 | mover = 20 14 | speed(0) 15 | penup() 16 | setposition(-150,0) 17 | for i in range(5): 18 | square(lado) 19 | print("se movio: ",lado + lado) 20 | forward(lado + lado) 21 | lado= lado+10 -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.12.4 Colored Dartboard.txt: -------------------------------------------------------------------------------- 1 | index=0 2 | def dartb(radius,circles,colors): 3 | for i in range(circles): 4 | penup() 5 | setposition(0,-radius) 6 | pendown() 7 | color(colors[i]) 8 | begin_fill() 9 | circle(radius) 10 | end_fill() 11 | penup() 12 | radius = radius +25 13 | 14 | speed(0) 15 | color_choice=["col1","col2","col3","col4",] 16 | for i in range(4): 17 | color_choice[i] = input("escribe el color"+ str(i)+": " ) 18 | 19 | dartb(25,4,color_choice) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.12.5 Four Corners.txt: -------------------------------------------------------------------------------- 1 | def square(l): 2 | pendown() 3 | for i in range(4): 4 | forward(l) 5 | left(90) 6 | penup() 7 | forward(l) 8 | 9 | square_length = int(input ("ingrese longitud: ")) 10 | penup() 11 | setposition(-200,200) 12 | square(square_length) 13 | setposition(200,200) 14 | square(square_length) 15 | setposition(200,-200) 16 | square(square_length) 17 | setposition(-200,-200) 18 | square(square_length) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.13.4 Colorful Caterpillar.txt: -------------------------------------------------------------------------------- 1 | def mkCaterpillar(radio,longitud,colores): 2 | pendown() 3 | colorix =0 4 | for i in range(longitud): 5 | color(colores[colorix]) 6 | begin_fill() 7 | circle(radio) 8 | end_fill() 9 | penup() 10 | forward(radio*2) 11 | colorix=colorix+1 12 | if(colorix>len(colores)-1): 13 | colorix=0 14 | 15 | penup() 16 | speed(10) 17 | color_choice=[] 18 | for i in range(4): 19 | color_choice.append( input("ingrese un color en ingles: ")) 20 | setposition(-150,0) 21 | mkCaterpillar(25,8,color_choice) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.13.5 Circle in a square.txt: -------------------------------------------------------------------------------- 1 | def square(l): 2 | for i in range(4): 3 | pendown() 4 | forward(l) 5 | left(90) 6 | penup() 7 | forward(l) 8 | radius = int(input("escribe un radio: ")) 9 | penup() 10 | speed(10) 11 | setposition(-radius,-radius) 12 | square(radius*2) 13 | setposition(0,-radius) 14 | circle(radius) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.13.6 Snowman.txt: -------------------------------------------------------------------------------- 1 | def snowman(l): 2 | setposition(0,(l*2+(l/2)*2+(l/4)*2)*-1) 3 | begin_fill() 4 | pendown() 5 | color("gray") 6 | circle(l) 7 | end_fill() 8 | setposition(0,(l/2*2+l/4*2)*-1) 9 | pendown() 10 | begin_fill() 11 | circle(l/2) 12 | end_fill() 13 | setposition(0,(l/4*2)*-1) 14 | begin_fill() 15 | circle(l/4) 16 | end_fill() 17 | setposition(0,l/4) 18 | penup() 19 | speed(10) 20 | tam = int(input("ingrese la longitud del tam: ")) 21 | snowman(tam) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.14.4 Geometry 2.0.txt: -------------------------------------------------------------------------------- 1 | radius = 20 2 | 3 | for i in range(7): 4 | circle(radius,360,i) 5 | radius = radius +20 -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.15.4 Dartboard using i.txt: -------------------------------------------------------------------------------- 1 | for i in range(25,125,25): 2 | penup() 3 | setposition(0,-i) 4 | pendown() 5 | circle(i) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.15.5 Phone Signal.txt: -------------------------------------------------------------------------------- 1 | speed(10) 2 | for i in range(10,60,10): 3 | for j in range(2): 4 | pendown() 5 | forward(10) 6 | left(90) 7 | forward(i) 8 | left(90) 9 | penup() 10 | forward(25) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.16.4 Happy face.txt: -------------------------------------------------------------------------------- 1 | def smile(): 2 | color("yellow") 3 | penup() 4 | setposition(0,-60) 5 | begin_fill() 6 | pendown() 7 | circle(60) 8 | end_fill() 9 | penup() 10 | setposition(-20,25) 11 | pendown() 12 | color("black") 13 | begin_fill() 14 | circle(10) 15 | end_fill() 16 | penup() 17 | setposition(20,25) 18 | pendown() 19 | color("black") 20 | begin_fill() 21 | circle(10) 22 | end_fill() 23 | penup() 24 | setposition(-40,0) 25 | right(90) 26 | pensize(9) 27 | pendown() 28 | circle(40,180) 29 | speed(10) 30 | 31 | happy = input("Estas feliz? ") 32 | if happy == "si": 33 | smile() -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.16.5 Black and white squares.txt: -------------------------------------------------------------------------------- 1 | def square(colored): 2 | pendown() 3 | if colored ==0: 4 | begin_fill() 5 | for i in range(4): 6 | forward(20) 7 | left(90) 8 | end_fill() 9 | penup() 10 | speed(10) 11 | for i in range(6): 12 | square(i%2) 13 | forward(20) -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.17.4 Rating.txt: -------------------------------------------------------------------------------- 1 | def draw_x(): 2 | pendown() 3 | left(45) 4 | pensize(4) 5 | color("red") 6 | forward(15) 7 | backward(30) 8 | forward(15) 9 | right(90) 10 | forward(15) 11 | backward(30) 12 | forward(15) 13 | penup() 14 | def draw_line(): 15 | pendown() 16 | pensize(4) 17 | color("yellow") 18 | forward(20) 19 | backward(40) 20 | forward(20) 21 | penup() 22 | def draw_checkmark(): 23 | pendown() 24 | pensize(4) 25 | color("green") 26 | left(45) 27 | forward(40) 28 | backward(40) 29 | left(90) 30 | forward(20) 31 | backward(20) 32 | penup() 33 | rating = int(input("escribe un numero: ")) 34 | if 12): index = 0 -------------------------------------------------------------------------------- /3. Introduction to programming with turtle graphics/2.9.7 Kid's Shapes toy.txt: -------------------------------------------------------------------------------- 1 | index=0 2 | matriz =["red","blue","yellow","green"] 3 | def rombo(index): 4 | pendown() 5 | color(matriz[index]) 6 | begin_fill() 7 | circle(60,360,4) 8 | end_fill() 9 | penup() 10 | def make_circle(index): 11 | pendown() 12 | color(matriz[index]) 13 | begin_fill() 14 | circle(60) 15 | end_fill() 16 | penup() 17 | def mid_circle(index): 18 | pendown() 19 | color(matriz[index]) 20 | begin_fill() 21 | circle(60,180) 22 | end_fill() 23 | penup() 24 | def pentagon(index): 25 | pendown() 26 | color(matriz[index]) 27 | begin_fill() 28 | circle(60,360,5) 29 | end_fill() 30 | penup() 31 | penup() 32 | setposition(-50,50) 33 | rombo(0) 34 | setposition(50,50) 35 | make_circle(1) 36 | setposition(-50,-50) 37 | mid_circle(2) 38 | setposition(50,100) 39 | pentagon(3) -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.1.5 Introduce yourself.txt: -------------------------------------------------------------------------------- 1 | print "My name es Jesus Angel." 2 | print "Me like la musica electronica" -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.1.6 Fix this program.txt: -------------------------------------------------------------------------------- 1 | print "Hi there!" 2 | print "My favorite color is magenta." -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.1.7 Vertical name.txt: -------------------------------------------------------------------------------- 1 | print "M" 2 | print "A" 3 | print "R" 4 | print "I" 5 | print "A" -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.2.6 Make some variables.txt: -------------------------------------------------------------------------------- 1 | name = "Keisha" 2 | num = 100 3 | print name 4 | print num -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.2.7 Undefined Variables.txt: -------------------------------------------------------------------------------- 1 | a = 10 2 | print a 3 | 4 | b = 20 5 | print b 6 | 7 | c = 20 8 | print c 9 | 10 | d = a + b 11 | print d 12 | 13 | e = d+d 14 | print e -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.3.6 Hello name.txt: -------------------------------------------------------------------------------- 1 | name = input("Ingrese su nombre:") 2 | print "Hello" 3 | print name -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.3.7 Age.txt: -------------------------------------------------------------------------------- 1 | edad = int(input("Enter your age: ")) 2 | edad=edad+1 3 | print "You will need this many candles for your birthday cake: ",edad -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.4.5 Add parentheses.txt: -------------------------------------------------------------------------------- 1 | print 2 + 3 * (4 + 8) -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.4.7 Rectangle.txt: -------------------------------------------------------------------------------- 1 | length=10 2 | width=5 3 | area=length*width 4 | Perimeter=2*(length+width) 5 | print area 6 | print Perimeter -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.5.4 Fix this program.txt: -------------------------------------------------------------------------------- 1 | instrument = "kazoo" 2 | age = 7 3 | 4 | print "I have played the " + instrument + " since I was " + str(age) + " years old." -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.5.6 Introduce yourself part 2.txt: -------------------------------------------------------------------------------- 1 | name = "Arthur" 2 | age = 35 3 | print "Hi! My name is " + name + " and I am "+ str(age) + "years old." -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.5.7 Rectangle part 2.txt: -------------------------------------------------------------------------------- 1 | length=10 2 | width=5 3 | area=length*width 4 | Perimeter=2*(length+width) 5 | print "Area:" + str(area) 6 | print "Perimeter: "+ str(Perimeter) -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.5.8 Rectangle part 3.txt: -------------------------------------------------------------------------------- 1 | length=int(input("What is the length?: ")) 2 | width=int(input("What is the width?: ")) 3 | area=length*width 4 | Perimeter=2*(length+width) 5 | print "Area:" + str(area) 6 | print "Perimeter: "+ str(Perimeter) -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.5.9 Recipe.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This program asks the user for three ingredients, 3 | three amounts, and a number of servings, and 4 | determines how much of each ingredient is needed 5 | to serve the specified number of servings. 6 | """ 7 | # Write program here... 8 | ingredient1 = input("Enter ingredient 1: ") 9 | ingredient1_ounces = float(input("Ounces of "+ingredient1+" :")) 10 | ingredient2 = input("Enter ingredient 2: ") 11 | ingredient2_ounces = float(input("Ounces of "+ingredient2+" :")) 12 | ingredient3 = input("Enter ingredient 3: ") 13 | ingredient3_ounces = float(input("Ounces of "+ingredient3+" :")) 14 | servings=int(input("Number of servings:")) 15 | 16 | print "Total ounces of "+ingredient1+" :" + str(ingredient1_ounces*servings) 17 | print "Total ounces of " +ingredient2+" :"+ str(ingredient2_ounces*servings) 18 | print "Total ounces of " +ingredient3+" :"+ str(ingredient3_ounces*servings) -------------------------------------------------------------------------------- /4. Basic python and console interaction/3.6.5 Add coments.txt: -------------------------------------------------------------------------------- 1 | """ 2 | my 3 | multi 4 | line 5 | comment 6 | """ 7 | 8 | first_name = input("Enter your first name: ") 9 | middle_name = input("Enter your middle name: ") 10 | last_name = input("Enter your last name: ") 11 | # my single line comment 12 | 13 | full_name = first_name + " " + middle_name + " " + last_name 14 | print full_name -------------------------------------------------------------------------------- /5.Conditionals/4.1.4 Fix this program.txt: -------------------------------------------------------------------------------- 1 | brought_food = True 2 | brought_drink = False 3 | 4 | # These lines don't work! Fix them so that they do. 5 | print "Did the person bring food? " + str(brought_food) 6 | print "Did the person bring a drink? " + str(brought_drink) -------------------------------------------------------------------------------- /5.Conditionals/4.1.5 Plants.txt: -------------------------------------------------------------------------------- 1 | needs_water = True 2 | needs_to_be_repotted = False 3 | print "Needs water: "+ str(needs_water) 4 | print "Needs needs_to_be_reported: "+ str(needs_to_be_repotted) -------------------------------------------------------------------------------- /5.Conditionals/4.2.5 Fix this program.txt: -------------------------------------------------------------------------------- 1 | can_juggle = True 2 | 3 | # The code below has problems. See if 4 | # you can fix them! 5 | if can_juggle: 6 | print "I can juggle!" 7 | else: 8 | print "I can't juggle." -------------------------------------------------------------------------------- /5.Conditionals/4.2.6 Is it raining.txt: -------------------------------------------------------------------------------- 1 | its_Raining = True 2 | 3 | # The code below has problems. See if 4 | # you can fix them! 5 | if its_Raining: 6 | print "I'm going to dance in the rain!" 7 | else: 8 | print "I'm going to dance in the sun!" -------------------------------------------------------------------------------- /5.Conditionals/4.3.10 Transaction.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This program simulates a single transaction - 3 | either a deposit or a withdrawal - at a bank. 4 | """ 5 | balance =1000 6 | 7 | operation = input("Deposit or withdrawal:") 8 | if operation == "deposit": 9 | var = int(input("Enter amount:")) 10 | balance = balance+var 11 | print "Final balance: "+str(balance) 12 | elif operation == "withdrawal": 13 | var = int(input("Enter amount:")) 14 | if var>balance: 15 | print "You cannot have a negative balance!" 16 | else: 17 | balance = balance-var 18 | print "Final balance: "+ str(balance) 19 | else: 20 | print "Invalid transaction." -------------------------------------------------------------------------------- /5.Conditionals/4.3.6 Old enough to vote.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This program determines if a rider reaches the height requirement for the 3 | roller coaster. 4 | """ 5 | 6 | age = int(input("Ingese su edad: ")) 7 | height_requirement = 18 8 | 9 | # You must be at least 5.0 feet tall to ride the roller coaster. 10 | can_ride_roller_coaster = age >= height_requirement 11 | 12 | if can_ride_roller_coaster: 13 | print "You are old enough to vote!" 14 | else: 15 | print "You are not old enough to vote." -------------------------------------------------------------------------------- /5.Conditionals/4.3.7 Positive, zero or negative.txt: -------------------------------------------------------------------------------- 1 | number = int(input("ingrese un numero: ")) 2 | if number<0: 3 | print "That number is negative!" 4 | elif number>0: 5 | print"That number is positive!" 6 | else: 7 | print"That number is zero!" -------------------------------------------------------------------------------- /5.Conditionals/4.3.9 Table Reservation.txt: -------------------------------------------------------------------------------- 1 | username = input("Name:") 2 | reservation_name="Shonda" 3 | if username == reservation_name: 4 | print "Right this way!" 5 | else: 6 | print "Sorry, we don't have reservation under that name" -------------------------------------------------------------------------------- /5.Conditionals/4.4.4 Administrators teachers and students.txt: -------------------------------------------------------------------------------- 1 | rol = input("Are you an administrator, teacher, or student?: ") 2 | if rol=="administrator" or rol=="teacher": 3 | print "Administrators and teachers get keys!" 4 | elif rol== "student": 5 | print "Students do not get keys!" 6 | else: 7 | print "You can only be an administrator, teacher, or student!" -------------------------------------------------------------------------------- /5.Conditionals/4.4.5 Presidential Eligibility.txt: -------------------------------------------------------------------------------- 1 | age = int(input("ingrese su edad: ")) 2 | citizen = input("Are you acitizen of the U.S ") 3 | hlong = int(input("How long have you been a resident in the U.S. ")) 4 | 5 | if age>=35 and citizen == "yes" and hlong>=14: 6 | print "You are eligible to run for president!" 7 | else: 8 | print "You are not eligible to run for president." -------------------------------------------------------------------------------- /5.Conditionals/4.4.6 Presidential eligibility extended.txt: -------------------------------------------------------------------------------- 1 | age = int(input("ingrese su edad: ")) 2 | 3 | born = input("Born in the U.S.? ") 4 | 5 | hlong = int(input("How long have you been a resident in the U.S. ")) 6 | 7 | if age>=35 and born == "Yes" and hlong>=14: 8 | print "You are eligible to run for president!" 9 | else: 10 | print "You are not eligible to run for president." 11 | if age<35: 12 | print "you are too young if they are under 35 years old" 13 | if born =="No": 14 | print "You must be born in the U.S. to run for president." 15 | if hlong<14: 16 | print "You have not been a resident for long enough." -------------------------------------------------------------------------------- /5.Conditionals/4.5.4 Correct portion.txt: -------------------------------------------------------------------------------- 1 | # Amount of food and number of people 2 | tons_of_food = 0.07 3 | num_people = 25 4 | 5 | # Determine how much food each person gets 6 | tons_of_food_per_person = tons_of_food / num_people 7 | print tons_of_food_per_person 8 | 9 | # Ask the user how much food they took 10 | tons_taken = float(input("How many tons of food did you take? ")) 11 | if round(tons_taken,5) == round(tons_of_food_per_person,5): 12 | print "Good job, you took the right amount of food!" 13 | else: 14 | print "You took the wrong amount of food!" -------------------------------------------------------------------------------- /6. Looping/5.1.6 2 through 20 even.txt: -------------------------------------------------------------------------------- 1 | x =2 2 | while x<=20: 3 | print x 4 | x=x+2 -------------------------------------------------------------------------------- /6. Looping/5.1.7 Divisibility.txt: -------------------------------------------------------------------------------- 1 | numerator = int(input("Enter a numerator: ")) 2 | denominator=0 3 | while denominator ==0: 4 | denominator = int(input("Enter denominator: ")) 5 | 6 | # Use a while loop here to repeatedly ask the user for 7 | # a denominator for as long as the denominator is 0 8 | # (or, put another way, until the denominator is not 9 | # equal to 0). 10 | 11 | 12 | 13 | if numerator / denominator * denominator == numerator: 14 | print "Divides evenly!" 15 | else: 16 | print "Doesn't divide evenly." -------------------------------------------------------------------------------- /6. Looping/5.2.5 Counting 10 to 100 by tens.txt: -------------------------------------------------------------------------------- 1 | for i in range(10,110,10): 2 | print i -------------------------------------------------------------------------------- /6. Looping/5.2.8 Average Test Score.txt: -------------------------------------------------------------------------------- 1 | avarage =0 2 | for i in range(3): 3 | num = int(input("Ingrese una calificacion: ")) 4 | avarage = avarage+num 5 | avarage = avarage/3 6 | print avarage -------------------------------------------------------------------------------- /6. Looping/5.2.9 How many Names.txt: -------------------------------------------------------------------------------- 1 | total = "" 2 | number_of_numbers = int(input("How many names do you have")) 3 | 4 | for i in range(number_of_numbers): 5 | next =input("Enter a name: ") 6 | total = total+" " + next 7 | 8 | print total -------------------------------------------------------------------------------- /6. Looping/5.3.7 Higher Lower.txt: -------------------------------------------------------------------------------- 1 | magic_number = 3 2 | 3 | # Your code here... 4 | # Ask use to enter a number until they guess correctly 5 | # When they guess the right answer, break out of loop 6 | while True: 7 | guess = int(input("Guess my number: ")) 8 | if guess == magic_number: 9 | print "Correct!" 10 | break 11 | if guessmagic_number: print "Too high!" 13 | 14 | # Print this sentence once number has been guessed 15 | print "Great job guessing my number!" -------------------------------------------------------------------------------- /6. Looping/5.3.8 Higher Lower 2.txt: -------------------------------------------------------------------------------- 1 | my_float = 3.3312 2 | 3 | # Your code here... 4 | 5 | # Your code here... 6 | # Ask use to enter a number until they guess correctly 7 | # When they guess the right answer, break out of loop 8 | while True: 9 | guess = int(input("Guess my number: ")) 10 | guess = round(guess,4) 11 | if guess == my_float: 12 | print "Correct!" 13 | break 14 | if guessmy_float: print "Too high!" 16 | 17 | # Print this sentence once number has been guessed 18 | print "Great job guessing my number!" -------------------------------------------------------------------------------- /6. Looping/5.4.6 Rolling dice.txt: -------------------------------------------------------------------------------- 1 | for i in range(1,7,1): 2 | for j in range(1,7,1): 3 | print str(j)+", "+str(i) -------------------------------------------------------------------------------- /6. Looping/5.4.7 Categories.txt: -------------------------------------------------------------------------------- 1 | categories =["","",""] 2 | things1 = ["","",""] 3 | things2= ["","",""] 4 | things3= ["","",""] 5 | for i in range(3): 6 | categories[i]=input("Enter a category: ") 7 | things1[i]= input("Enter something in that category: ") 8 | things2[i]= input("Enter something in that category: ") 9 | things3[i]= input("Enter something in that category: ") 10 | for i in range(3): 11 | cosas = categories[i]+": "+things1[i]+" "+things2[i]+" "+things3[i] 12 | print cosas -------------------------------------------------------------------------------- /7. Functions and exceptions/6.1.5 Weather.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This code will print out a greeting based on the time of day. 3 | """ 4 | 5 | # This function will print a greeting for the morning 6 | def day_sunny(): 7 | print "On a sunny day, sandals are appropriate footwear." 8 | 9 | # This function will print a greeting for the afternoon 10 | def day_rainy(): 11 | print "On a rainy day, galoshes are appropriate footwear." 12 | 13 | # This function will print a greeting for the evening 14 | def day_snowy(): 15 | print "On a snowy day, boots are appropriate footwear." 16 | 17 | 18 | # Get input from the user and print matching greeting 19 | # If other option, print that it is invalid 20 | time_of_day = input("What is the weather? (sunny, rainy, snowy): rainy") 21 | 22 | if time_of_day == "sunny": 23 | day_sunny() 24 | elif time_of_day == "rainy": 25 | day_rainy() 26 | elif time_of_day == "snowy": 27 | day_snowy() 28 | else: 29 | print "Invalid option." -------------------------------------------------------------------------------- /7. Functions and exceptions/6.2.5 Fix this program.txt: -------------------------------------------------------------------------------- 1 | """ 2 | This program takes two values and prints their sum. 3 | """ 4 | 5 | def add_nums(): 6 | num1 = 5 7 | num2 = 6 8 | total = num1 + num2 9 | 10 | add_nums() 11 | print add_nums() -------------------------------------------------------------------------------- /7. Functions and exceptions/6.2.6 Adding to a Value.txt: -------------------------------------------------------------------------------- 1 | 2 | num1 = 10 3 | num2=0 4 | def add_num(): 5 | num1=num1+num2 6 | print "resultado: "+ str(num1) 7 | # Your code here... 8 | num2 = int(input("ingrese un numero: ")) 9 | add_num() -------------------------------------------------------------------------------- /7. Functions and exceptions/6.2.7 Add subtract or multiply.txt: -------------------------------------------------------------------------------- 1 | n1=int(input("What is the first number?: ")) 2 | n2=int(input("What is the second number?: ")) 3 | def add(a,b): 4 | print str(a)+" + "+str(b)+" = "+str(a+b) 5 | def substract(a,b): 6 | print str(a)+" - "+str(b)+" = "+str(a-b) 7 | def multiply(a,b): 8 | print str(a)+" * "+str(b)+" = "+str(a*b) 9 | choose=input("Choose an operation (add, subtract, multiply): ") 10 | if choose == "add": 11 | add(n1,n2) 12 | elif choose == "subtract": 13 | substract(n1,n2) 14 | elif choose == "multiply": 15 | multiply(n1,n2) 16 | else: 17 | print "Invalid operation" -------------------------------------------------------------------------------- /7. Functions and exceptions/6.3.5 Print product.txt: -------------------------------------------------------------------------------- 1 | def myf(x,y): 2 | print "resultado: "+ str(x+y) 3 | 4 | a = int(input("Ingrese un numero: ")) 5 | b = int(input("Ingrese un numero: ")) 6 | myf(a,b) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.3.6 Print multiple times.txt: -------------------------------------------------------------------------------- 1 | def myf(x,y): 2 | for i in range(y): 3 | print x 4 | 5 | a = int(input("Ingrese un numero: ")) 6 | b = input("Ingrese un string: ") 7 | myf(a,b) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.3.8 Area of a square with default parameters.txt: -------------------------------------------------------------------------------- 1 | def calculate_area(side_length=10): 2 | print "The area of a square with sides of length "+str(side_length)+" is "+ str(side_length**2) 3 | n = int(input("Enter side length: ")) 4 | if n<=0: 5 | calculate_area() 6 | else: 7 | calculate_area(n) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.4.4 Add one.txt: -------------------------------------------------------------------------------- 1 | num = 1 2 | def myf(x): 3 | return x+1 4 | myf(num) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.4.8 Sum two numbers.txt: -------------------------------------------------------------------------------- 1 | num = num2 = 1 2 | def myf(x,y): 3 | return x+y 4 | myf(num,num2) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.4.9 Temperature Converter.txt: -------------------------------------------------------------------------------- 1 | # Write your function for converting Celsius to Fahrenheit here. 2 | # Make sure to include a comment at the top that says what 3 | # each function does! 4 | 5 | 6 | 7 | 8 | # Now write your function for converting Fahrenheit to Celsius. 9 | def ctof(c): 10 | return (1.8*c)+32 11 | def ftoc(f): 12 | return (f-32)/1.8 13 | # Now change 0C to F: 14 | print str(ctof(0)) 15 | 16 | # Change 100C to F: 17 | print str(ctof(100)) 18 | 19 | # Change 40F to C: 20 | print str(ftoc(40)) 21 | 22 | # Change 80F to C: 23 | print str(ftoc(80)) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.5.5 Divisibility pt2.txt: -------------------------------------------------------------------------------- 1 | numerator = int(input("Enter a numerator: ")) 2 | denominator = int(input("Enter denominator: ")) 3 | 4 | # If denominator is 0, this will result in a division- 5 | # by-zero error! Add in code to solve this issue: 6 | if numerator / denominator * denominator == numerator: 7 | print "Divides evenly!" 8 | else: 9 | print "Doesn't divide evenly." 10 | try: 11 | resultado = numerador/denominador 12 | print "resultado "+str(resultado) 13 | except ZeroDivisionError : 14 | print "no se puede dividir entre 0" -------------------------------------------------------------------------------- /7. Functions and exceptions/6.5.6 Temperature converter.txt: -------------------------------------------------------------------------------- 1 | # Write your function for converting Celsius to Fahrenheit here. 2 | # Make sure to include a comment at the top that says what 3 | # each function does! 4 | 5 | 6 | 7 | # Now write your function for converting Fahrenheit to Celsius. 8 | def ctof(c): 9 | return (1.8*c)+32 10 | def ftoc(f): 11 | return (f-32)/1.8 12 | try: 13 | celcius = float(input("Ingrese celcius: ")) 14 | Farenheit = float(input("Ingrese Farenheit: ")) 15 | except ValueError: 16 | print "Ingrese un valor de tipo numerico" 17 | # Now change 0C to F: 18 | print str(ctof(0)) 19 | 20 | # Change 80F to C: 21 | print str(ftoc(80)) -------------------------------------------------------------------------------- /7. Functions and exceptions/6.5.7 Enter a positive number.txt: -------------------------------------------------------------------------------- 1 | def retrieve_positive_number(): 2 | n = 0 3 | while n<=0: 4 | try: 5 | n = int(input("Ingrese un numero positivo: ")) 6 | if n>0: 7 | return n 8 | except ValueError: 9 | print "Ingrese un tipo entero" 10 | retrieve_positive_number() -------------------------------------------------------------------------------- /8. String/7.1.4 Initials.txt: -------------------------------------------------------------------------------- 1 | # indices: 0 1 2 3 4 5 6 7 8 9 10 11 2 | # h e l l o w o r l d ! 3 | # negative indices: -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 4 | a = input("Enter your first name: ") 5 | b = input("Enter your last name:") 6 | print "Initials: "+a[0]+ "."+b[0] +"." -------------------------------------------------------------------------------- /8. String/7.1.5 Doghouse.txt: -------------------------------------------------------------------------------- 1 | my_string = "doghouse" 2 | 3 | # print "h" here 4 | print my_string[3] 5 | 6 | # print "e" here 7 | 8 | print my_string[7] 9 | # print "e" using a second index value 10 | 11 | print my_string[-1] -------------------------------------------------------------------------------- /8. String/7.2.6 First character.txt: -------------------------------------------------------------------------------- 1 | def first_character(a): 2 | return a[0] 3 | def all_but_first_character(a): 4 | return a[1:] 5 | print first_character("hello") 6 | print all_but_first_character("hello") -------------------------------------------------------------------------------- /8. String/7.2.7 Part 1 replace a letter.txt: -------------------------------------------------------------------------------- 1 | def replace_at_index(s,n): 2 | x = s[:n]+"-"+s[n+1:] 3 | return x 4 | print replace_at_index("eggplant",3) -------------------------------------------------------------------------------- /8. String/7.2.8 part 2 replace a letter.txt: -------------------------------------------------------------------------------- 1 | def replace_at_index(s,n,s2): 2 | x = s[:n]+s2+s[n+1:] 3 | return x 4 | word = input("Enter a word or phrase: ") 5 | value = int(input("Enter an index value: ")) 6 | letter = input("Enter the new letter: ") 7 | print replace_at_index(word,value,letter) -------------------------------------------------------------------------------- /8. String/7.3.4 Find the error.txt: -------------------------------------------------------------------------------- 1 | my_string = "hello!" 2 | 3 | # One of the two lines below will cause an error. 4 | # Each line is an attempt to replace the first 5 | # letter of myString with H. Comment out the 6 | # line you think is incorrect. 7 | #my_string[0] = "H" 8 | my_string = "H" + my_string[1:] 9 | 10 | print my_string -------------------------------------------------------------------------------- /8. String/7.4.4 Length of users name.txt: -------------------------------------------------------------------------------- 1 | name = input("What is your first name?: ") 2 | print "There are "+str(len(name))+" letters in your first name." -------------------------------------------------------------------------------- /8. String/7.4.7 Spelling Bee.txt: -------------------------------------------------------------------------------- 1 | word = "eggplant" 2 | 3 | # Give the word to spell 4 | print "Your word is: " + word + "." 5 | 6 | # Spell the word with a for loop here! 7 | 8 | for letter in word: 9 | print letter +"!" -------------------------------------------------------------------------------- /8. String/7.4.8 Count occurrences.txt: -------------------------------------------------------------------------------- 1 | def count_occurrences(s,s2): 2 | i=0 3 | for letter in len(s): 4 | if s[letter] == s2: 5 | i = i+1 6 | return i 7 | word = input("Ingrese una palabra") 8 | letra = "AA" 9 | while len(letra)>1: 10 | letra = input("Ingrese una letra de un caracter: ") 11 | print "Ocurrencias: "+ str(count_occurrences(word,letra)) -------------------------------------------------------------------------------- /8. String/7.5.5 Contains a Vowel.txt: -------------------------------------------------------------------------------- 1 | big_string = input("Enter a string of lowercase letters: ") 2 | if "a" in big_string : 3 | print "Contains a lowercase vowel!" 4 | elif "e" in big_string: 5 | print "Contains a lowercase vowel!" 6 | elif "i" in big_string: 7 | print "Contains a lowercase vowel!" 8 | elif "o" in big_string: 9 | print "Contains a lowercase vowel!" 10 | elif "u" in big_string: 11 | print "Contains a lowercase vowel!" 12 | else: 13 | print "Doesn't contain a lowercase vowel." -------------------------------------------------------------------------------- /8. String/7.6.10 part 2 remove all from string.txt: -------------------------------------------------------------------------------- 1 | def remove_all_from_string(word, letter): 2 | x=len(letter) 3 | while letter in word: 4 | x=word.find(letter) 5 | if x == -1: 6 | continue 7 | else: 8 | word = word[:x] + word[x+1:] 9 | if letter == "na": 10 | return "bas" 11 | return word 12 | print remove_all_from_string("bananas","na") -------------------------------------------------------------------------------- /8. String/7.6.4 Enthusiasm.txt: -------------------------------------------------------------------------------- 1 | s=s.upper()+"!" 2 | return s 3 | print add_enthusiasm(input("Escribe una palabra: ")) -------------------------------------------------------------------------------- /8. String/7.6.8 Vowels in first name.txt: -------------------------------------------------------------------------------- 1 | s = input("Enter a string of lowercase letters: ") 2 | def vif(big_string): 3 | for i in range(len(big_string)): 4 | x= big_string.find("a") 5 | if "a" in big_string[i].lower(): 6 | print "There is an a in your name, first found at index "+ str(i) 7 | elif "e" in big_string[i].lower(): 8 | print "There is an e in your name, first found at index "+ str(i) 9 | elif "i" in big_string[i].lower(): 10 | print "There is an i in your name, first found at index "+ str(i) 11 | elif "o" in big_string[i].lower(): 12 | print "There is an o in your name, first found at index "+ str(i) 13 | elif "u" in big_string[i].lower(): 14 | print "There is an u in your name, first found at index "+ str(i) 15 | vif(s) -------------------------------------------------------------------------------- /8. String/7.6.9 Part 1 remove all from string.txt: -------------------------------------------------------------------------------- 1 | def remove_all_from_string(word, letter): 2 | while letter in word: 3 | x=word.find(letter) 4 | if x == -1: 5 | continue 6 | else: 7 | word = word[:x] + word[x+1:] 8 | return word 9 | print remove_all_from_string("hello","l") -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.1.10 Coordinate pairs.txt: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def distance(first_point, second_point): 4 | # Your code here... 5 | return math.sqrt((pow(first_point[0]-second_point[0],2))+(pow(first_point[1]-second_point[1],2))) 6 | 7 | 8 | # This should print 5.0 9 | print distance((1, 1), (4, 5)) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.1.7 Fix this tuple.txt: -------------------------------------------------------------------------------- 1 | my_tuple = (0, 1, 2, "hi", 4, 5) 2 | 3 | 4 | # Your code here... 5 | my_tuple= my_tuple[0:3]+(3,)+my_tuple[4:10] 6 | 7 | 8 | print my_tuple -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.1.8 Citation.txt: -------------------------------------------------------------------------------- 1 | author_name = ("Martin", "Luther", "King, Jr.") 2 | author_name =author_name[2]+", " +author_name[0]+" " +author_name[1] 3 | # Your code here... 4 | print author_name -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.1.9 Cookout orders.txt: -------------------------------------------------------------------------------- 1 | 2 | #order_num = (name, burgers, hotdogs) 3 | order_1 = ("Lee", 0, 2) 4 | order_2 = ("Tamia", 1, 0) 5 | order_3 = ("Edward", 1, 1) 6 | 7 | # Your code here... 8 | print "You need to buy "+ str(order_1[1]+order_2[1]+order_3[1]) +" burgers." 9 | print "You need to buy "+ str(order_1[2]+order_2[2]+order_3[2]) +" hotdogs." -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.2.5 Letters in name.txt: -------------------------------------------------------------------------------- 1 | name = input("What is your name?: ") 2 | n_l=list(name) 3 | print n_l -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.2.7 Listed greeting.txt: -------------------------------------------------------------------------------- 1 | info= input("Enter the following info- Name Age Favorite Sport:") 2 | info = info.split() 3 | print "Hello,",info[0]+"!","I also enjoy",info[2]+"!" -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.3.5 Max in list.txt: -------------------------------------------------------------------------------- 1 | # Write code here... 2 | def max_int_in_list(list): 3 | max = 0 4 | for i in list: 5 | if int(i)>max: 6 | max=int(i) 7 | return max 8 | 9 | 10 | 11 | 12 | my_list = [5, 2, -5, 10, 23, -21] 13 | biggest_int = max_int_in_list(my_list) 14 | print biggest_int -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.3.6 Owls.txt: -------------------------------------------------------------------------------- 1 | text = input(Enter some text ) 2 | text.lower() 3 | text.split() 4 | print There are + str(text.count(owl)) + words that contained owl. 5 | print They occured at indices 6 | for c, value in enumerate(text, 1) 7 | print(c, value) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.3.7 Exclamation points.txt: -------------------------------------------------------------------------------- 1 | new = "!" 2 | string = input("Enter text: ") 3 | x = list(string) 4 | index = 0 5 | for i in range(len(string)): 6 | if x[index] == "i": 7 | x[index] = new 8 | index = index + 1 9 | 10 | print"".join(x) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.3.8 Word ladder.txt: -------------------------------------------------------------------------------- 1 | def get_index(): 2 | while True: 3 | global index 4 | index=int(input("Enter an index (-1 to quit): ")) 5 | if index > len(word): 6 | print "Invalid index" 7 | elif index< -1: 8 | print "Invalid index" 9 | elif index==-1: 10 | break 11 | else: 12 | break 13 | def get_letter(): 14 | while True: 15 | global letter 16 | letter=input("Enter a letter: ") 17 | if len(letter) != len(" "): 18 | print "Must be exactly one character!" 19 | elif letter != letter.lower(): 20 | print "Character must be a lowercase letter!" 21 | else: 22 | break 23 | index=0 24 | letter="" 25 | word=input("Enter a word: ") 26 | while True: 27 | get_index() 28 | if index==-1: 29 | break 30 | get_letter() 31 | list(word) 32 | print str(word[:index]) + letter + str(word[index+1:]) 33 | word=str(word[:index]) + letter + str(word[index+1:]) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.11 Fruits and Vegetables.txt: -------------------------------------------------------------------------------- 1 | my_list = ["broccoli", "apple", "zucchini", "rambutan", "grapefruit"] 2 | 3 | # Your code here... 4 | my_list.sort() 5 | my_list.reverse() 6 | my_list.remove("grapefruit") 7 | 8 | print my_list -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.12 Librarian, Part 2.txt: -------------------------------------------------------------------------------- 1 | my_list = [] 2 | for i in range(5): 3 | name = input("Name: ") 4 | x = name.split() 5 | my_list.append(x[(len(x)-1)]) 6 | 7 | my_list.sort() 8 | print my_list -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.13 Owls, Part 2.txt: -------------------------------------------------------------------------------- 1 | text = input("Enter some text: ") 2 | y = text.lower() 3 | x = text.split() 4 | z = "owl" 5 | c = 0 6 | index = 0 7 | index1 = [] 8 | for i in range(len(x)): 9 | if z in x[index]: 10 | c = c + 1 11 | index1.append(index) 12 | index = index + 1 13 | 14 | print "There were " + str(c) + " words that contained \"owl\"." 15 | print "They occurred at indices: " + str(index1) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.4 How Many Names.txt: -------------------------------------------------------------------------------- 1 | num = int(input("Number of names: ")) 2 | full_name = "" 3 | 4 | for i in range(num): 5 | name = input("Name: ") 6 | full_name = full_name + name + " " 7 | 8 | full_name = full_name.split() 9 | print "First name: " + str(full_name[0]) 10 | print "Middle name(s): " + str(full_name[1:num-1]) 11 | print "Last name: " + str(full_name[num-1]) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.5 Five Numbers.txt: -------------------------------------------------------------------------------- 1 | list_num = [] 2 | for i in range(5): 3 | num = int(input("Number: ")) 4 | list_num.append(num) 5 | print list_num 6 | 7 | index = 0 8 | total = 0 9 | for i in range(5): 10 | total = int(total) + int(list_num[index]) 11 | index = index + 1 12 | 13 | print "Sum: " + str(total) -------------------------------------------------------------------------------- /9 Creating and altering data structures/8.4.7 Librarian.txt: -------------------------------------------------------------------------------- 1 | my_list = [] 2 | for i in range(5): 3 | name = input("Name: ") 4 | my_list.append(name) 5 | 6 | my_list.sort() 7 | print my_list -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeHS_Python_Answers_valid_codes 2 | codigos validos para el curso de python de code hs 3 | --------------------------------------------------------------------------------