我目前正在编写一个交易游戏,用户连接到服务器,然后互相交易并赚钱等等.但是当我尝试时
if(input.lower() == 'sell'):
sMaterial = raw_input('Material: ')
if(sMaterial.lower() == 'gold'):
sAmount = int(input('Enter amount: '))
if(gold >= sAmount):
mon = mon + (100 * sAmount)
else:
print 'You do not have enough', sMaterial
Run Code Online (Sandbox Code Playgroud)
它抛出错误
> sell
Material: gold
Traceback (most recent call last):
File "Test.py", line 119, in <module>
sAmount = int(input('Enter amount: '))
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
我使用Linux,Python版本2.7.3,与Geany开发环境.提前致谢.
好吧,所以我在我的桌子上敲了几天这个,我仍然无法得到它我一直遇到这个问题:
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 44, in <module>
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 35, in main
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 15, in __init__
builtins.TypeError: can't multiply sequence by non-int of type 'float'
Run Code Online (Sandbox Code Playgroud)
一遍又一遍.我想我已经碰到了墙,我确实做了很多寻找和测试,但如果有人能指出我正确的方向,我将不胜感激.
from math import pi, sin, cos, radians
def getInputs():
a = input("Enter the launch angle (in degrees): ")
v = input("Enter the initial velocity (in meters/sec): ")
h = input("Enter the …Run Code Online (Sandbox Code Playgroud) 在python中,我们说一切都是对象,
例如:表达式x<y内部调用x.__lt__(y)
其中__lt__是在类的对象方法("INT"说,如果值是2和3)和x和y是参考变量的对象
和
用户定义的函数square(3)内部调用square.__call__(3)其中'square'是类'function'的对象的名称,引用变量'square'指向该对象名'square'.
所以,
if-elif-else,for,break,continue,pass,lambda语句如何在内部解释?作为对象?
如果是,您能举一些例子以上述方式进行可视化吗?
你能告诉我这段代码有什么问题吗?
def insert_sequence(str1, str2, index):
'''The first two parameters are DNA sequences and the third parameter
is an index. Return the DNA sequence obtained by inserting the second
DNA sequence into the first DNA sequence at the given index.
>>>insert_sequence('CCGG', 'AT',2)
CCATGG
'''
str1 = str1[0:index] + str2 + str1[index:len(str1)]
return str1
Run Code Online (Sandbox Code Playgroud) if len(user_hash) > 0:
with open(log_file, "w") as log_f:
for name in user_hash:
log_f.write("Name:%s \n Email: %s" % (name, email)
else len(user_hash) < 0:
print "Nothing happened :("
Run Code Online (Sandbox Code Playgroud)
我一直在else语句中遇到语法错误,我不确定为什么它会一直产生这个错误.我在同一个def中没有任何其他语句,但仍然会出错.我该怎么办?
我已将变量fiblist声明为全局变量,但它在gen10fib中获得None的值.
# Enter your code here. Read input from STDIN. Print output to STDOUT
#program to check if a number is fibonacci number
global fiblist
fiblist=[0,1] #list to store generated fibonacci numbers
global Nlist
Nlist=[] # list for T test cases
global solnList
solnList=[] #contains the solution 1 is fibo 0 not fibo
global head
head=1 #to denote the maximum element in the list
def comparator(fiblist,x,head):
if(head<x):
gen10fib(fiblist) #generates the next 10 numbers of fibonacci sequence and appends them to …Run Code Online (Sandbox Code Playgroud)