Docsity

Laboratory Exercise: For-Loop and While Loop Programming, Lab Reports of Physics

Partial preview of the text

Download Laboratory Exercise: For-Loop and While Loop Programming and more Lab Reports Physics in PDF only on Docsity!

LABORATORY EXERCISE NO. 8 AND 9: FOR-LOOP AND WHILE LOOP

PROGRAMMING

LABORATORY EXERCISE FORMAT

EXERCISE 1

  1. Use for loops to print a diamond like the one below.
  1. The Fibonacci numbers are the sequence below, where the first two numbers are 1, and each number thereafter is the sum of the two preceding numbers. Write a program that asks the user how many Fibonacci numbers to print and then prints that many.
  2. Write a program that prints out a list of the integers from 1 to 20 and their squares. The output should look like this:
  1. The GCD (greatest common divisor) of two numbers is the largest number that both are divisible by. Write a program that asks the user for two numbers and computes their gcd. (Hint: you can use Euclid’s Algorithm, Recursion or Loops). You can’t use math.gcd() function.