vendredi 18 décembre 2020

Number printer, Random integer not working

Alright, So I'm trying to create a program on repl.it that prints either even, odd, consecutive or random numbers In which you can decide the time it takes, The amount to print and (for random) the highest and lowest number.

However, whenever I select random and try to run it. This pops up

  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)

Here's the link to the repl project so you can see the code. (Or alternatively the code is below.)

https://repl.it/@MichaelGordon1/OddEvenConsecutive-Number-printer#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()



Aucun commentaire:

Enregistrer un commentaire