473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Basic while loop syntax error (101 stuff)

2
I am getting a syntax error as I try to run my little "Guess the number"-game, as directly copied from http://inventwithpython.com/chapter4.html. The error reads:
File "guess.py", line 12
while guessesTaken < 6:
^
SyntaxError: invalid syntax

The source code reads:
Expand|Select|Wrap|Line Numbers
  1. # This is a guess the number game.
  2. import random
  3.  
  4. guessesTaken = 0
  5.  
  6. print('Hello! What is your name?')
  7. myName = input()
  8.  
  9. number = random.randint(1, 20)
  10. print('Well, ' + myName + ', I am thinking of a number between 1 and 20.'
  11.  
  12. while guessesTaken < 6:
  13.     print('Take a guess.')
  14.     guess = input()
  15.     guess = int(guess)
  16.  
  17.     guessesTaken = guessesTaken + 1
  18.  
  19.     if guess < number:
  20.         print('Your guess is too low.')
  21.  
  22.     if guess > number:
  23.           print('Your guess is too high.')
  24.  
  25.     if guess == number:
  26.         break
  27.  
  28. if guess == number:
  29.       guessesTaken = str(guessesTaken)
  30.       print('Good job, ' + myNamen + '! You guessed my number in ' + guessesTaken + ' guesses!')
  31.  
  32. if guess != number:
  33.       number = str(number)
  34.       print('Nope. The number I was thinking of was ' + number)
I am running Python 3.3 on Windows 7, and have tried both running the program from IDLE and Command.
Aug 24 '13 #1
2 2522
eppi92
2
Solved it by pasting piece by piece into a new file, testing as I went along. Discovered 1 typo towards the end of the program (line 30, "myNamen" is not a variable), but still don't know what caused the original error. Ghost in the machine, I guess..
Aug 24 '13 #2
Rabbit
12,516 Expert Mod 8TB
The problem with the first one is because the print before line 12 never got closed.
Aug 24 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: sam | last post by:
When I run this SQL query: SELECT u.*, o.* FROM users u, orders o WHERE TO_DAYS(o.order_date) BETWEEN TO_DAYS('2003-09-20')-10 AND TO_DAYS('2003-09-20')+10
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
3
by: Balaji | last post by:
I'm trying to do some basic socket programming. here is the line of code which is creating problem.. int FAR PASCAL __declspec (dllexport)(char * addr,int port) Hers is the error I'm...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
4
by: gregpinero | last post by:
It's the strangest thing, I'm pulling some text out of a MySQL table and trying to run exec on it, and it keeps giving me a syntax error, always at the end of the first line. Thanks in advance...
7
by: Ray Dillinger | last post by:
Hi. I'm having a problem and I really want to understand it. Here's the situation: I have an array of pointers, and each pointer is the head of a linked list of structs. The structs are...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
2
by: Lieven | last post by:
The problem is fairly complex. I have a table where I can add records. These records have several parts. Each record consists of ID, Date, Train Number and many more. I have a form where I can...
3
by: dowlingm815 | last post by:
I am receiving a Do While Syntax Error - Loop without Do - Can't See it. I would appreciate any fresh eyes? Mary Private Sub Create_tblNJDOC() On Error GoTo Err_Hndlr
3
by: lingjun | last post by:
Hi, I am taking my first programing course in college... and I am completely lost on this assignment. I am not sure what is wrong with my current code. Any help will be appreciate it... thanks! ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.