Task1 Task2 Python

Downloads 1

Task 1

Create a program called task1.py.
This program needs to display the timetables for any number.
For example, say the user enters 6 the program must print:
The 6 times table is:
6 x 1 = 6
6 x 2 = 12

6 x 12 = 72
Compile, save and run your file

Task 2

A simple rule to determine whether a year is a leap year is to test whether it is
a multiple of 4.
Create a program called task2.py.
Write a program to input a year and a number of years.
Then determine and display which of those years were or will be leap
What year do you want to start with? 1994
How many years do you want to check? 8
1994 isn’t a leap year
1995 isn’t a leap year
1996 is a leap year
1997 isn’t a leap year
1998 isn’t a leap year
1999 isn’t a leap year
2000 is a leap year
2001 isn’t a leap year
Compile, save and run your file.

Switch Case Javascript

Downloads 2

Create a switch..case statement to check against highSchoolGrade within the switch statement. Then, within the case statements, set yourGrade to the appropriate string. Add your switch..case code to the provided updateGrade() function:in case 9, assign “Freshman” to the yourGrade variable
in case 10, assign “Sophomore” to the yourGrade variable
in case 11, assign “Junior” to the yourGrade variable
in case 12, assign “Senior” to the yourGrade variable
include a default case that assigns “Invalid” to yourGrade.

Queue Python

Downloads 3

Define a class Queue which implements the abstract data type queue. As part of your definition of Queue, define the following methods:__init__(self) which creates an empty queue.
enqueue(self, x) which adds x to the end of the queue.
dequeue(self) which removes and returns the first (= oldest) element in the queue.
__len__(self) which returns the total number of elements currently in the queue.
You are free to define and use suitable instance variables to store the items in

finance_calculators Python

Downloads 4

For this task, assume that you have been approached by a small financial
company and asked to create a program that allows the user to access two
different financial calculators: an investment calculator and a home loan
repayment calculator.
● Create a new Python file in this folder called finance_calculators.py.
● At the top of the file include the line import math
● Write the code that will do the following:
1. The user should be allowed to choose which calculation they want
to do. The first output that the user sees when the program runs
should look like this :
How the user capitalises their selection should not affect how the
program proceeds. I.e. ‘Bond’, ‘bond’, ‘BOND’ or ‘investment’,
‘Investment’, ‘INVESTMENT’, etc. should all be recognised as valid
entries. If the user doesn’t type in a valid input, show an appropriate
error message.
2. If the user selects ‘investment’, do the following:
■ Ask the user to input:
● The amount of money that they are depositing.
● The interest rate (as a percentage). Only the number
of the interest rate should be entered — don’t worry
about having to deal with the added ‘%’, e.g. The user
should enter 8 and not 8%.
● The number of years they plan on investing for.
● Then ask the user to input whether they want “simple”
or “compound” interest, and store this in a variable
called interest. Depending on whether they typed
“simple” or “compound”, output the appropriate
amount that they will get after the given period at the
interest rate. Look below in “Interest formulae” for the
formulae to be used.
Interest formula:
The total amount when simple interest is applied is calculated as
follows: A = P(1 + r * t)
The Python equivalent is very similar: A =P*(1+r*t)
The total amount when compound interest is applied is calculated as
follows: A = P(1 + r) ^ t
The Python equivalent is slightly different: A = P* math.pow((1+r),t)
In the formulae above:
● ‘r’ is the interest entered above divided by 100, e.g. if 8% is
entered, then r is 0.08.
● ‘P’ is the amount that the user deposits.
● ‘t’ is the number of years that the money is being invested for.
● ‘A’ is the total amount once the interest has been applied.
■ Print out the answer!
■ Try enter 20 years and 8 (%) and see what the difference is
depending on the type of interest rate!
3. If the user selects ‘bond’, do the following:
■ Ask the user to input:
● The present value of the house. E.g. 100000
● The interest rate. E.g. 7
● The number of months they plan to take to repay the
bond. E.g. 120
Bond repayment formula:
The amount that a person will have to be repaid on a home loan each
month is calculated as follows: repayment = x = (i.P)/(1 – (1+i)^(-n))
In the formulae above:
● ‘P’ is the present value of the house.
● ‘i’ is the monthly interest rate, calculated by dividing the annual
interest rate by 12.
● ‘n’ is the number of months over which the bond will be repaid.
■ Calculate how much money the user will have to repay each
month and output the answer.


Downloads 5

A (circular, solid) disk in the plane is completely determined by its radius and its centre (given as x- and y-coordinates). Define a class Disk for representing such disks. Instances of your class should have the following methods:
• init (self, r, x, y) which assigns r to the instance variable radius and assigns x and y to the instance variables centre_x and centre_y , respectively. If r 3 e , then the method should execute the statement
raise valueError
A radius of a is allowed. (What is the geometric meaning of this?)
• diameter (self ) which computes and returns the diameter of a disk.
• area (self ) which computes and returns the area of a disk.
• distance(self, other) which computes and returns the distance between two disks. Given disks D, and D0, where D, has centre (x,, )0 and radius r,, the distance between D, and D, is the maximum of 0 and xx./’ EY] — Y2/2 — —
•_repr_(self) which returns a representation of a disk as a string. This method is already provided below so you do not need to write it yourself.

Cafe Hash Counting Python

Downloads 6

Task 1
Create a new Python file in this folder called cafe.py.
Create a list called menu, which should contain at least 4 items in the
Next, create a dictionary called stock, which should contain the stock
value for each item on your menu.
Create another dictionary called price, which should contain the prices for
each item on your menu.
Next, calculate the total stock worth in the cafe. You will need to
remember to loop through the appropriate dictionaries and lists to do
Finally, print out the result of your calculation.

Task 2

Create a new Python file in this folder called hash.py
Create a dictionary called countryMap, where the KEYS are the name of a
country (i.e. a string), and the VALUE for each key is the name of that
country’s capital city.
○ For example:
countryMap = {
‘UnitedKingdom’: ‘London’,
‘Sweden’: ‘Stockholm’,
‘Canada’: ‘Ottawa’,
What does print(countryMap[‘Sweden’]) return?

Task 3

Write a Python program called counting.py to count the number of
times a character occurs (character frequency) in a string.
Store each letter followed by the number of occurrences in a dictionary
and print it out.
Sample String : ‘google.com’
Expected Result : {‘o’: 3, ‘g’: 2, ‘.’: 1, ‘e’: 1, ‘l’: 1, ‘m’: 1, ‘c’: 1}

Kruskal Wallis

Downloads 7

An instructor divided her class into four groups and asked them to keep track of the number of soft drinks that they consume per week. The data has been ranked and the sums determined for each group.

Soft Drinks Consumed per Week

Group A 7 10 14 12 8

Group B 4 20 6 11 9

Group C 2 5 13 15 10

Group D 3 9 16 17 18

The sums of the ranks for the four groups is as follows:

RA = 51.5 ;RB = 48.5 ;RC = 45.5 ;RD = 64.5

Complete the Kruskal-Wallis test to determine if the hypothesis that the different groups consume the same amount of soft drinks per week is valid at α = 0.05


Downloads 8

You must have 2 functions: one computes the average and the other finds the letter grade. The average function should return back a Real value and the letter grade function should return back a string. All input and output must occur in main().•Only find and display the letter grade for the average,not each test score.


Downloads 9

Write a method that will check an array for an odd number followed by an even number. Find the first odd number. Then, after finding the odd number, start looking at that position for an even number and then return the distance between them. Return -1 if there are no odd numbers or no odd numbers followed by an even number.


Downloads 10

Complete the drawTriangle() function in script.js that draws a triangle with asterisks (*) based on the size parameter.Ex: drawTriangle(4) outputs to the console a triangle with size 4, so the longest side (4 asterisks) appears on the bot***** *****ne:*
Hint: Use a loop inside a loop to complete drawTriangle(). The outer loop is responsible for outputting the asterisk line, and the inner loop is responsible for building the asterisk line with the appropriate length by concatenating asterisks to a single string.To test the JavaScript in your web browser, call drawTriangle() from the JavaScript console.

New Download