首页 >
> 详细

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.5

False

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
- 微信：codinghelp2

- You Have Implemented A Simple Web Serv... 2020-05-31
- Stat 5511 Homework 4 2020-05-31
- Lab 7 2020-05-31
- 代写cosc 363作业、代做computer Graphics作业、代写c 2020-05-31
- Eie111课程作业代写、C++程序设计作业调试、代做c/C++语言作业、代 2020-05-31
- Math502作业代做、Mathematics课程作业代做、Java，Pyt 2020-05-31
- 代写sit114课程作业、代做data留学生作业、代写r编程设计作业、代做r 2020-05-31
- Envx3002作业代写、R程序语言作业调试、R课程设计作业代做、代写dat 2020-05-31
- Ee6435 Programming Homework 2020-05-30
- Computer Architecture Homework 3 2020-05-30
- Infs7450作业代做、Media Analytics作业代写、Pytho 2020-05-29
- 代写stats 782作业、代做r编程设计作业、代写data留学生作业、R课 2020-05-29
- 代写math223作业、R课程设计作业代做、代写data课程作业、R程序语言 2020-05-28
- 代写kxo151留学生作业、代做programming作业、Java语言作业 2020-05-28
- Math 160作业代做、Data课程作业代写、Matlab程序设计作业调试 2020-05-28
- 代做csci 3120作业、Program课程作业代做、C/C++语言作业代 2020-05-28
- St2020课程作业代做、Statistics作业代做、R程序设计作业调试、 2020-05-28
- Com1005作业代写、Ai Techniques作业代做、Java语言作业 2020-05-28
- 代写sit216留学生作业、Python程序语言作业调试、Java/C++实 2020-05-28
- 代写artificial课程作业、Java，Python程序语言作业调试、C 2020-05-27