d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Python Help.
Add Reply New Topic New Poll
Member
Posts: 263
Joined: Mar 13 2018
Gold: 0.00
Oct 25 2018 09:41am
Hello!

Was hoping someone could help me here. I need to make a program that asks a user to ask for a range (min & max int) then guess between those range. I need to ask the user for a number (as a function used by 1 for an input, and in the main for getting a guess from the user that returns an int. Determines if that guess between the range is too low or too high. I also need 3 working functions besides the main one.

This is my "rough draft" that I have so far..


import random

def main():
print("")
print("Hello! Please give two numbers, a min and a max") # ask user for a min and max. then guess the number between
MinNumber = int(input("Select a Min: "))
MaxNumber = int(input("Select a Max: "))
if MinNumber > MaxNumber:
print("Please enter an integer that the maximum is large then the minimum")
return main()
else:
guess()

def guess():
ran = int(input("What is your guess: "))
guess(ran)


def ran():
guess = random.randint(MinNumber, MaxNumber)
print(guess) # Need to add function where if input =/ guess then ask to guess again
while:
if ran > guess:
print("Too high, try again") # make def to check if it's too high or too low
return guess()

elif ran < guess:
print("Too Low, try again")
return guess()
print("Excellent! You guessed the correct number!")

main()

This post was edited by RaiseIt on Oct 25 2018 09:49am
Member
Posts: 263
Joined: Mar 13 2018
Gold: 0.00
Oct 25 2018 05:26pm
I have a lil more updated code, been working on it for a few hours.

Still struggling making the functions work with each other though

Member
Posts: 16,662
Joined: Nov 24 2007
Gold: 15,245.00
Trader: Trusted
Oct 27 2018 10:03am
I would try something like this :

from random import randint

def play(min, max) :
(tab) unknown = randint(min, max)
(tab) answer = min - 1
(tab) while answer != unknown :
(tab) (tab) answer = int(input("Your guess ?\n"))
(tab) (tab) if answer < unknown :
(tab) (tab) (tab) print("Too low...\n")
(tab) (tab) if answer > unknown :
(tab) (tab) (tab) print("Too high...\n")
(tab) return "YOU WIN !!!"

Notice that the initial range is given as arguments (min, max) of the function 'play'.

If you need it done in another way, just let me know.
Go Back To Homework Help Topic List
Add Reply New Topic New Poll