CS1101_Assignment06_GrpB_Friday
CS1101_Assignment06_GrpB_Friday
Login to the system. Create a directory called assignment06 under your home directory. Change
to that directory (using the cd command) and do all your work there. At the end of the class,
archive the directory assignment06 and upload to WeLearn.
1. (a) Define the function product_of_odds (n), which will calculate the product of all odd
numbers from 1 to n.
(b) Use a loop to test the function for values n=1 to n=9 and print the results.
2. (a) Define a function fibonacci that calculates the n-th Fibonacci number. You may recall
that Fibonacci sequence is defined as:
(b) Show the usage of the function by calculating Fibonacci numbers from n=1 to n=8.
3. If you need to evaluate mathematical operations (log, sin, cos, pi etc), you need to
declare import math at the beginning of your program. For example, to find the value of
cosine of 60◦, your program should look like:
Import math
print math.cos(60*math.pi/180)
##pi gives you the value of π and θπ/180 converts θ from degree to radian.
(a) Define a function tan_square that takes an argument t (in degrees) and returns the
square of the tangent of t. Remember to convert t from degrees to radians when using
trigonometric functions.
(b) Then, write a loop that uses this function to print θ and tan 2(θ) for
θ=0,15,30,45,60,75,90
4. Suppose the length of three sticks are given by three numbers. Define a function which
takes the three lengths (as arguments) and determines whether these sticks can form a
triangle. The function should return True or False depending on whether the triangle is
formed or not. Your program should take three numbers from the user and should print
whether a triangle is possible or not. [Hint: three lengths form a triangle if the sum of any
two lengths is greater than the third.]
5. Define a function called find_min that takes three numbers as arguments and returns the
smallest of the three. Test the function with 3 different sets of numbers.
6. (a) In a program, define a function takes an input argument x and calculates the quotient q
= x//4 and r = x%4 and returns q and r.
(b)In the same program, take an input from the user, store it in a variable (say, s). Now,
call the function f(s) with two storage variables (to store the output). Finally, print the
stored variables.
Additional practice problems that will not be marked. All should attempt to solve these
problems in the lab itself after you finish problems 1-6.
7. Write a program which takes two integers from the user and returns all prime numbers
between the two integers. The result should not depend on the order in which the integers
are entered by the user.
The function should then return the final grade as a percentage and also the corresponding
letter grade based on this scale:
The function should then return the final grade as a percentage and also the corresponding
letter grade based on this scale:
90–100: A
80–89: B
70–79: C
60–69: D
Below 60: F
Write a program that uses grade_calculator to print the final grade and letter grade for three
different sets of scores.