数字打印机,随机整数不工作



好的,所以我试图在repl.it上创建一个程序,它可以打印偶数、奇数、连续数或随机数。在这个程序中,你可以决定所需的时间、打印的数量以及(对于随机数(最高和最低数。

然而,每当我选择随机并尝试运行它时。这会弹出

File "main.py", line 76, in <module>
massprint()
File "main.py", line 24, in massprint
print(random.randint(int(randhighcap),int(randlowcap)),flush=True, end=" ")
File "/usr/lib/python3.8/random.py", line 248, in randint
return self.randrange(a, b+1)
File "/usr/lib/python3.8/random.py", line 226, in randrange
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (100, 1, -99)

这是repl项目的链接,因此您可以查看代码。(或者代码在下面。(

https://repl.it/@MichaelGordon1/OddEven连续数字打印机#main.py

import time
import random
from random import randint
import sys
def massprint():
againagain = int(times)
even=0
odd=1
consec=0
rand=0
while againagain >= 0:
time.sleep(float(speed))
againagain -= 1
if eocr=="e":
print(even,flush=True, end=" ")
even=even+2
elif eocr=="o":
print(odd,flush=True, end=" ")
odd=odd+2
elif eocr=="c":
print(consec,flush=True, end=" ")
consec=consec+1
elif eocr=="r":
print(random.randint(int(randhighcap),int(randlowcap)),flush=True, end=" ")
else:
print("Unrecognized. Type either e, o or c")
if againagain<=1:
print(" n")
print("Do you want to print even numbers, odd numbers n, consecutive or random numbers? ")
eocr=input("e/o/c/r ")
time.sleep(1)
times=input("And how many times should it do this? ")
time.sleep(1)
speed=input("Okay, And What speed should it print the numbers, nAnswer in seconds. (0.02 Is Default) ")
time.sleep(1)
againagain = int(times)
if eocr=="e":
print("Alright, The final number will be",str(againagain * 2))
varcontinue=input("Is this okay? (y/n) ")
if varcontinue=="y":
print(" ")
massprint()
time.sleep(1)
print("Done!")
else:
exit()
elif eocr=="o":
print("Alright, The final number will be",str(againagain * 2+1))
varcontinue=input("Is this okay? (y/n) ")
if varcontinue=="y":
print(" ")
massprint()
time.sleep(1)
print("Done!")
else:
exit()
elif eocr=="c":
print("Alright, The final number will be",str(againagain))
varcontinue=input("Is this okay? (y/n) ")
if varcontinue=="y":
print(" ")
massprint()
time.sleep(1)
print("Done!")
elif eocr=="r":
time.sleep(1)
randhighcap=input("And what do you want the highest random number to be? ")
time.sleep(1)
randlowcap=input("And what do you want the lowest random number to be? ")
time.sleep(1)
print("Alright, It will print",str(againagain),"random numbers nWith a high cap of",randhighcap,"nAnd a low cap of",randlowcap)
varcontinue=input("Is this okay? (y/n) ")
if varcontinue=="y":
print(" ")
massprint()
time.sleep(1)
print("Done!")
else:
exit()
else:
exit()

As"Johnny Mopp";说,

翻转参数,使较低的数字先出现:print(random.randint(int(randlowcap(,int(randhighcap((,flush=True,end="(。randint((返回一个随机整数N,使得<=N<=b.randrange(a,b+1(的别名。

说实话,真不敢相信我没有想到这一点。

相关内容

最新更新