Python bootcamp 001

 Day 1 into python bootcamp

(with Dr Angela Yu)

Day 1 is pretty simple. Studied functions are print, input and len. As well as the fundamental for variables in python.


The final project is the "Band Name Generator", witch take two strings and concatenate them to form a "Band Name". Now, in my opinion presenting more details on this projects would be disrespectful to Dr Yu and her team. So let's try a different exercise with the same goal: String Concatenation

 

 

Order Confirmation

Let's assume we are developing a app for a restaurant that ask the costumer what will they like to eat and drink, then we print the order to someone in the kitchen.

  1. Present a greetings for your program.
  2. Ask "What would you like to drink today?" 
  3. Ask "What would you have for dinner?"
  4. Print "Your order is: " food + dinner




  print("Welcome to your favorite pub!! or bar...")
  drink = input("What would you like to drink today?\n")
  food = input("What would you have for dinner?\n")
  print("Your order is: " + food + " " + diner)
  

Let's us review the code one line at a time:


  print("Welcome to your favorite pub!! or bar...")
  

Pretty much self explanatory, print will print what ever is inside of the parentheses


  drink = input("What would you like to drink today?\n")
  

This line contains 3 concepts touch in the lecture: variables, input, and \n. The function input will print the message inside the parentheses and immediately after will ask for a user input, this means that the user input will "susbtitute" the entire function. \n will generate a new line so that the user can type her input on line bellow the input message, otherwise it will be right after the message. Finally, variables; here the variable "drink" is used to save the user's data, whitout this variable this information would be lost as soon as the program goes into the next line.


  food = input("What would you have for dinner?\n")
  

See previous explanation


  print("Your order is: " + drink + " and " + food)
  

Now, this is interesting. Inside of the function print there are several strings

  1. "Your order is: " containing an extra space at the end
  2. drink Remember everything obtain with input is a string
  3. " and " with extra espaces, without them the contains of drink and food would be merge together
  4. food
  5. There are other ways to get this result, the one that come to mind is:

    
      print("Your order is:", drink, "and", food)
      

    Finally, len.

    This function count the amount od characters in a string, not very useful for my example

Comments

Popular posts from this blog

Python bootcamp Day002