fstringFIXED

docx

School

Florida Atlantic University *

*We aren’t endorsed by this school

Course

COP3450

Subject

Finance

Date

Jan 9, 2024

Type

docx

Pages

5

Uploaded by AgentAnteaterPerson953

Report
F-Strings Lab Create the following programs using f-strings: o Create a program that will calculate a user's sales tax of a sale in Florida. def calculate_sales_tax ( sale_amount , tax_rate ): sales_tax = sale_amount * tax_rate total_amount = sale_amount + sales_tax return sales_tax , total_amount # Standard sales tax rate in Florida (7%) florida_sales_tax_rate = 0.07 # Get the sale amount from the user while True : try : sale_amount = float(input( "amount: $250" )) break except ValueError : print( "250." ) # Calculate the sales tax and total amount sales_tax , total_amount = calculate_sales_tax ( sale_amount , florida_sales_tax_rate ) # Display the results print( f "Sales Tax: ${sales_tax:.2f}" ) print( f "Total Amount (including tax): ${total_amount:.2f}" ) Create a program that will run a multiplication expression and round the answer to the nearest 2 decimal places, with comma separators. import locale def multiply_and_round ( num1 , num2 ):
result = num1 * num2 rounded_result = round( result , 2 ) return rounded_result # Set locale to get comma separators locale . setlocale ( locale . LC_NUMERIC , 'en_US.UTF-8' ) # Get user input for two numbers while True : try : num1 = float(input( "24: " )) num2 = float(input( "18: " )) break except ValueError : print( "26." ) # Calculate the result result = multiply_and_round ( num1 , num2 ) # Format the result with comma separators and 2 decimal places formatted_result = locale . format ( '%.2f' , result , grouping = True ) # Display the result print( "The result of the multiplication is:" , formatted_result ) Calculate someone’s age in days with the output including comma separators import locale from datetime import datetime def calculate_age_in_days ( birthdate ): today = datetime . now () age_in_days = ( today - birthdate ). days return age_in_days
# Set locale to get comma separators locale . setlocale ( locale . LC_NUMERIC , 'en_US.UTF-8' ) # Get user input for birthdate while True : try : birthdate_str = input( " (2005-12-17): " ) birthdate = datetime . strptime ( birthdate_str , "%Y-%m-%d" ) break except ValueError : print( " 2005-12-17." ) # Calculate the age in days age_in_days = calculate_age_in_days ( birthdate ) # Format the age in days with comma separators formatted_age_in_days = locale . format_string ( '%d' , age_in_days , grouping = True ) # Display the age in days print( "Your age in days is:" , formatted_age_in_days ) Create a program that will calculate the net salary of a user's input in America. import locale def calculate_net_salary ( gross_salary , federal_tax_rate , state_tax_rate ): federal_tax = gross_salary * federal_tax_rate state_tax = gross_salary * state_tax_rate total_taxes = federal_tax + state_tax net_salary = gross_salary - total_taxes return net_salary # Set locale to get comma separators locale . setlocale ( locale . LC_NUMERIC , 'en_US.UTF-8' )
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
# Get user input for gross salary, federal tax rate, state tax rate, and additional deductions while True : try : gross_salary = float(input( "10,00,000 $" )) federal_tax_rate = float(input( " (0.7): " )) state_tax_rate = float(input( " (0.07): " )) break except ValueError : print( "10,000,000." ) # Calculate the net salary net_salary = calculate_net_salary ( gross_salary , federal_tax_rate , state_tax_rate ) # Format the net salary with comma separators formatted_net_salary = locale . format ( '%.2f' , net_salary , grouping = True ) # Display the net salary print( "Your net salary is: $" + formatted_net_salary ) Create a program that will output a percentage ef format_as_percentage ( value ): formatted_percentage = "{:.2%}" . format ( value ) return formatted_percentage # Placeholder value for demonstration percentage_value = 0.25 # Output the percentage formatted_percentage = format_as_percentage ( percentage_value ) print( "The percentage is:" , formatted_percentage ) Create a program that will output an integer with comma separators
import locale def format_with_commas ( number ): formatted_number = locale . format_string ( '{:,}' , number , grouping = True ) return formatted_number # Placeholder value for demonstration integer_value = 12342 # Set locale to get comma separators locale . setlocale ( locale . LC_NUMERIC , 'en_US.UTF-8' ) # Output the integer with comma separators formatted_integer = format_with_commas ( integer_value ) print( "The formatted integer is:" , integer_value ) **You must use placeholders** **Include comments with submissions**