import random
print('-\n')
begin=int(raw_input('-\n')
end=int(raw_input('-\n')
rep=int(raw_input('-\n')
def dop():
print random.randinterga
ivfhoierh
while count < rep:
print do
count = count + 1
print('Thanks for using this program!\n')
raw_input('press enter to continue')
好的,所以我真的不知道我做错了什么但是我一直收到语法错误而且IDLE突出显示'结束'。
编辑:C
答案 0 :(得分:1)
这就是我要这样做的方式:
import random
print 'I will print out random integers from a range you specify.'
begin = int(raw_input('Please enter the starting range: '))
end = int(raw_input('Please enter the end range: '))
rep = int(raw_input('Please enter the repeat value: '))
def get_random():
return random.randint(begin, end)
for _ in range(rep):
print get_random()
注重细节非常重要。
解决的问题:
print
do()
raw_input()
不需要\n
个新行randint()
对浮点值生成ValueError: non-integer arg 1 for randrange()
感到不安;相应地施放raw_input()
count
和赋值希望这有帮助!
答案 1 :(得分:-1)
我猜你使用的是Python 2,用raw_input来判断。 将您的代码更正为:
import random
print 'Hi, I will print out random intergers from a range you specify.\n'
#No need for parenthesis
begin=float(raw_input('Please enter the starting range. \n'))
end=float(raw_input('Please enter the end range. \n'))
rep=float(raw_input('Please enter how many times you cant to repeat the function. \n'))
# ERROR you forgot an extra parenthesis on the end of each of the last 3 lines.
def do():
print random.randint(begin, end)
count = 0
while count < rep:
do() # <- Parenthesis, and no need to print.
count = count + 1
print 'Thanks for using this program!\n' #No need for parenthesis
raw_input('press enter to continue')
还有:
count = 0
while count < rep:
do() # <- Parenthesis, and no need to print.
count = count + 1
可以替换为:
for count in range(rep):
do()