This file contains hidden or 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
| # Calculadora em Python | |
| # Desenvolva uma calculadora em Python com tudo que você aprendeu nos capítulos 2 e 3. | |
| # A solução será apresentada no próximo capítulo! | |
| # Assista o vídeo com a execução do programa! | |
| #importando biblioteca Math para realizar a raiz quadrada | |
| import math | |
| #criando função para realizar a soma |
This file contains hidden or 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
| '''Exercise 36 (and Solution) | |
| This exercise is Part 4 of 4 of the birthday data exercise series. The other exercises are: Part 1, Part 2, and Part 3. | |
| In the previous exercise we counted how many birthdays there are in each month in our dictionary of birthdays. | |
| In this exercise, use the bokeh Python library to plot a histogram of which months the scientists have birthdays in! Because it would take a long time for you to input the months of various scientists, you can use my scientist birthday JSON file. Just parse out the months (if you don’t know how, I suggest looking at the previous exercise or its solution) and draw your histogram. | |
| If you are using a purely web-based interface for coding, this exercise won’t work for you, since it requires installing the bokeh Python package. Now might be a good time to install Python on your own computer.''' | |
| import json | |
| from collections import Counter |
This file contains hidden or 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
| '''Birthday Months | |
| Exercise 35 (and Solution) | |
| This exercise is Part 3 of 4 of the birthday data exercise series. The other exercises are: Part 1, Part 2, and Part 4. | |
| In the previous exercise we saved information about famous scientists’ names and birthdays to disk. In this exercise, load that JSON file from disk, extract the months of all the birthdays, and count how many scientists have a birthday in each month. | |
| Your program should output something like: | |
| { | |
| "May": 3, |
This file contains hidden or 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
| '''Exercise 34 (and Solution) | |
| This exercise is Part 2 of 4 of the birthday data exercise series. The other exercises are: Part 1, Part 3, and Part 4. | |
| In the previous exercise we created a dictionary of famous scientists’ birthdays. In this exercise, modify your program from Part 1 to load the birthday dictionary from a JSON file on disk, rather than having the dictionary defined in the program. | |
| Bonus: Ask the user for another scientist’s name and birthday to add to the dictionary, and update the JSON file you have on disk with the scientist’s name. If you run the program multiple times and keep adding new names, your JSON file should keep getting bigger and bigger.''' | |
| '''JSON FILE birthday.json | |
| {"Albert Einstein": "14/03/1879", "Benjamin Franklin": "17/01/1706", "Ada Lovelace": "10/12/1815", "Luciano": "03/03/1986", "Debora": "23/05/1989"} |
This file contains hidden or 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
| '''Birthday Dictionaries | |
| Exercise 33 (and Solution) This exercise is Part 1 of 4 of the birthday data exercise series. The other exercises are: Part 2, Part 3, and Part 4. | |
| For this exercise, we will keep track of when our friend’s birthdays are, and be able to find that information based on their name. Create a dictionary (in your file) of names and birthdays. When you run your program it should ask the user to enter a name, and return the birthday of that person back to them. The interaction should look something like this: | |
| Welcome to the birthday dictionary. We know the birthdays of: Albert Einstein Benjamin Franklin Ada Lovelace Who's birthday do you want to look up? Benjamin Franklin Benjamin Franklin's birthday is 01/17/1706. Happy coding!''' | |
| #creating a dictionary with birthday of suggestions | |
| mydict = {'Albert Einstein': '14/03/1879', 'Benjamin Franklin': '17/01/1706', 'Ada Lovelace': '10/12/1815'} |
This file contains hidden or 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
| '''Exercise 32 (and Solution) | |
| This exercise is Part 3 of 3 of the Hangman exercise series. The other exercises are: Part 1 and Part 2. | |
| You can start your Python journey anywhere, but to finish this exercise you will have to have finished Parts 1 and 2 or use the solutions (Part 1 and Part 2). | |
| In this exercise, we will finish building Hangman. In the game of Hangman, the player only has 6 incorrect guesses (head, body, 2 legs, and 2 arms) before they lose the game. | |
| In Part 1, we loaded a random word list and picked a word from it. In Part 2, we wrote the logic for guessing the letter and displaying that information to the user. In this exercise, we have to put it all together and add logic for handling guesses. | |
| Copy your code from Parts 1 and 2 into a new file as a starting point. Now add the following features: |
This file contains hidden or 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
| '''Exercise 31 (and Solution) | |
| This exercise is Part 2 of 3 of the Hangman exercise series. The other exercises are: Part 1 and Part 3. | |
| Let’s continue building Hangman. In the game of Hangman, a clue word is given by the program that the player has to guess, letter by letter. The player guesses one letter at a time until the entire word has been guessed. (In the actual game, the player can only guess 6 letters incorrectly before losing). | |
| Let’s say the word the player has to guess is “EVAPORATE”. For this exercise, write the logic that asks a player to guess a letter and displays letters in the clue word that were guessed correctly. For now, let the player guess an infinite number of times until they get the entire word. As a bonus, keep track of the letters the player guessed and display a different message if the player tries to guess that letter again. Remember to stop the game when all the letters have been guessed correctly! Don’t worry about choosing a word randomly or keeping track of the number of gue |
This file contains hidden or 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
| '''Exercise 30 (and Solution) | |
| This exercise is Part 1 of 3 of the Hangman exercise series. The other exercises are: Part 2 and Part 3. | |
| In this exercise, the task is to write a function that picks a random word from a list of words from the SOWPODS dictionary. Download this file and save it in the same directory as your Python code. This file is Peter Norvig’s compilation of the dictionary of words used in professional Scrabble tournaments. Each line in the file contains a single word. | |
| Hint: use the Python random library for picking a random word.''' | |
| #import Exercise22 with ready method to read file and convert in a list | |
| import Exercise22 | |
| import random |
This file contains hidden or 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
| # coding: utf-8 | |
| # In[1]: | |
| #creating function to identify the winner | |
| def verifyWinner(matrix): | |
| endGame = False | |
| #validate winner by line 0 |
This file contains hidden or 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
| '''Exercise 28 (and Solution) | |
| Implement a function that takes as input three variables, and returns the largest of the three. Do this without using the Python max() function! | |
| The goal of this exercise is to think about some internals that Python normally takes care of for us. All you need is some variables and if statements!''' | |
| #function to receive 3 numbers | |
| def verifyMaxFrom3(num1, num2, num3): | |
| maxi = verifyMaxFrom2(num1, num2) | |
| return verifyMaxFrom2(maxi, num3) |
NewerOlder