Skip to content

Commit d937285

Browse files
committed
first step of adding types. and running mypy on terminal
1 parent eb5b9e2 commit d937285

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Sprint5/type.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
def open_account(balances, name, amount): #dic type str and int
1+
2+
from typing import Dict
3+
def open_account(balances: Dict[str,int], name:str, amount:int): #dic type str and int
4+
#Adding a new account
25
balances[name] = amount
36

4-
def sum_balances(accounts): #takes type dic[str, int}returns int
5-
total = 0
7+
def sum_balances(accounts:Dict[str,int])-> int: #takes type dic[str, int}returns int
8+
total = int = 0
69
for name, pence in accounts.items():
710
print(f"{name} had balance {pence}")
811
total += pence
912
return total
1013

11-
def format_pence_as_string(total_pence): #type int returns type str
14+
def format_pence_as_string(total_pence: int)-> str: #type int returns type str
15+
#formatting pence as a string
1216
if total_pence < 100:
1317
return f"{total_pence}p"
14-
pounds = int(total_pence / 100)
18+
pounds =int(total_pence / 100)
19+
reveal_type(pounds)
1520
pence = total_pence % 100
21+
reveal_type(pence)
1622
return f"£{pounds}.{pence:02d}"
1723

18-
balances = { #dic type {str:int}
24+
balances:Dict[str,int] = { #dic type {str:int}
1925
"Sima": 700,
2026
"Linn": 545,
2127
"Georg": 831,
@@ -25,6 +31,7 @@ def format_pence_as_string(total_pence): #type int returns type str
2531
open_account("Olya", "£7.13")
2632

2733
total_pence = sum_balances(balances) #returntype int
28-
total_string = format_pence_as_str(total_pence) #returntype str and wrong function name
29-
34+
reveal_type(total_pence)
35+
total_string = format_pence_as_str(total_pence) #returntype str and wrong function name
36+
reveal_type(total_string)
3037
print(f"The bank accounts total {total_string}")

0 commit comments

Comments
 (0)