Sheet-4 Invo 2022-Python Programming
Sheet-4 Invo 2022-Python Programming
Question Two
…,Write a program that generates the first N terms of Fibonacci series 1,1,2,3,5 -1
2-Without the aid of a computer, work out the order in which each of the following
expressions would be computed and their value.
i. 2 + 6/4-3*5+1
ii. 17 + -3**3/2
iii. 26+3**4*2
iv. 2*2**2+2
.Verify your answer using Python
1
3- Without the aid of a computer, work out these successive expressions and give the values
of a, b, c and d upon completion. Then check your answer using a Python script:
a=4
b=9
c=5
d= a*2+b*3
Question Three
1. Write a Python program that prompts the user for two numbers, reads them in, and
prints out the product, labeled.
3. Given a string s, write an expression for a string that includes s repeated five times.
4. Given an odd positive integer n, write a Python expression that creates a list of all the
odd positive numbers up through n. If n were 7, the list produced would be [1, 3, 5, 7]
5. Write a Python expression for the first half of a string s. If s has an odd number of
characters, exclude the middle character. For example if s were “abcd”, the result would
be “ab”. If s were “12345”, the result would be “12”.
6. Given a positive integer n, write Python code that prints out n rows, each with one more
‘x’ on it than the previous row. For instance, if n were 4, the following lines would be
printed:
x
xx
xxx
xxxx
Write a python code to get the factorial of any number n .7
Question Four
2
3