我是靠谱客的博主 和谐羊,最近开发中收集的这篇文章主要介绍python在冒号处显示语法错误_python – 在if语句中的冒号上的语法错误,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我是

python的新手,我正在做一个游戏,作为我的第一个项目之一,猜测1到10之间的数字,然后用户猜测.他们有三个猜测,程序会告诉用户他们是否需要在下一个猜测中更高或更低.带有错误的代码部分并不重要,因为如果用户将两次相同的答案放在同一个答案中,这样做只会造成一个猜测,从而允许他们第一次重做猜测,但不允许重新使用第二.在代码中,我已经标记出问题所在.就像我说的,我真的很喜欢python,这可能是一些业余noobie的错误.提前致谢.

import time # This imports the time module.

import random # This imports the random module.

MyNumber = random.randrange(1,10) # This picks a number for the variable 'MyNumber'.

# Intro text and instructions.

print('=====================================')

print('=Welcome to GuessMyNumber! =')

print('= =')

print('=I will make a random number between=')

print('=1 and 10, and you must guess it. If=')

print('=you are wrong, I will tell you if =')

print('=you need to go higher or lower. Be =')

print('=careful, as you only have three =')

print('=guesses! =')

print('=====================================')

print()

firstGuess = int(input('Ok then, we shall begin! What is your first guess?'))

print()

if firstGuess == (MyNumber):

print('Well done! You win!')

time.sleep(3)

exit()

if firstGuess < MyNumber:

print('Go Higher!')

time.sleep(1)

if firstGuess > MyNumber:

print('Go Lower!')

time.sleep(1)

print()

secondGuess = int(input('Better luck this time! What is your second guess?'))

print()

if secondGuess == firstGuess:

print('You tried that one last time! Don't worry, I won't count that one!')

bungled = (1)

secondGuess = int(input('What is your second guess?')

if secondGuess == firstGuess:#This colon is causing the problem.

print('You've already tried that one twice!')

bungled = (2)

if secondGuess == MyNumber:

print('Well done! You win!')

time.sleep(3)

exit()

if secondGuess < MyNumber:

print('Go Higher!')

time.sleep(1)

if secondGuess > MyNumber:

print('Go Lower!')

time.sleep(1)

print()

thirdGuess = int(input('This is your final chance! What is your third guess?'))

print()

if thirdGuess == MyNumber:

print('Well done! You win!')

time.sleep(3)

exit()

if thirdGuess < MyNumber:

MyNumber = str(MyNumber)

print('Sorry! You lost! The number was '+MyNumber)

time.sleep(1)

exit()

if thirdGuess > MyNumber:

MyNumber = str(MyNumber)

print('Sorry! You lost! The number was '+MyNumber)

time.sleep(1)

exit()

最后

以上就是和谐羊为你收集整理的python在冒号处显示语法错误_python – 在if语句中的冒号上的语法错误的全部内容,希望文章能够帮你解决python在冒号处显示语法错误_python – 在if语句中的冒号上的语法错误所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部