n = 1 + 2 + 3the addition proceeds from left to right, the first two numbers are added; then the sum is added to the third: 1 + 2 == 3; 3 + 3 == 6. Even if 100 numbers are added in this loop:
sum = 0.0 for n in 1..100 sum += n end print sumn is added to sum to produce the updated sum.
initialize product
input a line
while line is not blank
convert line to float value
update product
input another line
end
output product
Ans:
product = 1.0
line = input("Enter a float value: ")
while line != "":
value = float(line)
product *= value
line = input("Enter a float value: ")
print("Product: ", product)
Ans:
product = 1.0
fin = open("values.txt", "r")
line = readline( )
while line != "":
value = float(line.strip( ))
product *= value
line = readline( )
print("Product: ", product)
Fix up the the Employees Example
to work these problems. Use the input file employees.txt.
Here are the answers to the following sequential processing problems.
# define method
def say_moo( ):
print("moooooooo...")
# Invoke method three times.
say_moo( )
say_moo( )
say_moo( )
# Output:
moooooooo...
moooooooo...
moooooooo...
for i in range(0, 10):
for j in range(0, 10):
print("$")
************************* ************************* ************************* ************************* ************************* ************************* ************************* ************************* ************************* ************************* ************************* *************************The restriction is that your print statement is not allowed to print more than one * at a time.
* ***** * ** ** **** ** **** *** *** *** ****** **** ** **** ******** ***** * ***** ********** Triangle 1 Triangle 2 Triangle 3 Triangle 4Ans: here is a script for drawing triangles 1, 2, and 3..