I need to write this program using a loop
this is what i have so far but my program has to look exactly and the picture???
def main():
sum=0.0
for i in range(1,6):
x,y=eval(input("Please enter length and width of room:"))
sf=(x*y)
sum=sum+sf
print("The total square footage is",sum)
main()
Thank you for your help...
Just drop the indent on the print statement.
sum=0.0
for i in range(1,6):
x,y=eval(input("Please enter length and width of room:"))
sf=(x*y)
sum=sum+sf
print("The total square footage is",sum)
edited:
This is a common technique in python you could use to achieve what you want:
sum=0.0
for i in range(1,6):
x,y=eval(input("Please enter length and width of room %i:" % i ))
sf=(x*y)
sum=sum+sf
print("The total square footage is %i" % sum )
What i'm doing here is placing a wildcard in the middle of the string and then pass the parameters. '%i' tells the % operator that you are going to insert an integer. You can also put '%s' if you were going to add a string. There are a couple more you can check out. This is another example for the console:
>>> user_name = 'mauricio'
>>> sum = 42
>>> line_to_print = 'Hello user %s, your sum is %i' % (user_name, sum)
>>> print(line_to_print)
Hello mauricio, your sum is 42