JK Week9 HMK

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Junior Knights Review Homework for Programming Contest (Due 11/30/2012)

Problem A (5 points): Movie Tickets (movie.py)


It's Christmas time and you're taking your whole family to the movies! To make your task easier,
you want to write a program that determines the cost of the tickets. Child tickets cost $7 per
ticket and Adult tickets cost $10 per ticket, with tax already included. Write a program to ask the
user how many adult and child tickets they want to buy and print out the total cost of their
purchase.

Input and Output Restrictions


The user will enter two non-negative integers less than 100. Your program output should follow
the sample below and output the total cost as an integer number of dollars.

Sample Run
How many child tickets do you want?
3
How many adult tickets do you want?
7
Your cost will be $91.

Problem B (5 points): Movie Ticket Discounts (discount.py)


You've been buying so many movie tickets, you believe that you deserve a discount! You ask the
manager at the movie theater and she agrees to implement a discount for large purchases. In
particular, if a single purchase contains in between 10 and 24 tickets, inclusive, a 10% discount
will be given. If a single purchase contains 25 or more tickets a 25% discount will be given. The
original prices of tickets are still the same as in problem A. Given this discounting system,
determine the cost of the tickets.

Input and Output Restrictions


The user will enter two non-negative integers less than 100. Your program output should follow
the sample below and output the total cost as a double rounded to 2 decimal places.

Sample Run
How many child tickets do you want?
3
How many adult tickets do you want?
7
Your cost will be $81.90.
Problem C (5 points): Fish Tank Glass (fishtank.py)
You work for a large aquarium and are helping them decide some parameters for a new fishtank
they are buying. In particular, you need to help them calculate the cost of a fishtank and the
amount of water (in cubic inches) that will fit in it.

A fishtank is made out of five panes of glass. (The top is left open, so no pane of glass is needed
for the top.) The cost of a pane of glass is based on the area of its main surface. In particular, one
square inch of glass costs 15 cents. (This is a high price, but the glass used for large fishtanks is
special glass that is very strong.) Thus, a 4" x 8" pane of glass would cost 4 x 8 x $.15 = $4.80.

The user will enter the length, width and height of the proposed fish tank in inches.

Input and Output Restrictions


The dimensions the user will enter will be in inches and each value will be a positive integer less
than 200. Your program output should follow the sample below and output the total cost of
building the fish tank to the nearest cent as well as the volume of water it can hold, in cubic
inches, as an integer.

Sample Run
Enter the length, width and height of the fish tank in inches.
18 36 24
Your cost for building the tank will be $486.00.
The volume is 15552 cubic inches.
Problem D (10 points): Paper Folding (fold.py)
If you take a piece of paper and fold it in half, then fold it in half again, and again and so on, the
paper becomes thicker each time. Assuming you can continually fold the paper (it has been said
you can only fold a piece of paper in half 8 times, it is referred to as the “Folding Paper
Problem”) the thickness of it will exponentially grow. After 50 folds of a standard piece of paper
(0.1 mm thick) it would be nearly the distance from the Earth to the Sun (1.475 x 1011 meters).

Input and Output Restrictions


Prompt the user for the thickness of the piece of paper, the number of folds they want to perform
on a given sheet of paper and a fold increment value. The thickness (in millimeters) will be a
positive real number less than 100. The last two numbers will both be positive integers and have
a product less than or equal to 50. You'll print out a chart labeled with the number of folds,
which increments by the given value, and the thickness of the paper (in meters) for each fold.
The number of folds will be a non-negative integer and the thickness should be printed in meters
to 6 decimal places. (Note: 6 decimal places is the default output for printing a double.)

Sample Run
How thick is your sheet of paper (in millimeters)?
.1
How many times would you like to fold the paper?
50
What increment would you like to use for the table?
10
Folds Thickness
0 0.000100
10 0.102400
20 104.857600
30 107374.182400
40 109951162.777600
50 112589990684.262405
Problem E (10 points): Difference of Sums (sumdiff.py)
The sum of squares of the first 3 natural numbers is
12 + 22 + 32 = 14

The square of the sum of the first 3 natural numbers is


(1 + 2 + 3)2 = 36

The difference between these two is 36 – 14 = 22. (Note that the latter is always greater than or
equal to the former.) Your task is to write a program that computes the difference between the
square of the sums and the sum of the squares for natural numbers in a given range.

Input and Output Restrictions


The user will enter two positive integers less than or equal to 1000. The first integer (minimum)
will be less than or equal to the second integer (maximum). The range described will be
inclusive. Hence, the range of values from 3 to 5 includes 3, 4 and 5. Follow the input and output
format below and output the difference as a non-negative integer.

Sample Run
Enter the minimum value of the range.
5
Enter the maximum value of the range.
15
The desired difference is 10890.

Problem F (10 points): Number of Tiles (tiles.py)


You are attempting to tile a room with square tiles. You are given the dimensions of the room in
feet (length and width). In addition, you are given the number of feet on the side of a single tile.
Given this information, your goal is to figure out the maximum number of tiles (without any
cutting) that fit on the floor of the room. For example, if the room was 9' x 6' and each tile was a
2' x 2' tile, then 12 tiles would fit. (A 4 by 3 tile design would fit. No more tiles would fit in
either dimension.)

Input and Output Restrictions


All values entered will be positive integers less than 500.

Sample Run
Enter the dimensions of the room, in feet.
9 6
Enter the length of the side of a tile, in feet.
2
You can place a maximum of 12 complete tiles.
Problem G (15 points): Flag Designs (flag.py)
The US flag has stars for each state on it. They are arranged such that the odd numbered rows
have 6 stars and the even numbered rows have 5 stars. Given the number of stars and a total
number of rows (which is always odd), one can determine whether or not a star pattern like the
US flag is possible. Your job is to determine this. If it's possible, print out the star design.

Input and Output Restrictions


The user will enter a positive integer for the number of stars that is less than 1000. The user will
enter a positive odd integer for the number of rows that is less than 1000. If there is no valid
configuration of stars for the numbers entered, output the following sentence.

Sorry, no star design fits your specification.

Otherwise, print out the star design, with a single space between each star on each row. For
example, the star design for the US flag (50 stars, 9 rows), should be printed as follows:

* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *

Sample Run
Enter the number of stars for your design.
50
Enter the number of rows for your design.
13
Sorry, no star design fits your specification.

Sample Run
Enter the number of stars for your design.
29
Enter the number of rows for your design.
3
* * * * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Problem H (15 points): Arup's Pseudoprimes (fakeprimes.py)
Many students think that if a number is not divisible by 2, 3, 5 or 7, that it is prime. However,
this isn’t always true. For example, 121 isn’t divisible by any of those four values, but 121 = 11
x 11, so it isn’t prime. Arup pseudoprimes are numbers that ARE NOT prime, but also are not
divisible by 2, 3, 5 or 7. Write a program, that, given a range of positive integers, prints out all
the integers within the range that are Arup pseudoprimes.

Input and Output Restrictions


Both integers entered will be positive integers less than or equal to 10000. The first integer will
be less than or equal to the second integer. The range of numbers described will be inclusive.
Hence, if the user enters 119 for the low bound and 121 for the high bound, then your program
should consider the integers 119, 120 AND 121. From these, only 121 is an Arup pseudoprime
and should be printed. For the output, simply output one Arup pseudoprime per line and list them
in numerically increasing order.

Sample Run
Enter the low bound for your search of Arup pseudoprimes.
50
Enter the high bound for your search of Arup pseudoprimes.
200
121
143
169
187

You might also like