我想编写一个程序来计算用户输入的一组数字(一次一个)的平均值。当用户输入标记值''时(ENTER无输入),每个组应该结束。两个连续的哨兵值应退出该计划。每组的数量应与其平均值一起显示:
这是我的代码:
x = eval(input('Enter a number: '))
lis = []
while x != '':
lis.append(x)
if x == '':
avg = sum(lis) / len(lis)
print(avg)
答案 0 :(得分:0)
只需将var path = require('path')
module.exports = {
entry: {
app: './src/main.js'
},
output: {
path: path.resolve(__dirname, '../dist/static'),
publicPath: '/static/',
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.vue', 'styl'],
alias: {
'src': path.resolve(__dirname, '../src')
}
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
},
module: {
preLoaders: [
{
test: /\.vue$/,
loader: 'eslint',
exclude: /node_modules/
},
{
test: /\.js$/,
loader: 'eslint',
exclude: /node_modules/
}
],
loaders: [
{
test: /\.vue$/,
loader: 'vue'
},
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
query: {
limit: 10000,
name: '[name].[ext]?[hash:7]'
}
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader'
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&minetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
},
eslint: {
formatter: require('eslint-friendly-formatter')
}
}
移动到循环中:
input
此外,您不需要x = None
lis = []
while x != '':
x = input('Enter a number: ')
if x != '':
lis.append(int(x))
avg = sum(lis) / len(lis)
print(avg)
语句,因为if
必须等于x
,以便''
循环终止。