TIL: Python Basics Day 2 - data types

이다연·2020년 11월 22일
0

Udemy Python Course

목록 보기
2/64

Primitive Data Types:

  • String: text

Subscripting: can pull out individual text

print("Hello"[0]) #print H
  • Integer: whole numbers,num w/o any decimal places. e.g. 123
print(123_456_789) #print 123456789

Underbars with number: easier to see for human to read a long number

  • Float: floating point number e.g. 3.14159

  • Bloolean: True / False

print(type()): to investigate the type of data

type conversion:

conversion = str(variable_name_which_isnt_string)

use conversion variable accordingly

Mathematical Operations

+
-
*
/
'**' : exponents , raise a number to a power
2**3 = 8

data scientists love python as it's optimised towards manipulating and handling numbers!

Priority: PEMDAS
Parenthesis ()
Exponents **

Multiplication *
Division /

Addition +
Subtraction -

Number Manipulation

print(round(2.6666, 2)) : round it to two decimal places. (2의 자리)
#2.67

// : you will get 'int' result after division

score = 0
score /=1
score +=1

handy: previous version of score and plus, minus from it,
instead of typing score again

F-strings

instead of having to convert into all different types
you can use F-strings

score = 0
height = 1.8
isWinning = True
print(f"your score is {score}, your height is {height},you are winning is {isWinning} ")

task weeks remaining

# 🚨 Don't change the code below 👇
age = input("What is your current age? ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
LONGEVITY = 80 
days = 365 
weeks = 52
months = 12 

age_int = int(age)

#remaining : years_remaining = 80 - age_int

days_left = LONGEVITY*days - age_int*days 
weeks_left = LONGEVITY*weeks - age_int*weeks 
months_left = LONGEVITY*months - age_int*months 

msg = f"You have {days_left} days, {weeks_left} weeks, and {months_left} months left."

print(msg)

tip-calculator

#If the bill was $150.00, split between 5 people, with 12% tip. 
#Each person should pay (150.00 / 5) * 1.12 = 33.6
#Format the result to 2 decimal places = 33.60
#Tip: You might need to do some research in Google to figure out how to do this.

print("welcome")
bill = float(input("What was the total bill? $")) 
bill_int = int(bill) #don't need! 

tip = int(input("What percentage tip would you like to give? 10, 12, or 15? "))
#tip_int = (int(tip) * 0.01 ) + 1

num_people = int(input("How many people to split the bill? "))
#num_people_int = int(num_people)

result = round((bill + tip) / num_people, 2 )
print(f"Each person should pay: ${result}")

https://waitbutwhy.com/2014/05/life-weeks.html
[ ] square bracket

profile
Dayeon Lee | Django & Python Web Developer

0개의 댓글