Lab Manual 6
Lab Manual 6
The following tasks are to be completed in the lab. Follow the think-code-test-debug procedure. Write the algorithm of
each task on a separate page.
1. Write a program to calculate and print all the prime numbers from 1 to 100. Use the function prime no which takes
no formal argument and nothing is returned back.
2. Write a program to calculate the average of all the numbers entered by the user. Keep taking input from the user until
the user enters -1.
3. Use list to print the following table.
a. Create two lists to store marks and grades. Use both the lists to print the following table.
b. Create two lists to store marks and grades. Store both the lists into another single list and then using this single
list to print the following table.
Marks Grade
Above 90 A+
80-90 A-
70-80 B+
60-70 B-
50-60 C+
Less than 50 F
4. Write a program which uses recursive function power(base, exponent) that when invoked returns
For example, power(3, 4) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than or equal to 1.
Hint: The recursion step would use the relationship
5. For the following code, use the debugging mode of the SPYDER software to determine the following values.
a. The value of y just before the 2nd for loop starts.
b. The value of y just before the 3rd for loop starts.
c. The value of y just before the 4th for loop starts.
6. Write the following code and determine its output.
a. What is the output?
b. Will lists L1 and L change while the for loop is being executed? Use debugging mode to answer. L1 is called an
_______ of L.
c. Use cloning to print all the values from 1 to 5.
d. Modify the code so that L is a tuple and the output displays all integers from 1 to 5.