Need help with gallons of paint problem please

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

Need help with gallons of paint problem please

Postby callia » Sun Sep 25, 2016 7:56 pm

program:
250.0 square feet wall will need:
0.714285714286 gallons of paint

Code: Select all
wall_area = 250.0
gallons_paint = 0.0

wall_area = float(input('What is the area of the wall (in square feet)?'))
gallons_paint = wall_area*1.0/350;
print(str(wall_area)+" square feet will need:"+ str(gallons_paint)+" gallons of paint")
   
print(wall_area, 'square feet wall will need:')
print(gallons_paint, 'gallons of paint')


Result:

What is the area of the wall (in sq ft)?Traceback (most recent call last):
File "main.py", line 4, in
wall_area = float(input('What is the area of the wall (in sq ft)?'))
EOFError: EOF when reading a line

The solution is the middle 3 lines and there's something wrong with the first line but I cannot figure it out. Any help is greatly appreciated!! :D :D
User avatar
callia
 
Posts: 4
Joined: Mon Sep 12, 2016 3:36 pm

Re: Need help with gallons of paint problem please

Postby micseydel » Sun Sep 25, 2016 8:09 pm

How is your program getting its input?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Need help with gallons of paint problem please

Postby Ofnuts » Sun Sep 25, 2016 8:15 pm

The only way I can reproduce something close to your error is when I input an empty line ([enter] without any data, or empty line in input file), executing your code under Python v2 (despite the Python v3 syntax in the print() calls).
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: Need help with gallons of paint problem please

Postby callia » Sun Sep 25, 2016 8:19 pm

I stumbled upon...

I started taking away lines of code until I was left with:

Code: Select all
wall_area = 250.0
gallons_paint = 0.0

gallons_paint = wall_area*1.0/350;

print(wall_area, 'square feet wall will need:')
print(gallons_paint, 'gallons of paint')


and then I was successful!
User avatar
callia
 
Posts: 4
Joined: Mon Sep 12, 2016 3:36 pm

Re: Need help with gallons of paint problem please

Postby sparkz_alot » Sun Sep 25, 2016 10:00 pm

Given your original code, with comments
Code: Select all
wall_area = 250.0    # Do not need
gallons_paint = 0.0   # Do not need

wall_area = float(input('What is the area of the wall (in square feet)?'))
gallons_paint = wall_area*1.0/350;    # Do not need to multiply by 1.0, do not need trailing semi-colan
print(str(wall_area)+" square feet will need:"+ str(gallons_paint)+" gallons of paint")
   
print(wall_area, 'square feet wall will need:')
print(gallons_paint, 'gallons of paint')


and using the print format, we can scrunch it up to:
Code: Select all
wall_area = float(input('What is the area of the wall (in square feet)?'))
gallons_paint = wall_area / 350

print("A {} square foot wall will need:\n{} gallons of paint".format(wall_area, gallons_paint))


Not sure where you can buy 0.714285714286 gallons of paint though :D . Are you allowed to import modules?
THIS FORUM WILL BE CLOSING OCT 1, 2016. PLEASE STOP BY AND REGISTER AT THE NEW LOCATION
http://python-forum.io
User avatar
sparkz_alot
 
Posts: 269
Joined: Sat Dec 06, 2014 2:55 pm
Location: US

Re: Need help with gallons of paint problem please

Postby Yoriz » Sun Sep 25, 2016 10:50 pm

The code shown is python3 code but I expect you are using python2, either change to python 3 or change
Code: Select all
input

to
Code: Select all
raw_input

and the prints remove the ()
Code: Select all
print('some text')

to
Code: Select all
print 'some text'
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to Homework

Who is online

Users browsing this forum: No registered users and 1 guest

cron