In: Computer Science
this is a python code:
QUESTION 3:
Imagine that the IRA is giving stimulus package in the COVID-19
season. The package amount is determined by the number of adults in
the family and the total amount of salary the family gets.
Each adult will get 1200 dollars if the total salary is 100000 or less.
Each adult will get 800 dollars if the total salary is 150000 or less.
Write a python program to ask the user the number of adults in the family and total number of family salary and determine the total amount of stimulus package the IRA will provide for that family.
QUESTION 4:
Write a program that will ask user length and width of a right triangle and find the area of the right angled triangle. The formula for finding the area of right angle triangle is
ab/2. Also find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
Question 3:
Source Code:
Output:
Code to Copy (refer above images of code for indentation):
#read number of adults from user
adults=int(input("Enter number of adults: "))
#read family salary from user
salary=float(input("Enter salary of the family: "))
#check for salary and calculate amount
if(salary<=100000):
amount=adults*1200
elif(salary>100000 and salary<150000):
amount=adults*800
else:
amount=0
#print total amount
print("The total amount of stimulus package is: ",amount)
Question 4:
Source Code:
Ouput:
Code to Copy (Refer above image of code for indentation):
#read length and width of right triangle
a=int(input("Enter the length of a right triangle: "))
b=int(input("Enter the width of a right triangle: "))
#calulate area
area=a*b/2
aarea=(a*b)/2
#print area
print("Area using ab/2 =",area)
print("Area using (ab)/2 =",aarea)
ab/2 and (ab/2) are same because there are two operations in both those are multiplication and division there is no problem in result whenever any operation is evaluated first in this case.
Ex:
5*4/2 = 5*2=10 (4/2 =2)
(5*4)/2 = 20/2 =10 (5*4=20)
The result is same