ITI 1120留学生代做、代写Python程序设计

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



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 


因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:99515681@qq.com

微信:codehelp


相关文章