2015-10-06 106 views
-2

我在使用random.random()功能的Python上做了一個簡單的遊戲,但是我在腳本的最後得到了random.random()上的無效語法。 我不是很有天賦,可能解決方案非常簡單,但我不明白爲什麼它會向我發送錯誤,我非常感謝您的幫助。random.random無效語法

#Text based game 
import time 
import os 
import sys 
import random 

start_time = time.clock() 

def cls(): 
    os.system(['clear','cls'][os.name == 'nt']) 

Class = "warrior" 

print("Welcome to THE Game, the most epic text based Game you have ever played.")  #Please make a better name, thanks :) 
start = input("Are you ready to start?: ") 
cls() 
if start == 'yes': 
    name = input("What is your name?: ") 
    cls() 
    print("Welcome young traveler, here you will experience like nothing you've experienced before (Ha, as if anything is new these days), but remember ", name,", no one can protect you from this point on.") 
    input("Press any key to continue: ") 
    cls() 
    print("Please choose a character.") 
    print("") 

else: 
    print random.random() 
    input() 
    quit() 
+2

的Python 3? 'print random.random()',所以:'print(random.random())' – cdarke

+0

Python 3? 'print'是一個函數,所以它應該是'print(random.random())'。 –

+3

順便說一句,下次您發佈時,請複製並粘貼整個錯誤消息,包括追溯。 – cdarke

回答

0

你缺少周圍print(),該行應爲:

print(random.random()) 
+0

'os.system(['clear','cls'] [os.name =='nt'])'應該與if statememt相同:when'os.name –