Skip to content

STE-Technology/ICS3U-2.9-Algorithms-Using-for-Loops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flowcharts & Tables: Algorithms Using for Loops

Program 1: Counting Distance

Write a program, miles.py, that outputs values for kilometres and equivalent miles every 10 km up to 100 km. No input is required, but runtime output should look like this:

10 km = 6.25 miles
20 km = 12.5 miles
30 km = 18.75 miles
40 km = 25.0 miles
50 km = 31.25 miles
60 km = 37.5 miles
70 km = 43.75 miles
80 km = 50.0 miles
90 km = 56.25 miles
100 km = 62.5 miles

Program 2: Calculating Totals

Write a program, sum.py, that takes an input number n, and calculates the sum of numbers from 1 to n using an accumulator variable. Sample runtime should look like:

Enter a number: 5

Sum of numbers from 1 to 5: 15

Program 3: Factorials

Write a program, factorial.py, that asks the user to input a number n, then calculates and outputs the factorial value n! Do not use any built-in math functions to calculate this value. Instead, do it iteratively and manually, for example:

$$5! = 5 \times 4 \times 3 \times 2 \times 1 = 120$$

Sample runtime should look like this:

Enter a number: 5

5! = 120

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages