我为项目制作了代码,我试图将最终输出(a / b)输出到外部文本文档。我已经尝试了很多,但目前没有任何工作。
#SUITABLE GREETING FOR THE USER
print ("Hi Jim, welcome to the bear factory wage calculator program.")
#INPUT bears made
bears_made = int(input("Enter the number of bears you made: "))
#INPUT hours worked
hours_worked = int(input("Enter the number of hours you worked: "))
#ABILITY TO CHANGE THE WAGE PER BEAR AND HOUR
z = str(input("Would you like to change the wage? "))
if z =="yes":
x = int(input("Enter how much the user should get per bear: "))
a = bears_made*(x)
e = int(input("Enter how much the user should get an hour: "))
b = hours_worked*(e)
else:
#BEARSMADE x 2 = a
a = (bears_made *2)
#HOURSWORKED x 5 = b
b = (hours_worked *5)
#OUTPUT BIGGER VALUE
if a > b:
#OUTPUT A
print ("You earned", a," pounds")
else:
#OUTPUT B
print ("You earned", b," pounds")
#f = open("exported.txt",'w') ###This is the area trying to troubleshoot
#text = (a) (b)
#f.write (text)
#f.close()
#END OF PROGRAM
编辑:对不起,刚刚意识到我应该添加更多内容。我收到以下错误:
Traceback (most recent call last):
File "C:\Users\samho\OneDrive\Desktop\plannedcode.py", line 37, in <module>
text = (a) (b)
TypeError: 'int' object is not callable
答案 0 :(得分:1)
在您的代码中,您为a
和b
分配值,这两个变量中包含数字,类型为int
。
当你跑步时
text = (a)(b)
你实际上是在调用它:1(2)
,这是无效的。
我假设您要将这两个输出到文本文件中,因此请用以下内容替换该语句:
text = "({})({})".format(a, b)
答案 1 :(得分:1)
试试这个
Run chrome.exe web.whatsapp.com
sleep, 2000
WinWait, WhatsApp - Google Chrome
WinWaitClose
{some code}
这样做是打开文件,然后写一个字符串。
字符串将是两个数字a和b
答案 2 :(得分:0)
这就是你要做的。希望它有所帮助。
#SUITABLE GREETING FOR THE USER
print ("Hi Jim, welcome to the bear factory wage calculator program.")
#INPUT bears made
bears_made = int(input("Enter the number of bears you made: "))
#INPUT hours worked
hours_worked = int(input("Enter the number of hours you worked: "))
#ABILITY TO CHANGE THE WAGE PER BEAR AND HOUR
z = str(input("Would you like to change the wage? "))
if z =="yes":
x = int(input("Enter how much the user should get per bear: "))
a = bears_made*(x)
e = int(input("Enter how much the user should get an hour: "))
b = hours_worked*(e)
else:
#BEARSMADE x 2 = a
a = (bears_made *2)
#HOURSWORKED x 5 = b
b = (hours_worked *5)
#OUTPUT BIGGER VALUE
if a > b:
#OUTPUT A
print ("You earned", a," pounds")
else:
#OUTPUT B
print ("You earned", b," pounds")
f = open("exported.txt",'w') ###This is the area trying to troubleshoot
text = str(a)+" "+str(b)
f.write (text)
f.close()
#END OF PROGRAM