CompSci
  • Home
  •  Unit 1
    Output Exercises
     Unit 2
    Variables Math Modules Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    Iteration / Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Lists Exercises
     Unit 7
    Functions Exercises
  •  Unit 1
    Java Introduction Java Syntax Errors & Coding Conventions Format Method Exercises
     Unit 2
    Variable Introduction Math / Arithmetic Operators Obtaining a Value Formatting Numeric Output Concatenation & Constants Division & Type Casting Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    while Loops for Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Methods Method Parameters Method Return Types Exercises
  • Muddy City
  • Github Classroom
  •  Assignments
    Add an Assignment Edit Assignment Search Program Code
     Forum
    Ask a Question Search the Forum
     New Account
    New Account


Account Mgmt
Reset Password

Python - Loops / Iteration


Exercises

Sum of Numbers

Difficulty: Low

Title: Sum of Numbers

Description:
Using a loop write a program to have the user input 5 numbers (prompt them each time for each number) and find the sum and average of the numbers.

Output:
Input a number: 1
Input a number: 2
Input a number: 3
Input a number: 4
Input a number: 5

The sum is: 15
The average is: 3


Cube

Difficulty: Low

Title: Cube

Description:
Write a program to display the cube of x numbers up to an inputted number.

Cubed Formula: 2 x 2 x 2 = 8

NOTE: Your output must match the example output below.

Output:
Cube Up To: 3

Cube 1: 1 cubed is: 1
Cube 2: 2 cubed is: 8
Cube 3: 3 cubed is: 27


Number Nine

Difficulty: Low

Title: Number Nine

Description:
Write a program to find the numbers of all integers within the range specified by a user, which are evenly divisible by 9.

  • Prompt the user for the beginning and ending range.
  • Output all numbers that are evenly divisible by 9 in one line.
  • Output the sum of the numbers that are evenly divisible by 9 on its own line. Don't forget the commas.

Output:
Enter the start of the range: 100
Enter the end of the range: 200

108 117 126 135 144 153 162 171 180 189 198
The sum is: 1,683


Right Triangle

Difficulty: Medium

Title: Right Triangle

Description:
Write a program to make a right angle triangle with the number increased by 1 using a loop.

  • Prompt the user for the number of rows and draw a right triangle with that number of rows
  • HINT: Outer and Inner loop is the best way to solve this problem.

Output:
Enter Number of Rows: 4

1
2 3
4 5 6
7 8 9 10



Computer Science