Lab 5
Lab 5
Lab5 Iteration
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
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
)
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()