私はちょうど学校でのPythonの学習を始めました。私は自宅でそれを練習してきましたので、私はPythonには新しいです。 私は問題を持っているが、私は、print()または計算にそれらを入れるために私が{0}を使うとき、def two()からmain()に値を持ち越そうとしているということです、任意の値を持ちます。ここ別のdefの値をどのように持ち越しますか?
は私のコードです:
def two():
print("Hello world!")
print("Please enter three numbers")
nam=int(input("Enter the first number: "))
num=int(input("Enter the second number: "))
nom=int(input("Enter the third number: "))
print("So the numbers you have entered are {0}, {1},{2}.".format(nam,nom,num))
def main():
main=two()
inpt=input("what math related problem would you like me to do with them? tell me here: ").capitalize()
if inpt== "Divide":
ans=({0}/{1}/{2})/1
print("{0}, there you go!")
elif inpt== "Times":
ans=(nam*num*nom)/1
print("{1}, there you go!")
そしてHERESに私はそれを実行しているから何を得る:
>>> main()
Hello world!
Please enter three numbers
Enter the first number: 30
Enter the second number: 30
Enter the third number: 30
So the numbers you have entered are 30, 30, 30.
what math related problem would you like me to do with them? tell me here: divide
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
main()
File "C:\Users\chemg\Documents\PracticePY.py", line 40, in main
ans=({0}/{1}/{2})/1
TypeError: unsupported operand type(s) for /: 'set' and 'set'
これは完璧に機能しました。しかし私は私のコードでは、プリントの最後に.formatを追加する必要があることに気づいた。それはすべて今うまく動作します。ありがとう! –