Learning to code in Python 3 diary #2

in #learning6 years ago (edited)

Dear Diary,

Today I finally sort of figured out two things that bothered me in the course I'm taking.

  1. When the functions were introduced, the parameters would be interchangeably called variables or values. That was confusing because they didn't explain that the parameters are indeed variables 😆
    ---- solved by checking it out on Code Academy, where they explain it plain and simple. I suppose it could be just in Python and other languages might distinguish between a parameter and a variable in a more stricter way.

  2. One of the tasks had me scratching my head again, when they asked to make a function and call another function from a previous task.
    Mind blown... you can do that? Nice!
    But how?
    ---- After several unsuccessful attempts, I went back to the Code Academy. Where they also show how it's done, sort of.

Both of these things happened because of the following two tasks:

# [ ] define title_it_rtn() which returns a titled string instead of printing
# [ ] call title_it_rtn() using input for the string argumetnt and print the result

def title_it_rtn(book):
    book = book_entry.title()
    return book

book_entry = input("Input book title here: ")
print("This is the book title I've mentioned before: " + title_it_rtn(book_entry))

bookstoreprogram.jpeg

The above part where they ask to call title_it_rtn() with book parameter, is very confusing.

# [ ] create, call and test bookstore() function
def bookstore(book, price):
    example_output = "Title: " + title_it_rtn(book) + ", costs $" + price
    return example_output


price_entry = input("input Price: ")
print(bookstore(book_entry,price_entry))
  • This is how I solved it, but since I already had a book_entry input inside the title_it_rtn()
    adding one to call bookstore() it just prints whatever input I get in the title_it_rtn()🤔

Now that still makes me puzzled somewhat since it doesn't exactly do what the task is asking for.
But when I tried getting a separate book input just for the bookstore() it would keep printing whatever I input in the title_it_rtn() earlier (understandably).

  • So now I tried to do it again. I have deleted the book_entry input from the title_it_rtn()
    which gives a NameError. But works after I run the bookstore(), which now has a book_entry input.

Not the most elegant way to do it I suppose and it smells like spaghetti 🍝

nameerror.jpeg

LolLol.jpeg

taken from Module 2 Practice - notebook 3 of the edx course.

Suggestions and advice are highly appreciated ^^

~ Anmitsu

Sort:  
Loading...

Congratulations @anmitsu! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made your First Vote

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @anmitsu! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got your First payout

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemitBoard Ranking update - Resteem and Resteemed added

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.031
BTC 71238.01
ETH 3865.22
USDT 1.00
SBD 3.51