Uploaded by balthazar274

INSY 336 - Homework 1

advertisement
INSY 336 – Assignment 1
1. Calculate the following expressions using Python
a) (((4720/16)**4)*36)%17 = 8.0
b) (1026/3*4-(26+120)*8)**3
2.
Answer the following questions
a) Line:
b) Line:
Console:
Line:
Console:
Console:
c) Line:
Console:
Line for question 2:
c=23
c1 = c + 5
print(c1)
F=(c1*9/5)+32
print(F)
side_1 = 8
side_2 = 6
hypothenuse = (side_1**2 + side_2**2)**(1/2)
print(hypothenuse)
perimeter = side_1 + side_2 + hypothenuse
perimeter_inches = perimeter/2.54
print(perimeter)
print(perimeter_inches)
import random
temp = random.randint(50,100)
print(temp)
random_square = temp**2
print(random_square)
3.
Rob earns $7,500/ month from his day job. He gets a scholarship of $ 1,800/ month
and earns $1100 per month on his night job.
a) Line:
Console:
b) Line:
Console:
c) Line:
Console:
Line for question 3:
day_job = 7500
scholarship = 1800
night_job = 1100
monthly_income = day_job + scholarship + night_job
print(monthly_income)
yearly_income = monthly_income*12
print("yearly income: " + str(yearly_income))
tax_rate = 0.2
taxes_paid = yearly_income*tax_rate
print("Taxes paid : " + str(taxes_paid))
groceries_annual = 1500*12
household_expense = 20000
net_income = yearly_income - taxes_paid - groceries_annual - household_expense
print ("Net Income: " + str(net_income))
interest_rate = 0.04
period = 4
account = net_income * (1+interest_rate)**period
print("Savings at t=5: " + str(account))
4.
A fruit vendor has 3 types of fruits in his basket and he wants to know how many of
each he has in his basket, as the price varies depending on the fruit. (Apple- “A”,
Oranges-“O”, Guava-“G”)
a)
Line:
Console:
b) Line:
Console:
Line for question 4:
fruits =
["A","A","G","G","A","A","O","O","A","G","O","O","O","G","G","G","A","A","O","G","O","A"]
A = fruits.count("A")
G = fruits.count("G")
O = fruits.count("O")
print("A: " + str(A))
print("G: " + str(G))
print("O: " + str(O))
Aprice = 4
Oprice = 2
Gprice = 5
revenue = A*Aprice + G*Gprice + O*Oprice
print("Fruits vendor revenue in $: " + str(revenue))
c) A class has five students: John, Emma, Rai, Omar, and Chloe. After an exam, you are
given the following list which you need to copy to Python and store it in a variable.
a)
Line:
Console:
a) Line:
Console:
Line for question 5:
classroom = ["John 70", "Emma 90", "Rai 85", "Omar 87", "Chloe 80"]
sub0 = classroom[0]
sub1 = classroom[1]
sub2 = classroom[2]
sub3 = classroom[3]
sub4 = classroom[4]
grade0 = int(sub0[-2:])
grade1 = int(sub1[-2:])
grade2 = int(sub2[-2:])
grade3 = int(sub3[-2:])
grade4 = int(sub4[-2:])
average = ((grade0 + grade1 + grade2 + grade3 + grade4)/5)
print("Class Average: " + str(average))
sum_differencessquared = ((grade0-average)**2 + (grade1-average)**2 + (grade2-average)**2
+ (grade3-average)**2 + (grade4-average)**2)
print(sum_differencessquared)
n=5
SD = ((sum_differencessquared)/n)**(1/2)
print("Standard Deviation: " + str(SD))
d)
Answer the following questions
a) Line :
Console:
b) Line:
Console:
Line for question 6:
number_1 = (input("Enter a number: "))
number_2 = (input("Enter a number: "))
number_3 = (input("Enter a number: "))
result = number_1[-1] + number_2[-1] + number_3[-1]
print(result)
sum1 = int(number_1) + int(number_2) + int(number_3)
print(sum1)
sum1/7
Download