tuomasvaltanen

Untitled

Oct 14th, 2021 (edited)
671
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Adobe Connect - coding workshop, 14.10.2021
  2. print("Welcome!")
  3.  
  4. # some example Fibonacci numbers
  5. # 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
  6. # the idea is to ask the user of which Fibonacci number should be shown
  7. # for example, 3 would result => 1, 7 would result => 8, and so on...
  8.  
  9. # this will be asked from input later
  10. # it makes it faster to test the application
  11. # with a hardcoded number instead
  12. # if the user inputs 13, that should result in number 3
  13. choice = input("Which Fibonacci number you wish to know?\n")
  14. choice = int(choice)
  15.  
  16. # the first two numbers in Fibonacci sequence,
  17. # this is where we start!
  18. old_number = 0
  19. new_number = 1
  20.  
  21. # we have to change the choice-variable a little bit
  22. # because we already have the first two numbers in the variables above!
  23. choice = choice - 2
  24.  
  25. # find out the correct Fibonacci number in a loop!
  26. for number in range(choice):
  27.     fibonacci = old_number + new_number
  28.  
  29.     # to proceed with the Fibonacci sequence
  30.     # we have to place the previous "new number" as the old number
  31.     # and calculate the new "new number"
  32.     old_number = new_number
  33.     new_number = fibonacci
  34.     print("Cycle!")
  35.  
  36.  
  37. # print the result
  38. print(f"Fibonacci number with index {choice + 2} equals to {fibonacci}")
  39.  
  40. # NEW FILE
  41.  
  42. # this should be asked from user
  43. number_from_user = "12345"
  44. # this could also be : one two three four five
  45.  
  46. if number_from_user.isnumeric():
  47.     # the maximum length allowed was 5
  48.     if len(number_from_user) <= 5:
  49.         print("Numbers given")
  50.         number_from_user.replace("1", "one")
  51.         # and so on
  52. else:
  53.     print("words!")
  54.    
  55.     # here you can check how many words was given by user
  56.     # approach 1: count the number of words by counting amount spaces between words
  57.     # and then +1. because if you have 5 words, you'll have 4 spaces between them and so on
  58.    
  59.     # approach 2: the more typical way is to split the word into a list (collection
  60.     # and count the words there.... we will go through colelctions next lecture :)
  61.     # parts = number_from_user.split(" ")
  62.  
  63.     # do the replacing part here again
  64.     # number_from_user = number_from_user.replace("one", "1")
  65.  
  66.  
RAW Paste Data