错误 - 输入预计最多 1 个参数,得到 3 [英] Error - input expected at most 1 argument, got 3

查看:45
本文介绍了错误 - 输入预计最多 1 个参数,得到 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了以下 for 循环来接受 5 个测试分数.我希望循环提示用户输入 5 个不同的分数.现在我可以通过输入请输入您的下一个测试分数"来做到这一点,但我宁愿让每个输入的分数提示其关联的数字.

I've set up the following for loop to accept 5 test scores. I want the loop to prompt the user to enter 5 different scores. Now I could do this by writing the input "Please enter your next test score", but I'd rather have each inputted score prompt for its associated number.

因此,对于第一个输入,我希望它显示请输入您的测试 1 分数",然后对于第二个分数,显示请输入您的测试 2 分数".当我尝试运行此循环时,出现以下错误:

So, for the first input, I'd like it to display "Please enter your score for test 1", and then for the second score, display "Please enter your score for test 2". When I try to run this loop, I get the following error:

Traceback (most recent call last):
  File "C:/Python32/Assignment 7.2", line 35, in <module>
    main()
  File "C:/Python32/Assignment 7.2", line 30, in main
    scores = input_scores()
  File "C:/Python32/Assignment 7.2", line 5, in input_scores
    score = int(input('Please enter your score for test', y,' : '))
TypeError: input expected at most 1 arguments, got 3

这是代码

def input_scores():
    scores = []
    y = 1
    for num in range(5):
        score = int(input('Please enter your score for test', y, ': '))

        while score < 0 or score > 100:
            print('Error --- all test scores must be between 0 and 100 points')
            score = int(input('Please try again: '))
        scores.append(score)
        y += 1
        return scores

推荐答案

一种简单(而且正确!)的方式来写你想要的东西:

A simple (and correct!) way to write what you want:

score = int(input('Please enter your score for test ' + str(y) + ': '))

这篇关于错误 - 输入预计最多 1 个参数,得到 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆