Practical Assignment

advertisement
Practical Assignment (Python)
Session 2013-14 (XI)
1)(Convert Celsius to Fahrenheit) Write a program that reads a Celsius degree from the console and converts it to
Fahrenheit and displays the result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32
2) (Find the number of years and days) Write a program that prompts the user to enter the minutes (e.g., 1 billion), and
displays the number of years and days for the minutes. For simplicity, assume a year has 365 days.
3) (Science: calculate energy) Write a program that calculates the energy needed to heat water from an initial
temperature to a final temperature. Your program should prompt the user to enter the amount of water in kilograms
and the initial and final temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature – initialTemperature) * 4184
where M is the weight of water in kilograms, temperatures are in degrees Celsius, and energy Q is measured in joules
4) (Physics: find runway length) Given an airplane’s acceleration a and take-off speed v, you can compute the
minimum runway length needed for an airplane to take off using the following formula:
Write a program that prompts the user to enter v in meters/second (m/s) and the acceleration a in meters/second
squared and displays the minimum runway length.
5) (Financial application: investment amount) Suppose you want to deposit a certain amount of money into a savings
account with a fixed annual interest rate. What amount do you need to deposit in order to have $5,000 in the account
after three years? The initial deposit amount can be obtained using the following formula:
6) (Geometry: area of a triangle) Write a program that prompts the user to enter the three points (x1, y1), (x2, y2), and
(x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is
7) (Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same
length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for
computing the area of a regular polygon is :
Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a
regular polygon and displays its area.
8) (Geometry: great circle distance) The great circle distance is the distance between two points on the surface of a
sphere. Let (x1, y1) and (x2, y2) be the geographical latitude and longitude of two points. The great circle distance
between the two points can be computed using the following formula:
Write a program that prompts the user to enter the latitude and longitude of two points on the earth in degrees and
displays its great circle distance. The average earth radius is 6,371.01 km. Note that you need to convert the degrees
into radians using the math.radians function since the Python trigonometric functions use radians. The latitude and
longitude degrees in the formula are for north and west.Use negative to indicate south and east degrees.
9) (Geography: estimate areas) Find the GPS locations for Atlanta, Georgia;Orlando, Florida; Savannah, Georgia; and
Charlotte, North Carolina from and compute the estimated area enclosed by these four cities.
Yo compute the distance between two cities.
Divide the polygon into two triangles and use the formula
10) (Decimal to hex) Write a program that prompts the user to enter an integer between 0 and 15 and displays its
corresponding hex number.
11) (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of
the week. The formula is
12)
is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero,
the equation has one root. If it is negative, the equation has no real roots. Write a program that prompts the user to enter
values for a, b, and c and displays the result based on the discriminate. If the discriminant is positive, display two
roots. If the discriminant is 0, display one root. Otherwise, display The equa- tion has no real roots.
13) Write a program to compute the
14)
up to n terms .
Define a function get Bigger Number (x,y) to take in two numbers and return the bigger of them
15 Display the following figure
16
(Palindromic prime) A palindromic prime is a prime number that is also palindromic. For example, 131 is a prime and
also a palindromic prime, as are 313 and 757. Write a program that displays the first 100 palindromic prime numbers.
. Display 10 numbers per line and align the numbers properly, as follows:
2
3
5
7
11 101 131 151 181 191 313 353 373 383 727 757 787 797 919 929
17
18
19(Decimal to hex) Write a program that prompts the user to enter a decimal integer and displays its corresponding
hexadecimal value.
20(Display leap years) Write a program that displays, ten per line, all the leap years in the twenty-first century
(from year 2010 to 2100). The years are separated by exactly one space.
21(Twin primes) Twin primes are a pair of prime numbers that differ by 2. For example, 3 and 5, 5 and 7, and 11 and 13
are twin primes. Write a program to find all twin primes less than 1,000. Display the output as follows:
(3, 5)
(5, 7)..
22
23(Palindrome number) Write a program that prompts the user to enter a three-digit integer and determines
whether it is a palindrome number. A number is a palindrome if it reads the same from right to left and from left
to right.
24 (Geometry: points in triangle?) Suppose a right triangle is placed in a plane as shown below. The right-angle
point is at (0, 0), and the other two points are at (200, 0), and (0, 100). Write a program that prompts the user
to enter a point with x- and y-coordinates and determines whether the point is inside the triangle. Here are
some sample runs:
25 (Geometry: point position) Given a directed line from point p0(x0, y0) to p1(x1,y1), you can use the following condition to
decide whether a point p2(x2, y2) is on the left side of the line, on the right side of the line, or on the same line
Download