首页 >
> 详细

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

- Data Visualisation And Analytics Assi... 2019-11-15
- Block Breaker Assignment Game Engine ... 2019-11-15
- Data Visualisation And Analytics 2019 2019-11-15
- Event Driven Computing 2019 Assignment... 2019-11-15
- Fit1043 Assignment 3 2019-11-15
- Event Driven Computing Assignment 3 - ... 2019-11-15
- 代做data Ming作业、代写systematic课程作业、代写r编程语言 2019-11-15
- Cs210留学生作业代做、Java编程语言作业调试、Java课程设计作业代写 2019-11-15
- 代写stat 385作业、代做r程序语言作业、代写r课程设计作业、Progr 2019-11-15
- 代写cpeg 222作业、Java，C/C++程序语言作业调试、Python 2019-11-15
- Ece 547作业代做、代写python编程设计作业、代做networks留 2019-11-15
- Csc8202作业代做、Web编程语言作业代写、代做web、Html课程设计 2019-11-15
- 代写mathematics课程作业、Matlab编程语言作业代做、代写mat 2019-11-15
- 代做pyopencl留学生作业、Python程序设计作业调试、Python实 2019-11-15
- Rtos Kernel作业代做、代写python，C++程序语言作业、代做j 2019-11-14
- Algorithm课程作业代写、代做r课程设计作业、R编程语言作业调试、代写 2019-11-14
- 代做fpu留学生作业、代写python，Java编程设计作业、代写c++语言 2019-11-14
- 代写msc/Icy课程作业、代写software留学生作业、代做java语言 2019-11-14
- Cse105留学生作业代做、Java程序语言作业调试、代做programmi 2019-11-14
- 代写fm 9528留学生作业、代做risk Analytics作业、Java 2019-11-14