2017-02-20 51 views
0

Добрый день! Я просто установил Python и VSC с небольшим фоном на обоих, и мне было интересно, почему я не смог выполнить простой код, поскольку я копирую его слово в слово с YouTube. (Количество угадывания игры) На данный момент у меня есть(код Python на Visual Studio) СинтаксисError: недействительный синтаксис

import random 
num == 0 

print("Who are you?") 
name = input() 

print("Hi ", +name, "! Let's play!") 

number = random.randint(1,20) 
print("I'm thinking of a number between 1 to 20.") 

while num < 6; 
    print("Try me.") 
    guess = input() 
    guess = int(guess) 

    numberofguesses = numberofguesses + 1 

if guess < number: 
    print("Number is too low") 
if guess > number: 
    print("Number is too high") 
if guess == number; 
    break 
if guess == number: 
    numberofguesses = str(numberofguesses) 
    print("Well done ", +name, "! You guessed the number in " 

+numberofguesses) 
if guess != number: 
    number = str(number) 

и ошибка, я получаю

File "c:\dir\test.py", line 12 
while num < 6 
      ^

SyntaxError: invalid syntax

Я получаю эту ошибку работает питон от CMD, а также с помощью встроенного в отладчике VSC.

+4

вы хотите двоеточие не с запятой ', а NUM <6:' – EdChum

ответ

2

Поскольку EdChum заявляет, что вам нужно использовать двоеточие не в виде двоеточия.

Также вы не хотите отступать от оператора импорта в начале.

пожалуйста, проверьте этот код близко к твоему есть несколько ошибок

import random 
num = 0 
numberofguesses = 0 

print("Who are you?") 
name = input() 

print("Hi " + name + "! Let's play!") 

number = random.randint(1,20) 
print("I'm thinking of a number between 1 to 20.") 

while num < 6: 
    print("Try me.") 
    guess = input() 
    guess = int(guess) 

    numberofguesses = numberofguesses + 1 

    if guess < number: 
     print("Number is too low") 
    if guess > number: 
     print("Number is too high") 
    if guess == number: 
     break 
if guess == number: 
    numberofguesses = str(numberofguesses) 
    print("Well done " + name + "! You guessed the number in " 

+numberofguesses) 
if guess != number: 
    number = str(number) 
+1

Спасибо за указав его! Именно это и поставило проблему. – polors2

 Смежные вопросы

  • Нет связанных вопросов^_^