ITI 1120 - Assignment

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 或邮箱:[email protected]

微信:codehelp

原文地址:https://www.cnblogs.com/clga/p/11604339.html

时间: 2024-08-30 18:28:59

ITI 1120 - Assignment的相关文章

PatentTips - Device virtualization and assignment of interconnect devices

BACKGROUND Standard computer interconnects, particularly for personal computers or workstations, may employ a bus such as Peripheral Component Interconnect ("PCI"), Industry Standard Architecture ("ISA"), or Extended ISA ("EISA&qu

Algorithm Part I:Programming Assignment(2)

问题描述: Programming Assignment 2: Randomized Queues and Deques Write a generic data type for a deque and a randomized queue. The goal of this assignment is to implement elementary data structures using arrays and linked lists, and to introduce you to g

RailsCast26 Hackers Love Mass Assignment rails中按params创建、更新model时存在的安全隐患

Mass assignment是rails中常用的将表单数据存储起来的一种方式.不幸的是,它的简洁性成了黑客攻击的目标.下面将解释为什么及如何解决. 上述表单为一个简单的注册表单.当用户填入name,点击提交时,一个新用户被创建.用户模型被如下定义: ruby create_table :users do |t| t.string :name t.boolean :admin, :default => false, :null => false end 当用户点击提交时,如下的action被执

hdu4781 Assignment For Princess(构造)

题目链接:hdu4781 Assignment For Princess 题意:n个点m条边,每条有向边的权值分别是1,2,3…m,一个点能到达任意一个点,没有重边和自环,没有任何两条边的权值相同,任意一个有向环的权值和必须是3的倍数,现在需要把这个图输出来. 题解:注意到题目给出的范围m >= n+3,所以一定是可以构造出一个1~n的回路使得权值和为3的倍数的,可以让前n-1条边权值为1~n-1,第n条边(n->1)可以为n, n+1, n+2从而满足题意,后面再连任意两条不相邻的边时,边权

1120 机器人走方格 V3

1120 机器人走方格 V3 基准时间限制:1 秒 空间限制:131072 KB N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走.并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10007的结果. Input 输入一个数N(2 <= N <= 10^9). Output 输出走法的数量 Mod 10007. Input示例 4 Output示例 10 思路:这个在对角线的上方,就可以转换为,火车进

多学科仿真ITI SimulationX 3.7.1.39440 1CD+UDA.ConstructionSuite.v7.0 1CD

多学科仿真ITI SimulationX 3.7.1.39440 1CDITI SimulationX 在统一的平台实现 了多学科领域的系统工程的建模和仿 真.SimulationX可以根据用户需求自定 义界面,而简单快捷的建模方式可以满 足不同用户的要求.根据不同行业的特 点,用户可以利用Type Designer工具自 定义标准元件.对元件库的标准元件进行扩展.对已有模型进行封装以及对所 建模型加密,且具有良好的开放性.继 承性和保密性. SimulationX经过严格复杂的专业 验证和应用

&lt;Effective C++&gt;读书笔记--Ctors、Dtors and Assignment Operators

<Item 5> Know what functions C++ silently writes and calls 1.If you don't declare them yourself, compilers will declare their own versions of a copy constructor, a copy assignment operator, and a destructor. Furthermore, if you declare no constructo

题目1120:全排列

题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列.我们假设对于小写字母有'a' < 'b' < ... < 'y' < 'z',而且给定的字符串中的字母已经按照从小到大的顺序排列. 输入: 输入只有一行,是一个由不同的小写字母组成的字符串,已知字符串的长度在1到6之间. 输出: 输出这个字符串的所有排列方式,每行一个排列.要求字母序比较小的排列在前面.字母序如下定义:已知S = s1s2...sk , T = t1t2...tk,则S < T 等价

POJ 3189 Steady Cow Assignment(最大流)

POJ 3189 Steady Cow Assignment 题目链接 题意:一些牛,每个牛心目中都有一个牛棚排名,然后给定每个牛棚容量,要求分配这些牛给牛棚,使得所有牛对牛棚的排名差距尽量小 思路:这种题的标准解法都是二分一个差值,枚举下界确定上界,然后建图判断,这题就利用最大流进行判断,值得一提的是dinic的效率加了减枝还是是卡着时间过的,这题理论上用sap或者二分图多重匹配会更好 代码: #include <cstdio> #include <cstring> #inclu