-1

I'm making a guessing game where I guess words. Is it possible to make it without the random module? I got to here:

print("What`s your name?")
name = input()
print("Hello, %s! this is a guessing game." %name)
print("If you want to start hit ENTER, if not you can exit")

input()

print("Okay, so you want to continue! Nice lets start")
print("What animal lives in Africa and has a long neck")

animal = "giraffe"

while animal != "giraffe":
    print("Wrong answer! Try again.")

Basically, I got to an infinitive loop and I don't know how to make people try again. Also for every person that asked "why don't you want to use the random module", well I'm trying to learn do I learn when I make it easier for myself? I need to solve problems and this is the problem I wanted to solve.

Ziolekx
  • 1
  • 1
  • 4
    You have not used an input statement, for the answer. – PCM Sep 06 '21 at 14:45
  • 1
    If you need something random, then random module is a way to go. Why don't you want to use it? Standard library exists for the sole reason of being available whenever you need it – h4z3 Sep 06 '21 at 14:50
  • Can you please clarify *why* you don't want to use the ``random`` module so that it's clear what else people can/cannot use? For example, is using Unix ``/dev/random`` allowed? Is using a custom PRNG allowed? – MisterMiyagi Sep 06 '21 at 14:53
  • Or for that matter, how randomness is relevant in this case at all? The code has no choice at all, so there is nothing to randomise. – MisterMiyagi Sep 06 '21 at 14:56
  • For the second part see [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response). – martineau Sep 06 '21 at 15:08
  • What does this have anything to do with the random module to begin with? You haven't gotten anywhere close to needing it yet. – Mad Physicist Sep 06 '21 at 15:13
  • I checked about what I wanted to do on the internet before creating this post. There I saw people using the random module for problems related to mine. That's why I created this post so I could ask about how do I fix the code to make it work without this module if it were needed. – Ziolekx Sep 06 '21 at 15:18

3 Answers3

1

Try:

guess = input("What animal lives in Africa and has a long neck?")

while guess!="giraffe":
    guess = input("Wrong answer! Try again:")
not_speshal
  • 22,093
  • 2
  • 15
  • 30
1

this could work @Ziolekx ?

#! /usr/bin/env python3


print("What`s your name?")
name = input()
print("Hello, %s! this is a guessing game." %name)
print("If you want to start hit ENTER, if not you can exit")

input()

print("Okay, so you want to continue! Nice lets start")
print("What animal lives in Africa and has a long neck")

animal = ''

while animal != "giraffe":
    animal = input('Enter your guess: ')
    if(animal == 'giraffe'):
        print('You win!')
    else:
        print("Wrong answer! Try again.")
  • a nice addition to your script would be to lowercase the input and then compare, in case someone added "Giraffe" for example
billybadass
  • 278
  • 2
  • 9
0

you can take input form the user inside your for loop. And also you are making wrong comparison.

correct code:

while name!= animal:
    print("Wrong answer! Try again.")
    name = input('Input Answer again: ')