Q1. Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old. Extras:
-
Add on to the previous program by asking the user for another number and printing out that many copies of the previous message.
-
Print out that many copies of the previous message on separate lines. (Hint: the string "\n is the same as pressing the ENTER button)
Q2. Take a list, say for example this one: a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] and write a program that prints out all the elements of the list that are less than 5.
Extras:
- Instead of printing the elements one by one, make a new list that has all the elements less than 5 from this list in it and print out this new list.
- Write this in one line of Python.
- Ask the user for a number and return a list that contains only elements from the original list a that are smaller than that number given by the user.
Q3. Write a program that asks the user how many Fibonacci numbers to generate and then generates them. Take this opportunity to think about how you can use functions. Make sure to ask the user to enter the number of numbers in the sequence to generate.(Hint: The Fibonacci seqence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, ...)
Q4. Write a program (function!) that takes a list and returns a new list that contains all the
elements of the first list minus all the duplicates.
Extras:
- Write two different functions to do this - one using a loop and constructing a list, and another using sets.
Q5. Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a prime number is a number that has no divisors.). Use functions