introtoproghw8

introtoproghw8 - intX-= 1 Loop Programming Exercises 7...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
IT 103 08/16/14 Homework 8 6. An infinite loop is continuous loop that will repeat until the program is interrupted. WHILE y = 1 THEN: X = X + 1 END WHILE 7. a for loop looks like a while loop in a flowchart. 8. It is critical to initialize the accumulator because if the value of the accumulator is anything other than 0 then the accumulator’s value at the end of loop will be incorrect. 9. An advantage of using a sentinel is to tell the programmer or user when to a loop has reached its end. For example when processing a long sequence of values. 10. A sentinel value must be carefully selected because if it isn’t it could be mistaken for actual data in sequence. Algorithm Workbench 3.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
For intNum = 0 To 1000 Step 10 lstNumbers.Items.Add(intNum) Next intNum 4.. For intNum = 0 To 1000 Step 10 lstNumbers.Items.Add(intNum) Next intNumFor intCount = 1 To 10 intNum = CInt(InputBox("Enter a number.")) intTotal += intNum Next count
Image of page 2
9. For intCount = 0 To 49 lstOutput.Items.Add(intCount) Next intCount 10. intX = 50 Do While intX >= 0 lstOutput.Items.Add(intX)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: intX -= 1 Loop Programming Exercises 7. Average Rainfall: def main(): years = int(input('Enter the number of years: ')) total_rainfall = 0.0 for a in range(years): for b in range(12): rainfall = float(input('Enter inches of rain for the month: ')) total_rainfall += rainfall months = years * 12 print('Number of months:', months) print('Total inches of rainfall:', total_rainfall) print('Average rainfall per month for entire period: ', format(total_rainfall / months, '.2f')) main() 9. Pennies for Pay: def main(): days = int(input('Enter number of days: ')) print('\nDay\t\tSalary') print('-----------------------') total_salary = 0.0 for d in range(1, days + 1): salary = (2 ** (d - 1)) / 100 total_salary += salary print(d, '\t\t', '$', format(salary, ',.2f'), sep='') print('\nTotal Pay: $', format(total_salary, ',.2f'), sep='') main() 10. Largest and Smallest: def main(): for r in range(6): print('#', end='') for c in range(r): print(' ', end='') print('#') main()...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern