Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A. Multiplication
- Given a value N, print a multiplication table with N as the base value. For example, if N = 5, print
- 5x1 = 5
- 5x2 = 10
- 5x3 = 15
- until
- 5x12 = 60
- To construct each line's output, you might find it useful to use string concatenation (+). Don't forget to change int into string first.
- B. Prime
- Write a program that prints out the first N prime numbers. (N is user input. N >= 1.)
- For example, if N = 5 your program should print 2, 3, 5, 7, 11, each number on a separate line.
- Subtask (if you can't solve the main problem, try solving these subproblems first)
- 1. Write a program that receives a value x and print if it is prime or not. (Hint: you will need some kind of flag/boolean variable to note that you have finally found a divisor for x therefore x is not prime.)
- 2. Write a program that prints out all prime numbers <= N (N=10 print 2, 3, 5, 7).
- Hint: You will probably need a nested loop. (So, try solving subtask 1 first.)
- C. Fibonacci
- Given a value N. Print first N numbers of the fibonacci sequence. You can assume N >= 3.
- For example, if N=10 you should print 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, each number on a separate line.
- Recall Fibonacci number is define as F[n]=F[n-1]+F[n-2] for n>=3 and F[1]=1 and F[2]=1 as the base cases.
- Note that you will need to be very careful about what you do *initially* (outside of the loop) and what you do in each iteration of the loop. Consider what variables you will need.
- Hint: Copy this code to Python and run to read the hint message.
- print(".ecneuqes iccanobiF ni srebmun owt tsal eht erots ot selbairav owt rehtona neht dna ,gnitnirp era uoy rebmun hcihw tnuoc ot elbairav a deen uoY"[::-1])
Add Comment
Please, Sign In to add comment