最新回答 / 椰汁菠萝
你报的啥错啊?你这代码写的没问题,不管你在哪里写的代码,运行报错都有很明确的提示,你的print f(3),f和括号之间的空格是认真的吗?你确定用的是python2.7.8?在python3中print已经没有这个语法了;命令行里多是做实验用的,真正开发的话肯定要在编译器里,比如,VSCode,idea之类的
2019-09-20
import math
def quadratic_equation(a, b, c):
t=math.sqrt(b**2-4*a*c)
return (-b+t)/2/a,(-b-t)/2/a
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
t=math.sqrt(b**2-4*a*c)
return (-b+t)/2/a,(-b-t)/2/a
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-09-20
def square_of_sum(L):
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-09-20
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print('%s:%d'%(x[0],x[1]))
for x in s:
print('%s:%d'%(x[0],x[1]))
2019-09-20
months = set(['Feb'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2019-09-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print("%s:%d"%(name,d[name]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print("%s:%d"%(name,d[name]))
2019-09-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam: %d'%d['Adam'])
print('Lisa: %d'%d.get('Lisa'))
print('Bart: %d'%d['Bart'])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam: %d'%d['Adam'])
print('Lisa: %d'%d.get('Lisa'))
print('Bart: %d'%d['Bart'])
2019-09-20
for x in [1,2,3,4,5,6,7,8]:
for y in [2,3,4,5,6,7,8,9]:
if x<y: print(str(x)+str(y))
for y in [2,3,4,5,6,7,8,9]:
if x<y: print(str(x)+str(y))
2019-09-20
已采纳回答 / 椰汁菠萝
可以写啊,为啥不能写???def average(*args): if len(args)==0: return 0.0 return float(sum(args))/len(args)print average()print average(1, 2)print average(1, 2, 2, 3, 4)
2019-09-19
#Enter a code
print(45678+0x12fd2)
print('Lern Python in imooc')
print(100<99)
print(0xff==255)
print(45678+0x12fd2)
print('Lern Python in imooc')
print(100<99)
print(0xff==255)
2019-09-19
x1 = 1
d = 3
n = 100
x100 = x1 + d * 99
s = x1 * 100 + 99 * 50 * d
print s
d = 3
n = 100
x100 = x1 + d * 99
s = x1 * 100 + 99 * 50 * d
print s
2019-09-19
#Enter a code
#coding=utf-8
print 45678 + 0x12fd2
print 'Learn Python in imooc。'
print 100 < 99
print 0xff == 255
#coding=utf-8
print 45678 + 0x12fd2
print 'Learn Python in imooc。'
print 100 < 99
print 0xff == 255
2019-09-19