Hack Forums
[Python] Decimal places - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Decimal places (/showthread.php?tid=5712417)



Decimal places - Will Patterson - Sep 7, 2017

My teacher has asked me to "Display all amounts in currency format with the $ sign right up against the first digit and two decimal places."

The code is:
Code
# program2_3.py
# by Will Patterson (SPC ID: 209479)

# Prompt user for the value of Kenny's estate
# For Stan, divide the value by 1/2
# For Kyle, use the value of Stan and multiply it by 0.66666666666
# For Butters & Wendy, take the estate value and then subtract the total of Kyle and Stan's total value.
# Take Kyle & Stan's subtracted value from the value of Kenny's Estate then divide it by 2.
# Print out each of there values

def main():
    # get the users input for the value of Kenny's estate.
    estate = float(input("What is the value of Kenny's estate?: "))
    # divide the value by 2 (1/2)
    stan = (estate) / 2
    # multiply Stan's value by 0.66666666666 (2/3)
    kyle = (stan * 2/3)
    # add the total the value of Stan & Kyle then subtract it from the estate value
    sk = estate - (stan + kyle)
    # divide the total of the variable sk by 2
    bw = (sk) / 2
    # print out Stan
    print('Stan receives a total of: $'+str(stan))
    # print out Kyle
    print('Kyle recieves a total of: $'+str(kyle))
    # print out Butters & Wendy's total
    print('Butters and Wendy each get $'+str(bw))

main()

How would I do what he asked?


* - koolkid - Sep 7, 2017

like that

PHP Code

<?php 
def main
():
    
# get the users input for the value of Kenny's estate.
    
estate = float(input("What is the value of Kenny's estate?: "))
    print(
'Kenny\'s estate value is: ${0:.2f}'.format(estate))
    
# divide the value by 2 (1/2)
    
stan = estate / 2
    
print('stan\'s estate value is: ${0:.2f}'.format(stan))
    
# multiply Stan's value by 0.66666666666 (2/3)
    
kyle = (stan * 0.66666666666)
    print(
'Kyle\'s estate value is: ${0:.2f}'.format(kyle))
    
# add the total the value of Stan & Kyle then subtract it from the estate value
    
sk = estate - (stan + kyle)
    
# divide the total of the variable sk by 2
   
main() 



* - HFDone - Sep 7, 2017

https://docs.python.org/3/library/string.html#format-examples