Adieu, adieu -Problem Set 4 (CS50's Introduction to Programming with Python)

preview_player
Показать описание
hello, everyone and welcome to another video, in this video, I will explain and solve problem set 4, Adieu, adieu.

if you haven't already submitted this problem, You have to try this on your own.
This video is to just give you a way to solve this problem, try solving it using a different approach, to get the most benefits out of this experience.

Don't forget to hit the like button and subscribe to the channel, and if you have any questions or want an explanation for a specific problem leave a comment down below.

Рекомендации по теме
Комментарии
Автор

My Solution:
import inflect
p = inflect.engine()
lst = [ ]
while True:
try:
name = input("Names: ")
lst.append(name)
except EOFError:
print ("\n")
break
for name in lst:
mylist = p.join((lst), final_sep=", ")
print(f"Adieu, adieu, to {mylist}")

moviemania
Автор

I’m not sure if I made it too simple but it worked:

import inflect

p = inflect.engine()

family = []

while True:
try:
kname = input("Name: ")
family.append(kname)
except EOFError:
print("Adieu, adieu, to", p.join(family))
break

jimmypaquette
Автор

import inflect

p = inflect.engine()

adieu = []

while True:
try:
name = input("Name: ").strip()
adieu.append(name)
except EOFError:
print()
break

mylist = p.join(adieu)

print("Adieu, adieu, to " + mylist)

cirkusanette
Автор

i did it:
import inflect

names = []
while True:
try:
name = input("Name:")
names.append(name)
except EOFError:
break

n = len(names)
msg = "Adieu, adieu, to"
if n == 1:
print(msg, names[0])
elif n == 2:
print(msg, names[0], "and", names[1])
else:
# separate all but the last name with commas
message = msg + ", ".join(names[:-1])
# add "and" before the last name
message += ", and " + names[-1]
print(message)

JhonnyAlvesTecnologia
Автор

My Solution:


names = []
while True:
try:
usr = input("Input: ")
names.append(usr)
except EOFError:
print()
break
if len(names) == 1:
print(f"\nAdieu, adieu, to {names[0]}")
elif len(names) == 2:
print()
print("Adieu, adieu, to", names[0], "and", names[1])
else:
index = len(names) - 1
last_member = names[index]
names.pop(index)
print("Adieu, adieu, to", ", ".join(names)+", ", "and", last_member)

loser-qw
Автор

import inflect
p = inflect.engine()
names = []
while True:
try:
name = input("Name: ")
names.append(name)
except EOFError:
break
if len(names) != 0:
print("\nAdieu, adieu, to ", p.join(names))
else:
exit()

coolfire-gop
Автор

my solution:
names = []

while True:
try:
name = input('Name: ')
names.append(name.strip())
except EOFError:
print()
if len(names) > 2:
print('Adieu, adieu, to ', end='')
for name in names[:-1]:
print(f'{name}, ', end='')
print(f'and {names[-1]}')
break

elif len(names) > 1:
print(f'Adieu, adieu, to {names[0]} and {names[1]}')
break

else:
print(f'Adieu, adieu, to {names[0]}')
break

rosudamian
Автор

names = [ ]
text = "Adieu, adieu, to "

while True:
try:
name = input("Name: ")
names.append(name)
except EOFError:
print()
break

join_names = p.join(names)
print(text + join_names)

alvinpatrolia
welcome to shbcf.ru