2023. 2. 23. 00:10ㆍ개인적인 공부/Python
💪 This is a Difficult Challenge 💪
Instructions
You are going to write a program that tests the compatibility between two people.
To work out the love score between two people:
: 무슨 어릴때 이름 두개 합쳐서 획 수로 뭐 하는 거 같은데
영미권 애들은 TRUE LOVE 스펠링 나오는걸로 점수 합치는가 보다
사람사는 세상 비슷한거 같다.
Take both people's names and check for the number of times the letters in the word TRUE occurs.
Then check for the number of times the letters in the word LOVE occurs.
Then combine these numbers to make a 2 digit number.
For Love Scores less than 10 or greater than 90, the message should be:
"Your score is **x**, you go together like coke and mentos."
For Love Scores between 40 and 50, the message should be:
"Your score is **y**, you are alright together."
Otherwise, the message will just be their score. e.g.:
"Your score is **z**."
e.g.
name1 = "Angela Yu"
name2 = "Jack Bauer"
T occurs 0 times
R occurs 1 time
U occurs 2 times
E occurs 2 times
Total = 5
L occurs 1 time
O occurs 0 times
V occurs 0 times
E occurs 2 times
Total = 3
Love Score = 53
Print: "Your score is 53."
Example Input 1
name1 = "Kanye West"
name2 = "Kim Kardashian"
Example Output 1
Your score is 42, you are alright together.
Example Input 2
name1 = "Brad Pitt"
name2 = "Jennifer Aniston"
Example Output 2
Your score is 73.
The testing code will check for print output that is formatted like one of the lines below:
"Your score is 47, you are alright together."
"Your score is 125, you go together like coke and mentos."
"Your score is 54."
Score Comparison
Not sure you're getting the correct score for the exercise? Use this table to check your code's score against mine.
Name 1 | Name 2 | Score |
Catherine Zeta-Jones | Michael Douglas | 99 |
Brad Pitt | Jennifer Aniston | 73 |
Prince William | Kate Middleton | 67 |
Angela Yu | Jack Bauer | 53 |
Kanye West | Kim Kardashian | 42 |
Beyonce | Jay-Z | 23 |
John Lennon | Yoko Ono | 18 |
나의 코드
# 골때리는 사랑계산기
# 🚨 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 👆
#Write your code below this line 👇
lower_name1 = name1.lower()
lower_name2 = name2.lower()
t = lower_name1.count("t") + lower_name2.count("t")
r = lower_name1.count("r") + lower_name2.count("r")
u = lower_name1.count("u") + lower_name2.count("u")
e = lower_name1.count("e") + lower_name2.count("e")
true = t + r + u + e
l = lower_name1.count("l") + lower_name2.count("l")
o = lower_name1.count("o") + lower_name2.count("o")
v = lower_name1.count("v") + lower_name2.count("v")
e = lower_name1.count("e") + lower_name2.count("e")
love = l + o + v + e
lovetotal = str(true) + str(love)
total = int(lovetotal)
if total < 10 or total > 90:
print(f"Your score is {total}, you go together like coke and mentos.")
elif total >=40 and total <= 50:
print(f"Your score is {total}, you are alright together.")
else:
print(f"Your score is {total}.")
나와 다른 코드
1-1 다른사람
#Write your code below this line 👇
combined_string = name1 + name2 # 이름을 처음부터 합친다.
lower_case_string = combined_string.lower() # 그다음에 lower()을 한다.
t= lower_case_string.count("t") #lower() 한것을 계산한다.
1-2 나의 코드
#Write your code below this line 👇
lower_name1 = name1.lower() # 각각의 이름을 따로 lower_case 함
lower_name2 = name2.lower()
t = lower_name1.count("t") + lower_name2.count("t") #그걸 여기서 더함
2-1 다른사람
love_score = int(str(true) + str(love)) # 그냥 바로 정수형으로 지정해줌
2-2 나의 코드
lovetotal = str(true) + str(love)
total = int(lovetotal) #다시 한번 int 형을 선언함
'개인적인 공부 > Python' 카테고리의 다른 글
day 4-2 python (Head or Tails), 동전 앞 뒤 (0) | 2023.02.24 |
---|---|
day 4-1 python (Randomisation), 무작위화 (0) | 2023.02.23 |
day 3-8 python (논리 연산자) (0) | 2023.02.22 |
day 3-7 python (피자주문) (0) | 2023.02.22 |
day 3-6 python (다중 연속 if 문) (0) | 2023.02.22 |