In: Computer Science
Code in Python. You can only use while loops NOT for loops.
Program 1: cost_living
In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note: this program requires no input).
Program 2: discount
A discount store is having a sale where everything is 15% off. Write a program to display a table showing the original price and the discounted price. This program requires no input and your table should include headings and the original prices should go from 99 cents to $9.99 in increments of 50 cents.
Program 3: numbers
Write a program to input a sequence of 8 integers, count all the odd numbers and sum all the negative integers. One integer is input and processed each time around the loop.
Thanks for the question. Below is the code you will be needing with while loops only. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== def main(): starting_year = 2020 present_cost = 3850 rise_rate = 2.1 while present_cost < 4450: present_cost = present_cost + present_cost * rise_rate / 100 starting_year += 1 print(f'In {starting_year} year the cost of living will be over $4450.') main()
==============================================================
def main(): discount_percentage = 15 print('{:<15}{:>15}'.format('Original','Discount Price')) cents = 99 while cents<=999: price = cents/100 discounted_price = price - price*discount_percentage/100 print('{:<15.2f}{:>13.2f}'.format(price,discounted_price)) cents+=50 main()
def main(): counter = 0 odds = 0 negative_sum = 0 while counter < 8: num = float(input('Enter a number: ')) if num % 2 == 1 or num % 2 == -1: odds += 1 if num < 0: negative_sum += num counter += 1 print('Total Odd number entered:', odds) print('Sum of all negative numbers:', negative_sum) main()