-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ajitonelsonn/dev
String width no Alignment
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# String width no Alignment | ||
|
||
Iha Python, ita bele kontrola width no alignment (alinhamentu) husi string bazeia ba karakter sira ne'ebé ita inklui iha string. Ne'e importante bainhira ita kria output sira ne'ebé formatadu iha maneira ne'ebé di'ak, hanesan tabela ka relatóriu. | ||
|
||
Ita bele kontrola width no alignment liu husi fórmata string ho `str.format()` ka f-string. Ita uza notasaun especial ne'ebé inklui dala balun ho {} iha string formatadu atu indika width no alignment. | ||
|
||
Exemplos: | ||
|
||
1. **Alignment (Alinhamentu)**: | ||
|
||
Ita bele kontrola alinhamentu husi string iha kada fórmata liu husi sinais `-` (left-align), `^` (center-align), ka `>` (right-align). | ||
|
||
```python | ||
nome = "Jedy" | ||
idade = 21 | ||
|
||
# Alinhamentu left, center, no right | ||
print("{:<10}".format(nome)) # Sai "Ana " | ||
print("{:^10}".format(idade)) # Sai " 30 " | ||
print("{:>10}".format(idade)) # Sai " 30" | ||
``` | ||
|
||
2. **Width (Largura)**: | ||
|
||
Ita bele kontrola width husi string ho indikasaun husi dala iha {}. | ||
|
||
```python | ||
nome = "Jedy" | ||
idade = 21 | ||
|
||
# Largura 10 | ||
print("{:<10}".format(nome)) # Sai "Ana " | ||
print("{:^10}".format(idade)) # Sai " 30 " | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
### Exerciciu I | ||
|
||
Exercísiu sira hodi pratika string width no alignment iha Python: | ||
|
||
1. **Exercísiu 1**: Kria tabela ho alignment no width ne'ebé adekuadu ba informasaun ida. | ||
|
||
```python | ||
# Dados ba tabela | ||
produtus = [ | ||
("Lapiseira", 2, 1.50), | ||
("Kareta Rais", 1, 20.00), | ||
("Kadernu", 3, 3.75) | ||
] | ||
|
||
# Hatudu tabela | ||
print("PRODUTU KANTIDADE PREÇU UNITÁRIU") | ||
for produto in produtus: | ||
print("{:<15} {:^10} {:>15.2f}".format(*produto)) | ||
``` | ||
|
||
2. **Exercísiu 2**: Kria mensajen ho alignment ne'ebé klaru. | ||
|
||
```python | ||
# Dados ba mensajen | ||
nome = "Ana" | ||
idade = 30 | ||
|
||
# Hatudu mensajen ho alignment | ||
mensagem = "O nome {} iha idade {}.".format(nome, idade) | ||
print("{:^50}".format(mensagem)) | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
nome = "Jedy" | ||
idade = 21 | ||
# Alinhamentu left, center, no right | ||
print("{:<10}".format(nome)) # Sai "Ana " | ||
print("{:^10}".format(idade)) # Sai " 30 " | ||
print("{:>10}".format(idade)) # Sai " 30" |