![](/img/trans.png)
[英]Why am I getting an invalid syntax error in Python REPL right after IF statement?
[英]Why am I getting invalid syntax in an 'If else' statement? (Python)
我正在創建我的第一個 python 項目,我對此很陌生。 所以我不明白為什么我在 VSCode 中收到錯誤消息。 這是代碼:
import random
import numpy
from numlst import numlist_1
# this is not in the actual code, but I wanted to say that the import numlist
# 1 is an actual code file in my game, and it has nothing to do with the python
# module in the standard python library
def get_name():
name = input("Before we start, what is your name?")
print("You said your name was: " + name)
tries = 5
# game_over = 5
# while game_over < 6:
def get_number(get_name, random):
get_name()
print(input("guess your number, since this is the first level you need to choose a number between 1 and 10 "))
number = random.choice(numlist_1)
if input == number:
print("Congratulations! You got the number correct!")
else:
tries -1
print("Oops, you got the number wrong you have: " + str(tries) + " tries left")
print(input(" Do you want to try again?")):
if input == "yes":
get_number(get_name, random)
elif input == "no":
print("Well goodbye then... I hope you have a great rest of your day")
# get_number(get_name, random)
get_number(get_name, random)
所以每當我運行它時,我都會收到這個無效的語法消息。 它抱怨我在
print(input(" Do you want to try again?")):
我已經嘗試刪除它並且發生的情況是,在終端中代碼運行完美,直到我收到消息:“你想再試一次嗎?”,所以無論我回答什么(是,否,blablabla),它只是返回。
另外,另一個問題是如何使這里的while循環工作? 我知道while循環被注釋掉了,但是如果我真的正確格式化它,當我用while循環運行代碼時,我不會從終端得到output(我開始懷疑它甚至是一個while循環)。 但這對我來說是下一步,因為我想先解決前面的問題。
如果您有時間可以回答其中一個問題或兩個問題,我將不勝感激。 感謝您花時間閱讀本文,如果您嘗試解決此問題,我們將更加感謝您。
我正在創建我的第一個 python 項目,我對此很陌生。 所以我不明白為什么我在 VSCode 中收到錯誤消息。 這是代碼:
import random
import numpy
from numlst import numlist_1
# this is not in the actual code, but I wanted to say that the import numlist
# 1 is an actual code file in my game, and it has nothing to do with the python
# module in the standard python library
def get_name():
name = input("Before we start, what is your name?")
print("You said your name was: " + name)
tries = 5
# game_over = 5
# while game_over < 6:
def get_number(get_name, random):
get_name()
print(input("guess your number, since this is the first level you need to choose a number between 1 and 10 "))
number = random.choice(numlist_1)
if input == number:
print("Congratulations! You got the number correct!")
else:
tries -1
print("Oops, you got the number wrong you have: " + str(tries) + " tries left")
print(input(" Do you want to try again?")):
if input == "yes":
get_number(get_name, random)
elif input == "no":
print("Well goodbye then... I hope you have a great rest of your day")
# get_number(get_name, random)
get_number(get_name, random)
所以每當我運行它時,我都會收到這個無效的語法消息。 它抱怨我在
print(input(" Do you want to try again?")):
我已經嘗試刪除它並且發生的情況是,在終端中代碼運行完美,直到我收到消息:“你想再試一次嗎?”,所以無論我回答什么(是,否,blablabla),它只是返回。
另外,另一個問題是如何使這里的while循環工作? 我知道while循環被注釋掉了,但是如果我真的正確格式化它,當我用while循環運行代碼時,我不會從終端得到output(我開始懷疑它甚至是一個while循環)。 但這對我來說是下一步,因為我想先解決前面的問題。
如果您有時間可以回答其中一個問題或兩個問題,我將不勝感激。 感謝您花時間閱讀本文,如果您嘗試解決此問題,我們將更加感謝您。
我正在創建我的第一個 python 項目,我對此很陌生。 所以我不明白為什么我在 VSCode 中收到錯誤消息。 這是代碼:
import random
import numpy
from numlst import numlist_1
# this is not in the actual code, but I wanted to say that the import numlist
# 1 is an actual code file in my game, and it has nothing to do with the python
# module in the standard python library
def get_name():
name = input("Before we start, what is your name?")
print("You said your name was: " + name)
tries = 5
# game_over = 5
# while game_over < 6:
def get_number(get_name, random):
get_name()
print(input("guess your number, since this is the first level you need to choose a number between 1 and 10 "))
number = random.choice(numlist_1)
if input == number:
print("Congratulations! You got the number correct!")
else:
tries -1
print("Oops, you got the number wrong you have: " + str(tries) + " tries left")
print(input(" Do you want to try again?")):
if input == "yes":
get_number(get_name, random)
elif input == "no":
print("Well goodbye then... I hope you have a great rest of your day")
# get_number(get_name, random)
get_number(get_name, random)
所以每當我運行它時,我都會收到這個無效的語法消息。 它抱怨我在
print(input(" Do you want to try again?")):
我已經嘗試刪除它並且發生的情況是,在終端中代碼運行完美,直到我收到消息:“你想再試一次嗎?”,所以無論我回答什么(是,否,blablabla),它只是返回。
另外,另一個問題是如何使這里的while循環工作? 我知道while循環被注釋掉了,但是如果我真的正確格式化它,當我用while循環運行代碼時,我不會從終端得到output(我開始懷疑它甚至是一個while循環)。 但這對我來說是下一步,因為我想先解決前面的問題。
如果您有時間可以回答其中一個問題或兩個問題,我將不勝感激。 感謝您花時間閱讀本文,如果您嘗試解決此問題,我們將更加感謝您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.