#๐ Homework help: Try except blocks not working
1069 messages ยท Page 2 of 2 (latest)
Stop it
Oh shit
Ah ok
name = 'hello'
guess = {index: letter for index, letter in enumerate(name)}
guessed = {index: '*' for index in guess.keys()}
while any(i == '*' for i in guessed.values()):
inp = input('Letter: ')
try ord(inp):
if ord(inp) in range(97,122):
for index, letter in guess.items():
if inp == letter:
guessed[index] = inp
print(''.join(guessed.values()))
else:
print('Enter Valid')
except:
print('Enter letter and 1 digit')
With dictionary it's really easy
You get 2 values to put
Uh no..? I think with dictionary it's easier
when is the answer invalid?
If you read through the code you'll see a couple scenarios where you can input something for ans
There are if statements handling if the answer is invalid
yk about recursions?
how much yk about it
But not coding wise
Recursion is embedding something inside itself
So a fractal is a kind of recursion, or if I had a little mini me that had everything I do that mini me would therefore also have a mini me
And so on
# i prolly wouldn't make secname an argument if its not neeeded!!
guessing_lab = {"Name": guessname, "Number": guessnum}
def guessing_games():
game_type = input('Awesome! I like guessing games. Wanna guess a Name or a Number?')
guessing_lab[game_type](secname)
def ask():
response = input('Wanna play a game? Y/N')
if not response or response not in "YN":
print('Try a capital! "Y" or "N" remember?')
elif response == "Y": guessing_games()
elif response == "N": print('Then why did you run this function? SCRAM!')
Real quick
Can you explain what you're doing with the guessing lab variable?
Like is it an index?
its the key
u could also do
x = print
# and then
x("hi its me")
WOAH, okay hold on.
So....
so basically
w_map = {"foo": print}
w_map["foo"]("hi its me")
assuming u know how dictionary works
# So I can do this?
def anscheck(ans,ans1,ans2)
if ans!=any([ans1,ans2])
print('ERROR')
ans=input('Wanna play a Guessing Game? Y/N')
anscheck(ans,Y,N)
elif ans==Y
ans=input('Great! Guessing games are my favorite! Name or Number?')
anscheck(ans,Name,Number)
elif ans==Name
guessname(secname)```
I'm hung up on short hands for functions
So basically condensing repetitive functions into just one name
I know I'm taking the wrong thing from your example
But I'm sorry I thought it was so cool
What I wanted to do was make the function go BACK to the question if the answer is invalid
return func()
return None
Thank you for finally teaching me how the return function actually works
Google fucking sucks dude
What is the point of returning none though?
a function by default return None
we also do it to stop recursion and end the function earlier
some bozos do sys.exit ig
So could I do...
# Imagine my whole guessing name function is here except the you win part
if tries>=10
return print('You win!')
``` Or would this not print?
i don't see no print()
How about that?
If you still wanna help
I have a lab to do, which is a much smaller and more focused version of this
but otherwise I've had my questions answered
I am extremely thankful for this.
And for everyone who helped
And I guess I'll be talking to y'all later, or that's the hope anyways
Cheerio.
!close
This help channel has been closed. 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.