刚开始使用python 3进行编程,我试图从将input()命令放在第一行的input()中拉出,然后进一步使用output()来检索input()。 / p>
这里是一个例子:
rent = eval(input("How much does rent cost per year? $"))
现在,我想获取输入的内容(10,000),并使用output()或其他命令从输入中自动检索它。
print output("The family rent is", _______ , "per year."
________中将包含什么代码,以便我可以检索输入的内容?
谢谢-新手
答案 0 :(得分:0)
使用字符串格式:
print('The family rent is {} per year'.format(rent))
有关字符串格式的文档,请参见此处: https://docs.python.org/3/library/string.html#format-string-syntax
答案 1 :(得分:0)
原样的代码:
# get user input
user_input = input("How much does rent cost per year? $")
# cast to int or whaterver you're expecting
try :
cost = int(user_input)
except :
print ("expecting a number")
# stop here maybe return
# print output
print ("The family rent is", cost , "per year.")