首页 >
> 详细

ITI 1120 - Assignment 1

Submit a zip file with a1q1.py, a1q2.py, a1q3.py, a1q4.py.

1. (2 points) Two numbers a and b are called pythagorean pair if both a and b are

integers and there exists an integer c such that a

2 + b2 = c2. Write a

function pythagorean_pair(a,b) that takes two integers a and b as input and returns

True if a and b are pythagorean pair and False otherwise.

2. (3points ) Write a function in_out(xs,ys,side) that takes three numbers as input, where

side is non-negative. Here xs and ys represent the x and y coordinates of the bottom

left corner of a square; and side represents the length of the side of the square.

(Notice that xs, ys, and side completely define a square and its position in the plane).

Your function should first prompt the user to enter two numbers that represent the x

and y coordinates of some query point. Your function should print True if the given

query point is inside of the given square, otherwise it should print False. A point on the

boundary of a square is considered to be inside the square.

Examples.:

in_out(0, 0, 2.5)

Enter a number for the x coordinate of a query point: 0

Enter a number for the y coordinate of a query point: 1.2

True

in_out(2.5, 1, 1)

Enter a number for the x coordinate of a query point: -1

Enter a number for the y coordinate of a query point: 1.5False

3. (7 points) As few coins as possible, please!

Suppose that a cashier owes a customer some change and that the cashier only has

quarters, dimes, nickels, and pennies. Write a program the computes the minimum

number of coins that the cashier can return. To solve this problem use the greedy

algorithm explained below.

PROBLEM STATEMENT: Your program should first ask the user for the amount of

money he/she is owed (in dollars). You may assume that the user will enter a positive

number. It should then print the minimum number of coins with which that amount can

be made. Assume that the only coins available are quarters (25 cents), dimes (10

cents), nickels (5 cents), and pennies (1 cent).

EXAMPLES: If cashier owes 56 cents (i.e. $0.56) to the customer, the minimum number

of coins the cashier can return is 4 (in particular, 2 quarters, 0 dimes, 1 nickel and 1

penny. It is not possible to return 3 or less coins). If cashier owes $1.42 to the customer,

the minimum number of coins the customer can return is 9 (in particular 5 quarters, 1

dime, 1 nickel and 2 cents). Thus your program will look like this, for different runs:

Enter the amount you are owed in $: 0.56

The minimum number of coins the cashier can return is: 4

Enter the amount you are owed in $: 1.42

The minimum number of coins the cashier can return is: 9

Enter the amount you are owed in $: 1.00

The minimum number of coins the cashier can return is: 4

4. (8 points) Light years.

In order to build a space communication system we need to be able to calculate

distances between planets and stars, and time intervals required for transmissions. Our

communication is done with electromagnetic waves that travel at the speed of light.

One unit for measuring distances is the light-year, the distance traveled by light in one

year. But how many days are there in one year? There are several possible

interpretations. We adopt the definition of a sidereal year. The sidereal year is the time

for the Sun to return to the same position in respect to the stars of the celestial sphere.

The sidereal year is the orbital period of Earth and consists of 365.26 days.

Implement a function that converts a given number of sidereal years into seconds,

knowing that there are 365.26 days in a sidereal year. The program a1q4.py should

read a number of second from the keyboard; call the function to converts it into

seconds, and display the result.

b) A light-second is the distance traveled by light in one second. Write a function to

convert a given number of light-seconds into kilometers, knowing that the speed of light

is about 300,000 kilometers/second. Expend your program a1q4.py to transform the

number of second calculates in part a) into a distance by using your new function, and

to display the result.

c) Using your functions from a) and b), implement a function to find the distance (in

kilometers) traveled by a communication signal from one star to another via Earth. Your

program a1q3.py should be extended to ask the user to input the distances between

each star and Earth (in light-years), call the function and display the result.

Example:

Input a number of light-years: 7

The number of seconds is 220909248.0

The distance is 66272774400000.0 km.

Input the distance to the first star, in light years: 0.5

Input the distance to the second star, in light years: 1.2

The distance between the two stars is 16094816640000.0 km

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp

- 95-712留学生作业代做、代写java编程设计作业、代做polymorph 2019-10-18
- 代做ols留学生作业、代写r程序语言作业、代做r编程设计作业、代写linea 2019-10-18
- Sdgb 7844作业代做、R编程设计作业代做、代写markdown留学生作 2019-10-18
- 代写math4/68091作业、代做statistical Computin 2019-10-18
- Analytics留学生作业代做、代写data Visualisation作 2019-10-18
- 代写frt留学生作业、代写r语言作业、代做datasets课程作业、R编程设 2019-10-18
- 代做sta 442课程作业、代写effects Models作业、Pytho 2019-10-17
- Se 3316A作业代做、代写web Technologies作业、Java 2019-10-17
- 代写csi213留学生作业、代做data Structures作业、代写ja 2019-10-17
- Cse 325作业代写、C/C++编程设计作业调试、Program留学生作业 2019-10-17
- 代做fit2014留学生作业、代做c++课程设计作业、Information 2019-10-17
- Scm 460课程作业代做、代写r编程设计作业、代做r实验作业、代写data 2019-10-17
- 代写rad留学生作业、代做r, Matlab/C++编程语言作业、代写r课程 2019-10-17
- Comp5338作业代写、Sql程序语言作业调试、代写schema Desi 2019-10-17
- 代做159.20留学生作业、代写rle课程作业、Java编程设计作业调试、P 2019-10-17
- 代做gu4206/Gr5206作业、代写r程序语言作业、代写data留学生作 2019-10-16
- Fit2104留学生作业代做、代写sql语言作业、Sql编程语言作业调试、代 2019-10-16
- 代写glfrustum课程作业、代做python程序语言作业、代写java， 2019-10-15
- 代写software留学生作业、代做information Technolo 2019-10-15
- 31927留学生作业代做、Net Applications作业代写、C++程 2019-10-15