How to write a python program to guess a number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write a python program to guess a number

Guessing a random number between 1 9

11th Apr 2020, 1:48 PM
Ogunniyi Jesutofunmi John
Ogunniyi Jesutofunmi John - avatar
3 Answers
+ 8
Hints: 1. Store input in a variable 2. make a random guess between 1-9 3. Compare your guess with input. 3.1 if input larger than guess reduce the value of your variable by a fixed(variable?) amount. 3.2 otherwise try to do inverse by increasing it. 4. (Write step 4)
11th Apr 2020, 5:38 PM
Lord Krishna
Lord Krishna - avatar
+ 6
It would be great if you try it yourself first and link your code from playground in your post here.
11th Apr 2020, 2:10 PM
Lothar
Lothar - avatar
+ 3
import random difval=random.randrange(10) print(difval ) Just import random module then use its randrange function to sepicify it's range. Each time when u run thies code it will generate a different number
12th Apr 2020, 6:29 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar