2014-11-14 67 views
-5
import random 

print "\n wlecome to fortune game" 


your_fortune = random.randrange(1,8) 

if your_fortune == 1: 
    print "your are lucky" 
else: 
    print "you are not lucky" 

的raw_input(“按Enter键退出”)无法执行此程序。错误:无效的语法random.py

+0

您的代码看起来不错,发布准确的追踪消息。 –

+0

你使用的是什么版本的Python? –

+0

你的代码适合我 –

回答

1

我觉得阿什维尼的版本已经做了工作。当我看着你原来的代码,它说这个:

import random 
print "\n wlecome to fortune game" 
your_fortune = random.randrange(1,8) 
if your_fortune == 1: print "your are lucky" else: print "you are not lucky" 
raw_input("press enter to exit") 

在第四行中,我看到在同一行的if和else语句。这是一个不可思议的语法。使用此:

import random 

print "\nWelcome to fortune game" 
your_fortune = random.randrange(1,8) 
if your_fortune == 1: print "your are lucky" 
else: print "you are not lucky" 

raw_input("press enter to exit") 

或者这样:

import random 

print "\nWelcome to fortune game" 
your_fortune = random.randrange(1,8) 
p = "your are lucky" if your_fortune == 1 else "you are not lucky" 
print p 

raw_input("press enter to exit")