AquaBlitz11

Gunn coding Jan 9 homework

Jan 14th, 2021 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. A. Multiplication
  2.  
  3. Given a value N, print a multiplication table with N as the base value. For example, if N = 5, print
  4. 5x1 = 5
  5. 5x2 = 10
  6. 5x3 = 15
  7. until
  8. 5x12 = 60
  9.  
  10. To construct each line's output, you might find it useful to use string concatenation (+). Don't forget to change int into string first.
  11.  
  12. B. Prime
  13.  
  14. Write a program that prints out the first N prime numbers. (N is user input. N >= 1.)
  15. For example, if N = 5 your program should print 2, 3, 5, 7, 11, each number on a separate line.
  16.  
  17. Subtask (if you can't solve the main problem, try solving these subproblems first)
  18. 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.)
  19. 2. Write a program that prints out all prime numbers <= N (N=10 print 2, 3, 5, 7).
  20.  
  21. Hint: You will probably need a nested loop. (So, try solving subtask 1 first.)
  22.  
  23. C. Fibonacci
  24.  
  25. Given a value N. Print first N numbers of the fibonacci sequence. You can assume N >= 3.
  26. For example, if N=10 you should print 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, each number on a separate line.
  27. 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.
  28.  
  29. 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.
  30.  
  31. Hint: Copy this code to Python and run to read the hint message.
  32. 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