Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1. Show the result of evaluating each expression. Be sure that the value is in the proper form
to indicate, its type (int, long int, or float). If the expression is illegal, explain why.
4.0 / 10.0 + 3.5 * 2 = 7,4 (float)
>>> The first count 4 divided by 10 and 3.5 multiplied by 2 and then adds up the
two results. Calculation :(4.0/10.0) + (3.5 * 2) = (0.4)+(7)= 7.4
10 % 4 + 6 / 2 = 5.0 (float)
>>> The first count 10 % by 4 and 6 divided by 2 and then adds up the two result.
Calculation: (10%4) + (6/2) = 2 + 3.0 = 5.0
abs(4 - 20 / 3) ** 3 = 18.96296296296297 (float)
>>> The first count 20 divided by 3 equal to 6.667, then 4 subtracts by 6.667 and
then the result squared by 3. Calculation: [4 – (20/3) ]3 = 18.96296296296297
sqrt(4.5 - 5.0) + 7 * 3 = (NameError: name 'sqrt' is not defined)
>>> because sqrt() is not a builtin function, it's located in the 'math' module. Must
have imported it at some point. Or it could be be getting imported without your
direct knowledge through ~/.pythonrc.py, $PYTHONSTARTUP, and/or by doing
'import user'. For that matter, size() is not built into Python either, so you're
definitely importing these things somewhere. Adding explicit imports of the
modules/functions in question to the top of the file(s) in question should fix the
problem.
3 * 10 / 3 + 10 % 3 = 11.0 (float)
>>> The first count 3 multiplied 10 and the result divided by 3, and count 10 %
by 3 then adds up the two result. Calculation : ((3 * 10) / 3 )+ (10 % 3 )= 11.0
3L ** 3 = (SyntaxError: invalid syntax)
>>> because Longs were defined by appending an L to the end of the number,
and they could be, well, longer than ints. In Python 3, there is only one integer
type, called int, which mostly behaves like the long type in Python 2.
2. The Konditorei coffee shop sells coffee at $10.50 a pound plus the cost of shipping. Each
order ships for $0.86 per pound + $1.50 fixed cost for overhead. Write a program that
calculates the cost of an order.
def main():
print ("Program that calculates the cost of an order :")
cost = float(input("Enter the Order (pound):"))
if (cost<=1):
price = cost * 10.50 + 0.86
if (cost >1):
price = cost * 10.50 + 0.86 + 1.50
print ("Total Cost must be paid", price)
main()
3. Write a program that accepts two points (see previous problem) and determines the
distance between them. D= (x2-x1)2 + (y2 + y1)
import math
def Welcome():
print ('the distance between X and Y')
x1 = float(input ('Enter the x1 value here:'))
y1 = float(input ('Enter the y1 value here:'))
x2 = float(input ('Enter the x2 value here:'))
y2 = float(input ('Enter the y2 value here:'))
points = (x2 - x1)**2+(y2 + y1)**2
Answer = math.sqrt(points)
print('The distance is', Answer)
Welcome()