0% found this document useful (0 votes)
38 views

Lab 5

The document provides instructions for Lab 5 of a computer science fundamentals course. It includes 7 tasks to write Python programs that use concepts like iteration, factors, random number generation, and the turtle graphics module. It asks students to write pseudocode, draw flowcharts, and code programs that calculate factorials, products using repeated addition, digit sums, factor sums, prime number checks, and more. It also includes bonus tasks about strategies for a guessing game to always win and modifying turtle graphics code.

Uploaded by

Alazar Andualem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Lab 5

The document provides instructions for Lab 5 of a computer science fundamentals course. It includes 7 tasks to write Python programs that use concepts like iteration, factors, random number generation, and the turtle graphics module. It asks students to write pseudocode, draw flowcharts, and code programs that calculate factorials, products using repeated addition, digit sums, factor sums, prime number checks, and more. It also includes bonus tasks about strategies for a guessing game to always win and modifying turtle graphics code.

Uploaded by

Alazar Andualem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Addis Ababa institute of Technology

Center of Information Technology and Scientific Computing


Fundamentals of computer science and programming

Lab5 Iteration

Write pseudocode then draw flowchart finally code


1. Write a python program that accepts a number and prints its factorial

2. Write a python program that allows the user to input two numbers, computes their
product and print out the product. Assume multiplication operation is not primitive
(not allowed) operation for the computer that you are writing the program. i.e. you
are not allowed to compute the product by directly multiplying the numbers. In other
words, your program should compute the product by repeated addition method.
3. Write a python program that accepts a positive number and prints the sum of the
digits in the number. i.e. if the number is 576, it should print 18 = 5 + 7 + 6.
4. Write a python program that accepts a number and prints the sum of its factors.

5. Write a python program that determines if a given number is prime number or not.

6. Write a python program that finds the average, maximum, minimum, and sum of n
numbers input by the user.
7. Write a python program that generates a random number in the range 0 to 100 and
prompts the user to guess and enter the number continuously until the user’s input
matches the randomly generated number. The program should inform the user if
his/her guess is less/more than the random number. if the user can't guess the value
by entering at most 7 guesses the program should print GAME OVER

BONUS: stop accepting more guesses. Find a strategy that always results in a win
(i.e guess based on the less/greater clues)? Why does it always result in a win?
Back to Turtle
1. Modify the function that draws a square to use loop.
2. Write a function that draws a square using input parameters

x, y: x position and y position

length: length of the side of the square

3. Write a program that draws the picture below using the square function
written in question number 2

4. Write a function that could plot any regular polygon with equal side length
given parameters
 Number of sides
 Side length
 Starting point
(Hint: for a regular polygon the rotation angle is given by the formula
360/number_of_sides
)

5. Turtle has a circle function that takes radius as an input


Write a program using the turtle module that draws the picture bel ow

Use the following function to get random colors for the circles

6. Modify the above program to fill the circles with different colors
Use

<turtle_name>.fillcolor(<random color>)
# where the turtle name is the one you gave for the turtle and the random color you can get from
# get_random_color function

<turtle_name>.begin_fill()
# where the turtle starts filling the color

<turtle_name>.end_fill()

You might also like