-1

I am trying to take my shot at building a super simple score counter in Python, the language I am teaching myself. The counter should only go to 200 and not over. I am stuck at my second loop and I am getting an invalid syntax error in line 13 at the second condition "> 200".

I haven't finished the code yet, because I am testing each block as I go. Can I receive help as to why I am getting the error? Also I am sure this is messy code, but I am just now learning about functions and paremeters, and conditions, so this is so far what I know. The entire code is as follows:

global score #creating starting score
score = 0 # set to 0
global high_score # highest score attainable
high_score = 200 # set to 200
global new_score # name to get current score 
new_score = score + int(input("score: ")) # how current score is reached
def total(): # function to find the complete score
    while score(): # loop for score at zero to add points
        if score is 0:
            print(new_score) #asks user for first score
            break
    while score(): # loop to keep adding numbers
        if new_score < 0 and > 200:
            print("next score: ", + score)
        break
  • The parts before and after `and` are *independent expressions*. Computers don't understand English grammar, where you can drop pronouns and know that the other human knows what you mean from context. – Martijn Pieters May 15 '18 at 17:09
  • Ah so I have to clarify what I am asking from it. Thank you! – Lindsey Betancourt May 15 '18 at 17:12
  • Also, don't use `and`. `new_score` can't be both smaller than 0 *and at the same time* be greater than 200. You want `or` here. – Martijn Pieters May 15 '18 at 17:12
  • So either `new_score < 0 or new_score > 200`, or use `not (0 <= new_score <= 200)`. – Martijn Pieters May 15 '18 at 17:14
  • Another issue: don't use `is` on numbers. Use `==` to test for the *value*, so `if score == 0:`. That `score is 0` works is an accident of an implementation optimisation, not by design. See ["is" operator behaves unexpectedly with integers](//stackoverflow.com/q/306313) – Martijn Pieters May 15 '18 at 17:15
  • Next, `score` is not a function, don't call it. `while score:` will be false if `score` is set to `0`, so you'll never reach the `if score == 0:` line. – Martijn Pieters May 15 '18 at 17:16
  • Yea I just tried to run it after fixing the first error. It does say 'int" object is not callable. I didn't realize I had so many errors. I thought I had it set up to be more than 0 but less than 200. I will look at the link you posted thank you again! – Lindsey Betancourt May 15 '18 at 17:20

1 Answers1

0
if new_score < 0 and new_score > 200:

By the way, that condition will NEVER occur :) You should rethink your logic.

d g
  • 1,594
  • 13
  • 13
  • Thank you, this and above helps greatly, each time I use the "and" I must say the name of the variable on both expressions. – Lindsey Betancourt May 15 '18 at 17:14
  • Yea I got them so mixed up. I think I am going to dump this code and start a different code for the same thing. So many errors, I think I jumped the gun on trying it out before I completely understood how functions work. – Lindsey Betancourt May 15 '18 at 17:31
  • Glad I could help. Spend some time reading/doing some online tutorials. It will save you a lot of time & frustration. – d g May 15 '18 at 17:45
  • I have been. Currently I am reading "the self taught programmer" and was following along perfectly. Just got done with all the basics and decided to test myself. But I do believe I am going to find more books that will go a little deeper into well everything. – Lindsey Betancourt May 15 '18 at 17:49