Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
repeating a user_input
#9
okay, you're right, i did the following and it worked:

import random

RNumber = random.randint(1,10)

user_input = int(input("please guess a number between 0 and 10: \n"))

while user_input != RNumber:
    if user_input > RNumber:
        user_input = int(input("choose a lower number: \n"))
    elif user_input < RNumber:
        user_input = int(input("choose a higher number: \n"))

print("the number you chose is correct (", RNumber, ")")
is this correct to do ? (i know it gets the job done, but is it correct to implement it like this ?)
ibreeden likes this post
Reply


Messages In This Thread
repeating a user_input - by astral_travel - Oct-25-2022, 03:49 PM
RE: repeating a user_input - by rob101 - Oct-25-2022, 03:55 PM
RE: repeating a user_input - by astral_travel - Oct-25-2022, 04:25 PM
RE: repeating a user_input - by deanhystad - Oct-25-2022, 04:25 PM
RE: repeating a user_input - by astral_travel - Oct-25-2022, 05:23 PM
RE: repeating a user_input - by astral_travel - Oct-25-2022, 04:30 PM
RE: repeating a user_input - by rob101 - Oct-25-2022, 04:40 PM
RE: repeating a user_input - by astral_travel - Oct-25-2022, 04:41 PM
RE: repeating a user_input - by rob101 - Oct-25-2022, 04:54 PM
RE: repeating a user_input - by astral_travel - Oct-25-2022, 05:05 PM
RE: repeating a user_input - by rob101 - Oct-25-2022, 05:10 PM
RE: repeating a user_input - by deanhystad - Oct-25-2022, 05:11 PM
RE: repeating a user_input - by rob101 - Oct-25-2022, 05:17 PM
RE: repeating a user_input - by deanhystad - Oct-25-2022, 09:25 PM
RE: repeating a user_input - by rob101 - Oct-26-2022, 07:55 AM
RE: repeating a user_input - by perfringo - Oct-26-2022, 08:41 AM
RE: repeating a user_input - by Pedroski55 - Oct-26-2022, 09:17 AM
RE: repeating a user_input - by astral_travel - Oct-26-2022, 04:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 790 Dec-12-2023, 09:09 AM
Last Post: buran
  if else repeating Frankduc 12 2,655 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  factorial, repeating Aldiyar 4 2,865 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Repeating equations Tbot100 2 3,322 May-29-2019, 02:38 AM
Last Post: heiner55
  repeating for loop Kaldesyvon 5 3,917 Dec-06-2018, 08:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020