英文:
I cant find how to write many mutiple names at once
问题
我想要求那个人为课程写下名字,但我不知道如何一次性询问他/她并将它们存储为不同的值。这是我的代码:
print("欢迎使用小费计算器 :D")
bill = float(input("总账单金额(£): "))
tip = float(input("您想给多少百分比的小费?10?12?15?更多?: "))
people = float(input("要与多少人分摊小费?: "))
name_1 = input("第一个人的名字是什么:")
msg = bill * (tip / 100) / people
new_msg = round(msg, 2)
new_msg = "{:.2f}".format(msg)
print(f"每个人应支付 £{new_msg}")
我想要添加这部分代码:
# 在这里获取人们的名字
name_2 = input("第二个人的名字是什么:")
# 以及其他人的名字...
print(f"{name_1}支付 {new_msg},{name_2}支付 {new_msg}")
# 以及其他人的支付...
但我不知道如何做。
英文:
i wanted to ask the person to write down the names for a lesson but I dont know how to ask him/her all at once and store them as different values. This is my code:
print("welcome to the tip calculator :D")
bill = float(input("what was the total bill £: "))
tip = float(input("what percentage tip would you like to give 10? 12? 15? More?: "))
people = float(input(" how many people to split the tip: "))
name_1 = input("what is the name")
msg = bill * (tip / 100) / people
new_msg = round(msg, 2)
new_msg = "{:.2f}".format(msg)
print(f"each of you should pay £{new_msg}")
I wanted to add this:
input(write down the names of the people)
print(f"{name_1} pays {new_msg}, {name_2} pays {new_msg}
but I dont know how to.
答案1
得分: 0
我认为你想要的代码大致如下:
print("欢迎使用小费计算器 :D")
bill = float(input("总共消费多少钱 £: "))
tip = float(input("你想给多少小费(10、12、15或更多)?: "))
people = float(input("要与多少人分账?: "))
names = []
for i in range(int(people)):
name = input(f"请输入第 {i+1} 个人的名字: ")
names.append(name)
msg = bill * (tip / 100) / people
new_msg = round(msg, 2)
new_msg = "{:.2f}".format(msg)
print(f"\n每人应支付 £{new_msg}")
for name in names:
print(f"{name}支付 £{new_msg}")
注意:我已经更正了代码中的一个错误,将变量名从"ip"更正为"tip",以便计算正确的小费。
英文:
I think the code you want is something along the lines of
print("Welcome to the tip calculator :D")
bill = float(input("What was the total bill £: "))
ip = float(input("What percentage tip would you like to give (10, 12, 15, or more)?: "))
people = float(input("How many people to split the bill?: "))
names = []
for i in range(int(people)):
name = input(f"Enter the name of person {i+1}: ")
names.append(name)
msg = bill * (tip / 100) / people
new_msg = round(msg, 2)
new_msg = "{:.2f}".format(msg)
print(f"\nEach person should pay £{new_msg}")
for name in names:
print(f"{name} pays £{new_msg}")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论