Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Adobe Connect - coding workshop, 14.10.2021
- print("Welcome!")
- # some example Fibonacci numbers
- # 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
- # the idea is to ask the user of which Fibonacci number should be shown
- # for example, 3 would result => 1, 7 would result => 8, and so on...
- # this will be asked from input later
- # it makes it faster to test the application
- # with a hardcoded number instead
- # if the user inputs 13, that should result in number 3
- choice = input("Which Fibonacci number you wish to know?\n")
- choice = int(choice)
- # the first two numbers in Fibonacci sequence,
- # this is where we start!
- old_number = 0
- new_number = 1
- # we have to change the choice-variable a little bit
- # because we already have the first two numbers in the variables above!
- choice = choice - 2
- # find out the correct Fibonacci number in a loop!
- for number in range(choice):
- fibonacci = old_number + new_number
- # to proceed with the Fibonacci sequence
- # we have to place the previous "new number" as the old number
- # and calculate the new "new number"
- old_number = new_number
- new_number = fibonacci
- print("Cycle!")
- # print the result
- print(f"Fibonacci number with index {choice + 2} equals to {fibonacci}")
- # NEW FILE
- # this should be asked from user
- number_from_user = "12345"
- # this could also be : one two three four five
- if number_from_user.isnumeric():
- # the maximum length allowed was 5
- if len(number_from_user) <= 5:
- print("Numbers given")
- number_from_user.replace("1", "one")
- # and so on
- else:
- print("words!")
- # here you can check how many words was given by user
- # approach 1: count the number of words by counting amount spaces between words
- # and then +1. because if you have 5 words, you'll have 4 spaces between them and so on
- # approach 2: the more typical way is to split the word into a list (collection
- # and count the words there.... we will go through colelctions next lecture :)
- # parts = number_from_user.split(" ")
- # do the replacing part here again
- # number_from_user = number_from_user.replace("one", "1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement