我读了其他的问题,但我试图做的事情是不同的我试图在python中制作一个计算器,并试图将变量输入事物变成一个整数,所以我可以添加它.这是我的代码还没有完成,我是一个初学者:
print("Hello! Whats your name?")
myName = input()
print("What do you want me to do? " + myName)
print("I can add, subtract, multiply and divide.")
option = input('I want you to ')
if option == 'add':
print('Enter a number.')
firstNumber = input()
firstNumber = int(firstNumber)
print('Enter another number.')
secondNumber = input()
secondNumber = int(secondNumber)
answer = firstNumber + secondNumber
print('The answer is ' + answer)
Run Code Online (Sandbox Code Playgroud)
它能做什么:
Hello! Whats your name?
Jason
What do you want me to do? Jason
I can add, subtract, multiply and divide.
I want you to add
Enter a number.
1
Enter another number.
1
Traceback (most recent call last):
File "C:/Python33/calculator.py", line 17, in <module>
print('The answer is ' + answer)
TypeError: Can't convert 'int' object to str implicitly
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激 :)
归档时间: |
|
查看次数: |
16254 次 |
最近记录: |