#๐Ÿ”’ Homework help: Try except blocks not working

1069 messages ยท Page 2 of 2 (latest)

alpine oasis
#

The guessing counter

austere flume
#

Stop it

alpine oasis
#

Oh shit

austere flume
#

the assignment is done

#

No no

#

You're okay

#

The assignment is done

alpine oasis
#

Ah ok

austere flume
#

I've got my answer

#

I'm okay to see other answers now that I've made my own

alpine oasis
#
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

austere flume
#

Dictionary seems like it made this harder

#

But I'm following the logic mostly

alpine oasis
#

Uh no..? I think with dictionary it's easier

cobalt panther
#

when is the answer invalid?

austere flume
#

There are if statements handling if the answer is invalid

cobalt panther
#

yk about recursions?

austere flume
#

I know the word recursion

cobalt panther
#

how much yk about it

austere flume
#

But not coding wise

austere flume
#

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

cobalt panther
#
# 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!')
austere flume
#

Can you explain what you're doing with the guessing lab variable?

#

Like is it an index?

cobalt panther
#

its the key

cobalt panther
austere flume
#

So....

cobalt panther
#

assuming u know how dictionary works

austere flume
#
# 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

austere flume
cobalt panther
#
return func()
return None
austere flume
#

Huh

#

Okay

#

IT FUCKING WOOOOORRRRKKKKKSSSS

#

I have a good project now

austere flume
#

Google fucking sucks dude

#

What is the point of returning none though?

cobalt panther
austere flume
#

Hm

#

Okay

cobalt panther
#

we also do it to stop recursion and end the function earlier

#

some bozos do sys.exit ig

austere flume
#

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?
austere flume
#

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

vagrant gustBOT
#
Python help channel closed with !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.