• Welcome to ForumKorner!
    Join today and become a part of the community.

Python Question

Status
Not open for further replies.

MCG

Active Member
Reputation
0
*Q9 Write a program to say whether for a given amount of petrol and a given miles per gallon a driver has enough to make a journey of a given number of miles.
TEST this for:
a) 15.7 gallons, doing 47.1 mpg, for 746 miles, and
b) 14.6 gallons, doing 38.3 mpg, for 555 miles.

Solution:

print('Please enter the number of gallons')
gallons=float(input())
print('Please enter the amount of mpg (miles per gallon)')
mpg=float(input())
print('Please enter the number of miles')
miles=float(input())
petrol=miles/mpg
if petrol<gallons:
print('You would need',petrol,'gallons and you have',gallons,'You have enough petrol for this journey')

if petrol>gallons:
print('You would need',petrol,'gallons and you have',gallons,'You do not have enough petrol for this journey')

*Q10 Write a program which inputs three numbers and then says which is the largest and which is the smallest.
TEST this for:
a) 17, 13.5, 16.2, and
b) 0.0001, 0.000001, 0.00001


I know these are pretty simple to some people but I haven't learnt how to do this shit yet.
EDIT: I worked out the solutions.
 
Status
Not open for further replies.
Top