0
我試圖編寫一個程序,產生隨機數,詢問你想要它有多大,例如1-4之間,然後我想問它你有多少個數字希望並最終問你是否要再次運行它。我試圖掌握遞歸和類型轉換的概念,只是試圖用Python學習面向對象設計的概念。我試圖從迄今爲止在Learn Python Hard Way網站上閱讀的內容中收集。使用用戶輸入來控制隨機數發生器
from random import randint
def random_with_N_digits(n):
range_start = 10**(n-1)
range_end = (10**n)-1
return randint(range_start, range_end)
# Here I am attempting to define the variables I need to convert keyboard input to int
size = raw_input()
intsize = # unsure of how to define this variable
intsize = int(size)
print "How many Digits?",
size = raw_input()
print "How many Times?".
times = raw_input()
# I want to construct a method here that sends my size input to random_with_N_digits(n)
# I need a method that runs the random_with_N_digits according to the input.
# while True:
reply = input('Enter text:')
if reply == 'stop':
break
if reply = times # not sure what to put here
print(def random_with_N_digits)
else:
# I want to tell the my method to run as many as much as 'times' is equal to
print "Again?"
answerMe = raw_input()
# here I want to have a if answerMe = Enter run the method again
print random_with_N_digits()