Quality of my code? Beginner programmer <6 weeks into learning /u/Lawstu77 Python Education

Establish Variables and Input Requests

print('Enter the starting salary:') starting_salary = float(input()) # Initializing another starting salary variable to reset after each iteration starting_salary1 = starting_salary # Initializing more variables total_cost = 1000000 portion_down_payment = 0.25 * total_cost months = 0 current_savings = 0 r = 0.04 semi_annual_raise = 0.07 high = 10000 low = 0 num_guess = 0 # Execute the following while loop until one of the conditions (with break) is met. while True: # If the difference between current savings and down payment is within acceptable range if current_savings - portion_down_payment < -100: guess = (high + low) // 2.0 current_savings += current_savings * r / 12 current_savings += (guess / 10000.0) * (starting_salary / 12) months += 1 # Add semi-annual raise every 6 months if months % 6 == 0: starting_salary += semi_annual_raise * starting_salary # If months exceed 36 and savings not in range, adjust low bound and reset if months > 36 and current_savings - portion_down_payment < -100: low = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If salary is too low to save for the down payment, print and break if guess - 10000 >= -1 and current_savings - portion_down_payment < -100: print('It is not possible to pay the down payment in three years.') break # If current savings exceed the down payment range, adjust high bound and reset elif current_savings - portion_down_payment > 100: high = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If savings are within the acceptable range, print results and exit elif current_savings - portion_down_payment<=100 and current_savings -portion_down_payment>=-100: print('Best savings rate:'+ str(guess/10000.0)) print('Steps in bisection search:' + str(num_guess)) break 

submitted by /u/Lawstu77
[link] [comments]

​r/learnpython Establish Variables and Input Requests print(‘Enter the starting salary:’) starting_salary = float(input()) # Initializing another starting salary variable to reset after each iteration starting_salary1 = starting_salary # Initializing more variables total_cost = 1000000 portion_down_payment = 0.25 * total_cost months = 0 current_savings = 0 r = 0.04 semi_annual_raise = 0.07 high = 10000 low = 0 num_guess = 0 # Execute the following while loop until one of the conditions (with break) is met. while True: # If the difference between current savings and down payment is within acceptable range if current_savings – portion_down_payment < -100: guess = (high + low) // 2.0 current_savings += current_savings * r / 12 current_savings += (guess / 10000.0) * (starting_salary / 12) months += 1 # Add semi-annual raise every 6 months if months % 6 == 0: starting_salary += semi_annual_raise * starting_salary # If months exceed 36 and savings not in range, adjust low bound and reset if months > 36 and current_savings – portion_down_payment < -100: low = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If salary is too low to save for the down payment, print and break if guess – 10000 >= -1 and current_savings – portion_down_payment < -100: print(‘It is not possible to pay the down payment in three years.’) break # If current savings exceed the down payment range, adjust high bound and reset elif current_savings – portion_down_payment > 100: high = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If savings are within the acceptable range, print results and exit elif current_savings – portion_down_payment<=100 and current_savings -portion_down_payment>=-100: print(‘Best savings rate:’+ str(guess/10000.0)) print(‘Steps in bisection search:’ + str(num_guess)) break submitted by /u/Lawstu77 [link] [comments] 

Establish Variables and Input Requests

print('Enter the starting salary:') starting_salary = float(input()) # Initializing another starting salary variable to reset after each iteration starting_salary1 = starting_salary # Initializing more variables total_cost = 1000000 portion_down_payment = 0.25 * total_cost months = 0 current_savings = 0 r = 0.04 semi_annual_raise = 0.07 high = 10000 low = 0 num_guess = 0 # Execute the following while loop until one of the conditions (with break) is met. while True: # If the difference between current savings and down payment is within acceptable range if current_savings - portion_down_payment < -100: guess = (high + low) // 2.0 current_savings += current_savings * r / 12 current_savings += (guess / 10000.0) * (starting_salary / 12) months += 1 # Add semi-annual raise every 6 months if months % 6 == 0: starting_salary += semi_annual_raise * starting_salary # If months exceed 36 and savings not in range, adjust low bound and reset if months > 36 and current_savings - portion_down_payment < -100: low = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If salary is too low to save for the down payment, print and break if guess - 10000 >= -1 and current_savings - portion_down_payment < -100: print('It is not possible to pay the down payment in three years.') break # If current savings exceed the down payment range, adjust high bound and reset elif current_savings - portion_down_payment > 100: high = guess current_savings = 0 starting_salary = starting_salary1 num_guess += 1 months = 0 # If savings are within the acceptable range, print results and exit elif current_savings - portion_down_payment<=100 and current_savings -portion_down_payment>=-100: print('Best savings rate:'+ str(guess/10000.0)) print('Steps in bisection search:' + str(num_guess)) break 

submitted by /u/Lawstu77
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *