为什么我不能在输入("text")中使用str变量?



尝试通过使用str输入变量,将幸运轮计算器作为类中的任务。

示例:

int(input("In which day of",a(defiend as a month inputed before),"were you born?"))

你不能这样做。你会得到一个错误,它说明了一切,输入只需要一个(!(参数。这不是打印((:

TypeError: input expected at most 1 arguments, got 3

这对你有帮助吗?我使用了Python 3.7中引入的新f-Strings!

month = "april"
day = int(input(f"In which day of {month} were you born? "))
print(f"{day}. {month}")

如果您使用早期的Python版本,则必须使用.format(…(:

month = "april"
day = int(input("In which day of {} were you born? ".format(month)))
print("{}. {}".format(day, month))

快乐的蟒蛇。

最新更新