TIL: Python Basics Day 1 - input, variable

이다연·2020년 11월 22일
0

Udemy Python Course

목록 보기
1/64
post-thumbnail

Udemy course: Angela Yu's Python, 100 Days of Code 를 공부하며 남긴 노트입니다.

목표: 튜토리얼을 통해 파이썬 문법, GUI, Crawling, API, Flask 의 개념을 배우고 미니 프로젝트로 응용하기.

기간: Nov 20' ~ March 21'

print()

input()

input function: flash or solid cursor will stay in the end of your code. input function gets replaced by input data.

parenthesis: (괄호) a pair of round brackets ( ) used to mark off a parenthetical word or phrase.

print("Hi "+ input("What is your name? "))

#print
What is your name? D
Hi D
length = input("What is your name? ")
print(len(length))

Variables

store the data, give a name to refer to it later
e.g. James = 07717122342

naming: no previleged names (e.g. input, print), underbar_is_okay,

name = input("What is your name? ")
length = len(name)
print(length)

Imagine a coffee cup and a water glass and a third empty container (logic!)

a = input("a: ")
b = input("b: ")

c = a
a = b
b = c

print("a: " + a)
print("b: " + b)

String

Text needs 'single quote' or "double quote"

- backslash + n for creating a new line

print("Hi \n There")
  • concartenation: taking seperate strings of charaters and merge them into one
print("Hello" + " " + "There")

Challenge: band name generator

#1. Create a greeting for your program.
print("Hi welcome to Band Name Generator!")
#2. Ask the user for the city that they grew up in.
city_name = input("What's the name of the city you grew up in? \n ")

print(city_name)

#3. Ask the user for the name of a pet.
pet_name = input("What's the name of your pet? \n") 
print(pet_name) 

#4. Combine the name of their city and pet and show them their band name.
print("Your band name is " + city_name + pet_name)

#5. Make sure the input cursor shows on a new line, see the example at:
#   https://band-name-generator-end.appbrewery.repl.run/

https://band-name-generator-end.appbrewery.repl.run/

'#': hash tag or pound sign
ctrl + enter = run
ctrl + z : undo

Thonny: To see how the code exucuted step by step
pythontutor: same as above

profile
Dayeon Lee | Django & Python Web Developer

0개의 댓글