Reputation: 25
Simple ATM simulation exercise - Need to return some information including strings and integers however return is spitting out the whole line of code, not just the string and integers combined.
from SimpleCashPoint_v2 import cashpoint
print('\nTEST-EXAMPLE 1')
result = cashpoint('1234',3415.55)
print('\n---------\nRESULT:', result)
print('-' * 40, '\n')
SimpleCashPoint_v2
)elif trans_type == '2' :
withdraw = float(input('Amount to withdraw: '))
result = ('\nYou have withdrawn ', withdraw, ' your remaining balance is ', (balance-withdraw),'£')
return result
In[36]result
Out[36] You have withdrawn 10 your remaining balance is 50 £
In[36]result
Out[36]: ('\nYou have withdrawn ', 10, ' your remaining balance is ', 50, '£')
Upvotes: 0
Views: 47
Reputation: 1145
You're making a tuple when you made result.
type(result)
<class 'tuple'>
So I think if you combine your elements into a single string, it would work.
One very naive way would be the following:
withdraw = ...
result = "/nYou have withdrawn" + str(withdraw) + "your remaining balnce is" + str(balance-withdraw) + "$"
return result
Upvotes: 0
Reputation: 1587
You can replace:
result = ('\nYou have withdrawn ', withdraw, ' your remaining balance is ', (balance-withdraw),'£')
with:
result = "\nYou have withdrawn {} your remaining balance is {} £".format(withdraw, balance-withdraw)
Have a search for string formatting, e.g. https://realpython.com/python-string-formatting/
Upvotes: 1