Python Forum

Full Version: Homework help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I add a $ sign to this
total_value = int ( Input (“total value of booty in dollars: ”))
yes and no
total_value = int ( Input (“total value of booty in dollars: ”))
it would have to be a string:
ptotal_value = '${}'.format(total_value)
There is no builtin function 'Input'. It is lower case.
(Sep-17-2018, 07:39 AM)abdullahali Wrote: [ -> ]How can I add a $ sign to this
total_value = int ( Input (“total value of booty in dollars: ”))
You add the $ when you output the value, not when you store the numeric value. At least, that's the case if you want to user standard integers or floats. (You could create your own class that supports currency numerics including currency symbols.)

Standard approach:
total_value = int(input("total value of booty in dollars: "))  # expect only a number to be entered
print(f'Total value: ${total_value}')  # this is using f-strings
Look at locale module.