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
| #!/usr/bin/env python3 | |
| # guess.py: a simple number guessing game | |
| from random import randint | |
| print('Hello, please type your name:') | |
| name = input() | |
| print('Hi, ', name, '!', sep='') | |
| print("I will select a number from 1 to what number? You can choose, dear user.") |
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
| /* | |
| Display3digits | |
| Controle de um display de 7 segmentos com 3 digitos, anodo comum. | |
| */ | |
| int pinos_digitos[] = {4, 3, 2}; | |
| int NUM_DIGITOS = 3; | |
| // segmentos datasheet A B C D E F G | |
| int pinos_segmentos[] = {8, 6, 10, 12, 13, 7, 9}; |
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
| file = open('List_of_Elements.wiki', encoding='utf-8') | |
| text = file.read() | |
| # print(len(text), 'chars in the text') | |
| lines = text.split('\n') # split by newlines | |
| # print(len(lines), 'lines in the text') | |
| for line in lines: | |
| cells = line.split('||') | |
| if len(cells) < 3 or not cells[2].startswith(' [['): |
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
| >>> class Coisa: | |
| ... __slots__ = ('tamanho', 'sabor') | |
| ... | |
| >>> c = Coisa() | |
| >>> c.tamanho | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: tamanho | |
| >>> c.tamanho = 'G' | |
| >>> c.tamanho |
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
| from random import shuffle | |
| class Tombola(object): | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) | |
| def misturar(self, misturadora=None): | |
| if misturadora: # LR: isso funciona mas é melhor sempre testar explicitamente argumento is None |
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
| from random import shuffle | |
| class Tombola(object): | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) | |
| def misturar(self, pairswap=None): | |
| pairswap(self.itens) if pairswap else shuffle(self.itens) # LR: funciona mas é melhor testar explicitamente arg is None |
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
| from random import shuffle | |
| class Tombola(object): | |
| from inplace import pairswap # LR: esse import é desnecessário, e este é um lugar estranho para fazer imports | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) |
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
| I am a happy paying customer of Dropbox, but the news that you have | |
| appointed Condoleezza Rice to your board is extremely disturbing and | |
| I will ditch your service if this decision is not reversed. | |
| Dr. Rice defends warrantless wiretapping. How am I supposed to trust | |
| Dropbox with my personal files if your management cannot understand | |
| the implications of this appointment? And if they do understand | |
| -- which may well be the case -- then I am very sorry I ever shared | |
| any of my files with you. |
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
| class State(object): | |
| def __init__(self, value): | |
| self.value = value | |
| def __repr__(self): | |
| return '%s(%r)' % (self.__class__.__name__, self.value) | |
| def __str__(self): | |
| return state.value |
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
| Double-click LXTerminal and type: | |
| $ idle -n | |
| (the IDLE window appears) | |
| >>> from turtle import * | |
| >>> fd(100) | |
| (a window with a line appears) | |
| How to draw a square: | |
| >>> fd(100) | |
| >>> rt(90) | |
| >>> fd(100) |