학습내용: 사랑계산기 제작, .lower(), .count("")
참고자료:https://replit.com/@appbrewery/day-3-5-exercise
LOVE 점수 Less than 10 or greater than 90 ⇒ "Your score is x, you go together like coke and mentos." 출력
Love 점수 40~50 사이 ⇒ "Your score is y, you are alright together." 출력
Otherwise(나머지의 경우) ⇒ "Your score is z." 출력
Arianna Rebolini
Channing Tatum
T:2 L:1
R:2 O:1
U:1 V:0
E:1 E:1
합:6 합:3 = 63%
name1 = "Angela Yu"
name2 = "Jack Bauer"
T occurs 0 times
R occurs 2 times
U occurs 2 times
Total = 5
L occurs 1 time
O occurs 0 time
V occurs 0 times
E occurs 2 times
Total = 3
Love Score = 53
Print: "Your score is 53."
2 3 3 2
* .lower() 은 문자열의 대문자를 모두 소문자로 바꿔줌
"Frigate".lower()
#실행결과: frigate
* .count("") 는 문자열에서 글자가 나오는 횟수를 알려줌
"Angela".count("a") #괄호안의 세고자 하는 글자를 특정해줌
#실행결과: 1 #소문자 a만 세어줌
lower_case_name = "Angela".lower()
lower_case_name.count("a")
#실행결과: 2 # .lower() 점함수로 "Angela"를 모두 소문자로 변환해준 뒤, .count("a")함수로 소문자 a 갯수 셈
if count_LOVE <10 or count_LOVE >90 : 이렇게 표현해야 함. 위의 >90의 비교대상을 명시해줘야함
# 🚨 Don't change the code below 👇
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
# 🚨 Don't change the code above 👆
#First *fork* your copy. Then copy-paste your code below this line 👇
#Finally click "Run" to execute the tests
count_TRUE = name1.lower().count("t") + name2.lower().count("t") + name1.lower().count("r") + name2.lower().count("r") + name1.lower().count("u") + name2.lower().count("u") + name1.lower().count("e") + name2.lower().count("e")
count_LOVE = name1.lower().count("l") + name2.lower().count("l") + name1.lower().count("o") + name2.lower().count("o") + name1.lower().count("v") + name2.lower().count("v") + name1.lower().count("e") + name2.lower().count("e")
if count_LOVE <10 or count_LOVE >90 :
print(f"Your score is {10*count_TRUE+count_LOVE}, you go together like coke and mentos.")
elif count_LOVE >=10 and count_LOVE <=50 :
print(f"Your score is {10*count_TRUE+count_LOVE}, you are alright together.")
else:
print(f"Your score is {10*count_TRUE+count_LOVE}.")
또 다른 표현
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
combined_string = name1 + name2 #이름합해주기, 결국 모든 이름을 카운팅해야대므로..
lower_case_string = combine_string.lower() #소문자로 통일해주기
t = lower_case_string.count("t")
r= lower_case_string.count("r")
u = lower_case_string.count("u")
e = lower_case_string.count("e")
true = t+r+u+e # 10의 자리 수 구함!
l = lower_case_string.count("l")
o = lower_case_string.count("o")
v = lower_case_string.count("v")
e = lower_case_string.count("e")
love = l+o+v+e
love_score = str(true) + str(love) # 각 숫자를 이어서 2자릿수 만들기. true와 love는 정수임
# 정수인 데이터 2개를 문자취급해서 10의자리 하나, 1의 자리 하나 출력되게할려면
문자열로 형변환해서 하나로 이어줄 수 있음
int_score = int(love_score) #이 구문 없으면 print오류뜸.
if (love_score <10) or (love_score >90) : #괄호는 가독성을 위함. 연산자 or은 둘중 조건하나만 참이면 실행결과True임
print(f"Your love score is {love_score}, you go together like coke and mentos.")
elif (love_score>=40 and (love_score <=50) : # 두조건이 모두 TRUE여야함
print("Your score is {love_score}, you are alright together.")
else :
print(f"Your score is {love_score}")
#실행결과: 오류 뜸. 이유는 love_score가 문자열이기 때문임. love_score = int(str(true) + str(love)) 이렇게 표현해줘야함