Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON HELP! 1) Write a program that prompts the user for two integers and then

ID: 3787303 • Letter: P

Question

PYTHON HELP!

1)

Write a program that prompts the user for two integers and then prints: a) The sum b) The difference c) The product d) The average e) The distance (absolute value of the difference) f) The maximum (the larger of the two) g) The minimum (the smaller of the two)

2)

Write a program that asks the user to input: a) The number of gallons of gas in the tank b) The fuel efficiency in miles per gallon c) The price of gas per gallon Then print: a) The cost per 100 miles b) How far the car can go with the gas in the tank MUST BE IN PYTHON! Thanks You

Explanation / Answer

Hi,

The code is written below, well i have used python27 you can use some other versions too there will be slight difference in syntax but same logic and code. If you have any further doubt or querry feel free to ask.

1) code-

a=int(raw_input("Enter 1st integer:"))
b=int(raw_input("Enter 2nd integer:"))

if a>=b:
   print "Maximum number is:",a
   print "The distance(absolute difference) is:",(a-b) #distance always positive
else
   print "Minimum number is:",b
   print "The distance(absolute difference) is:",(b-a) #distance always positive

print "The sum is:",(a+b)
print "The difference is:",(a-b)
print "Average:",(a+b)/2
print "Product of numbers:",(a*b)

2) code-

a=int(raw_input("Enter gallons of gas in tank:"))
b=int(raw_input("Enter fuel efficiency in miles/gallon:"))
c=int(raw_input("Enter the price of gas per gallon:"))

d=a*b #total miles travelled by gas present in tank
e=d*c #total cost for d miles
f=(e/d)*100 #cost for 100 miles

print "Cost per 100 miles:",f
print " the car can go with the gas in the tank for:",d

Thankyou for using Chegg!!!