1

Basically, I have a question about cricket, and getting the user to input their score for each of the 6 bowls by using a while loop, and then give them the total of the over at the end. This is the code I have done, but it doesn't work, and I'm not sure on how to make it right.

    cricket_balls=0
    while cricket_balls < 6:
        score= int(input('What was the score of bowl', cricket_balls , '?:' )
        cricket_balls = cricket_balls + 1
        print (score)
    total_score = score
    print ('The total score for this over is', total_score)
skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
clare.python
  • 145
  • 1
  • 1
  • 10
  • 1
    `total_score = total_score + score` put this in while loop at end – vks Jan 19 '16 at 20:00
  • Possible duplicate of [How do I do variable variables in Python?](http://stackoverflow.com/questions/1373164/how-do-i-do-variable-variables-in-python) – Morgan Thrapp Jan 19 '16 at 20:00
  • 1
    By "doesn't work" do you mean it produces a `SyntaxError` because you're missing a closing parenthesis on line 3? And after you fix that, you'll have an error with too many arguments to `input`, which doesn't work like `print()`. And then it won't do what you want because you're always adding 1 instead of doing something with `score`. – TigerhawkT3 Jan 19 '16 at 20:00
  • 4
    Overall, I'd say you need to read a [tutorial](https://docs.python.org/3.4/tutorial/index.html) and then spend some time debugging your code. – TigerhawkT3 Jan 19 '16 at 20:01
  • @TigerhawkT3 yes i realise i need to do that, i will ask my teacher in my next lesson for some help - i haven't been doing computing for long so i don't really understand everything – clare.python Jan 19 '16 at 20:06

2 Answers2

0

There are three problems. You forgot to write counter for the score, one closing parenthesis and input() takes only one positional argument. You code should be like:

cricket_balls, total_score = 0, 0
while cricket_balls < 6:
    score = int(input('What was the score of bowl {} ?'.format(cricket_balls)))
    cricket_balls += 1
    total_score += score
    print(score)
total_score = score
print('The total score for this over is', total_score)
George Petrov
  • 2,729
  • 1
  • 13
  • 20
  • Thanks for pointing out the mistakes . It came up with: Traceback (most recent call last): File "/Users/apple/Documents/aqdivice.py", line 3, in score= int(input('What was the score of bowl', cricket_balls , '?: ')) TypeError: input expected at most 1 arguments, got 3 – clare.python Jan 19 '16 at 20:11
0

input takes one argument, so you need to concatenate the component strings to create a single string. There are several options:

score = int(input('What was the score of bowl %d ?:' % (cricket_balls,)))
score = int(input('What was the score of bowl ' + str(cricket_balls) + '?:'))
score = int(input('What was the score of bowl {} ?:'.format(cricket_balls)))
chepner
  • 497,756
  • 71
  • 530
  • 681
  • Because, as I mentioned, in addition to improper syntax and passing incorrect arguments to a function, your basic algorithm is wrong. – TigerhawkT3 Jan 19 '16 at 20:16