0

I have been trying to figure out how to round off whole numbers in python for a while now and I can't seem to find a way to do it.

if attempt == 5:
  z = input("Do you want a hint? ")
  if z == ("Yes") or ("yes"):
    print("The number is around", a / 10 , round(a),a * 10)
    print(a)
  failedAttempt -= 1

I know it is not much to go on. I am trying to round off a number randomly chosen from random.randint(1, 100). As you can see I am trying to divide the number by 10 and later round it if since pythons "round()" future only seems to accept numbers with decimals, I later multiply it with 10 so I can get the rounded number. The output will either be "None" or (let's say the number is 26) "The number is around 2.6 26 260"

I fixed the problem by switching out print("The number is around", a / 10 , round(a),a * 10) to print("The number is around", round(X / 10) * 10). So the final thing now looks like this. (I added some things)

  if attempt == 5:
while hint == False:
  z = input("Do you want a hint? ")
  if z.lower() in ("yes"):
    print("The number is around", round(X / 10) * 10) 
    hint = True
  elif z.lower() in ("no"):
    hint = True
    continue
  else:
    print("Invalid input, Yes or No?")
    attempt -= 1
    hint = False
    print()
Neo
  • 1
  • 4

0 Answers0