Skip to content

Commit bae06cd

Browse files
committed
Terminado o ex 112 e iniciado o 113
1 parent 352116a commit bae06cd

File tree

8 files changed

+126
-6
lines changed

8 files changed

+126
-6
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ None of the exercises in this project were copied from the teacher's answer, all
1010
so it is likely to be different from the answer the teacher shows in the video, but in no way does it escape requested in the statement.
1111

1212
## WORLD 01:
13-
### First commands:
13+
### First Commands:
1414
* Ex001: ‘Create a program that writes "Hello World!" on the screen’
1515
* Ex002: ‘Make a program that reads a person's name, and shows a welcome message’
1616

@@ -300,4 +300,9 @@ Also make a program that imports this module and uses some of these functions.'
300300
* Ex110: 'Add to the currency.py module created in the precious challenges, a function called summary(), which shows on the screen some information generated by the functions we already have in the module created so far.'
301301
* Ex111: 'Create a package called utilitiesCeV that has two built-in modules called currency and data.
302302
Transfer all the functions used in challenges 107, 108, 109 to the first package and keep every running.'
303-
* Ex112: '
303+
* Ex112: 'Within the utilitiesCeV package that we created in challenge 111, we have a module called data.
304+
Create a function called readmoney() that is capable of working like the input() function, but with a data validation to only accept values that are monetary.'
305+
### Error and Exception Handling:
306+
* Ex113: 'Rewrite the readint() funciton we did in challenge 104, now including the possibility of typing a number of a valid type.
307+
Enjoy and also create a readfloat() function with the same functionality.'
308+
* Ex114: '

README_ptbr.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Nenhum dos exercícios deste projeto foi copiado da resposta do professor, todos
1010
por isso é provável que seja diferente da resposta que o professor mostra no vídeo, mas todos estão dentro do objetivo da aula.
1111

1212
## MUNDO 01:
13-
### primeiros comandos:
13+
### Primeiros Comandos:
1414
* Ex001: ‘Crie um programa que escreva 'Olá Mundo' na tela.’
1515
* Ex002: ‘Faça um programa que leia o nome de uma pessoa, e mostre uma mensagem de bem vindo.’
1616

@@ -299,4 +299,8 @@ Faça também um programa que importe esse módulo e use algumas dessas funçõe
299299
* Ex110: 'Adicione ao módulo moeda.py criado nos desafios anteriores, uma função chamada resumo(), que mostre na tela algumas informações geradas pelas funções que já temos no módulo criado até aqui.'
300300
* Ex111: 'Crie um pacote chamado utilidadesCeV que tenha dois módulos internos chamados moeda e dado.
301301
Transfira todas as fuções utilizadas nos desafios 107, 108 e 109 para o primeiro pacote e mantenha tudo funcionando.'
302-
* Ex112: '
302+
* Ex112: 'Dentro do pacote utilidadesCeV que criamos nos desafio 111, temos um módulo chamado dado. Crie uma função chamada leiadinheiro() que seja capaz de funcionar como a função input(), mas com uma validação de dados para aceitar apenas valores que sejam monetários.'
303+
### Tratamento de Erros e Exceções:
304+
* Ex113: 'Reescreva a função leiaint() que fizemos no desafio 104, incluindo agora a possibilidade da digitação de um número de tipo válido.
305+
Aproveite e crie também uma função leiafloat() com a mesma funcionalidade.'
306+
* Ex114: '

reworked exercices/ex104.2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def readint(message):
88
number = str(input(message))
99
if number.isnumeric():
1010
number = int(number)
11-
return number
1211
break
1312
else:
1413
print('\033[31mINVALID COMMAND, PLEASE ENTER A VALID NUMBER\033[m')
14+
return number
1515

1616
number = readint('Enter a number: ')
1717
print(f'\033[32mYou just typed the number \033[35m{number}\033[32m.\033[m')

reworked exercices/ex111.2/utilitiescev/currency/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def decrease(value, porcentage, monetary=False):
3434

3535
def currency(value):
3636
result = f'RS: {value:.2f}'
37-
result.replace('.', ',')
37+
result = result.replace('.', ',')
3838
return result
3939

4040
def summary(value, increases, decreases):

reworked exercices/ex112.2/ex112.2.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ex112.2
2+
"""Within the utilitiesCeV package that we created in challenge 111, we have a module called data.
3+
Create a function called readmoney() that is capable of working like the input() function, but with a data validation to only accept values that are monetary."""
4+
5+
from utilitiescev import currency, data
6+
7+
print("\033[34m==\033[m" * 21)
8+
price = data.readmoney('Enter a price: ')
9+
currency.summary(price, 80, 35)
10+
print("\033[34m==\033[m" * 21)
11+
print('xD')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
def half(value, monetary=False):
2+
result = value / 2
3+
if monetary:
4+
return currency(result)
5+
else:
6+
return result
7+
8+
9+
def double(value, monetary=False):
10+
result = value * 2
11+
if monetary:
12+
return currency(result)
13+
else:
14+
return result
15+
16+
17+
def increase(value, porcentage, monetary=False):
18+
increase = value * porcentage / 100
19+
result = value + increase
20+
if monetary:
21+
return currency(result)
22+
else:
23+
return result
24+
25+
26+
def decrease(value, porcentage, monetary=False):
27+
increase = value * porcentage / 100
28+
result = value - increase
29+
if monetary:
30+
return currency(result)
31+
else:
32+
return result
33+
34+
35+
def currency(value):
36+
result = f'RS: {value:.2f}'
37+
result = result.replace('.', ',')
38+
return result
39+
40+
def summary(value, increases, decreases):
41+
print("\033[34m<>\033[m" * 21)
42+
print(f"{'VALUE SUMMARY':^40}")
43+
print("\033[34m<>\033[m" * 21)
44+
print(f"{'Analysed price:':.<30}\033[32m{currency(value):>10}\033[m")
45+
print(f"{'Double the price:':.<30}\033[32m{double(value, True):>10}\033[m")
46+
print(f"{'Half-price:':.<30}\033[32m{half(value, True):>10}\033[m")
47+
print(f"{f'{increases}% increase':.<30}\033[32m{increase(value, increases, True):>10}\033[m")
48+
print(f"{f'{decreases}% reduction':.<30}\033[32m{decrease(value, decreases, True):>10}\033[m")
49+
print("\033[34m<>\033[m" * 21)
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def readmoney(message):
2+
while True:
3+
value = str(input(message).strip())
4+
value = value.replace(',', '.')
5+
if value.replace('.', '').isnumeric():
6+
value = float(value)
7+
break
8+
else:
9+
print(f"\033[31mError, '{value}' is an invalid price!\033[m")
10+
return value

reworked exercices/ex113.2.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Ex113.2
2+
"""Rewrite the readint() funciton we did in challenge 104, now including the possibility of typing a number of a valid type.
3+
Enjoy and also create a readfloat() function with the same functionality."""
4+
5+
def readint(message):
6+
while True:
7+
try:
8+
value = int(input(message))
9+
except (ValueError, TypeError):
10+
print('\033[31mError, please enter a valid integer!\033[m')
11+
continue
12+
except KeyboardInterrupt:
13+
print('\033[31mUsuário preferiu não digitar esse número\033[m')
14+
return 0
15+
else:
16+
return value
17+
18+
19+
20+
21+
def readfloat(message):
22+
while True:
23+
try:
24+
value = float(message)
25+
except (ValueError, TypeError):
26+
print('\033[31mError, please enter a valid real number!\033[m')
27+
except KeyboardInterrupt:
28+
print('\033[31mUsuário preferiu não digitar esse número\033[m')
29+
return 0
30+
else:
31+
return value
32+
33+
print(f'\033[7:40m{"="}\033[m' * 25)
34+
integer = readint('Enter an interger: ')
35+
floater = readfloat('Enter a real number: ')
36+
print(f'\033[7:40m{"="}\033[m' * 25)
37+
print('xD')
38+
39+
40+
# Não esta terminado, bugado!!!

0 commit comments

Comments
 (0)