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(“按回车键退出”)
答案 0 :(得分:1)
我认为Ashwini的版本已经完成了这项工作。当我看到原始代码时,它说:
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语句。这是一种invallid语法。使用此:
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")