2017-09-26 2 views
-1

ので、Pythonの初心者をIMと私はそうのようにランダムに入力varibleを配置する方法を見つけるカント、Variblesをランダムに使用しますか? (パイソン)

import time 
 
import random 
 
choice = input('easy (max of 100 number), medium(max of 1000) or hard (max of 5000)? Or custom)') 
 
time.sleep(2) 
 
if choice == 'custom': 
 
    cus = input(' max number?') 
 
print ('okey dokey!') 
 
eh = 1 
 
cuss = random.randrange(0, (cus)) 
 
easy = random.randint(0, 100) 
 
medium = random.randint(0, 1000) 
 
hard = random.randint (0, 5000) 
 
if choice == 'easy' or 'medium' or 'hard' or cus: 
 
    while eh == 1: 
 
     esy = int(input('what do you think the number is?)')) 
 
     if esy > easy: 
 
      time.sleep(2) 
 
      print ('too high!') 
 
     elif esy == easy: 
 
      print (' CORRECT!') 
 
      break 
 
     elif esy < easy: 
 
      print ('TOO low') 
 
    

は私がその数を置くことができますどのような方法があります誰かが9行目のようにランダムに入力したものですか?

+0

あなたの角括弧を削除し、 '(0、int(cus)) 'を使用してください – AK47

答えて

0

はあなたの変数cus int型に変換して、通常はあなたのコードと間違って複数のものがあります

cuss = random.randrange(0, int(cus)) 
1

と同じようにそれを渡します。 。あなたは、これはあなたがcus = input()を行う際に、CUSは現在の文字列であることを意味し、あなたがのpython3を使用している示唆している、印刷での(使用しているあなたは、おそらくchoice == 'easy' or 'medium' or 'hard' or cusを行うと、常にTrueになりますcus = int(input())

やりたい; I

values = {'easy': 100, 'medium': 1000, 'hard': 5000} 

。もちろん、それを行うには良い方法が辞書である。人々はPythonでこれをやっておくが、あなたはchoice == 'easy' or choice == 'medium' or choice == 'hard' or choice == 'cus'を行う必要がある理由はわかりません。そして

value = values.get(choice) 
if not value: 
    value = int(input("Please enter custom value")) 

を行うと、あなたはすることができますdo randomvalue = random.randint(1,value)

+0

私はqrong tahnksに行った場所を見ます! –

関連する問題