#๐Ÿ”’ Don't understand where to start with this "fruit guessing game" with initially given template

76 messages ยท Page 1 of 1 (latest)

strong currentBOT
#

@remote girder

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quick agate
#

!paste

strong currentBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

remote girder
#

from random import choice

#In the game you have 3 attempts to guess the correct fruit
#Info on what the function does (e.g. input, output)
def guess_fruit(random_fruit):
pass #Here you need to code
return -1 ## <-- why and what does that -1 do?

#main

fruits= ['apple','banana','orange','pear','plums','kiwi','strawberry', #list of possible fruit
'pineapple','melon','paprika','mango']
random_fruit= choice(fruits)
fruit= guess_fruit(random_fruit)

if fruit != -1:
print("you guessed correctly")
else:
print("you guessed wrong")

strong currentBOT
#

Hey @remote girder!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
quick agate
#
from random import choice

#In the game you have 3 attempts to guess the correct fruit
#Info on what the function does (e.g. input, output)
def guessfruit(randomfruit):
  pass        #Here you need to code
  return -1 ## <-- why and what does that -1 do?


#__main

fruits= ['apple','banana','orange','pear','plums','kiwi','strawberry',  #list of possible fruit
          'pineapple','melon','paprika','mango']
random_fruit= choice(fruits)
fruit= guess_fruit(random_fruit)

if fruit != -1:
  print("you guessed correctly")
else:
  print("you guessed wrong")```
#

whats the problem ?

#

do you know what input() is ?

remote girder
#

yeah I know that but am not sure where you need to put it in this instance ?

quick agate
#

now youll add code in guessfruit() only

#

youll need an input so user can guess

#

and add code so it has 3 tries only u can do that with a for loop for i in range(3) + if else

remote girder
#

right! ok but what does that -1 do exactly?

quick agate
#

it returns -1

#

and that value get stored at fruit = guess_fruit() so fruit if user didnt guess will have value -1

#

wait

remote girder
#

so it's giving the correct answer the value of -1?

quick agate
#

no any value other than -1 will give correct

remote girder
#

ok I think I get it is it ok if I come back with an update and or I get stuck again?

quick agate
#

sure

remote girder
#

ok so the guess_fruit function should look like this then ?

#

def guess_fruit(random_fruit):
attempt = input("What is your guess? ")
for i in range(3):
return -1

#

'''def guess_fruit(random_fruit):
attempt = input("What is your guess? ")
for i in range(3):
return -1'''

quick agate
#

`

#

not '

#

under "ESC" that key

remote girder
#
  attempt = input("What is your guess? ")
  for i in range(3):
    return -1```
quick agate
#

that loop will run 1 time

#

you didnt make the logic of guessing if attempt == random_fruit

remote girder
#

right sure but now it always says correct ? def guess_fruit(random_fruit): attempt = input("What is your guess? ") if attempt == random_fruit: for i in range(3): return -1

strong currentBOT
#

Hey @remote girder!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
quick agate
#
  • the attempt
remote girder
#

right ok so like this then for i in range(3): attempt = input("What is your guess ") if attempt == random_fruit: return -1

strong currentBOT
#

Hey @remote girder!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
quick agate
#

that will give u wrong

#

even tho you correct

remote girder
#

ok so what would the next step be?

quick agate
#

you are done you just need to return smth else other than -1

#

and then if you didnt guess it right return -1

remote girder
#

so I need an else there under that that returns a diffrent value?

quick agate
#

yes

remote girder
#

ok awesome thank you ๐Ÿ˜‰ it seems to work perfectly now

quick agate
#

show me code lemme see the final code

remote girder
#

sure give me a sec

#

#In the game you have 3 attempts to guess the correct fruit
#Info on what the function does (e.g. input, output)
def guess_fruit(random_fruit):
    for i in range(3):
      attempt = input("What is your guess ")
      if attempt == random_fruit:
        return -1 
      else:
        return 1

#__main__

fruits= ['apple','banana','orange','pear','plums','kiwi','strawberry',  #list of possible fruit
          'pineapple','melon','paprika','mango']
random_fruit= choice(fruits)
fruit= guess_fruit(random_fruit)

if fruit != -1:
  print("you guessed correctly")
else:
  print("you guessed wrong") ```
quick agate
#

you did the opposite

#

if user guesses correctly then he loses

remote girder
#

oh!

quick agate
#

add this to the print print(f"you guessed wrong the fruit was {random_fruit)")

remote girder
#

ok so like this? if fruit != -1:
print("you guessed correctly")
else:
print(f"you guessed wrong the fruit was {random_fruit}")

quick agate
#

ye

remote girder
#

ok but how do I implement 3 attempts?

quick agate
#

you already did

#

wait

#

ah because

#

you make if else and if the statment is wrong it will go to else therefore it will return so it will stop for loop

#

add return -1 outside of the loop

#

and remove the else

remote girder
#

that gives me an indent error :/

quick agate
#

show

remote girder
#

#In the game you have 3 attempts to guess the correct fruit
#Info on what the function does (e.g. input, output)
def guess_fruit(random_fruit):
    for i in range(3):
      attempt = input("What is your guess ")
      if attempt == random_fruit:
  return -1
      

#__main__

fruits= ['apple','banana','orange','pear','plums','kiwi','strawberry',  #list of possible fruit
          'pineapple','melon','paprika','mango']
random_fruit= choice(fruits)
fruit= guess_fruit(random_fruit)

if fruit != -1:
  print("you guessed correctly")
else:
  print(f"you guessed wrong the fruit was {random_fruit}")```
quick agate
#

you need to return 1 or smth inside if statement

#

if attempt == random_fruit:

remote girder
#

ok there it goes it's just colab not updating the cell correctly

quick agate
#

wdym

remote girder
#

it was saying it was expecting an indent but not anymore

quick agate
#

you cant just add a if statement: without smth inside it

if  a == 1:
  print("")```
remote girder
#

no I know it was the return -1 outside it was complaining about

#

but seems to work now

quick agate
#

yea

remote girder
#

#In the game you have 3 attempts to guess the correct fruit
#Info on what the function does (e.g. input, output)
def guess_fruit(random_fruit):
    for i in range(3):
      attempt = input("What is your guess ")
      if attempt == random_fruit:
        return 1
    return -1
      

#__main__

fruits= ['apple','banana','orange','pear','plums','kiwi','strawberry',  #list of possible fruit
          'pineapple','melon','paprika','mango']
random_fruit= choice(fruits)
fruit= guess_fruit(random_fruit)

if fruit != -1:
  print("you guessed correctly")
else:
  print(f"you guessed wrong the fruit was {random_fruit}")```
quick agate
#

good

strong currentBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.