错误 - 输入预计最多1的说法,得到了3 [英] Error - input expected at most 1 argument, got 3

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

问题描述

我已经设置了循环下接受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

这里的code

Here's the code

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 

感谢你这么多的帮助:)
〜达斯汀

Thank you so much for the help :) ~Dustin

推荐答案

一个简单的(正确的!)的方式来写你想要什么:

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天全站免登陆