Uploaded by balthazar274

INSY 336 Assignment 1

advertisement
INSY 336-Data Handling and Coding for Analytics
Assignment #1 – Intro to Python
o Please attempt the assignment in groups of no more than 2 students. That is, a group can be one
student or two students.
• Please do not ask the instructor who is enrolled in the course. According to the Mcgill Policy, the
list of students cannot be shared.
o Please remember to put the names and ID numbers of all students in the group at the top of the
assignment.
• For example, if you are the only student of the group, put your name and ID number at the top of
the assignment. If you have the other student in the group, put all students’ names and ID
numbers at the top of the assignment.
o Please upload the assignment individually to MyCourses before the start of class on 22nd September.
• Even if you do the assignment as a group, you should run the code on your computer and upload
it individually.
• The purpose of the assignment is to learn how to apply what you learned in class.
o Any student who plagiarizes will receive a zero for the assignment.
• If you have the other student in the group, two of you bear equal responsibility for plagiarism
because each student in the group is held responsible for the assignment.
o For each of the questions, please submit the following:
• The relevant lines of code are copied into the word file.
• Screenshot of the output you obtain after you execute the code.
• For example, if the question is to print the strings “hello” and “first assignment”, your answer
should comprise of:
print("hello")
print("first assignment")
1. Calculate the following expressions using Python.
a) What is the modulus of the expression? (((4720/16)4)* 36) when divided by 17
b) What is the value of the expression? (1026/3*4-(26+120)*8)3
2. Answer the following questions.
a) The initial temperature of the room is 23℃. The temperature has increased 8℃ after 5 hours. What is
the room temperature of the room after 5 hours in ℉?
Use the formula: F=(C*9/5) +32
b) A right triangle has sides of length 8 cm and 6 cm. Calculate the length of the hypotenuse in cm, and
then calculate the area and perimeter of the right triangle in inches. (1 inch = 2.54 cm)
c) Generate a random number in the range of 50 to 100 (inclusive) and calculate the square of the number.
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) What is his total income per month?
b) He has to pay 20% on his total income in a year in tax. How much tax should he pay at the end of the
year?
c) Rob is spending $20,000 per year for his household expenses and $1,500 per month on groceries. After
paying his taxes and expenses, Rob is saving the remaining of his income. If Rob starts a new savings
account with the remainder of his income from this year, how much money will Rob have at the end of
year 5. The bank has an annual compound interest rate of 4%. Rob does not put in any money into the
account after the first year (only savings of year 1 are saved for 5 years).
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","A","G","G","A","A","O","O","A","G","O","O","O","G","G","G","A","A","O","G","O","A"]
a) Using the above list, write a program that counts the number of Apples, Oranges and Guavas in the fruit
vendor’s basket?
b) If the fruit vendor sells Apples at $4 each, Oranges at $2 each and Guava at $5 each, calculate the
amount he earns after selling all the fruits.
Note: The quotes around the names of the fruits may not be recognized by Python. If you encounter a
problem, you will need to manually change the quotes to those that Python recognizes.
5. 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.
["John 70", "Emma 90", "Rai 85", "Omar 87", "Chloe 80"]
As a class administrator, you are required to calculate the average and standard deviation of the class.
a) What is the average of the class?
Hint: Manipulate the list to extract the numbers, and use only variables in your calculations. You may
need to use the split variable multiple times.
b) What is the standard deviation of the class?
Hint: Formula for standard deviation is:
6. Answer the following questions.
a) Write a piece of code asking the user to enter 3 numbers: a, b, and c, and then take the last digit of
every number and create a concatenated result. For example, if the user enters: 25, 21, and 125, then
the result would be 515 (it is a concatenation not an addition)
b) Now add the three numbers entered by the user and divide them by the total number of digits in all
numbers. Continuing with the example above, this will be 25+21+125 = 171, total number of digits
= 7, and the final answer is 171/7 = 24.42
Download